mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zi Yan <ziy@nvidia.com>
To: Kiryl Shutsemau <kas@kernel.org>,
	"David Hildenbrand (Arm)" <david@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Nico Pache <nico.pache@linux.dev>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
	Usama Arif <usama.arif@linux.dev>,
	Brendan Jackman <brendan.jackman@linux.dev>,
	Johannes Weiner <hannes@cmpxchg.org>, Ye Liu <ye.liu@linux.dev>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v3] mm/huge_memory: prevent losing PG_waiters in __split_folio_to_order()
Date: Tue, 10 Nov 2026 11:36:53 -0500	[thread overview]
Message-ID: <117526B0-43C1-4F60-BA2A-3726AD1A9BDA@nvidia.com> (raw)
In-Reply-To: <avMaQIdAj5Zal3rd@thinkstation>

On 10 Nov 2026, at 8:48, Kiryl Shutsemau wrote:

> On Tue, Nov 10, 2026 at 12:31:21PM +0100, David Hildenbrand (Arm) wrote:
>>> This is V3 of the patch. Instead of using prep_compound_page_atomic(),
>>> PG_head is written before clear_compound_page(), after which new_head
>>> is visible to the reference-less writers.
>>
>> I'm confused, how is it then valid to have PG_waiters set concurrently while we
>> read new_folio->flags.f?
>
> It is not. The comment names the wrong word: PG_waiters can be set
> concurrently on the old head, not on new_folio.

Yes, thank you for the explanation. I confused myself when writing
the comment. At this code place, before clear_compound_head(),
reference-less accessors can only see the old folio.

>
> CPU1 and CPU2 below are two faults on a migration entry that points at
> new_head. Both take this path:
>
>   do_swap_page()
>     migration_entry_wait()
>       softleaf_entry_wait_on_locked()
>         softleaf_to_folio()
>           page_folio()           <-- old head or new_head?
>         folio_set_waiters()
>           set_bit(PG_waiters)    <-- on that folio's flags
>
> Which one page_folio() returns depends on clear_compound_head():
>
> CPU0: __split_folio_to_order()  CPU1: fault           CPU2: fault
>
>                                 1. page_folio()
>                                    -> old head
> 2. flags  = new_folio->flags.f
>    flags |= folio->flags.f
>                                 3. set_bit(PG_waiters)
>                                    -> folio->flags.f
> 4. new_folio->flags.f =
>            flags | PG_head
>    smp_wmb()
> 5. clear_compound_head()
>                                                       6. page_folio()
>                                                          -> new_head
>                                                       7. set_bit(PG_waiters)
>                                                          -> new_folio->flags.f
>
> 2 and 3 race on the old head's flags word.
>
> That is Ye Liu's KCSAN report, and it is benign: PG_waiters is not in
> the cloned mask. new_folio->flags.f gets PG_waiters only at 7, after
> CPU0's last plain write to it at 4.
>
> So only the folio->flags.f read needs data_race().
>
> The new_folio->flags.f read needs nothing; the READ_ONCE() I had there
> in my sketch was not needed.

Yes and I should have checked it more carefully, but my focus was mostly
on whether PG_head could be set before smp_wmb() and clear_compound_head().

I will clean this up and send v4. Sorry for the confusion.

Best Regards,
Yan, Zi

  reply	other threads:[~2026-11-10 16:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 19:32 Zi Yan
2026-11-09 20:21 ` David Hildenbrand (Arm)
2026-11-09 21:05   ` Zi Yan
2026-11-09 21:18     ` Zi Yan
2026-11-10 11:31     ` David Hildenbrand (Arm)
2026-11-10 13:48       ` Kiryl Shutsemau
2026-11-10 16:36         ` Zi Yan [this message]
2026-11-10 17:03       ` Zi Yan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=117526B0-43C1-4F60-BA2A-3726AD1A9BDA@nvidia.com \
    --to=ziy@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=brendan.jackman@linux.dev \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=kas@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=nico.pache@linux.dev \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=ye.liu@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®