]> Git Repo - linux.git/commitdiff
mm: uninitialized struct page poisoning sanity checking
authorPavel Tatashin <[email protected]>
Thu, 5 Apr 2018 23:22:47 +0000 (16:22 -0700)
committerLinus Torvalds <[email protected]>
Fri, 6 Apr 2018 04:36:25 +0000 (21:36 -0700)
During boot we poison struct page memory in order to ensure that no one
is accessing this memory until the struct pages are initialized in
__init_single_page().

This patch adds more scrutiny to this checking by making sure that flags
do not equal the poison pattern when they are accessed.  The pattern is
all ones.

Since node id is also stored in struct page, and may be accessed quite
early, we add this enforcement into page_to_nid() function as well.
Note, this is applicable only when NODE_NOT_IN_PAGE_FLAGS=n

[[email protected]: v4]
Link: http://lkml.kernel.org/r/[email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Pavel Tatashin <[email protected]>
Reviewed-by: Ingo Molnar <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Cc: Baoquan He <[email protected]>
Cc: Bharata B Rao <[email protected]>
Cc: Daniel Jordan <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Kirill A. Shutemov <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Steven Sistare <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
include/linux/mm.h
include/linux/page-flags.h
mm/memblock.c

index f945dff34925b3d4b67fa9abb911cbd62aaac091..2e40a44a1fae29fd055b3f917e6f35893889c9af 100644 (file)
@@ -903,7 +903,9 @@ extern int page_to_nid(const struct page *page);
 #else
 static inline int page_to_nid(const struct page *page)
 {
-       return (page->flags >> NODES_PGSHIFT) & NODES_MASK;
+       struct page *p = (struct page *)page;
+
+       return (PF_POISONED_CHECK(p)->flags >> NODES_PGSHIFT) & NODES_MASK;
 }
 #endif
 
index 50c2b8786831d839067c879ad95114cc4cabd161..e34a27727b9a740c8be71acae0e968211c46f93d 100644 (file)
@@ -156,9 +156,18 @@ static __always_inline int PageCompound(struct page *page)
        return test_bit(PG_head, &page->flags) || PageTail(page);
 }
 
+#define        PAGE_POISON_PATTERN     -1l
+static inline int PagePoisoned(const struct page *page)
+{
+       return page->flags == PAGE_POISON_PATTERN;
+}
+
 /*
  * Page flags policies wrt compound pages
  *
+ * PF_POISONED_CHECK
+ *     check if this struct page poisoned/uninitialized
+ *
  * PF_ANY:
  *     the page flag is relevant for small, head and tail pages.
  *
@@ -176,17 +185,20 @@ static __always_inline int PageCompound(struct page *page)
  * PF_NO_COMPOUND:
  *     the page flag is not relevant for compound pages.
  */
-#define PF_ANY(page, enforce)  page
-#define PF_HEAD(page, enforce) compound_head(page)
+#define PF_POISONED_CHECK(page) ({                                     \
+               VM_BUG_ON_PGFLAGS(PagePoisoned(page), page);            \
+               page; })
+#define PF_ANY(page, enforce)  PF_POISONED_CHECK(page)
+#define PF_HEAD(page, enforce) PF_POISONED_CHECK(compound_head(page))
 #define PF_ONLY_HEAD(page, enforce) ({                                 \
                VM_BUG_ON_PGFLAGS(PageTail(page), page);                \
-               page;})
+               PF_POISONED_CHECK(page); })
 #define PF_NO_TAIL(page, enforce) ({                                   \
                VM_BUG_ON_PGFLAGS(enforce && PageTail(page), page);     \
-               compound_head(page);})
+               PF_POISONED_CHECK(compound_head(page)); })
 #define PF_NO_COMPOUND(page, enforce) ({                               \
                VM_BUG_ON_PGFLAGS(enforce && PageCompound(page), page); \
-               page;})
+               PF_POISONED_CHECK(page); })
 
 /*
  * Macros to create function definitions for page flags
index f7f76513a0c5ea8154e45a49b896b6fd4affe1f8..c2fed302c2f82b183648def0995fb1b5dc08a8b3 100644 (file)
@@ -1345,7 +1345,7 @@ void * __init memblock_virt_alloc_try_nid_raw(
                                           min_addr, max_addr, nid);
 #ifdef CONFIG_DEBUG_VM
        if (ptr && size > 0)
-               memset(ptr, 0xff, size);
+               memset(ptr, PAGE_POISON_PATTERN, size);
 #endif
        return ptr;
 }
This page took 0.053375 seconds and 4 git commands to generate.