From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23D2BC77B61 for ; Mon, 24 Apr 2023 11:34:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACCE26B0074; Mon, 24 Apr 2023 07:34:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A7CBE6B0075; Mon, 24 Apr 2023 07:34:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 944396B0078; Mon, 24 Apr 2023 07:34:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 851B86B0074 for ; Mon, 24 Apr 2023 07:34:28 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4358880369 for ; Mon, 24 Apr 2023 11:34:28 +0000 (UTC) X-FDA: 80716076616.05.DA15647 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf22.hostedemail.com (Postfix) with ESMTP id 48303C000B for ; Mon, 24 Apr 2023 11:34:26 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=NvZMB6AO; spf=pass (imf22.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682336066; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HMIfA/TnrdlusW1/9QprMQTD2M6SSr1Kzxz81o0jjbg=; b=MmILRLU3fyytsixb9j7ItpVpq/dTLd3TnqKppg0S0QB7+z4eZO3DpaycX1K6ZjrPbAtBsO lRhgM21/J+rDUVonDi045IOROc+JP0RVHvgdJ/9puPcmhSZI366gL7NGEGDNWj/61FkYfr O+FuhKnlHgt2VrBnBJ6nRdaoD03R3Ks= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=NvZMB6AO; spf=pass (imf22.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682336066; a=rsa-sha256; cv=none; b=Z2AQCVhD84/HKmfndM3jDocinaY+g8PR63voztNFWE6/WHC27ONpOZzcKb4okv1JADq1RJ bnx8Bgp4G9HwP1AtTFccD35tTtJzgVLyKw4Y8Ky4cCR9+UIs3OdFbAmMXon+E76e072/Vg Esvy6P/+xv+cSzOdEI7jQecEO/w9JTw= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id DF8BE21A84; Mon, 24 Apr 2023 11:34:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1682336064; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=HMIfA/TnrdlusW1/9QprMQTD2M6SSr1Kzxz81o0jjbg=; b=NvZMB6AOhzTTfvqxMBIo3aqvff5L9LJJzetX19S6QQqyUpRcEDyF3mArEHBbmeburzNugO vzJ9eyzLwTVTDXNlK1HXxyvOxjGq7FC3ET7jy5FP7cYiLg4y1rZzBnzlBmwGMf5+NqkffC 5kvwfwWPubZYJ6M0YTLaAtZYDBcFVf8= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id BC82F13780; Mon, 24 Apr 2023 11:34:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 7HckK0BpRmTOVQAAMHmgww (envelope-from ); Mon, 24 Apr 2023 11:34:24 +0000 Date: Mon, 24 Apr 2023 13:34:23 +0200 From: Michal Hocko To: Baolin Wang Cc: akpm@linux-foundation.org, rppt@kernel.org, ying.huang@intel.com, mgorman@techsingularity.net, vbabka@suse.cz, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/2] mm/page_alloc: add some comments to explain the possible hole in __pageblock_pfn_to_page() Message-ID: References: <9fc85cce8908938f4fd75ff50bc981c073779aa5.1682229876.git.baolin.wang@linux.alibaba.com> <0733a4cf57109a4136de5ae46fac83fb15bdd528.1682229876.git.baolin.wang@linux.alibaba.com> <9a20c0b5-9d8a-2b1d-570a-61c17a4ce5e8@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9a20c0b5-9d8a-2b1d-570a-61c17a4ce5e8@linux.alibaba.com> X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 48303C000B X-Stat-Signature: hhu4rrdqay14nsd6suq3akpin67rhtds X-HE-Tag: 1682336066-881013 X-HE-Meta: U2FsdGVkX1/JzArP9nOoK9eQNAsEvP7FKi8tms0eG5El5D9xBYoExm/lizhTougRyYt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lHlP1FcCot2WKxAD1jheBk3YEt95nvtgrUAYonERpTwaL8TCNaK7/2UU2kIoo/6OhCNlNwOkYGdRuRduyo9AhUXhUAuxgEuwH8A50xcl0qhqRTxglvZdcGrjsphtVVACJIHvLeLOX6Hj86VFnXVtBI2TxWzCq/N28mp1fmdU+YgqjHIlBKBw6kaqQiwIO8sDmMmlrXYnR41sg1FvUKwhrc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon 24-04-23 19:20:43, Baolin Wang wrote: > > > On 4/24/2023 5:54 PM, Michal Hocko wrote: > > On Sun 23-04-23 18:59:11, Baolin Wang wrote: > > > Now the __pageblock_pfn_to_page() is used by set_zone_contiguous(), which > > > checks whether the given zone contains holes, and uses pfn_to_online_page() > > > to validate if the start pfn is online and valid, as well as using pfn_valid() > > > to validate the end pfn. > > > > > > However, the __pageblock_pfn_to_page() function may return non-NULL even > > > if the end pfn of a pageblock is in a memory hole in some situations. For > > > example, if the pageblock order is MAX_ORDER, which will fall into 2 > > > sub-sections, and the end pfn of the pageblock may be hole even though > > > the start pfn is online and valid. > > > > > > This did not break anything until now, but the zone continuous is fragile > > > in this possible scenario. So as previous discussion[1], it is better to > > > add some comments to explain this possible issue in case there are some > > > future pfn walkers that rely on this. > > > > > > [1] https://lore.kernel.org/all/87r0sdsmr6.fsf@yhuang6-desk2.ccr.corp.intel.com/ > > > > Do I remember correctly you've had a specific configuration that would > > trigger this case? > > Yes, I provided an example in previous thread [2] so show the > __pageblock_pfn_to_page() is fragile in some cases. > > [2] https://lore.kernel.org/all/52dfdd2e-9c99-eac4-233e-59919a24323e@linux.alibaba.com/ Please make it a part of the changelog. > > > > > Signed-off-by: Baolin Wang > > > --- > > > Changes from v1: > > > - Update the comments per Ying and Mike, thanks. > > > --- > > > mm/page_alloc.c | 7 +++++++ > > > 1 file changed, 7 insertions(+) > > > > > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > > index 6457b64fe562..9756d66f471c 100644 > > > --- a/mm/page_alloc.c > > > +++ b/mm/page_alloc.c > > > @@ -1502,6 +1502,13 @@ void __free_pages_core(struct page *page, unsigned int order) > > > * interleaving within a single pageblock. It is therefore sufficient to check > > > * the first and last page of a pageblock and avoid checking each individual > > > * page in a pageblock. > > > + * > > > + * Note: the function may return non-NULL even if the end pfn of a pageblock > > > + * is in a memory hole in some situations. For example, if the pageblock > > > + * order is MAX_ORDER, which will fall into 2 sub-sections, and the end pfn > > > + * of the pageblock may be hole even though the start pfn is online and valid. > > > + * This did not break anything until now, but be careful about this possible > > > + * issue when checking whether all pfns of a pageblock are valid. > > > > It is not really clear what you should be doing (other than to be > > careful which is not helpful much TBH) when you encounter this > > situation. If the reality changes and this would break in the future > > what would breakage look like? What should be done about that? > > That depends on what the future pfn walkers do, which may access some hole > memory with zero-init page frame. For example, if checking the > __PageMovable() for a zero-init page frame, that will crash the system. But > I can not list all the possible cases. > > So how about below words? > > * Note: the function may return non-NULL even if the end pfn of a pageblock > * is in a memory hole in some situations. For example, if the pageblock > * order is MAX_ORDER, which will fall into 2 sub-sections, and the end pfn > * of the pageblock may be hole even though the start pfn is online and > valid. > * This did not break anything until now, but be careful about this possible > * issue when checking whether all pfns of a pageblock are valid, that may > * lead to accessing empty page frame, and the worst case can crash the > system. > * So you should use pfn_to_onlie_page() instead of pfn_valid() to valid the > * pfns in a pageblock if such case happens. Does that mean that struct page is not initialized and PagePoisoned will trigger or it is just zero-prefilled? -- Michal Hocko SUSE Labs