Commit 4cffb2df authored by Eric Auger's avatar Eric Auger Committed by Marc Zyngier

KVM: selftests: vgic_init kvm selftests fixup

Bring some improvements/rationalization over the first version
of the vgic_init selftests:

- ucall_init is moved in run_cpu()
- vcpu_args_set is not called as not needed
- whenever a helper is supposed to succeed, call the non "_" version
- helpers do not return -errno, instead errno is checked by the caller
- vm_gic struct is used whenever possible, as well as vm_gic_destroy
- _kvm_create_device takes an addition fd parameter
Signed-off-by: default avatarEric Auger <eric.auger@redhat.com>
Suggested-by: default avatarAndrew Jones <drjones@redhat.com>
Reviewed-by: default avatarAndrew Jones <drjones@redhat.com>
Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20210407135937.533141-1-eric.auger@redhat.com
parent dc0e058e
......@@ -225,7 +225,7 @@ void *vcpu_map_dirty_ring(struct kvm_vm *vm, uint32_t vcpuid);
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_create_device(struct kvm_vm *vm, uint64_t type, bool test);
int _kvm_create_device(struct kvm_vm *vm, uint64_t type, bool test, int *fd);
int kvm_create_device(struct kvm_vm *vm, uint64_t type, bool test);
int _kvm_device_access(int dev_fd, uint32_t group, uint64_t attr,
void *val, bool write);
......
......@@ -1739,22 +1739,19 @@ int _kvm_device_check_attr(int dev_fd, uint32_t group, uint64_t attr)
.attr = attr,
.flags = 0,
};
int ret = ioctl(dev_fd, KVM_HAS_DEVICE_ATTR, &attribute);
if (ret == -1)
return -errno;
return 0;
return ioctl(dev_fd, KVM_HAS_DEVICE_ATTR, &attribute);
}
int kvm_device_check_attr(int dev_fd, uint32_t group, uint64_t attr)
{
int ret = _kvm_device_check_attr(dev_fd, group, attr);
TEST_ASSERT(ret >= 0, "KVM_HAS_DEVICE_ATTR failed, errno: %i", errno);
TEST_ASSERT(ret >= 0, "KVM_HAS_DEVICE_ATTR failed, rc: %i errno: %i", ret, errno);
return ret;
}
int _kvm_create_device(struct kvm_vm *vm, uint64_t type, bool test)
int _kvm_create_device(struct kvm_vm *vm, uint64_t type, bool test, int *fd)
{
struct kvm_create_device create_dev;
int ret;
......@@ -1763,17 +1760,21 @@ int _kvm_create_device(struct kvm_vm *vm, uint64_t type, bool test)
create_dev.fd = -1;
create_dev.flags = test ? KVM_CREATE_DEVICE_TEST : 0;
ret = ioctl(vm_get_fd(vm), KVM_CREATE_DEVICE, &create_dev);
if (ret == -1)
return -errno;
return test ? 0 : create_dev.fd;
*fd = create_dev.fd;
return ret;
}
int kvm_create_device(struct kvm_vm *vm, uint64_t type, bool test)
{
int ret = _kvm_create_device(vm, type, test);
int fd, ret;
TEST_ASSERT(ret >= 0, "KVM_CREATE_DEVICE IOCTL failed,\n"
" errno: %i", errno);
ret = _kvm_create_device(vm, type, test, &fd);
if (!test) {
TEST_ASSERT(ret >= 0,
"KVM_CREATE_DEVICE IOCTL failed, rc: %i errno: %i", ret, errno);
return fd;
}
return ret;
}
......@@ -1790,8 +1791,6 @@ int _kvm_device_access(int dev_fd, uint32_t group, uint64_t attr,
ret = ioctl(dev_fd, write ? KVM_SET_DEVICE_ATTR : KVM_GET_DEVICE_ATTR,
&kvmattr);
if (ret < 0)
return -errno;
return ret;
}
......@@ -1800,8 +1799,7 @@ int kvm_device_access(int dev_fd, uint32_t group, uint64_t attr,
{
int ret = _kvm_device_access(dev_fd, group, attr, val, write);
TEST_ASSERT(ret >= 0, "KVM_SET|GET_DEVICE_ATTR IOCTL failed,\n"
" errno: %i", errno);
TEST_ASSERT(ret >= 0, "KVM_SET|GET_DEVICE_ATTR IOCTL failed, rc: %i errno: %i", ret, errno);
return ret;
}
......
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