Re: [PATCH 03/32] mm/shmem: reject userfaultfd fills during hole punch

From: Baolin Wang

Date: Wed Dec 02 2026 - 06:26:09 EST




On 11/30/26 3:47 AM, Jose A. Perez de Azpillaga wrote:
On 11/29/26 11:06 AM, 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.


the -EAGAIN approach looks good to me.

[snip]

+/* Disallow placing folios while hole-punch or a pin scan is in progress. */
+static bool __shmem_faults_blocked(struct inode *inode, pgoff_t pgoff)

to me this reads weird. I would drop the pin scan part, since only the
hole punch sets ->waitq.

+1.

Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>

otherwise LGTM:

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