Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2548580pxj; Mon, 10 May 2021 05:41:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCSNgzxVBQWCXxL8F3ctJ3tqYn7jtJsYOx11P6xd2zvbpJZyVHb5q/uY/73oWetZIyC2BZ X-Received: by 2002:a05:6402:54e:: with SMTP id i14mr30099014edx.210.1620650500727; Mon, 10 May 2021 05:41:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620650500; cv=none; d=google.com; s=arc-20160816; b=cIk7Db5SH2CwIOjoCOEFwbVjeFQL8CNDhebnfjD2YVowaSTln3tb2E8kptoayjMX/I ro8IU04Hmkjs//QuCeScubSmIn+rf/GFTgaanCq6nPglCUpXfZVWoegHoTZ0S8ajxwPB hNtCk7GR52yUA0TCHyBd87ce7lgpbvaB829sMz+E0zZg8wR09xdSmWVAgsTXpE8Nsd9B YRSz1QXMtiRTo4onN0OPc8+3O/77708FL2QllLmYv9IaxcmQpIzAZ+VFtRh/PFa3RfFM vzsr6oI6q9A6XrcmlkiWKwJhD+CnvAKgIq0GbOiEfE7xVNa3MIoXcWx0Wl4bkkOBOcfT Ashg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Tb65F8lz9WLki480D9xQ0+MG2eYyJfO2QX/hPj+/Jps=; b=HgBLLxICdXFJ+/wtLUr9C9yniEvspALqcDT3DoYy5BsZTgXuBofm0qx8IwJrPV8H0U nyL9oKTbzYTZQLFPlBr2uStvlCAvnnAVTHILQ/r4KbNS21EXfhgxB6l3nPQKijgpKdgS l6mibbf3AJFl35HewQBRUbG2Dh3h4ionIjxMDVZn5B3G98/cezEcLYbRBvYdxgTPq/df hTT4x+25CS05zzKVFtCYRFlbts7dNfbBKqV68cUvjjS65l7ByWtE9PXFjup12RczxY6u zUU2rIkO90PVRKVCxHnIluLR/qnuj3OtINwEI+hIcw2l+NHlCwR+gC6EOXqGLYcnCsAZ yf4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=l5qiTtX+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s27si14363779edy.9.2021.05.10.05.41.16; Mon, 10 May 2021 05:41:40 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=l5qiTtX+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245561AbhEJMgD (ORCPT + 99 others); Mon, 10 May 2021 08:36:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:53778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235751AbhEJLNo (ORCPT ); Mon, 10 May 2021 07:13:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7C6276101B; Mon, 10 May 2021 11:10:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620645027; bh=so06xh22x+eOvI3lB5XXERypi5HW9pgp260kwFsvtCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l5qiTtX+V3Z+S+FWFSlAi94GHMe6DHmf+dYoKE0YH8LNIhphuX5HJQaWCaHzVaa5G lWuJx1ptJ8mzmZ8DcICYZ1dXD+drEeMBw5KW9e5LML7U+gMJAzIvqXzBtTLDLcsBr0 lT1WfpNsbf4D7yUcSM0nBy3vurMbV+hCWJI6dshI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sergei Trofimovich , Vlastimil Babka , David Hildenbrand , Andrey Konovalov , Andrew Morton , Linus Torvalds Subject: [PATCH 5.12 321/384] mm: page_alloc: ignore init_on_free=1 for debug_pagealloc=1 Date: Mon, 10 May 2021 12:21:50 +0200 Message-Id: <20210510102025.378166191@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102014.849075526@linuxfoundation.org> References: <20210510102014.849075526@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sergei Trofimovich commit 9df65f522536719682bccd24245ff94db956256c upstream. 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: 8db26a3d4735 ("mm, page_poison: use static key more efficiently") Signed-off-by: Sergei Trofimovich Acked-by: Vlastimil Babka Reviewed-by: David Hildenbrand Cc: Andrey Konovalov Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/page_alloc.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -764,32 +764,36 @@ static inline void clear_page_guard(stru */ 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;