Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3918153pxf; Mon, 29 Mar 2021 15:31:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXXPmhR7FbubtKaVeO9yWx6D6zWXyN7Dm5lPSw8uQI+VCavs2hh/CA7+9SD3iIYXkz/3om X-Received: by 2002:a17:907:6289:: with SMTP id nd9mr30449082ejc.384.1617057116532; Mon, 29 Mar 2021 15:31:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617057116; cv=none; d=google.com; s=arc-20160816; b=FplZXJcX2x1UtlQSpPXB18iiv2OimZZ9SxrIBmtloAm1HVBTp0vhwKRMnookbZbQYF bDds7cJidEPxAOJjqz5ICNrX2DPR0ZtFtXkg/lD16x53Ps1/9LYidDSQy3A5qKaCKeyc xmZEdYzEiQkNCzKc63oaHPoQld6yYlNyC2Lf9361kBOSc6jihQsu+peiOLSKnChaSSn5 GL5m2uZr/RfbuxIit9+tb0q0kvN0DGxqtuyw2Ii5T2XvobY9su/CayksLpARtgDuE4mZ Mx4MEyiq6dGvU+VQo/U9vYHRxB6KNuGSNWGwLVE0VocixILvCBWZLhbsAxmI4iE5eX8L iJsQ== 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=oMnhSgI+8u3A/xzVrSdk3dWp+NLAqgUg/9JR2ptlajQ=; b=YKdaiPoUb+cPPd7J0p+TIzG8NLLQIb1v0CPcOCIpTFGKQBpHHBwFR7/DgY9O3xLKg2 oakrqRNWPukQebDNJW+731Pi4QFX6EEXGccCpJ3woO4KmJakgkt9FjJ7F2krROBqH07O xY3SSjza80If4IIPOEBwBlrB2Ax/wLDRtCDyG3QCw0TIQ22ikB8WBMVJ1JEMGWsRYG2m GHd+mVxcy/4YK38udiw/QYklPL0M9yqhcR1pM0x93OhLrsI1iipbRxA1BBvYS9cT3OeI f6eb10AaaeOC3RD/nVk6cFnOFIw8oUOeMTjOGpL9rQ88Q2wduFBZx5IqE68KfCDLb4wy xTJw== 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 ay27si262901edb.171.2021.03.29.15.31.34; Mon, 29 Mar 2021 15:31:56 -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 S232601AbhC2Wap (ORCPT + 99 others); Mon, 29 Mar 2021 18:30:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232981AbhC2W0L (ORCPT ); Mon, 29 Mar 2021 18:26:11 -0400 Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D3A7C061762; Mon, 29 Mar 2021 15:26:10 -0700 (PDT) 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 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 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. 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 *zone, struct page *page, */ void init_mem_debugging_and_hardening(void) { + bool page_poisoning_requested = 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 = 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); } -#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.1