From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FB9FC433DB for ; Mon, 29 Mar 2021 22:26:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CFE8361976 for ; Mon, 29 Mar 2021 22:26:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CFE8361976 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gentoo.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 528EB6B007D; Mon, 29 Mar 2021 18:26:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D9BD6B007E; Mon, 29 Mar 2021 18:26:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A31C6B0080; Mon, 29 Mar 2021 18:26:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0206.hostedemail.com [216.40.44.206]) by kanga.kvack.org (Postfix) with ESMTP id 1FD2E6B007D for ; Mon, 29 Mar 2021 18:26:13 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D90B42471 for ; Mon, 29 Mar 2021 22:26:12 +0000 (UTC) X-FDA: 77974346184.12.72EE961 Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by imf22.hostedemail.com (Postfix) with ESMTP id AD69FC0001FE for ; Mon, 29 Mar 2021 22:26:09 +0000 (UTC) Received: by sf.home (Postfix, from userid 1000) id E848C5A22061; Mon, 29 Mar 2021 23:26:04 +0100 (BST) From: Sergei Trofimovich To: Vlastimil Babka , Andrew Morton , David Hildenbrand , Andrey Konovalov Cc: linux-kernel@vger.kernel.org, Sergei Trofimovich , stable@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3] mm: page_alloc: ignore init_on_free=1 for debug_pagealloc=1 Date: Mon, 29 Mar 2021 23:25:54 +0100 Message-Id: <20210329222555.3077928-1-slyfox@gentoo.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: 41qhz43xn8i81f81i5xfchcexd7xa3so X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: AD69FC0001FE Received-SPF: none (gentoo.org>: No applicable sender policy available) receiver=imf22; identity=mailfrom; envelope-from=""; helo=smtp.gentoo.org; client-ip=140.211.166.183 X-HE-DKIM-Result: none/none X-HE-Tag: 1617056769-345502 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On !ARCH_SUPPORTS_DEBUG_PAGEALLOC (like ia64) debug_pagealloc=3D1 implies page_poison=3Don: if (page_poisoning_enabled() || (!IS_ENABLED(CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC) && debug_pagealloc_enabled())) static_branch_enable(&_page_poisoning_enabled); page_poison=3Don needs to override init_on_free=3D1. Before the change it did not work as expected for the following case: - have PAGE_POISONING=3Dy - have page_poison unset - have !ARCH_SUPPORTS_DEBUG_PAGEALLOC arch (like ia64) - have init_on_free=3D1 - have debug_pagealloc=3D1 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=3D1. Acked-by: Vlastimil Babka Fixes: 8db26a3d4735 ("mm, page_poison: use static key more efficiently") Cc: CC: Andrew Morton CC: linux-mm@kvack.org CC: David Hildenbrand CC: Andrey Konovalov Link: https://lkml.org/lkml/2021/3/26/443 Signed-off-by: Sergei Trofimovich --- Change since v2: - Added 'Fixes:' and 'CC: stable@' suggested by Vlastimil and David - Renamed local variable to 'page_poisoning_requested' for consistency suggested by David - Simplified initialization of page_poisoning_requested suggested by David - Added 'Acked-by: Vlastimil' mm/page_alloc.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index cfc72873961d..4bb3cdfc47f8 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -764,32 +764,36 @@ static inline void clear_page_guard(struct zone *zo= ne, struct page *page, */ void init_mem_debugging_and_hardening(void) { + bool page_poisoning_requested =3D false; + +#ifdef CONFIG_PAGE_POISONING + /* + * Page poisoning is debug page alloc for some arches. If + * either of those options are enabled, enable poisoning. + */ + if (page_poisoning_enabled() || + (!IS_ENABLED(CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC) && + debug_pagealloc_enabled())) { + static_branch_enable(&_page_poisoning_enabled); + page_poisoning_requested =3D true; + } +#endif + if (_init_on_alloc_enabled_early) { - if (page_poisoning_enabled()) + 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_enabled()) + 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); } =20 -#ifdef CONFIG_PAGE_POISONING - /* - * Page poisoning is debug page alloc for some arches. If - * either of those options are enabled, enable poisoning. - */ - if (page_poisoning_enabled() || - (!IS_ENABLED(CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC) && - debug_pagealloc_enabled())) - static_branch_enable(&_page_poisoning_enabled); -#endif - #ifdef CONFIG_DEBUG_PAGEALLOC if (!debug_pagealloc_enabled()) return; --=20 2.31.1