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

From: David Hildenbrand (Arm)

Date: Tue Dec 01 2026 - 04:45:29 EST


On 11/29/26 20:47, 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.

Agreed, I guess I'll just drop the comment entirely :)

--
Cheers,

David