Re: [PATCH 09/32] mm/khugepaged: check for uffd outside the i_pages lock
From: Jose A. Perez de Azpillaga
Date: Sun Nov 29 2026 - 15:08:14 EST
On 11/29/26 11:06 AM, 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>
LGTM:
Reviewed-by: Jose A. Perez de Azpillaga <azpijr@xxxxxxxxx>
--
cheers,
jose a. p-a