Re: [PATCH 09/32] mm/khugepaged: check for uffd outside the i_pages lock
From: Gregory Price (Meta)
Date: Wed Dec 02 2026 - 00:36:35 EST
On 2026-11-29 11:06 +0100, David Hildenbrand (Arm) wrote:
> collapse_file() walks the VMAs mapping a shmem range to check for UFFD
> missing registrations before filling holes. It does this with the
> i_pages lock held and interrupts disabled.
>
> Consequently, a large number of mappings can cause excessive interrupt
> latency.
>
> Let's fix it by moving the walk before taking the i_pages lock. Hold
> i_mmap_rwsem for read until the retry entries are stored, and take it for
> write when registering UFFD missing mode on a file-backed VMA. This
> prevents new missing-mode registrations between checking the VMAs and
> installing the retry entries.
>
> Move hole counting and retry-entry insertion into
> collapse_file_mark_holes().
>
> Also pass end - 1 to mapping_rmap_tree_foreach(), which takes an
> inclusive last index. Otherwise, a UFFD missing-mode registration
> immediately beyond the collapse range can incorrectly prevent collapse.
>
> This has medium urgency, as unprivileged users can trigger it.
>
> Fixes: ac492b9c70ca ("mm/khugepaged: skip shmem with userfaultfd")
> Cc: stable@xxxxxxxxxxxxxxx
> Reported-by: Chris Mason <mason@xxxxxxxxxx>
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
Was able to reproduce/validate that adjacent entries in that off-by-one
overlap can now collapse without EBUSY. Also validated that actual
overlaps can still return EBUSY.
Hammered on the exact conditions dealt with here so decent confidence
this change is correct.
Otherwise seems pretty reasonable to me.
Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
Reviewed-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
--
~Gregory