On Wed, Mar 16, 2022 at 12:08:23PM -0600, Ben Gardon wrote: > On Fri, Mar 11, 2022 at 12:02 AM Ricardo Koller <ricarkol@xxxxxxxxxx> wrote: > > > > Add a library function to get the backing source FD of a memslot. > > > > Signed-off-by: Ricardo Koller <ricarkol@xxxxxxxxxx> > > This appears to be dead code as of this commit, would recommend > merging it into the commit in which it's actually used. I was trying to separate lib changes (which are mostly arch independent) with the actual test. Would move the commit to be right before the one that uses be better? and maybe add a commit comment mentioning how it's going to be used. > > > --- > > .../selftests/kvm/include/kvm_util_base.h | 1 + > > tools/testing/selftests/kvm/lib/kvm_util.c | 23 +++++++++++++++++++ > > 2 files changed, 24 insertions(+) > > > > diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h > > index 4ed6aa049a91..d6acec0858c0 100644 > > --- a/tools/testing/selftests/kvm/include/kvm_util_base.h > > +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h > > @@ -163,6 +163,7 @@ int _kvm_ioctl(struct kvm_vm *vm, unsigned long ioctl, void *arg); > > void vm_mem_region_set_flags(struct kvm_vm *vm, uint32_t slot, uint32_t flags); > > void vm_mem_region_move(struct kvm_vm *vm, uint32_t slot, uint64_t new_gpa); > > void vm_mem_region_delete(struct kvm_vm *vm, uint32_t slot); > > +int vm_mem_region_get_src_fd(struct kvm_vm *vm, uint32_t memslot); > > void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid); > > vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min); > > vm_vaddr_t vm_vaddr_alloc_pages(struct kvm_vm *vm, int nr_pages); > > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c > > index d8cf851ab119..64ef245b73de 100644 > > --- a/tools/testing/selftests/kvm/lib/kvm_util.c > > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c > > @@ -580,6 +580,29 @@ kvm_userspace_memory_region_find(struct kvm_vm *vm, uint64_t start, > > return ®ion->region; > > } > > > > +/* > > + * KVM Userspace Memory Get Backing Source FD > > + * > > + * Input Args: > > + * vm - Virtual Machine > > + * memslot - KVM memory slot ID > > + * > > + * Output Args: None > > + * > > + * Return: > > + * Backing source file descriptor, -1 if the memslot is an anonymous region. > > + * > > + * Returns the backing source fd of a memslot, so tests can use it to punch > > + * holes, or to setup permissions. > > + */ > > +int vm_mem_region_get_src_fd(struct kvm_vm *vm, uint32_t memslot) > > +{ > > + struct userspace_mem_region *region; > > + > > + region = memslot2region(vm, memslot); > > + return region->fd; > > +} > > + > > /* > > * VCPU Find > > * > > -- > > 2.35.1.723.g4982287a31-goog > >