Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kvm: selftests: ucall improvements

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>

authored by

Andrew Jones and committed by
Paolo Bonzini
2c7c5d3d 511a8556

+14 -8
+1 -2
tools/testing/selftests/kvm/dirty_log_test.c
··· 121 121 uint64_t *guest_array; 122 122 uint64_t pages_count = 0; 123 123 struct kvm_run *run; 124 - struct ucall uc; 125 124 126 125 run = vcpu_state(vm, VCPU_ID); 127 126 ··· 131 132 /* Let the guest dirty the random pages */ 132 133 ret = _vcpu_run(vm, VCPU_ID); 133 134 TEST_ASSERT(ret == 0, "vcpu_run failed: %d\n", ret); 134 - if (get_ucall(vm, VCPU_ID, &uc) == UCALL_SYNC) { 135 + if (get_ucall(vm, VCPU_ID, NULL) == UCALL_SYNC) { 135 136 pages_count += TEST_PAGES_PER_LOOP; 136 137 generate_random_array(guest_array, TEST_PAGES_PER_LOOP); 137 138 } else {
+13 -6
tools/testing/selftests/kvm/lib/ucall.c
··· 125 125 uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc) 126 126 { 127 127 struct kvm_run *run = vcpu_state(vm, vcpu_id); 128 - 129 - memset(uc, 0, sizeof(*uc)); 128 + struct ucall ucall = {}; 129 + bool got_ucall = false; 130 130 131 131 #ifdef __x86_64__ 132 132 if (ucall_type == UCALL_PIO && run->exit_reason == KVM_EXIT_IO && 133 133 run->io.port == UCALL_PIO_PORT) { 134 134 struct kvm_regs regs; 135 135 vcpu_regs_get(vm, vcpu_id, &regs); 136 - memcpy(uc, addr_gva2hva(vm, (vm_vaddr_t)regs.rdi), sizeof(*uc)); 137 - return uc->cmd; 136 + memcpy(&ucall, addr_gva2hva(vm, (vm_vaddr_t)regs.rdi), sizeof(ucall)); 137 + got_ucall = true; 138 138 } 139 139 #endif 140 140 if (ucall_type == UCALL_MMIO && run->exit_reason == KVM_EXIT_MMIO && ··· 143 143 TEST_ASSERT(run->mmio.is_write && run->mmio.len == 8, 144 144 "Unexpected ucall exit mmio address access"); 145 145 memcpy(&gva, run->mmio.data, sizeof(gva)); 146 - memcpy(uc, addr_gva2hva(vm, gva), sizeof(*uc)); 146 + memcpy(&ucall, addr_gva2hva(vm, gva), sizeof(ucall)); 147 + got_ucall = true; 147 148 } 148 149 149 - return uc->cmd; 150 + if (got_ucall) { 151 + vcpu_run_complete_io(vm, vcpu_id); 152 + if (uc) 153 + memcpy(uc, &ucall, sizeof(ucall)); 154 + } 155 + 156 + return ucall.cmd; 150 157 }