Re: [PATCH 20/46] mm/gup: fix clearing folios in memfd_pin_folios()

From: David Hildenbrand (Arm)

Date: Wed Oct 28 2026 - 17:00:41 EST


On 10/28/26 12:40, Pratyush Yadav wrote:
> On Tue, Oct 27 2026, David Hildenbrand (Arm) wrote:
>
>> On 10/27/26 16:00, Pratyush Yadav wrote:
>>>
>>>
>>> Nit: this logic is repeated in a couple places in shmem.c and in
>>> memfd_luo.c. Perhaps it deserves a helper?
>>>
>>> Anyway, sounds like an important fix so don't make my nitpick stop you
>>> from landing this if you don't want to bother.
>>
>> Thanks! yeah, I had the same thought when trying to improve this. We should have
>> an easier way to just not hand out unzeroed folios outside of shmem core
>> functions in the first place ...
>
> Normally this should use shmem_read_folio() to get all the folios, which
> does zero the folios before handing them out. I guess memfd_pin_folios()
> uses filemap_get_folios_contig() for performance reasons.

That is my recollection from back then, yes.

> It does the
> lookup under RCU and doesn't need to take the folio lock. Perhaps we
> need a shmem_get_folios_contig()?

That sounds like a reasonable cleanup I think, without looking into some
of the nasty details. :)
--
Cheers,

David