Re: [PATCH 03/32] mm/shmem: reject userfaultfd fills during hole punch
From: Gregory Price (Meta)
Date: Tue Dec 01 2026 - 08:49:50 EST
On 2026-11-29 11:06 +0100, David Hildenbrand (Arm) wrote:
> While punching a shmem/tmpfs hole, regular page faults in the range wait
> for the hole punch to finish, but UFFDIO_COPY, UFFDIO_ZEROPAGE and
> UFFDIO_CONTINUE keep mapping pages into it. The hole punch must then
> repeatedly walk the file's VMAs to unmap these pages, while holding
> i_rwsem.
>
> Consequently, punching a hole can become very slow if userfaultfd keeps
> filling the range, blocking other writers. Any user that can read the
> file can trigger that through a MAP_PRIVATE mapping and UFFDIO_CONTINUE.
>
> Let's fix it by making UFFDIO_COPY, UFFDIO_ZEROPAGE and UFFDIO_CONTINUE
> return -EAGAIN when faults in the range are blocked, so user space can
> retry, instead of waiting in the uffd code.
>
> Returning -EAGAIN simplifies the implementation. These ioctls already
> return -EAGAIN, including before making any progress: for example,
> UFFDIO_CONTINUE can encounter this when khugepaged removes a shmem page
> table concurrently.
>
> QEMU, for example, prevents concurrent RAM discards and page placement
> during incoming postcopy entirely. Applications that allow concurrent
> hole punching and do not handle -EAGAIN could be affected, although
> existing races would already require proper -EAGAIN handling.
>
> The existing uffd code already handles partial progress and wakes
> resolved faults properly.
>
> Share the range check with shmem_falloc_wait() and preserve -EAGAIN from
> the filesystem in the UFFDIO_CONTINUE path.
>
> This has medium urgency, as unprivileged users can make a hole punch,
> and writers of the file, stall for minutes.
>
> Fixes: 4c27fe4c4c84 ("userfaultfd: shmem: add shmem_mcopy_atomic_pte for userfaultfd support")
> Cc: stable@xxxxxxxxxxxxxxx
> Reported-by: Chris Mason <mason@xxxxxxxxxx>
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
Reviewed-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
--
~Gregory