Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3530200pxf; Mon, 29 Mar 2021 05:00:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypBhItyrgROC+166lrIQPGgLbNKNSkSWAey/n/3Z9X/23qP/9JZN3arOiB/X37V998oIMf X-Received: by 2002:a05:6402:350f:: with SMTP id b15mr27959668edd.6.1617019229892; Mon, 29 Mar 2021 05:00:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617019229; cv=none; d=google.com; s=arc-20160816; b=Cs0yO0FphA9/Nx2TmZnyiLDFjOjmNQ4gS+vUxbnUj3Eq9AJ2l4SSHFM0Vfz689Mu0l LgkBnJnJqORShSDWf7103Cvz7dvBLr6deGK8elX+ZJSy751vJVvU35utIazoJCAN/4PN YQfK/SOg48rOnNgqTSv04UYuUS6x+9yaWtbF00gVB2PjkjZTVan1JgqT+MxpjA1BV5WH 7lsHz7IkZaQko+9B3UZXFl1yzI58cU1fGoO4xNC0aTl8YDUdMWeS92PhPpPhMnp00qLi 13Ztn+qSjgU5csfgMStkA0Uli90mSJt3TPGBEyLI25IHqexcJpmgwRn4lkWVby6w+mzW 1Qkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to; bh=ZBhw7YhGe/kFBjhmz3XsRQITgYt+42bUalCKDSM5avI=; b=Ej7WJoWOgG1Wx3fqeGqA8o9sARb66Mn2VFW0hUoWoHuqsqBxkTxJX0zZEO6o6nRnnU gJ8+gjlWfd0xOtq0P6OaoET6ONQCadWh+NEy1R8DX8tNpIYzZxit21g6JCgI9fK3cn3O lvhZWOhpwCTgrBQJOtpXDC9LmwAZswjALWJ5sOFXokNVQurNaGmFf5Ohc5mcZkIEtnv6 qD2r3e3YSLicMj+s+G+PmVPAgYGj8ccWzg4yh4Klx/TTWtbqGuMkMBcbwGScUdckuK+D rx2lh3ULUH6PdcDuFg/V0/KpBeBrAZ8ekHoWadV2+PcJgV7r9DjI9q5N5rOnL/5MRUBN wCZg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m24si12677656edp.422.2021.03.29.05.00.06; Mon, 29 Mar 2021 05:00:29 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231184AbhC2L7K (ORCPT + 99 others); Mon, 29 Mar 2021 07:59:10 -0400 Received: from mx2.suse.de ([195.135.220.15]:41512 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231614AbhC2L7J (ORCPT ); Mon, 29 Mar 2021 07:59:09 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 892A9B3C9; Mon, 29 Mar 2021 11:59:08 +0000 (UTC) To: Sergei Trofimovich , Andrew Morton , David Hildenbrand , Andrey Konovalov Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20210327180348.137d8fe2@sf> <20210327182144.3213887-1-slyfox@gentoo.org> From: Vlastimil Babka Subject: Re: [PATCH v2] mm: page_alloc: ignore init_on_free=1 for debug_pagealloc=1 Message-ID: Date: Mon, 29 Mar 2021 13:59:07 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210327182144.3213887-1-slyfox@gentoo.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/27/21 7:21 PM, Sergei Trofimovich wrote: > 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. Good catch, thanks for finding the root cause! > 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 Acked-by: Vlastimil Babka 8db26a3d4735 ("mm, page_poison: use static key more efficiently") Cc: > --- > 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; >