Skip to content

Commit bd33ef3

Browse files
Vinayak Menontorvalds
authored andcommitted
mm: enable page poisoning early at boot
On SPARSEMEM systems page poisoning is enabled after buddy is up, because of the dependency on page extension init. This causes the pages released by free_all_bootmem not to be poisoned. This either delays or misses the identification of some issues because the pages have to undergo another cycle of alloc-free-alloc for any corruption to be detected. Enable page poisoning early by getting rid of the PAGE_EXT_DEBUG_POISON flag. Since all the free pages will now be poisoned, the flag need not be verified before checking the poison during an alloc. [vinmenon@codeaurora.org: fix Kconfig] Link: http://lkml.kernel.org/r/1490878002-14423-1-git-send-email-vinmenon@codeaurora.org Link: http://lkml.kernel.org/r/1490358246-11001-1-git-send-email-vinmenon@codeaurora.org Signed-off-by: Vinayak Menon <vinmenon@codeaurora.org> Acked-by: Laura Abbott <labbott@redhat.com> Tested-by: Laura Abbott <labbott@redhat.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 2872bb2 commit bd33ef3

5 files changed

Lines changed: 17 additions & 88 deletions

File tree

‎include/linux/mm.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2487,7 +2487,6 @@ extern long copy_huge_page_from_user(struct page *dst_page,
24872487
#endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
24882488

24892489
extern struct page_ext_operations debug_guardpage_ops;
2490-
extern struct page_ext_operations page_poisoning_ops;
24912490

24922491
#ifdef CONFIG_DEBUG_PAGEALLOC
24932492
extern unsigned int _debug_guardpage_minorder;

‎mm/Kconfig.debug‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ config DEBUG_PAGEALLOC_ENABLE_DEFAULT
4242

4343
config PAGE_POISONING
4444
bool "Poison pages after freeing"
45-
select PAGE_EXTENSION
4645
select PAGE_POISONING_NO_SANITY if HIBERNATION
4746
---help---
4847
Fill the pages with poison patterns after free_pages() and verify

‎mm/page_alloc.c‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,10 +1689,10 @@ static inline int check_new_page(struct page *page)
16891689
return 1;
16901690
}
16911691

1692-
static inline bool free_pages_prezeroed(bool poisoned)
1692+
static inline bool free_pages_prezeroed(void)
16931693
{
16941694
return IS_ENABLED(CONFIG_PAGE_POISONING_ZERO) &&
1695-
page_poisoning_enabled() && poisoned;
1695+
page_poisoning_enabled();
16961696
}
16971697

16981698
#ifdef CONFIG_DEBUG_VM
@@ -1746,17 +1746,10 @@ static void prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags
17461746
unsigned int alloc_flags)
17471747
{
17481748
int i;
1749-
bool poisoned = true;
1750-
1751-
for (i = 0; i < (1 << order); i++) {
1752-
struct page *p = page + i;
1753-
if (poisoned)
1754-
poisoned &= page_is_poisoned(p);
1755-
}
17561749

17571750
post_alloc_hook(page, order, gfp_flags);
17581751

1759-
if (!free_pages_prezeroed(poisoned) && (gfp_flags & __GFP_ZERO))
1752+
if (!free_pages_prezeroed() && (gfp_flags & __GFP_ZERO))
17601753
for (i = 0; i < (1 << order); i++)
17611754
clear_highpage(page + i);
17621755

‎mm/page_ext.c‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@
5959

6060
static struct page_ext_operations *page_ext_ops[] = {
6161
&debug_guardpage_ops,
62-
#ifdef CONFIG_PAGE_POISONING
63-
&page_poisoning_ops,
64-
#endif
6562
#ifdef CONFIG_PAGE_OWNER
6663
&page_owner_ops,
6764
#endif
@@ -127,15 +124,12 @@ struct page_ext *lookup_page_ext(struct page *page)
127124
struct page_ext *base;
128125

129126
base = NODE_DATA(page_to_nid(page))->node_page_ext;
130-
#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAGE_POISONING)
127+
#if defined(CONFIG_DEBUG_VM)
131128
/*
132129
* The sanity checks the page allocator does upon freeing a
133130
* page can reach here before the page_ext arrays are
134131
* allocated when feeding a range of pages to the allocator
135132
* for the first time during bootup or memory hotplug.
136-
*
137-
* This check is also necessary for ensuring page poisoning
138-
* works as expected when enabled
139133
*/
140134
if (unlikely(!base))
141135
return NULL;
@@ -204,15 +198,12 @@ struct page_ext *lookup_page_ext(struct page *page)
204198
{
205199
unsigned long pfn = page_to_pfn(page);
206200
struct mem_section *section = __pfn_to_section(pfn);
207-
#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAGE_POISONING)
201+
#if defined(CONFIG_DEBUG_VM)
208202
/*
209203
* The sanity checks the page allocator does upon freeing a
210204
* page can reach here before the page_ext arrays are
211205
* allocated when feeding a range of pages to the allocator
212206
* for the first time during bootup or memory hotplug.
213-
*
214-
* This check is also necessary for ensuring page poisoning
215-
* works as expected when enabled
216207
*/
217208
if (!section->page_ext)
218209
return NULL;

‎mm/page_poison.c‎

Lines changed: 12 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <linux/poison.h>
77
#include <linux/ratelimit.h>
88

9-
static bool __page_poisoning_enabled __read_mostly;
109
static bool want_page_poisoning __read_mostly;
1110

1211
static int early_page_poison_param(char *buf)
@@ -18,75 +17,22 @@ static int early_page_poison_param(char *buf)
1817
early_param("page_poison", early_page_poison_param);
1918

2019
bool page_poisoning_enabled(void)
21-
{
22-
return __page_poisoning_enabled;
23-
}
24-
25-
static bool need_page_poisoning(void)
26-
{
27-
return want_page_poisoning;
28-
}
29-
30-
static void init_page_poisoning(void)
3120
{
3221
/*
33-
* page poisoning is debug page alloc for some arches. If either
34-
* of those options are enabled, enable poisoning
22+
* Assumes that debug_pagealloc_enabled is set before
23+
* free_all_bootmem.
24+
* Page poisoning is debug page alloc for some arches. If
25+
* either of those options are enabled, enable poisoning.
3526
*/
36-
if (!IS_ENABLED(CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC)) {
37-
if (!want_page_poisoning && !debug_pagealloc_enabled())
38-
return;
39-
} else {
40-
if (!want_page_poisoning)
41-
return;
42-
}
43-
44-
__page_poisoning_enabled = true;
45-
}
46-
47-
struct page_ext_operations page_poisoning_ops = {
48-
.need = need_page_poisoning,
49-
.init = init_page_poisoning,
50-
};
51-
52-
static inline void set_page_poison(struct page *page)
53-
{
54-
struct page_ext *page_ext;
55-
56-
page_ext = lookup_page_ext(page);
57-
if (unlikely(!page_ext))
58-
return;
59-
60-
__set_bit(PAGE_EXT_DEBUG_POISON, &page_ext->flags);
61-
}
62-
63-
static inline void clear_page_poison(struct page *page)
64-
{
65-
struct page_ext *page_ext;
66-
67-
page_ext = lookup_page_ext(page);
68-
if (unlikely(!page_ext))
69-
return;
70-
71-
__clear_bit(PAGE_EXT_DEBUG_POISON, &page_ext->flags);
72-
}
73-
74-
bool page_is_poisoned(struct page *page)
75-
{
76-
struct page_ext *page_ext;
77-
78-
page_ext = lookup_page_ext(page);
79-
if (unlikely(!page_ext))
80-
return false;
81-
82-
return test_bit(PAGE_EXT_DEBUG_POISON, &page_ext->flags);
27+
return (want_page_poisoning ||
28+
(!IS_ENABLED(CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC) &&
29+
debug_pagealloc_enabled()));
8330
}
8431

8532
static void poison_page(struct page *page)
8633
{
8734
void *addr = kmap_atomic(page);
8835

89-
set_page_poison(page);
9036
memset(addr, PAGE_POISON, PAGE_SIZE);
9137
kunmap_atomic(addr);
9238
}
@@ -140,12 +86,13 @@ static void unpoison_page(struct page *page)
14086
{
14187
void *addr;
14288

143-
if (!page_is_poisoned(page))
144-
return;
145-
14689
addr = kmap_atomic(page);
90+
/*
91+
* Page poisoning when enabled poisons each and every page
92+
* that is freed to buddy. Thus no extra check is done to
93+
* see if a page was posioned.
94+
*/
14795
check_poison_mem(addr, PAGE_SIZE);
148-
clear_page_poison(page);
14996
kunmap_atomic(addr);
15097
}
15198

0 commit comments

Comments
 (0)