Skip to content

Commit f165b37

Browse files
Pavel Tatashintorvalds
Pavel Tatashin
authored andcommitted
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 __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]>
1 parent 078eb6a commit f165b37

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

include/linux/mm.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,9 @@ extern int page_to_nid(const struct page *page);
903903
#else
904904
static inline int page_to_nid(const struct page *page)
905905
{
906-
return (page->flags >> NODES_PGSHIFT) & NODES_MASK;
906+
struct page *p = (struct page *)page;
907+
908+
return (PF_POISONED_CHECK(p)->flags >> NODES_PGSHIFT) & NODES_MASK;
907909
}
908910
#endif
909911

include/linux/page-flags.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,18 @@ static __always_inline int PageCompound(struct page *page)
156156
return test_bit(PG_head, &page->flags) || PageTail(page);
157157
}
158158

159+
#define PAGE_POISON_PATTERN -1l
160+
static inline int PagePoisoned(const struct page *page)
161+
{
162+
return page->flags == PAGE_POISON_PATTERN;
163+
}
164+
159165
/*
160166
* Page flags policies wrt compound pages
161167
*
168+
* PF_POISONED_CHECK
169+
* check if this struct page poisoned/uninitialized
170+
*
162171
* PF_ANY:
163172
* the page flag is relevant for small, head and tail pages.
164173
*
@@ -176,17 +185,20 @@ static __always_inline int PageCompound(struct page *page)
176185
* PF_NO_COMPOUND:
177186
* the page flag is not relevant for compound pages.
178187
*/
179-
#define PF_ANY(page, enforce) page
180-
#define PF_HEAD(page, enforce) compound_head(page)
188+
#define PF_POISONED_CHECK(page) ({ \
189+
VM_BUG_ON_PGFLAGS(PagePoisoned(page), page); \
190+
page; })
191+
#define PF_ANY(page, enforce) PF_POISONED_CHECK(page)
192+
#define PF_HEAD(page, enforce) PF_POISONED_CHECK(compound_head(page))
181193
#define PF_ONLY_HEAD(page, enforce) ({ \
182194
VM_BUG_ON_PGFLAGS(PageTail(page), page); \
183-
page;})
195+
PF_POISONED_CHECK(page); })
184196
#define PF_NO_TAIL(page, enforce) ({ \
185197
VM_BUG_ON_PGFLAGS(enforce && PageTail(page), page); \
186-
compound_head(page);})
198+
PF_POISONED_CHECK(compound_head(page)); })
187199
#define PF_NO_COMPOUND(page, enforce) ({ \
188200
VM_BUG_ON_PGFLAGS(enforce && PageCompound(page), page); \
189-
page;})
201+
PF_POISONED_CHECK(page); })
190202

191203
/*
192204
* Macros to create function definitions for page flags

mm/memblock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ void * __init memblock_virt_alloc_try_nid_raw(
13451345
min_addr, max_addr, nid);
13461346
#ifdef CONFIG_DEBUG_VM
13471347
if (ptr && size > 0)
1348-
memset(ptr, 0xff, size);
1348+
memset(ptr, PAGE_POISON_PATTERN, size);
13491349
#endif
13501350
return ptr;
13511351
}

0 commit comments

Comments
 (0)