From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Zhenwen Liang <zhenwenliang@google.com>,
David Hildenbrand <david@kernel.org>, Zi Yan <ziy@nvidia.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: "Liam R. Howlett" <liam@infradead.org>,
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>,
Kiryl Shutsemau <kas@kernel.org>,
linux-mm@kvack.org, Lorenzo Stoakes <ljs@kernel.org>
Subject: Re: [PATCH v2] mm/huge_memory: order the MMF_HUGE_ZERO_FOLIO test before the huge_zero_folio load
Date: Mon, 30 Nov 2026 16:11:33 +0800 [thread overview]
Message-ID: <0f23727a-400f-44b6-8932-e06179b34ae6@linux.alibaba.com> (raw)
In-Reply-To: <20261129125223.1182465-1-zhenwenliang@google.com>
On 11/29/26 8:52 PM, Zhenwen Liang wrote:
> With CONFIG_PERSISTENT_HUGE_ZERO_FOLIO=n, mm_get_huge_zero_folio() tests
> MMF_HUGE_ZERO_FOLIO with a plain test_bit() and then loads
> huge_zero_folio, ordered only by a control dependency. A reader can see
> the flag set by another thread of the same mm and still load NULL; the
> fault then falls back to a normal page. Add smp_rmb(), paired with the
> full barrier of mm_flags_test_and_set().
Yes, this is possible. But ...
>
> The problem was found, and this patch prepared, with the help of a
> formal analysis tool we are developing that uses AI assistance; I have
> reviewed the analysis and the patch.
>
> Fixes: 6fcb52a56ff6 ("thp: reduce usage of huge zero page's atomic counter")
> Cc: Lorenzo Stoakes <ljs@kernel.org>
> Signed-off-by: Zhenwen Liang <zhenwenliang@google.com>
> ---
> v2: Shorten the changelog (David Hildenbrand). No code change.
> v1: https://lore.kernel.org/r/20261129024728.282267-1-zhenwenliang@google.com/
>
> mm/huge_memory.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 75e8641bf9ff..c31fc1c7d01e 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -395,8 +395,11 @@ static void __init huge_zero_shrinker_exit(void)
>
> struct folio *mm_get_huge_zero_folio(struct mm_struct *mm)
> {
> - if (mm_flags_test(MMF_HUGE_ZERO_FOLIO, mm))
> + if (mm_flags_test(MMF_HUGE_ZERO_FOLIO, mm)) {
> + /* Paired with the full barrier of mm_flags_test_and_set(). */
> + smp_rmb();
> return READ_ONCE(huge_zero_folio);
> + }
Not a fan of adding a separate rmb() barrier. Why not use the acquire
bit test? Something like:
static inline bool mm_flags_test_acquire(int flag, const struct
mm_struct *mm)
{
return test_bit_acquire(flag, ACCESS_PRIVATE(&mm->flags, __mm_flags));
}
next prev parent reply other threads:[~2026-11-30 8:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 12:52 [PATCH v2] mm/huge_memory: order the MMF_HUGE_ZERO_FOLIO test before the huge_zero_folio load Zhenwen Liang
2026-11-29 13:35 ` Zi Yan
2026-11-30 8:11 ` Baolin Wang [this message]
2026-11-30 12:23 ` David Hildenbrand (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=0f23727a-400f-44b6-8932-e06179b34ae6@linux.alibaba.com \
--to=baolin.wang@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=kas@kernel.org \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=nico.pache@linux.dev \
--cc=ryan.roberts@arm.com \
--cc=usama.arif@linux.dev \
--cc=zhenwenliang@google.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