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

Sean Christopherson seanjc at google.com
Mon Nov 6 08:13:01 PST 2023


On Mon, Nov 06, 2023, Fuad Tabba wrote:
> On Sun, Nov 5, 2023 at 4:34 PM Paolo Bonzini <pbonzini at redhat.com> wrote:
> > +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.



More information about the kvm-riscv mailing list