Skip to content

Commit 9df65f5

Browse files
Sergei Trofimovichtorvalds
authored andcommitted
mm: page_alloc: ignore init_on_free=1 for debug_pagealloc=1
On !ARCH_SUPPORTS_DEBUG_PAGEALLOC (like ia64) debug_pagealloc=1 implies page_poison=on: if (page_poisoning_enabled() || (!IS_ENABLED(CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC) && debug_pagealloc_enabled())) static_branch_enable(&_page_poisoning_enabled); page_poison=on needs to override init_on_free=1. Before the change it did not work as expected for the following case: - have PAGE_POISONING=y - have page_poison unset - have !ARCH_SUPPORTS_DEBUG_PAGEALLOC arch (like ia64) - have init_on_free=1 - have debug_pagealloc=1 That way we get both keys enabled: - static_branch_enable(&init_on_free); - static_branch_enable(&_page_poisoning_enabled); which leads to poisoned pages returned for __GFP_ZERO pages. After the change we execute only: - static_branch_enable(&_page_poisoning_enabled); and ignore init_on_free=1. Link: https://lkml.kernel.org/r/20210329222555.3077928-1-slyfox@gentoo.org Link: https://lkml.org/lkml/2021/3/26/443 Fixes: 8db26a3 ("mm, page_poison: use static key more efficiently") Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org> Acked-by: Vlastimil Babka <vbabka@suse.cz> Reviewed-by: David Hildenbrand <david@redhat.com> Cc: Andrey Konovalov <andreyknvl@gmail.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent be5dba2 commit 9df65f5

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

mm/page_alloc.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -786,32 +786,36 @@ static inline void clear_page_guard(struct zone *zone, struct page *page,
786786
*/
787787
void init_mem_debugging_and_hardening(void)
788788
{
789+
bool page_poisoning_requested = false;
790+
791+
#ifdef CONFIG_PAGE_POISONING
792+
/*
793+
* Page poisoning is debug page alloc for some arches. If
794+
* either of those options are enabled, enable poisoning.
795+
*/
796+
if (page_poisoning_enabled() ||
797+
(!IS_ENABLED(CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC) &&
798+
debug_pagealloc_enabled())) {
799+
static_branch_enable(&_page_poisoning_enabled);
800+
page_poisoning_requested = true;
801+
}
802+
#endif
803+
789804
if (_init_on_alloc_enabled_early) {
790-
if (page_poisoning_enabled())
805+
if (page_poisoning_requested)
791806
pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
792807
"will take precedence over init_on_alloc\n");
793808
else
794809
static_branch_enable(&init_on_alloc);
795810
}
796811
if (_init_on_free_enabled_early) {
797-
if (page_poisoning_enabled())
812+
if (page_poisoning_requested)
798813
pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, "
799814
"will take precedence over init_on_free\n");
800815
else
801816
static_branch_enable(&init_on_free);
802817
}
803818

804-
#ifdef CONFIG_PAGE_POISONING
805-
/*
806-
* Page poisoning is debug page alloc for some arches. If
807-
* either of those options are enabled, enable poisoning.
808-
*/
809-
if (page_poisoning_enabled() ||
810-
(!IS_ENABLED(CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC) &&
811-
debug_pagealloc_enabled()))
812-
static_branch_enable(&_page_poisoning_enabled);
813-
#endif
814-
815819
#ifdef CONFIG_DEBUG_PAGEALLOC
816820
if (!debug_pagealloc_enabled())
817821
return;

0 commit comments

Comments
 (0)