aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorAndrea Arcangeli <aarcange@redhat.com>2011-03-17 19:16:35 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-03-17 19:31:13 -0400
commitef2b4b95a63a1d23958dcb99eb2c6898eddc87d0 (patch)
tree0a22745dba03926768552aa3006b166995e5342d /include/linux
parent7b7adc4a016a1decb806eb71ecab98721fa7f146 (diff)
mm: PageBuddy and mapcount robustness
Change the _mapcount value indicating PageBuddy from -2 to -128 for more robusteness against page_mapcount() undeflows. Use reset_page_mapcount instead of __ClearPageBuddy in bad_page to ignore the previous retval of PageBuddy(). Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> Reported-by: Hugh Dickins <hughd@google.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/mm.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 679300c050f5..ff83798e1c27 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -402,16 +402,23 @@ static inline void init_page_count(struct page *page)
402/* 402/*
403 * PageBuddy() indicate that the page is free and in the buddy system 403 * PageBuddy() indicate that the page is free and in the buddy system
404 * (see mm/page_alloc.c). 404 * (see mm/page_alloc.c).
405 *
406 * PAGE_BUDDY_MAPCOUNT_VALUE must be <= -2 but better not too close to
407 * -2 so that an underflow of the page_mapcount() won't be mistaken
408 * for a genuine PAGE_BUDDY_MAPCOUNT_VALUE. -128 can be created very
409 * efficiently by most CPU architectures.
405 */ 410 */
411#define PAGE_BUDDY_MAPCOUNT_VALUE (-128)
412
406static inline int PageBuddy(struct page *page) 413static inline int PageBuddy(struct page *page)
407{ 414{
408 return atomic_read(&page->_mapcount) == -2; 415 return atomic_read(&page->_mapcount) == PAGE_BUDDY_MAPCOUNT_VALUE;
409} 416}
410 417
411static inline void __SetPageBuddy(struct page *page) 418static inline void __SetPageBuddy(struct page *page)
412{ 419{
413 VM_BUG_ON(atomic_read(&page->_mapcount) != -1); 420 VM_BUG_ON(atomic_read(&page->_mapcount) != -1);
414 atomic_set(&page->_mapcount, -2); 421 atomic_set(&page->_mapcount, PAGE_BUDDY_MAPCOUNT_VALUE);
415} 422}
416 423
417static inline void __ClearPageBuddy(struct page *page) 424static inline void __ClearPageBuddy(struct page *page)