From: "Hui Zhu" <hui.zhu@linux.dev>
To: "Andrew Morton" <akpm@linux-foundation.org>
Cc: "David Hildenbrand" <david@kernel.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>,
"Kairui Song" <kasong@tencent.com>,
"Qi Zheng" <qi.zheng@linux.dev>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Barry Song" <baohua@kernel.org>,
"Axel Rasmussen" <axelrasmussen@google.com>,
"Yuanchu Xie" <yuanchu@google.com>, "Wei Xu" <weixugc@google.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
"Hui Zhu" <zhuhui@kylinos.cn>
Subject: Re: [PATCH v11] mm: fix ASSERT_EXCLUSIVE_BITS by passing memdesc_flags_t by pointer
Date: Thu, 09 Jul 2026 04:29:15 +0000 [thread overview]
Message-ID: <220399d6c91aa81704eca2f1485fed2b11bbaf1f@linux.dev> (raw)
In-Reply-To: <20260708204853.8542f27d6554c1ff3ce7162e@linux-foundation.org>
>
> On Wed, 8 Jul 2026 16:33:08 +0800 Hui Zhu <hui.zhu@linux.dev> wrote:
>
> >
> > From: Hui Zhu <zhuhui@kylinos.cn>
> >
> > KCSAN reports a data race between page_to_nid()/folio_pgdat() reading
> > page->flags and folio_trylock()/folio_lock() concurrently doing
> > test_and_set_bit_lock(PG_locked, ...) on the same word, e.g.:
> >
> > BUG: KCSAN: data-race in __lruvec_stat_mod_folio / shmem_get_folio_gfp
> >
> > The race is benign: nid/zone bits are set once at page init and never
> > overlap with PG_locked. However, ASSERT_EXCLUSIVE_BITS() inside
> > memdesc_nid/zonenum() was checking a by-value copy of the flags word,
> > not the live page->flags, so it failed to annotate the real access.
> >
> > Change memdesc_nid(), memdesc_zonenum(), memdesc_section(), and
> > memdesc_is_zone_device() to take a const memdesc_flags_t * and update
> > all callers to pass &page->flags / &folio->flags, so
> > ASSERT_EXCLUSIVE_BITS() operates on the actual shared word.
> >
> > Guard the ASSERT_EXCLUSIVE_BITS() call in memdesc_zonenum() under
> > ZONES_WIDTH != 0 to avoid a zero-mask check on configs where the zone
> > field is absent. memdesc_section() needs no such guard, since
> > SECTIONS_WIDTH is never 0 wherever SECTION_IN_PAGE_FLAGS is defined.
> > Under CONFIG_NUMA=n, memdesc_nid() itself is stubbed to "return 0"
> > instead of reading page->flags, since NODES_MASK is 0 and the check
> > can never fire; page_to_nid()/folio_nid() now just call memdesc_nid()
> > unconditionally and rely on that stub, instead of duplicating the
> > CONFIG_NUMA split at each call site.
> >
> Thanks.
>
> >
> > Co-developed-by: David Hildenbrand (Arm) <david@kernel.org>
> > Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
> > Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
> > Acked-by: David Hildenbrand (Arm) <david@kernel.org>
> > ---
> > Changelog:
> > v11:
> > According to the comments of David, simplify page_to_nid() to pass
> > &(PF_POISONED_CHECK(page)->flags) directly.
> > v10:
> > According to the comments of David, drop the redundant CONFIG_NUMA split
> > in page_to_nid()/folio_nid() and remove the SECTIONS_WIDTH != 0 guard
> > around ASSERT_EXCLUSIVE_BITS() in memdesc_section().
> >
> I'm having trouble comparing this changelogging with the actual v9->v11
> diff? "drop the redundant CONFIG_NUMA split"?
Because memdesc_nid already handles the non-config_NUMa case, the code
for page_to_nid and folio_nid handling the non-config_NUMa case is removed.
Sorry for the trouble, I will write more details in the changelog
next time.
Best,
Hui
>
> --- a/include/linux/mm.h~mm-fix-assert_exclusive_bits-by-passing-memdesc_flags_t-by-pointer-fix
> +++ a/include/linux/mm.h
> @@ -2303,29 +2303,15 @@ static inline int memdesc_nid(const memd
> #endif
> #endif
>
> -#ifdef CONFIG_NUMA
> static inline int page_to_nid(const struct page *page)
> {
> - const struct page *p = PF_POISONED_CHECK(page);
> -
> - return memdesc_nid(&p->flags);
> + return memdesc_nid(&(PF_POISONED_CHECK(page)->flags));
> }
>
> static inline int folio_nid(const struct folio *folio)
> {
> return memdesc_nid(&folio->flags);
> }
> -#else
> -static inline int page_to_nid(const struct page *page)
> -{
> - return 0;
> -}
> -
> -static inline int folio_nid(const struct folio *folio)
> -{
> - return 0;
> -}
> -#endif
>
> #ifdef CONFIG_NUMA_BALANCING
> /* page access time bits needs to hold at least 4 seconds */
> @@ -2566,9 +2552,7 @@ static inline void set_page_section(stru
>
> static inline unsigned long memdesc_section(const memdesc_flags_t *mdf)
> {
> -#if SECTIONS_WIDTH != 0
> ASSERT_EXCLUSIVE_BITS(mdf->f, SECTIONS_MASK << SECTIONS_PGSHIFT);
> -#endif
> return (mdf->f >> SECTIONS_PGSHIFT) & SECTIONS_MASK;
> }
> #else /* !SECTION_IN_PAGE_FLAGS */
> _
>
prev parent reply other threads:[~2026-07-09 4:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 8:33 [PATCH v11] mm: fix ASSERT_EXCLUSIVE_BITS by passing memdesc_flags_t by pointer Hui Zhu
2026-07-09 3:48 ` Andrew Morton
2026-07-09 4:29 ` Hui Zhu [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=220399d6c91aa81704eca2f1485fed2b11bbaf1f@linux.dev \
--to=hui.zhu@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=david@kernel.org \
--cc=kasong@tencent.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=qi.zheng@linux.dev \
--cc=rppt@kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=weixugc@google.com \
--cc=yuanchu@google.com \
--cc=zhuhui@kylinos.cn \
/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