Re: [PATCH v2] mm: avoid KCSAN false positive in memdesc_nid()
From: Andrew Morton
Date: Wed Jun 24 2026 - 21:58:38 EST
On Thu, 25 Jun 2026 01:32:49 +0000 "Hui Zhu" <hui.zhu@xxxxxxxxx> wrote:
> Good catch. ASSERT_EXCLUSIVE_BITS(mdf.f, ...) is checking a by-value
> copy of the flags word inside memdesc_nid(), not the actual shared
> page->flags/folio->flags being modified by folio_trylock(). Whatever
> made it appear to suppress the KCSAN report is likely an artifact of
> inlining/codegen (kcsan_atomic_next() happening to land on the real
> load after inlining), not a principled fix - so Sashiko's pass is
> not reassuring here.
Yeah, I was wondering if the inlining accidentally gave the macro the
correct thing. Which seems wrong - an inlined function should treat an
incoming arg purely as a local thing. Maybe we fooled the compiler.
> I'll move the assertion to where the real dereference happens (at
> the page_to_nid()/folio_nid() call sites) instead of inside the
> by-value helper. This probably also applies to the existing
> memdesc_zonenum() pattern - is that one actually verified to work,
> or does it have the same issue?
I assume the memdesc_zonenum() code worked, for the same (poorly
understood) reason as did your patch.
Yes, moving this into the sites where we officially have access to the
shared storage seems the right approach.