Re: [PATCH v2 09/15] mm/memfd: recheck the page cache before allocating a hugetlb folio
From: Gregory Price (Meta)
Date: Tue Nov 17 2026 - 03:34:29 EST
On 2026-11-16 19:29 +0100, David Hildenbrand (Arm) wrote:
> A concurrent fault or PIN request can populate the page cache
> after memfd_pin_folios() misses it in the page cache but before
> memfd_alloc_folio() takes the fault mutex. The latter still tries to
> allocate another folio and can return -ENOMEM even though the requested
> folio is already cached.
>
> In particular, hugetlb_reserve_pages() finds the existing reservation-map
> entry and reserves nothing. If no global reservations remain,
> alloc_hugetlb_folio_reserve() fails even when the pool has free pages,
> effectively failing memfd_pin_folios().
>
> Recheck the page cache before reserving or allocating. If the folio is
> present, drop the lookup reference and return -EEXIST so
> memfd_pin_folios() retries its lookup.
>
> This is probably not worth backporting to stable.
>
> Fixes: 89c1905d9c14 ("mm/gup: introduce memfd_pin_folios() for pinning memfd folios")
> Reported-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
> Acked-by: Muchun Song <muchun.song@xxxxxxxxx>
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
Reproduced using udmabuf to race and generated very consistent failures.
Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
--
~Gregory