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

From: Binbin Wu
Date: Tue Jun 03 2025 - 03:44:35 EST




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()?

+ }
r = 0;
for (index = start; index < end; ) {

[...]