Commit 38d4a385 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: selftests: Add __vcpu_run() helper

Add __vcpu_run() so that tests that want to avoid asserts on KVM_RUN
failures don't need to open code the ioctl() call.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent ffb7c77f
......@@ -55,10 +55,8 @@ static void guest_code(void)
static int run_vcpu(struct kvm_vm *vm, uint32_t vcpuid)
{
ucall_init(vm, NULL);
int ret = __vcpu_ioctl(vm, vcpuid, KVM_RUN, NULL);
if (ret)
return -errno;
return 0;
return __vcpu_run(vm, vcpuid) ? -errno : 0;
}
static struct vm_gic vm_gic_create_with_vcpus(uint32_t gic_dev_type, uint32_t nr_vcpus)
......
......@@ -509,7 +509,7 @@ static void generate_random_array(uint64_t *guest_array, uint64_t size)
static void *vcpu_worker(void *data)
{
int ret, vcpu_fd;
int ret;
struct kvm_vm *vm = data;
uint64_t *guest_array;
uint64_t pages_count = 0;
......@@ -517,8 +517,6 @@ static void *vcpu_worker(void *data)
+ sizeof(sigset_t));
sigset_t *sigset = (sigset_t *) &sigmask->sigset;
vcpu_fd = vcpu_get_fd(vm, VCPU_ID);
/*
* SIG_IPI is unblocked atomically while in KVM_RUN. It causes the
* ioctl to return with -EINTR, but it is still pending and we need
......@@ -539,7 +537,7 @@ static void *vcpu_worker(void *data)
generate_random_array(guest_array, TEST_PAGES_PER_LOOP);
pages_count += TEST_PAGES_PER_LOOP;
/* Let the guest dirty the random pages */
ret = ioctl(vcpu_fd, KVM_RUN, NULL);
ret = __vcpu_run(vm, VCPU_ID);
if (ret == -1 && errno == EINTR) {
int sig = -1;
sigwait(sigset, &sig);
......
......@@ -208,6 +208,12 @@ vm_paddr_t addr_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva);
struct kvm_run *vcpu_state(struct kvm_vm *vm, uint32_t vcpuid);
void vcpu_run(struct kvm_vm *vm, uint32_t vcpuid);
int _vcpu_run(struct kvm_vm *vm, uint32_t vcpuid);
static inline int __vcpu_run(struct kvm_vm *vm, uint32_t vcpuid)
{
return __vcpu_ioctl(vm, vcpuid, KVM_RUN, NULL);
}
int vcpu_get_fd(struct kvm_vm *vm, uint32_t vcpuid);
void vcpu_run_complete_io(struct kvm_vm *vm, uint32_t vcpuid);
struct kvm_reg_list *vcpu_get_reg_list(struct kvm_vm *vm, uint32_t vcpuid);
......
......@@ -1597,12 +1597,10 @@ void vcpu_run(struct kvm_vm *vm, uint32_t vcpuid)
int _vcpu_run(struct kvm_vm *vm, uint32_t vcpuid)
{
struct vcpu *vcpu = vcpu_find(vm, vcpuid);
int rc;
TEST_ASSERT(vcpu != NULL, "vcpu not found, vcpuid: %u", vcpuid);
do {
rc = ioctl(vcpu->fd, KVM_RUN, NULL);
rc = __vcpu_run(vm, vcpuid);
} while (rc == -1 && errno == EINTR);
assert_on_unhandled_exception(vm, vcpuid);
......@@ -1627,7 +1625,7 @@ void vcpu_run_complete_io(struct kvm_vm *vm, uint32_t vcpuid)
TEST_ASSERT(vcpu != NULL, "vcpu not found, vcpuid: %u", vcpuid);
vcpu->state->immediate_exit = 1;
ret = ioctl(vcpu->fd, KVM_RUN, NULL);
ret = __vcpu_run(vm, vcpuid);
vcpu->state->immediate_exit = 0;
TEST_ASSERT(ret == -1 && errno == EINTR,
......
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