From: "David Hildenbrand (Arm)" <david@kernel.org>
To: xueyuan.chen@vivo.com, Andrew Morton <akpm@linux-foundation.org>,
Lorenzo Stoakes <ljs@kernel.org>,
linux-mm@kvack.org
Cc: 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>,
Kiryl Shutsemau <kas@kernel.org>, Bob Liu <lliubbo@gmail.com>,
linux-kernel@vger.kernel.org,
Xueyuan Chen <xueyuan.chen21@gmail.com>
Subject: Re: [PATCH] mm/huge_memory: fix huge zero folio publication race
Date: Wed, 29 Jul 2026 08:44:12 +0200 [thread overview]
Message-ID: <37c40d62-51e2-45b4-9837-a4b96d1640b3@kernel.org> (raw)
In-Reply-To: <4ee89c27873fb4d9e598f8a5cfe71d700ecf894e.1785300563.git.xueyuan.chen@vivo.com>
On 7/29/26 06:50, xueyuan.chen@vivo.com wrote:
> From: Xueyuan Chen <xueyuan.chen@vivo.com>
>
> get_huge_zero_folio() uses huge_zero_refcount as the publication gate for
> lockless users. However, it publishes huge_zero_folio with cmpxchg()
> before storing huge_zero_pfn and initializes the refcount with an unordered
> atomic_set().
>
> On weakly ordered systems, a racing atomic_inc_not_zero() can observe the
> nonzero refcount without observing the huge_zero_pfn store.
> is_huge_zero_pmd() can then misidentify a huge zero PMD as a regular
> anonymous THP. The write-protect fault path may consequently mark the
> global huge zero folio anonymous, exclusive and writable.
>
> Use atomic_set_release() to publish the initialized folio and PFN. A
> successful atomic_inc_not_zero() is fully ordered, so a reader that obtains
> a reference also observes the state published before the refcount became
> nonzero.
>
> Fixes: 97ae17497e99 ("thp: implement refcounting for huge zero page")
> Cc: stable@vger.kernel.org
> Signed-off-by: Xueyuan Chen <xueyuan.chen@vivo.com>
> ---
> mm/huge_memory.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 032702a4637b..6c74d0375377 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -245,8 +245,11 @@ static bool get_huge_zero_folio(void)
> }
> WRITE_ONCE(huge_zero_pfn, folio_pfn(zero_folio));
>
> - /* We take additional reference here. It will be put back by shrinker */
> - atomic_set(&huge_zero_refcount, 2);
> + /*
> + * Publish the folio and PFN before making them available to lockless
> + * users. Pairs with a successful atomic_inc_not_zero() above.
> + */
> + atomic_set_release(&huge_zero_refcount, 2);
> preempt_enable();
> count_vm_event(THP_ZERO_PAGE_ALLOC);
> return true;
https://lore.kernel.org/r/20260728-fix-refcounted-huge-zero-v1-0-3f261f5447b4@kernel.org
--
Cheers,
David
next parent reply other threads:[~2026-07-29 6:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4ee89c27873fb4d9e598f8a5cfe71d700ecf894e.1785300563.git.xueyuan.chen@vivo.com>
2026-07-29 6:44 ` David Hildenbrand (Arm) [this message]
2026-07-30 1:02 ` Andrew Morton
2026-07-30 7:27 ` Lorenzo Stoakes (ARM)
2026-07-30 13:40 ` Xueyuan Chen
2026-07-30 14:02 ` Lorenzo Stoakes (ARM)
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=37c40d62-51e2-45b4-9837-a4b96d1640b3@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=dev.jain@arm.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=ljs@kernel.org \
--cc=lliubbo@gmail.com \
--cc=npache@redhat.com \
--cc=ryan.roberts@arm.com \
--cc=usama.arif@linux.dev \
--cc=xueyuan.chen21@gmail.com \
--cc=xueyuan.chen@vivo.com \
--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
all inboxes | Powered by JetHome®