Re: [PATCH v2 04/35] mm/hugetlb: return the reservation to the subpool on error

From: Jose A. Perez de Azpillaga

Date: Fri Dec 04 2026 - 05:27:01 EST


On 12/3/26 12:37 PM, David Hildenbrand (Arm) wrote:
> When we fault in a folio in a shared hugetlb mapping at an index that is
> not reserved yet on a min_size= mount, alloc_hugetlb_folio() can take the
> reservation from the subpool minimum, and we perform the reservation for
> the folio's index in the reserve map.
>
> If something goes wrong before adding the folio to the page cache,
> restore_reserve_on_error() is supposed to undo the reservation in the
> reserve map, and free_huge_folio() is supposed to return the reservation
> to the subpool, like we do for CoW mappings already.
>
> However, as the folio consumed a global reservation, it has
> HPG_restore_reserve set. So restore_reserve_on_error() keeps the
> reservation in the reserve map, and free_huge_folio() restores the global
> reservation instead of returning it to the subpool.
>
> Consequently, the reservation from the subpool minimum is stuck at that
> index until truncation. As vma_commit_reservation() does not charge the
> hugetlb cgroup reservation, a later fault at that index will consume it
> without a cgroup charge.
>
> Reproduced with a failing UFFDIO_COPY on a min_size= mount, followed by
> a fault at the same index, inside a hugetlb cgroup:
>
> hugetlb.2MB.rsvd.current: 0 instead of 2097152
>
> Let's fix it by clearing HPG_restore_reserve in shared mappings as well.
> On success, adding the folio to the page cache clears the flag.
>
> Note that we have to clear the flag before vma_commit_reservation()
> now, such that the race handling can set it again when we raced with
> another reservation.
>
> This has low urgency, as it only affects the subpool minimum and the
> hugetlb cgroup reservation accounting on min_size= mounts.
>
> Fixes: 1c5ecae3a93f ("hugetlbfs: add minimum size accounting to subpools")
> Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

with sashiko's points addressed:

Reviewed-by: Jose A. Perez de Azpillaga <azpijr@xxxxxxxxx>

--
cheers,
jose a. p-a