Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2440536pxf; Sat, 27 Mar 2021 11:25:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5Pp6Hvql8tOUrWfZ6cc2SGP/qFzGStyYUwdQ1bEcoAXVEZadqZMQimI7pKaz961ewYC+U X-Received: by 2002:a50:f314:: with SMTP id p20mr21303955edm.236.1616869526552; Sat, 27 Mar 2021 11:25:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616869526; cv=none; d=google.com; s=arc-20160816; b=Hv3qtgIMRzrx0kDmChj6FuruetaH9OFDiLJ1kjhG2L/npPeVf4RQtEvAEZ5ozG1RhX l+XYfgsKtWZp5CTPYkwToqqpzh/1pRlibo08DuyEDmCj/FXMvZnrBkI1Ms50OsYMe3Sv vWsnOb7duuAKsDZ3RabeKITL4vDt/LwrP9qRqC8DgOymDU/W1nZHEoB7RHGNOAyw0eQq MVAbIQpH+RTkG4PohlgswPKGVIWaPtdvL9BayudIGHAQSA+WiUx3MLwJk6R+kTrxvu2V lfIzza+D8oTahUHVhkqLRqKLYEKBlwjRFu32q3vkMJTdb8NjVdFGEKTXdsUvKHMidFWH 7RYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=C6zweukCja3HQ9bwFJg4ZgdkWn/9juFFoKdPmZOdIjE=; b=LXX11hDS7Uw2YporpYBHnjdTP0TesnMJfEtnqj96k4pMMgyUXlhcmLm9Px9b7sOCi5 2zA7ljuzX8wo8D6Kc7QDLtPFKm5XRLfSi7nW+ETH+yHlDm+WacvTOYYMogJgDd+y9c8m 2UoLxEvxHNdkqbQu1QXpjnIxKO6SoYkA0pRUv2nJfFMAwTP3PQq53jabey9bBxbj2oN2 hrYc46YZcMdFdicdRCV8jMC1QftfzW0rGHEwRdqQ8B3DszZoIq7ghfQx/T9XvYb7AqnJ GQRbGVnNBg+mWIGurN4BNmCNRxARgT2ywAirtDMQ4H6uZt8EdNJ8uzJOt8JqZVPabGVC GsHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gentoo.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lt12si9502787ejb.158.2021.03.27.11.25.02; Sat, 27 Mar 2021 11:25:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gentoo.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230210AbhC0SWN (ORCPT + 99 others); Sat, 27 Mar 2021 14:22:13 -0400 Received: from smtp.gentoo.org ([140.211.166.183]:35226 "EHLO smtp.gentoo.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230105AbhC0SVz (ORCPT ); Sat, 27 Mar 2021 14:21:55 -0400 Received: by sf.home (Postfix, from userid 1000) id A29665A22061; Sat, 27 Mar 2021 18:21:50 +0000 (GMT) From: Sergei Trofimovich To: Vlastimil Babka , Andrew Morton , David Hildenbrand , Andrey Konovalov Cc: linux-kernel@vger.kernel.org, Sergei Trofimovich , linux-mm@kvack.org Subject: [PATCH v2] mm: page_alloc: ignore init_on_free=1 for debug_pagealloc=1 Date: Sat, 27 Mar 2021 18:21:44 +0000 Message-Id: <20210327182144.3213887-1-slyfox@gentoo.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210327180348.137d8fe2@sf> References: <20210327180348.137d8fe2@sf> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 init_on_free=1. Before the change id happened too late 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. CC: Vlastimil Babka 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 --- 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 d57d9b4f7089..10a8a1d28c11 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -764,32 +764,36 @@ static inline void clear_page_guard(struct zone *zone, struct page *page, */ void init_mem_debugging_and_hardening(void) { + bool page_poison_requested = page_poisoning_enabled(); + +#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_poison_requested = true; + } +#endif + if (_init_on_alloc_enabled_early) { - if (page_poisoning_enabled()) + if (page_poison_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_poison_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_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; -- 2.31.0