[v2,2/2] mm/page_alloc: add some comments to explain the possible hole in __pageblock_pfn_to_page()
Message ID | 0733a4cf57109a4136de5ae46fac83fb15bdd528.1682229876.git.baolin.wang@linux.alibaba.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2134472vqo; Sun, 23 Apr 2023 04:01:19 -0700 (PDT) X-Google-Smtp-Source: AKy350YEnqCGdAGDi1Kzz88rSOZW8Y8ZOBdNKX+jtzmwhH9kOfqGDcspAjlvyqRqllM2/dlJLm0G X-Received: by 2002:a17:903:1250:b0:1a6:cd08:5594 with SMTP id u16-20020a170903125000b001a6cd085594mr12012444plh.69.1682247678727; Sun, 23 Apr 2023 04:01:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682247678; cv=none; d=google.com; s=arc-20160816; b=O+t8FNIvqxzCNKmDV6ww/07J2srP2/JRubTBTctNuAAU9lBjKyPD2HeM4TNm9ZeH2f +rXexC5UQttpzMfkQ3OpLtVdWYpBGRDRaTeJfUPWkYl4wOP/bgneaDx3pmFyTppIY9B6 Tp22FhQYAF8ZLrHlZGP+uDGHyStSZI3LaZjRLPcPLcQ4AXB37ncyOXtzdhWgv8V6PtQK YH8F1VmDeimkTsm7ZsPdgpokFamjIopdLzwmmKYfHxXRnMFHxLacJ14fG9ftp+5Wb+La yiWa7/iECW5+pEHiCzg4tVGCfC8oAv1WQoYYLsNJ1E+uaA3CYFhjeKj0UBHHaXGLugdF 6ykQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=LIqsSOzpJnrF9Fm+xJnpVjcr3PBFv0oWSPLLsllAJ6Q=; b=YFZ0x4c0Vn5UKcpOTv3HyJqfN/o9kQLCWPMIFOu470ERjReV7sTvvYrfku/EI+1TRD Dbg4itPRfHowgOneHONoDSkyLtzYOrjLtdJdXXfQT83TM4ewp7IFJUxWk7T6auSxUg/4 HOP5p2F07pJ19ZA0CSZfFW9w9MDsuLAlQIPL6SwIyXj51pfuJ5duZNVIJsc4PmI/MNMe u2rFrmCS1vGLKOa/X6Y0CLfo/0IFI4b+A9BzMDVkft7daAa+zMjA89pX7k+e2uGU/6Y/ nNiJ6MELAFReFX5Hed22wL8PGJg+qnthugVhwe1vFMymSeNt3WBL5VUDQWmXGIfBASss NFrw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j4-20020a170902758400b001a1f70cc7dbsi8283890pll.562.2023.04.23.04.01.05; Sun, 23 Apr 2023 04:01:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229695AbjDWLAg (ORCPT <rfc822;zxc52fgh@gmail.com> + 99 others); Sun, 23 Apr 2023 07:00:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229843AbjDWLAH (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 23 Apr 2023 07:00:07 -0400 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20F771728 for <linux-kernel@vger.kernel.org>; Sun, 23 Apr 2023 03:59:43 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0VgjjRNn_1682247580; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VgjjRNn_1682247580) by smtp.aliyun-inc.com; Sun, 23 Apr 2023 18:59:41 +0800 From: Baolin Wang <baolin.wang@linux.alibaba.com> To: akpm@linux-foundation.org Cc: rppt@kernel.org, ying.huang@intel.com, mgorman@techsingularity.net, vbabka@suse.cz, mhocko@suse.com, david@redhat.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] mm/page_alloc: add some comments to explain the possible hole in __pageblock_pfn_to_page() Date: Sun, 23 Apr 2023 18:59:11 +0800 Message-Id: <0733a4cf57109a4136de5ae46fac83fb15bdd528.1682229876.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <9fc85cce8908938f4fd75ff50bc981c073779aa5.1682229876.git.baolin.wang@linux.alibaba.com> References: <9fc85cce8908938f4fd75ff50bc981c073779aa5.1682229876.git.baolin.wang@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763964542089554778?= X-GMAIL-MSGID: =?utf-8?q?1763964542089554778?= |
Series |
[v2,1/2] mm/page_alloc: drop the unnecessary pfn_valid() for start pfn
|
|
Commit Message
Baolin Wang
April 23, 2023, 10:59 a.m. UTC
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/
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
Changes from v1:
- Update the comments per Ying and Mike, thanks.
---
mm/page_alloc.c | 7 +++++++
1 file changed, 7 insertions(+)
Comments
Baolin Wang <baolin.wang@linux.alibaba.com> writes: > 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/ > > Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com> Looks good to me! Thanks! Reviewed-by: "Huang, Ying" <ying.huang@intel.com> > --- > 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. > */ > struct page *__pageblock_pfn_to_page(unsigned long start_pfn, > unsigned long end_pfn, struct zone *zone)
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? > Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com> > --- > 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? > */ > struct page *__pageblock_pfn_to_page(unsigned long start_pfn, > unsigned long end_pfn, struct zone *zone) > -- > 2.27.0
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/ > >> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com> >> --- >> 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.
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 <baolin.wang@linux.alibaba.com> > > > --- > > > 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?
On 4/24/2023 7:34 PM, Michal Hocko wrote: > 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. Sure. > >>> >>>> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com> >>>> --- >>>> 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? In the example I provided[2], these page frames of the hole memory are zero-prefilled. [2] https://lore.kernel.org/all/52dfdd2e-9c99-eac4-233e-59919a24323e@linux.alibaba.com/
On Mon 24-04-23 19:40:30, Baolin Wang wrote: > > > On 4/24/2023 7:34 PM, Michal Hocko wrote: > > 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. > > Sure. > > > > > > > > > > Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com> > > > > > --- > > > > > 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? > > In the example I provided[2], these page frames of the hole memory are > zero-prefilled. OK, so make _that_ explicit in the comment. Essentially you want to say that there are cases where we have zero-initialized struct pages for memory holes. In general no pfn walker should touch a physical memory range for pfn where the struct page doesn't contain any metadata it recognizes. Zero fill struct pages do not contain any distinguishable state so that makes it less of a problem. All that being said I would reformulate the comment as follows: * Note: the function may return non-NULL struct page even for a * page block which contains a memory hole (i.e. there is no * physical memory for a subset of the pfn range). This should be * safe most of the time because struct pages are still zero * pre-filled and pfn walkers shouldn't touch any physical memory * range for which they do not recognize any specific metadata in * struct pages. > [2] https://lore.kernel.org/all/52dfdd2e-9c99-eac4-233e-59919a24323e@linux.alibaba.com/
On 4/24/2023 8:08 PM, Michal Hocko wrote: > On Mon 24-04-23 19:40:30, Baolin Wang wrote: >> >> >> On 4/24/2023 7:34 PM, Michal Hocko wrote: >>> 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. >> >> Sure. >> >>>>> >>>>>> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com> >>>>>> --- >>>>>> 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? >> >> In the example I provided[2], these page frames of the hole memory are >> zero-prefilled. > > OK, so make _that_ explicit in the comment. Essentially you want to say > that there are cases where we have zero-initialized struct pages for > memory holes. In general no pfn walker should touch a physical memory > range for pfn where the struct page doesn't contain any metadata it > recognizes. Zero fill struct pages do not contain any distinguishable > state so that makes it less of a problem. > > All that being said I would reformulate the comment as follows: > > * Note: the function may return non-NULL struct page even for a > * page block which contains a memory hole (i.e. there is no > * physical memory for a subset of the pfn range). This should be > * safe most of the time because struct pages are still zero > * pre-filled and pfn walkers shouldn't touch any physical memory > * range for which they do not recognize any specific metadata in > * struct pages. Thanks. That makes sense to me. A trivial thing is I still want to add the example in the comments to make it clear. Are you okay with below description? + * Note: the function may return non-NULL struct page even for a page block + * which contains a memory hole (i.e. there is no physical memory for a subset + * of the pfn range). 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 should be safe most of + * the time because struct pages are still zero pre-filled and pfn walkers + * shouldn't touch any physical memory range for which they do not recognize + * any specific metadata in struct pages.
On Mon 24-04-23 20:48:32, Baolin Wang wrote: > > > On 4/24/2023 8:08 PM, Michal Hocko wrote: > > On Mon 24-04-23 19:40:30, Baolin Wang wrote: > > > > > > > > > On 4/24/2023 7:34 PM, Michal Hocko wrote: > > > > 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. > > > > > > Sure. > > > > > > > > > > > > > > > > Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com> > > > > > > > --- > > > > > > > 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? > > > > > > In the example I provided[2], these page frames of the hole memory are > > > zero-prefilled. > > > > OK, so make _that_ explicit in the comment. Essentially you want to say > > that there are cases where we have zero-initialized struct pages for > > memory holes. In general no pfn walker should touch a physical memory > > range for pfn where the struct page doesn't contain any metadata it > > recognizes. Zero fill struct pages do not contain any distinguishable > > state so that makes it less of a problem. > > > > All that being said I would reformulate the comment as follows: > > > > * Note: the function may return non-NULL struct page even for a > > * page block which contains a memory hole (i.e. there is no > > * physical memory for a subset of the pfn range). This should be > > * safe most of the time because struct pages are still zero > > * pre-filled and pfn walkers shouldn't touch any physical memory > > * range for which they do not recognize any specific metadata in > > * struct pages. > > Thanks. That makes sense to me. A trivial thing is I still want to add the > example in the comments to make it clear. Are you okay with below > description? > > + * Note: the function may return non-NULL struct page even for a page block > + * which contains a memory hole (i.e. there is no physical memory for a > subset > + * of the pfn range). 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 should be safe most > of > + * the time because struct pages are still zero pre-filled and pfn walkers > + * shouldn't touch any physical memory range for which they do not > recognize > + * any specific metadata in struct pages. No objections of course. I do not see an additional value, quite honestly but if somebody does then it doesn't hurt.
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. */ struct page *__pageblock_pfn_to_page(unsigned long start_pfn, unsigned long end_pfn, struct zone *zone)