Commit 279eacbe authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: selftests: Multiplex return code and fd in __kvm_create_device()

Multiplex the return value and fd (on success) in __kvm_create_device()
to mimic common library helpers that return file descriptors, e.g. open().
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 98f94ce4
...@@ -643,8 +643,8 @@ static void test_v3_its_region(void) ...@@ -643,8 +643,8 @@ static void test_v3_its_region(void)
int test_kvm_device(uint32_t gic_dev_type) int test_kvm_device(uint32_t gic_dev_type)
{ {
struct vm_gic v; struct vm_gic v;
int ret, fd;
uint32_t other; uint32_t other;
int ret;
v.vm = vm_create_default_with_vcpus(NR_VCPUS, 0, 0, guest_code, NULL); v.vm = vm_create_default_with_vcpus(NR_VCPUS, 0, 0, guest_code, NULL);
...@@ -658,8 +658,8 @@ int test_kvm_device(uint32_t gic_dev_type) ...@@ -658,8 +658,8 @@ int test_kvm_device(uint32_t gic_dev_type)
return ret; return ret;
v.gic_fd = kvm_create_device(v.vm, gic_dev_type); v.gic_fd = kvm_create_device(v.vm, gic_dev_type);
ret = __kvm_create_device(v.vm, gic_dev_type, &fd); ret = __kvm_create_device(v.vm, gic_dev_type);
TEST_ASSERT(ret && errno == EEXIST, "create GIC device twice"); TEST_ASSERT(ret < 0 && errno == EEXIST, "create GIC device twice");
/* try to create the other gic_dev_type */ /* try to create the other gic_dev_type */
other = VGIC_DEV_IS_V2(gic_dev_type) ? KVM_DEV_TYPE_ARM_VGIC_V3 other = VGIC_DEV_IS_V2(gic_dev_type) ? KVM_DEV_TYPE_ARM_VGIC_V3
......
...@@ -485,7 +485,7 @@ void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...); ...@@ -485,7 +485,7 @@ void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...);
int _kvm_device_check_attr(int dev_fd, uint32_t group, uint64_t attr); int _kvm_device_check_attr(int dev_fd, uint32_t group, uint64_t attr);
int kvm_device_check_attr(int dev_fd, uint32_t group, uint64_t attr); int kvm_device_check_attr(int dev_fd, uint32_t group, uint64_t attr);
int __kvm_test_create_device(struct kvm_vm *vm, uint64_t type); int __kvm_test_create_device(struct kvm_vm *vm, uint64_t type);
int __kvm_create_device(struct kvm_vm *vm, uint64_t type, int *fd); int __kvm_create_device(struct kvm_vm *vm, uint64_t type);
int kvm_create_device(struct kvm_vm *vm, uint64_t type); int kvm_create_device(struct kvm_vm *vm, uint64_t type);
int _kvm_device_access(int dev_fd, uint32_t group, uint64_t attr, int _kvm_device_access(int dev_fd, uint32_t group, uint64_t attr,
void *val, bool write); void *val, bool write);
......
...@@ -51,8 +51,9 @@ int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs, ...@@ -51,8 +51,9 @@ int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs,
nr_vcpus, nr_vcpus_created); nr_vcpus, nr_vcpus_created);
/* Distributor setup */ /* Distributor setup */
if (__kvm_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3, &gic_fd)) gic_fd = __kvm_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3);
return -1; if (gic_fd < 0)
return gic_fd;
kvm_device_access(gic_fd, KVM_DEV_ARM_VGIC_GRP_NR_IRQS, kvm_device_access(gic_fd, KVM_DEV_ARM_VGIC_GRP_NR_IRQS,
0, &nr_irqs, true); 0, &nr_irqs, true);
......
...@@ -1639,27 +1639,25 @@ int __kvm_test_create_device(struct kvm_vm *vm, uint64_t type) ...@@ -1639,27 +1639,25 @@ int __kvm_test_create_device(struct kvm_vm *vm, uint64_t type)
return __vm_ioctl(vm, KVM_CREATE_DEVICE, &create_dev); return __vm_ioctl(vm, KVM_CREATE_DEVICE, &create_dev);
} }
int __kvm_create_device(struct kvm_vm *vm, uint64_t type, int *fd) int __kvm_create_device(struct kvm_vm *vm, uint64_t type)
{ {
struct kvm_create_device create_dev = { struct kvm_create_device create_dev = {
.type = type, .type = type,
.fd = -1, .fd = -1,
.flags = 0, .flags = 0,
}; };
int ret; int err;
ret = __vm_ioctl(vm, KVM_CREATE_DEVICE, &create_dev); err = __vm_ioctl(vm, KVM_CREATE_DEVICE, &create_dev);
*fd = create_dev.fd; TEST_ASSERT(err <= 0, "KVM_CREATE_DEVICE shouldn't return a positive value");
return ret; return err ? : create_dev.fd;
} }
int kvm_create_device(struct kvm_vm *vm, uint64_t type) int kvm_create_device(struct kvm_vm *vm, uint64_t type)
{ {
int fd, ret; int fd = __kvm_create_device(vm, type);
ret = __kvm_create_device(vm, type, &fd);
TEST_ASSERT(!ret, "KVM_CREATE_DEVICE IOCTL failed, rc: %i errno: %i", ret, errno); TEST_ASSERT(fd >= 0, "KVM_CREATE_DEVICE IOCTL failed, rc: %i errno: %i", fd, errno);
return fd; return fd;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment