]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
kvm: selftests: ucall improvements
authorAndrew Jones <drjones@redhat.com>
Mon, 27 May 2019 12:30:06 +0000 (14:30 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 4 Jun 2019 17:29:10 +0000 (19:29 +0200)
Make sure we complete the I/O after determining we have a ucall,
which is I/O. Also allow the *uc parameter to optionally be NULL.
It's quite possible that a test case will only care about the
return value, like for example when looping on a check for
UCALL_DONE.

Signed-off-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/dirty_log_test.c
tools/testing/selftests/kvm/lib/ucall.c

index fc27f890155baf9308dd38e641ea35605870719d..ceb52b9526375de63cadef26256a110d5e5637b8 100644 (file)
@@ -121,7 +121,6 @@ static void *vcpu_worker(void *data)
        uint64_t *guest_array;
        uint64_t pages_count = 0;
        struct kvm_run *run;
-       struct ucall uc;
 
        run = vcpu_state(vm, VCPU_ID);
 
@@ -132,7 +131,7 @@ static void *vcpu_worker(void *data)
                /* Let the guest dirty the random pages */
                ret = _vcpu_run(vm, VCPU_ID);
                TEST_ASSERT(ret == 0, "vcpu_run failed: %d\n", ret);
-               if (get_ucall(vm, VCPU_ID, &uc) == UCALL_SYNC) {
+               if (get_ucall(vm, VCPU_ID, NULL) == UCALL_SYNC) {
                        pages_count += TEST_PAGES_PER_LOOP;
                        generate_random_array(guest_array, TEST_PAGES_PER_LOOP);
                } else {
index b701a01cfcb62c619860783fb387c177d352bcbd..dd9a66700f96e5335ffd78128409ac9e49350498 100644 (file)
@@ -125,16 +125,16 @@ void ucall(uint64_t cmd, int nargs, ...)
 uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)
 {
        struct kvm_run *run = vcpu_state(vm, vcpu_id);
-
-       memset(uc, 0, sizeof(*uc));
+       struct ucall ucall = {};
+       bool got_ucall = false;
 
 #ifdef __x86_64__
        if (ucall_type == UCALL_PIO && run->exit_reason == KVM_EXIT_IO &&
            run->io.port == UCALL_PIO_PORT) {
                struct kvm_regs regs;
                vcpu_regs_get(vm, vcpu_id, &regs);
-               memcpy(uc, addr_gva2hva(vm, (vm_vaddr_t)regs.rdi), sizeof(*uc));
-               return uc->cmd;
+               memcpy(&ucall, addr_gva2hva(vm, (vm_vaddr_t)regs.rdi), sizeof(ucall));
+               got_ucall = true;
        }
 #endif
        if (ucall_type == UCALL_MMIO && run->exit_reason == KVM_EXIT_MMIO &&
@@ -143,8 +143,15 @@ uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)
                TEST_ASSERT(run->mmio.is_write && run->mmio.len == 8,
                            "Unexpected ucall exit mmio address access");
                memcpy(&gva, run->mmio.data, sizeof(gva));
-               memcpy(uc, addr_gva2hva(vm, gva), sizeof(*uc));
+               memcpy(&ucall, addr_gva2hva(vm, gva), sizeof(ucall));
+               got_ucall = true;
+       }
+
+       if (got_ucall) {
+               vcpu_run_complete_io(vm, vcpu_id);
+               if (uc)
+                       memcpy(uc, &ucall, sizeof(ucall));
        }
 
-       return uc->cmd;
+       return ucall.cmd;
 }