Re: [PATCH RFC 3/9] mm: add __GFP_PREZEROED flag and folio_test_clear_prezeroed()

David Hildenbrand (Arm)
2026-04-14T09:06:32Z

On 4/14/26 01:43, Michael S. Tsirkin wrote:
> On Mon, Apr 13, 2026 at 06:06:14PM -0400, Michael S. Tsirkin wrote:
>> On Mon, Apr 13, 2026 at 11:05:40AM +0200, David Hildenbrand (Arm) wrote:
>>
>> ...
>>
>>> (2) Use a dedicated allocation interface for user pages in the buddy.
>>>
>>> I hate the whole user_alloc_needs_zeroing()+folio_zero_user() handling.
>>>
>>> It shouldn't exist. We should just be passing GFP_ZERO and let the buddy handle
>>> all that.
>>>
>>>
>>> For example, vma_alloc_folio() already gets passed the address in.
>>>
>>> Pass the address from vma_alloc_folio_noprof()->folio_alloc_noprof(), and let
>>> folio_alloc_noprof() use a buddy interface that can handle it.
>>>
>>> Imagine if we had a alloc_user_pages_noprof() that consumes an address. It could just
>>> do what folio_zero_user() does, and only if really required.
>>>
>>> The whole user_alloc_needs_zeroing() could go away and you could just handle the
>>> pre-zeroed optimization internally.
>>
>> I looked at this a bit, and I think the issue is that the buddy
>> allocator doesn't do the arch-specific cache handling.
>> So allocating it is a fundamentally different thing from GFP_ZERO which
>> is "zero a kernel address range".
>>
>> So I don't get how you want to do it.
>

Saw your new mails just now.

> Oh, wait, do you mean we thread the userspace address through all the allocation calls?
> Like the below? This is on top of my patches, on top of mm it will be
> a tiny bit smaller. I can rebase no problem.
>
> But: isn't it a bit overkill for something that is, in the end, virtualization specific?
> It's all mechanical threading through of user_addr, but should we miss
> one place, and suddenly you get weird corruption on esoteric arches
> since we will get memset instead of folio_zero_user.
>
> Worth it?

See my other mail, we'd be forwarding it only for
vma_alloc_folio_noprof(), where we call a _user specific interface.

Then we can get rid of the user_alloc_needs_zeroing() hack and just do
the right thing in page_alloc.c

--
Cheers,

David