Thread (79 messages) 79 messages, 10 authors, 2025-10-07

Re: [PATCH 25/34] KVM: selftests: Add helpers to convert guest memory b/w private and shared

From: Sean Christopherson <seanjc@google.com>
Date: 2023-11-06 16:13:05
Also in: kvm, kvm-riscv, kvmarm, linux-arm-kernel, linux-fsdevel, linux-mips, linux-mm, linux-riscv, lkml

On Mon, Nov 06, 2023, Fuad Tabba wrote:
On Sun, Nov 5, 2023 at 4:34 PM Paolo Bonzini [off-list ref] wrote:
quoted
+void vm_guest_mem_fallocate(struct kvm_vm *vm, uint64_t base, uint64_t size,
+                           bool punch_hole)
+{
+       const int mode = FALLOC_FL_KEEP_SIZE | (punch_hole ? FALLOC_FL_PUNCH_HOLE : 0);
+       struct userspace_mem_region *region;
+       uint64_t end = base + size;
+       uint64_t gpa, len;
+       off_t fd_offset;
+       int ret;
+
+       for (gpa = base; gpa < end; gpa += len) {
+               uint64_t offset;
+
+               region = userspace_mem_region_find(vm, gpa, gpa);
+               TEST_ASSERT(region && region->region.flags & KVM_MEM_GUEST_MEMFD,
+                           "Private memory region not found for GPA 0x%lx", gpa);
+
+               offset = (gpa - region->region.guest_phys_addr);
nit: why the parentheses?
I simply forgot to remove them when I changed the function to support spanning
multiple memslots, i.e. when the code went from this

	fd_offset = region->region.gmem_offset +
		    (gpa - region->region.guest_phys_addr);

to what you see above.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help