Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1409056pxf; Fri, 26 Mar 2021 07:20:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyV18GtvBAKZ38dQFkfwOSsbb301l6YkcJ1ZP9Ayxu77laI3YISHzRLpR0u6m7jh7CFQnza X-Received: by 2002:a05:6402:b2d:: with SMTP id bo13mr15332254edb.120.1616768436711; Fri, 26 Mar 2021 07:20:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616768436; cv=none; d=google.com; s=arc-20160816; b=TTuPaVs0JddH9ZISe8xNa3bzSns2I1IJ+C+2NfqfOuMjdFAAqa8+jLTCT5k+huUzdx bviXGS8xbYqnLOcLRRZ5LCNb5DLx2evBiib5JCEIpQ7ghyb4uw4Pr8ODAvlqR/B52y/g 8RV+Jes990vD4epWFLM6cSmCP3U6zSAg66vsz/ULbdZK8Oble/xvk4Kg8pbV/cVL2iWk YD5EKNxidqhy71qCv0KOpJbetvOd3efAQyU/iegq1YYk3SsLm4jFevL/QAcaMYsBmZEz MrDh8/wmKWwIKGe6WXo2C4MXzT3eEsnG2ZLjwy1jsgSgslUHUt+1JFsbYpIEu4OjDmd9 JEEQ== 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=1juSRQwajKGbOikEia6sRRIoDL1wRCrqiCiJJ66A9yY=; b=m8MlAzuIGt8f2vavDOwDJy/v7ZAUf4IQkN2fIgrn9muwwugWo6U/mz2oNU+dK2Aryt JerrMF1mRKD80l/cGh+nQWWpPy+VbjEm7olviKbDZiotxcK3AOp8XNI0HZNenJ2QZKAd V97qibtvRCLSdXhDjroi184rnJkugXEnEGLsNs0Z4jKo+6YEonV98Fm/rU7aXkcQYjwB ZUeHTnO8Pnk1W/FBKYmiSPfM9qL+rtJ5Wy1NI8TFrCNfZ2b+AyDuU/E4upu66Y7hBN5U kSCS/fX0GQ02iMHNkp5llT9oHMW8+aXZasgDdp9N63sNbOxyLyQSENLBXa65Wv/Uo8k2 NA3Q== 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 w26si6825283edx.572.2021.03.26.07.20.13; Fri, 26 Mar 2021 07:20:36 -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 S230044AbhCZORE (ORCPT + 99 others); Fri, 26 Mar 2021 10:17:04 -0400 Received: from mx2.suse.de ([195.135.220.15]:43686 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229986AbhCZORB (ORCPT ); Fri, 26 Mar 2021 10:17:01 -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 D2F6FAC6A; Fri, 26 Mar 2021 14:17:00 +0000 (UTC) To: Sergei Trofimovich , Andrew Morton , linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, David Hildenbrand References: <20210326112650.307890-1-slyfox@gentoo.org> From: Vlastimil Babka Subject: Re: [PATCH] mm: page_alloc: ignore init_on_free=1 for page alloc Message-ID: <6c4a20f3-16ab-3c6c-1d6d-4708db4e9ebf@suse.cz> Date: Fri, 26 Mar 2021 15:17:00 +0100 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: <20210326112650.307890-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/26/21 12:26 PM, Sergei Trofimovich wrote: > init_on_free=1 does not guarantee that free pages contain only zero bytes. > > Some examples: > 1. page_poison=on takes presedence over init_on_alloc=1 / ini_on_free=1 Yes, and it spits out a message that you enabled both and poisoning takes precedence. It was that way even before my changes IIRC, but not consistent. > 2. free_pages_prepare() always poisons pages: > > if (want_init_on_free()) > kernel_init_free_pages(page, 1 << order); > kernel_poison_pages(page, 1 << order kernel_poison_pages() includes a test if poisoning is enabled. And in that case want_init_on_free() shouldn't be. see init_mem_debugging_and_hardening() > > I observed use of poisoned pages as the crash on ia64 booted with > init_on_free=1 init_on_alloc=1 (CONFIG_PAGE_POISONING=y config). > There pmd page contained 0xaaaaaaaa poison pages and led to early crash. Hm but that looks lika a sign that ia64 pmd allocation should use __GFP_ZERO and doesn't. It shouldn't rely on init_on_alloc or init_on_free being enabled. > The change drops the assumption that init_on_free=1 guarantees free > pages to contain zeros. The change assumes that page_poison=on also leaves want_init_on_free() enabled, but it doesn't. > Alternative would be to make interaction between runtime poisoning and > sanitizing options and build-time debug flags like CONFIG_PAGE_POISONING > more coherent. I took the simpler path. So that was done in 5.11 and the decisions can be seen in init_mem_debugging_and_hardening(). There might be of course a bug, or later changes broke something. Which was the version that you observed a bug? > Tested the fix on rx3600. > > CC: Andrew Morton > CC: linux-mm@kvack.org > Signed-off-by: Sergei Trofimovich > --- > mm/page_alloc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index cfc72873961d..d57d9b4f7089 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -2301,7 +2301,7 @@ inline void post_alloc_hook(struct page *page, unsigned int order, > kernel_unpoison_pages(page, 1 << order); > set_page_owner(page, order, gfp_flags); > > - if (!want_init_on_free() && want_init_on_alloc(gfp_flags)) > + if (want_init_on_alloc(gfp_flags)) > kernel_init_free_pages(page, 1 << order); > } > >