Re: [RFC PATCH] mm/thp: order huge zero folio PFN invalidation before removal
From: David Hildenbrand (Arm)
Date: Fri Jul 24 2026 - 14:55:11 EST
Hi,
How was this issue identified or observed?
On 7/24/26 12:05, Hengbin Zhang wrote:
> The nonpersistent huge-zero shrinker removes huge_zero_folio with
> xchg() and then invalidates huge_zero_pfn. A concurrent fault can
> publish a new folio and its PFN between these operations, after which
> the old shrinker invalidates the new generation's PFN identity.
You mean, the freeing path does
1) xchg(&huge_zero_folio, NULL);
2) WRITE_ONCE(huge_zero_pfn, ~0UL);
Whereby the allocation path does
1) cmpxchg(&huge_zero_folio, NULL, zero_folio)
2) WRITE_ONCE(huge_zero_pfn, folio_pfn(zero_folio));
Sashiko also IMHO correctly complains about a missing barrier when we re-set the
refcount.
So I wonder whether we should just stop these cmpxch games and just use a
spinlock around updating huge_zero_folio+huge_zero_pfn?
--
Cheers,
David