Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2522605pxj; Mon, 10 May 2021 05:08:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYdZ4saixFLKFQvpJu/16w6MVKYxGXx+kB6mYbY8wThv5X/AwniLo94eOiAMVnJTZT4+Gi X-Received: by 2002:a17:906:3ec9:: with SMTP id d9mr25288553ejj.479.1620648502347; Mon, 10 May 2021 05:08:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620648502; cv=none; d=google.com; s=arc-20160816; b=ve/mUADwBw8yzvXKEcHMOdsBv+do5HJjb5qwcYjFqNo3/cEFwI1HfOZLuTo1qrg+4t dIfYY+aYO2kLiei08/F4EKqYpTkB0nRefJYe4bk6ySrYIguCxsuTSxV5DZ7Zc9d0kYfB 4/oNA1I4ESc2u6+H1KYg4TU0Tit3zEU9OYyKuWpGbJPUlKHR+orG+DrAUs8eCfFK64xp Tc20iycSPQnSGzqgDYqGqAhmtjJsiYE8N/s2iXyo6Tq+OzubX717c2hn426jWlq2YWe+ IKwc0fCNoJj9h2SL+AnrnEw2mslR10pn7tOqnkmW2kFi1+uNg/NLak2yt0VnvTsSuuEG ofBg== 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=V83MQ7Yyplx2P0c89tVKr2Axw8HpIhoql22pNcgmP/nnr2QkRAHahUNiKK7/0ijj9R MUp8FTyvoPYVY0Ao/Roxce7cRNkcolTwgBuSSx2RIwfClQJ3uA90++5suO9CoCTTPZki uYcXyOGWXD8k/7fDb0fqg9fBiNWoXnPasVF1F89U0ojSDbZ3sWDvf72amDUzD4reBB7K LiL5IFcc5yH61DvGM3ffsWQUBgBNWIz62DUKA9PsZS86Wh41oFtixtR49ODKOVsJndMt Eto2rMDUJ0D2fEI49Wn000GssJPKkJfjqVH9Wn+9EwyHoFo2xW6cEsGmteyLmFV86xdB 7uDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bfKQZdJ7; 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 j19si13353810ejc.617.2021.05.10.05.07.53; Mon, 10 May 2021 05:08:22 -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=bfKQZdJ7; 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 S244096AbhEJL6R (ORCPT + 99 others); Mon, 10 May 2021 07:58:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:41148 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235815AbhEJLGO (ORCPT ); Mon, 10 May 2021 07:06:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0EA2A61554; Mon, 10 May 2021 10:56:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620644186; bh=so06xh22x+eOvI3lB5XXERypi5HW9pgp260kwFsvtCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bfKQZdJ7vIT5tPpsHv3DEwWkY0n/BJjmA8PlO1mPCJBM+V5jCyLVIQvwYqTQVJ16S gg33NpBZ8E5f3AeOk2/IlQJfU+UZ8myudOjaChRYFU5PsBb1THmfrLwycTN+Oexeec inzUIWaPhSQtMVkMrV06jdqo9UTSns7LDV/ohgXo= 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.11 288/342] mm: page_alloc: ignore init_on_free=1 for debug_pagealloc=1 Date: Mon, 10 May 2021 12:21:18 +0200 Message-Id: <20210510102019.633534202@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102010.096403571@linuxfoundation.org> References: <20210510102010.096403571@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;