selftests: kvm: Clear uc so UCALL_NONE is being properly reported
authorAaron Lewis <aaronlewis@google.com>
Mon, 12 Oct 2020 19:47:14 +0000 (12:47 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Sun, 8 Nov 2020 11:02:14 +0000 (06:02 -0500)
Ensure the out value 'uc' in get_ucall() is properly reporting
UCALL_NONE if the call fails.  The return value will be correctly
reported, however, the out parameter 'uc' will not be.  Clear the struct
to ensure the correct value is being reported in the out parameter.

Signed-off-by: Aaron Lewis <aaronlewis@google.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Alexander Graf <graf@amazon.com>
Message-Id: <20201012194716.3950330-3-aaronlewis@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/lib/aarch64/ucall.c
tools/testing/selftests/kvm/lib/s390x/ucall.c
tools/testing/selftests/kvm/lib/x86_64/ucall.c

index c8e0ec2..2f37b90 100644 (file)
@@ -94,6 +94,9 @@ uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)
        struct kvm_run *run = vcpu_state(vm, vcpu_id);
        struct ucall ucall = {};
 
+       if (uc)
+               memset(uc, 0, sizeof(*uc));
+
        if (run->exit_reason == KVM_EXIT_MMIO &&
            run->mmio.phys_addr == (uint64_t)ucall_exit_mmio_addr) {
                vm_vaddr_t gva;
index fd589dc..9d3b0f1 100644 (file)
@@ -38,6 +38,9 @@ uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)
        struct kvm_run *run = vcpu_state(vm, vcpu_id);
        struct ucall ucall = {};
 
+       if (uc)
+               memset(uc, 0, sizeof(*uc));
+
        if (run->exit_reason == KVM_EXIT_S390_SIEIC &&
            run->s390_sieic.icptcode == 4 &&
            (run->s390_sieic.ipa >> 8) == 0x83 &&    /* 0x83 means DIAGNOSE */
index da4d89a..a348997 100644 (file)
@@ -40,6 +40,9 @@ uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)
        struct kvm_run *run = vcpu_state(vm, vcpu_id);
        struct ucall ucall = {};
 
+       if (uc)
+               memset(uc, 0, sizeof(*uc));
+
        if (run->exit_reason == KVM_EXIT_IO && run->io.port == UCALL_PIO_PORT) {
                struct kvm_regs regs;