Re: [RFC PATCH v2 33/51] KVM: guest_memfd: Allocate and truncate from custom allocator

From: Ackerley Tng
Date: Wed Jul 16 2025 - 18:14:56 EST


Binbin Wu <binbin.wu@xxxxxxxxxxxxxxx> writes:

> On 5/15/2025 7:42 AM, Ackerley Tng wrote:
> [...]
>>
>> list_for_each_entry(gmem, gmem_list, entry)
>> kvm_gmem_invalidate_end(gmem, start, end);
>> @@ -776,6 +879,16 @@ static long kvm_gmem_allocate(struct inode *inode, loff_t offset, loff_t len)
>>
>> start = offset >> PAGE_SHIFT;
>> end = (offset + len) >> PAGE_SHIFT;
>> + if (kvm_gmem_has_custom_allocator(inode)) {
>> + size_t nr_pages;
>> + void *p;
>> +
>> + p = kvm_gmem_allocator_private(inode);
>> + nr_pages = kvm_gmem_allocator_ops(inode)->nr_pages_in_folio(p);
>> +
>> + start = round_down(start, nr_pages);
>> + end = round_down(end, nr_pages);
> It's weird here.
> Should the end be round_up()?
>

Thanks, you're right.

I believe the current consensus is that fallocate() will only be
permitted for offset and lengths that are aligned not only to PAGE_SIZE
but to allocator page size.

In a future revision I'll check for allocator page size earlier on,
before this function will get called, so this rounding will probably go
away.

>> + }
>>
>> r = 0;
>> for (index = start; index < end; ) {
>>
> [...]