Re: [PATCH v2 22/35] mm/hugetlb: serialize private faults with truncation

From: Jose A. Perez de Azpillaga

Date: Fri Dec 04 2026 - 06:21:21 EST


On 12/3/26 12:37 PM, David Hildenbrand (Arm) wrote:
> When we fault in a folio in a MAP_PRIVATE hugetlb mapping at an index
> without a page cache folio, hugetlb_no_page() checks that the index is
> not beyond EOF, allocates a new anonymous folio and maps it. Truncation
> first updates i_size under the invalidate lock, and then unmaps the
> truncated range from all VMAs.
>
> For page cache folios, we recently started rechecking EOF under
> filemap_invalidate_lock_shared() to handle exactly that.
>
> However, nothing serializes the allocation of anonymous folios with
> truncation: if truncation unmaps the range after we checked EOF, but
> before we mapped the new folio, the folio stays mapped beyond EOF.
>
> Consequently, accessing the truncated range does not raise SIGBUS, and
> the process keeps the folio mapped until it unmaps it.
>
> Reproduced by artificially delaying hugetlb_no_page() before allocating
> the folio, while another thread truncates the file: the page beyond EOF
> stays mapped.
>
> Let's fix it by also rechecking EOF under the invalidate lock for
> anonymous folios, and holding it until we mapped the folio, such that
> truncation will unmap it.
>
> Like faults in shared mappings, faults in private mappings now briefly take
> the invalidate lock in read mode, and might have to wait for a concurrent
> truncation. Which seems to be the right thing to do.
>
> This has low urgency, as it requires racing a page fault in a private
> mapping with truncation. No need to CC stable.
>
> Fixes: fa27759af4a6 ("hugetlb: clean up code checking for fault/truncation races")
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

LGTM:

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

--
cheers,
jose a. p-a