Commit f165b378 authored by Pavel Tatashin's avatar Pavel Tatashin Committed by Linus Torvalds

mm: uninitialized struct page poisoning sanity checking

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

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

[ v4]
Link: default avatarPavel Tatashin <>
Reviewed-by: default avatarIngo Molnar <>
Acked-by: default avatarMichal Hocko <>
Cc: Baoquan He <>
Cc: Bharata B Rao <>
Cc: Daniel Jordan <>
Cc: Dan Williams <>
Cc: Greg Kroah-Hartman <>
Cc: "H. Peter Anvin" <>
Cc: Kirill A. Shutemov <>
Cc: Mel Gorman <>
Cc: Steven Sistare <>
Cc: Thomas Gleixner <>
Cc: Vlastimil Babka <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 078eb6aa
......@@ -903,7 +903,9 @@ extern int page_to_nid(const struct page *page);
static inline int page_to_nid(const struct page *page)
return (page->flags >> NODES_PGSHIFT) & NODES_MASK;
struct page *p = (struct page *)page;
......@@ -156,9 +156,18 @@ static __always_inline int PageCompound(struct page *page)
return test_bit(PG_head, &page->flags) || PageTail(page);
static inline int PagePoisoned(const struct page *page)
return page->flags == PAGE_POISON_PATTERN;
* Page flags policies wrt compound pages
* check if this struct page poisoned/uninitialized
* the page flag is relevant for small, head and tail pages.
......@@ -176,17 +185,20 @@ static __always_inline int PageCompound(struct page *page)
* 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); \
#define PF_NO_TAIL(page, enforce) ({ \
VM_BUG_ON_PGFLAGS(enforce && PageTail(page), page); \
PF_POISONED_CHECK(compound_head(page)); })
#define PF_NO_COMPOUND(page, enforce) ({ \
VM_BUG_ON_PGFLAGS(enforce && PageCompound(page), page); \
* Macros to create function definitions for page flags
......@@ -1345,7 +1345,7 @@ void * __init memblock_virt_alloc_try_nid_raw(
min_addr, max_addr, nid);
if (ptr && size > 0)
memset(ptr, 0xff, size);
memset(ptr, PAGE_POISON_PATTERN, size);
return ptr;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment