aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/kvm/lib
diff options
context:
space:
mode:
authorSean Christopherson <seanjc@google.com>2022-02-17 12:16:20 -0800
committerPaolo Bonzini <pbonzini@redhat.com>2022-06-11 11:46:21 -0400
commit98f94ce42ac672b2abdcf38cfc0e60fd52e04995 (patch)
tree4e3ee8c2a404869ca09821616135fc29dd81e23b /tools/testing/selftests/kvm/lib
parentKVM: selftests: Drop @test param from kvm_create_device() (diff)
downloadlinux-dev-98f94ce42ac672b2abdcf38cfc0e60fd52e04995.tar.xz
linux-dev-98f94ce42ac672b2abdcf38cfc0e60fd52e04995.zip
KVM: selftests: Move KVM_CREATE_DEVICE_TEST code to separate helper
Move KVM_CREATE_DEVICE_TEST to its own helper, identifying "real" versus "test" device creation based on a hardcoded boolean buried in the middle of a param list is painful for readers. 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/aarch64/vgic.c3
-rw-r--r--tools/testing/selftests/kvm/lib/kvm_util.c23
2 files changed, 18 insertions, 8 deletions
diff --git a/tools/testing/selftests/kvm/lib/aarch64/vgic.c b/tools/testing/selftests/kvm/lib/aarch64/vgic.c
index c34f0f116f39..74b4bcaffcfa 100644
--- a/tools/testing/selftests/kvm/lib/aarch64/vgic.c
+++ b/tools/testing/selftests/kvm/lib/aarch64/vgic.c
@@ -51,8 +51,7 @@ int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs,
nr_vcpus, nr_vcpus_created);
/* Distributor setup */
- if (_kvm_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3,
- false, &gic_fd) != 0)
+ if (__kvm_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3, &gic_fd))
return -1;
kvm_device_access(gic_fd, KVM_DEV_ARM_VGIC_GRP_NR_IRQS,
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index cb2e42aa1c03..9c0122b0e393 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -1629,14 +1629,25 @@ int kvm_device_check_attr(int dev_fd, uint32_t group, uint64_t attr)
return ret;
}
-int _kvm_create_device(struct kvm_vm *vm, uint64_t type, bool test, int *fd)
+int __kvm_test_create_device(struct kvm_vm *vm, uint64_t type)
{
- struct kvm_create_device create_dev;
+ struct kvm_create_device create_dev = {
+ .type = type,
+ .flags = KVM_CREATE_DEVICE_TEST,
+ };
+
+ return __vm_ioctl(vm, KVM_CREATE_DEVICE, &create_dev);
+}
+
+int __kvm_create_device(struct kvm_vm *vm, uint64_t type, int *fd)
+{
+ struct kvm_create_device create_dev = {
+ .type = type,
+ .fd = -1,
+ .flags = 0,
+ };
int ret;
- create_dev.type = type;
- create_dev.fd = -1;
- create_dev.flags = test ? KVM_CREATE_DEVICE_TEST : 0;
ret = __vm_ioctl(vm, KVM_CREATE_DEVICE, &create_dev);
*fd = create_dev.fd;
return ret;
@@ -1646,7 +1657,7 @@ int kvm_create_device(struct kvm_vm *vm, uint64_t type)
{
int fd, ret;
- ret = _kvm_create_device(vm, type, false, &fd);
+ ret = __kvm_create_device(vm, type, &fd);
TEST_ASSERT(!ret, "KVM_CREATE_DEVICE IOCTL failed, rc: %i errno: %i", ret, errno);
return fd;