aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/kvm/lib
diff options
context:
space:
mode:
authorSean Christopherson <seanjc@google.com>2022-02-16 13:53:23 -0800
committerPaolo Bonzini <pbonzini@redhat.com>2022-06-11 11:47:21 -0400
commit5260db3eb8f96c0dc631b0f41035a5f1957d9a58 (patch)
tree66272430d03639e2957b5b6e66903a8305dde97f /tools/testing/selftests/kvm/lib
parentKVM: selftests: Remove vcpu_get() usage from dirty_log_test (diff)
downloadlinux-dev-5260db3eb8f96c0dc631b0f41035a5f1957d9a58.tar.xz
linux-dev-5260db3eb8f96c0dc631b0f41035a5f1957d9a58.zip
KVM: selftests: Require vCPU output array when creating VM with vCPUs
Require the caller of __vm_create_with_vcpus() to provide a non-NULL array of vCPUs now that all callers do so. It's extremely unlikely a test will have a legitimate use case for creating a VM with vCPUs without wanting to do something with those vCPUs, and if there is such a use case, requiring that one-off test to provide a dummy array is a minor annoyance. Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tools/testing/selftests/kvm/lib')
-rw-r--r--tools/testing/selftests/kvm/lib/kvm_util.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index c338713d8245..351c167e7b99 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -302,10 +302,11 @@ struct kvm_vm *__vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus
struct kvm_vcpu *vcpus[])
{
uint64_t vcpu_pages, extra_pg_pages, pages;
- struct kvm_vcpu *vcpu;
struct kvm_vm *vm;
int i;
+ TEST_ASSERT(!nr_vcpus || vcpus, "Must provide vCPU array");
+
/* Force slot0 memory size not small than DEFAULT_GUEST_PHY_PAGES */
if (slot0_mem_pages < DEFAULT_GUEST_PHY_PAGES)
slot0_mem_pages = DEFAULT_GUEST_PHY_PAGES;
@@ -326,11 +327,8 @@ struct kvm_vm *__vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus
vm = __vm_create(mode, pages);
- for (i = 0; i < nr_vcpus; ++i) {
- vcpu = vm_vcpu_add(vm, i, guest_code);
- if (vcpus)
- vcpus[i] = vcpu;
- }
+ for (i = 0; i < nr_vcpus; ++i)
+ vcpus[i] = vm_vcpu_add(vm, i, guest_code);
return vm;
}