diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 91455f0d22c1..6b208b1843bf 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -786,20 +786,7 @@ static inline void clear_page_guard(struct zone *zone, struct page *page, */ void init_mem_debugging_and_hardening(void) { - if (_init_on_alloc_enabled_early) { - if (page_poisoning_enabled()) - pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, " - "will take precedence over init_on_alloc\n"); - else - static_branch_enable(&init_on_alloc); - } - if (_init_on_free_enabled_early) { - if (page_poisoning_enabled()) - pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, " - "will take precedence over init_on_free\n"); - else - static_branch_enable(&init_on_free); - } + bool page_poisoning_requested = false; #ifdef CONFIG_PAGE_POISONING /* @@ -808,10 +795,27 @@ void init_mem_debugging_and_hardening(void) */ if (page_poisoning_enabled() || (!IS_ENABLED(CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC) && - debug_pagealloc_enabled())) + debug_pagealloc_enabled())) { static_branch_enable(&_page_poisoning_enabled); + page_poisoning_requested = true; + } #endif + if (_init_on_alloc_enabled_early) { + if (page_poisoning_requested) + pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, " + "will take precedence over init_on_alloc\n"); + else + static_branch_enable(&init_on_alloc); + } + if (_init_on_free_enabled_early) { + if (page_poisoning_requested) + pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, " + "will take precedence over init_on_free\n"); + else + static_branch_enable(&init_on_free); + } + #ifdef CONFIG_DEBUG_PAGEALLOC if (!debug_pagealloc_enabled()) return;