* [PATCH] KVM: selftests: Require KVM_CAP_USER_MEMORY2 for tests that create memslots
@ 2024-04-30 16:21 Sean Christopherson
2024-05-03 21:32 ` Sean Christopherson
0 siblings, 1 reply; 2+ messages in thread
From: Sean Christopherson @ 2024-04-30 16:21 UTC (permalink / raw)
To: Paolo Bonzini
Cc: kvm, linux-kernel, Dan Carpenter, Shuah Khan, Sean Christopherson
Explicitly require KVM_CAP_USER_MEMORY2 for selftests that create memslots,
i.e. skip selftests that need memslots instead of letting them fail on
KVM_SET_USER_MEMORY_REGION2. While it's ok to take a dependency on new
kernel features, selftests should skip gracefully instead of failing hard
when run on older kernels.
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/all/69ae0694-8ca3-402c-b864-99b500b24f5d@moroto.mountain
Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
tools/testing/selftests/kvm/lib/kvm_util.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 6b2158655baa..ad00e4761886 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -935,6 +935,10 @@ void vm_set_user_memory_region(struct kvm_vm *vm, uint32_t slot, uint32_t flags,
errno, strerror(errno));
}
+#define TEST_REQUIRE_SET_USER_MEMORY_REGION2() \
+ __TEST_REQUIRE(kvm_has_cap(KVM_CAP_USER_MEMORY2), \
+ "KVM selftests now require KVM_SET_USER_MEMORY_REGION2 (introduced in v6.8)")
+
int __vm_set_user_memory_region2(struct kvm_vm *vm, uint32_t slot, uint32_t flags,
uint64_t gpa, uint64_t size, void *hva,
uint32_t guest_memfd, uint64_t guest_memfd_offset)
@@ -949,6 +953,8 @@ int __vm_set_user_memory_region2(struct kvm_vm *vm, uint32_t slot, uint32_t flag
.guest_memfd_offset = guest_memfd_offset,
};
+ TEST_REQUIRE_SET_USER_MEMORY_REGION2();
+
return ioctl(vm->fd, KVM_SET_USER_MEMORY_REGION2, ®ion);
}
@@ -975,6 +981,8 @@ void vm_mem_add(struct kvm_vm *vm, enum vm_mem_backing_src_type src_type,
size_t mem_size = npages * vm->page_size;
size_t alignment;
+ TEST_REQUIRE_SET_USER_MEMORY_REGION2();
+
TEST_ASSERT(vm_adjust_num_guest_pages(vm->mode, npages) == npages,
"Number of guest pages is not compatible with the host. "
"Try npages=%d", vm_adjust_num_guest_pages(vm->mode, npages));
base-commit: 2489e6c9ebb57d6d0e98936479b5f586201379c7
--
2.44.0.769.g3c40516874-goog
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] KVM: selftests: Require KVM_CAP_USER_MEMORY2 for tests that create memslots
2024-04-30 16:21 [PATCH] KVM: selftests: Require KVM_CAP_USER_MEMORY2 for tests that create memslots Sean Christopherson
@ 2024-05-03 21:32 ` Sean Christopherson
0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2024-05-03 21:32 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini
Cc: kvm, linux-kernel, Dan Carpenter, Shuah Khan
On Tue, 30 Apr 2024 09:21:33 -0700, Sean Christopherson wrote:
> Explicitly require KVM_CAP_USER_MEMORY2 for selftests that create memslots,
> i.e. skip selftests that need memslots instead of letting them fail on
> KVM_SET_USER_MEMORY_REGION2. While it's ok to take a dependency on new
> kernel features, selftests should skip gracefully instead of failing hard
> when run on older kernels.
>
>
> [...]
Applied somewhat quickly to kvm-x86 selftests, but feel free to provide feedback.
It's the last commit in "selftests", and I don't have any more selftests patches
in the queue for 6.10, so making changes if someone has a better idea should be
quite easy.
[1/1] KVM: selftests: Require KVM_CAP_USER_MEMORY2 for tests that create memslots
https://github.com/kvm-x86/linux/commit/8a53e1302133
--
https://github.com/kvm-x86/linux/tree/next
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-05-03 21:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-30 16:21 [PATCH] KVM: selftests: Require KVM_CAP_USER_MEMORY2 for tests that create memslots Sean Christopherson
2024-05-03 21:32 ` Sean Christopherson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®