Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Zi Yan <ziy@nvidia.com>,
	 Baolin Wang <baolin.wang@linux.alibaba.com>,
	"Liam R. Howlett" <liam@infradead.org>,
	 Nico Pache <npache@redhat.com>,
	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>,
	Pankaj Raghav <p.raghav@samsung.com>,
	 Hannes Reinecke <hare@suse.de>, Hugh Dickins <hughd@google.com>,
	Yang Shi <shy828301@gmail.com>,  Kiryl Shutsemau <kas@kernel.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	 Hengbin Zhang <uqbarz@gmail.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH mm-hotfixes 0/2] mm/huge_memory: fix huge_zero_pfn race
Date: Thu, 30 Jul 2026 10:15:45 +0100	[thread overview]
Message-ID: <amsUw6_DjKRg3gJq@lucifer> (raw)
In-Reply-To: <773a043f-e135-4050-9ca1-0b5190f03ec4@kernel.org>

On Thu, Jul 30, 2026 at 11:05:49AM +0200, David Hildenbrand (Arm) wrote:
> On 7/29/26 10:15, Lorenzo Stoakes (ARM) wrote:
> > On Tue, Jul 28, 2026 at 09:02:57PM +0200, David Hildenbrand (Arm) wrote:
> >> On 7/28/26 14:05, Lorenzo Stoakes (ARM) wrote:
> >>> There is a subtle race in the reference-counted huge_zero_folio
> >>> implementation.
> >>>
> >>> The fast path atomic logic fails to account for the fact that the
> >>> shrinker (which drops the final huge_zero_refcount pin) can overwrite
> >>> huge_zero_pfn with the ~0UL sentinel value in shrink_huge_zero_folio_scan()
> >>> after a racing get_huge_zero_folio() installed a valid value there.
> >>>
> >>> This results in huge_zero_folio being correctly set but huge_zero_pfn being
> >>> set incorrectly and thus is_huge_zero_pfn() and consequently
> >>> is_huge_zero_pmd() will misidentify the huge zero folio as being an
> >>> ordinary THP folio.
> >>>
> >>> This can result in the huge zero folio being split and otherwise treated
> >>> incorrectly.
> >>>
> >>> The solution to this is very subtle as there is an atomic fast path, and
> >>> thus ordering in weakly ordered architectures has to be treated very
> >>> carefully.
> >>>
> >>> As a result, this series first reworks the
> >>> CONFIG_PERSISTENT_HUGE_ZERO_FOLIO logic so it is separated from the
> >>> refcounted code in order to make the subsequent fix reasonably
> >>> understandable.
> >>
> >> For at least somewhat easier backports, can we reverse the order?
> >
> > Since I'm going to be doing the backports can we keep it the same? :)
>
> I enjoy reviewing small targeted fixes (also for backports), so I want to
> understand why patch #1 is required at this point.
...
> >
> > I can figure things out for < persistent huge stable kernels. It'll be manual
> > work either way.
> >
> > (It'd be good to get some review on the actual changes also :)
> Sure, will get to it, but I have limited capacity.
>
> And I have more capacity for small targeted fixes :P

The fix is small and targeted, it's 2/2.

>
> >> The spinlock+proper ordering should be possible without #1, or am I missing
> >> something important?
> >
> > It's possible but this way it's a lot easier to deal with and I'd rather keep
> > things consistent for stable kernels.
>
> "A lot easier to deal with", can you elaborate?
>
> The shrinker code never runs with the persistent huge zero folio. So that is not
> a concern.
>
> So it's about get_huge_zero_folio().
>
> But there, it's simply that concurrent races are impossible.
>
> Please enlighten me.
>

Rather than debating I'll just drop that and respin.

>
> --
> Cheers,
>
> David


      reply	other threads:[~2026-07-30  9:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28 12:05 [PATCH mm-hotfixes 0/2] mm/huge_memory: fix huge_zero_pfn race Lorenzo Stoakes (ARM)
2026-07-28 12:05 ` [PATCH mm-hotfixes 1/2] mm/huge_memory: separate out CONFIG_PERSISTENT_HUGE_ZERO_FOLIO logic Lorenzo Stoakes (ARM)
2026-07-28 15:08   ` Kiryl Shutsemau
2026-07-28 15:41     ` Lorenzo Stoakes (ARM)
2026-07-28 12:05 ` [PATCH mm-hotfixes 2/2] mm/huge_memory: fix huge_zero_pfn race Lorenzo Stoakes (ARM)
2026-07-30  9:22   ` David Hildenbrand (Arm)
2026-07-30  9:55     ` Lorenzo Stoakes (ARM)
2026-07-28 19:02 ` [PATCH mm-hotfixes 0/2] " David Hildenbrand (Arm)
2026-07-29  8:15   ` Lorenzo Stoakes (ARM)
2026-07-30  0:55     ` Andrew Morton
2026-07-30  9:05     ` David Hildenbrand (Arm)
2026-07-30  9:15       ` Lorenzo Stoakes (ARM) [this message]

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=amsUw6_DjKRg3gJq@lucifer \
    --to=ljs@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=hare@suse.de \
    --cc=hughd@google.com \
    --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=npache@redhat.com \
    --cc=p.raghav@samsung.com \
    --cc=ryan.roberts@arm.com \
    --cc=shy828301@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=uqbarz@gmail.com \
    --cc=usama.arif@linux.dev \
    --cc=ziy@nvidia.com \
    /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