diff options
| author | Sean Christopherson <[email protected]> | 2022-10-06 00:34:04 +0000 |
|---|---|---|
| committer | Sean Christopherson <[email protected]> | 2022-11-16 16:58:51 -0800 |
| commit | ef38871eb22879438d2af8642ed7a52c1616f410 (patch) | |
| tree | bcbd4bf18b53bf9b26016eaff9b1e22ab008518f /tools/testing/selftests/kvm/lib/ucall_common.c | |
| parent | 7046638192d52416adbfc273c36950f0e3311191 (diff) | |
KVM: selftests: Consolidate boilerplate code in get_ucall()
Consolidate the actual copying of a ucall struct from guest=>host into
the common get_ucall(). Return a host virtual address instead of a guest
virtual address even though the addr_gva2hva() part could be moved to
get_ucall() too. Conceptually, get_ucall() is invoked from the host and
should return a host virtual address (and returning NULL for "nothing to
see here" is far superior to returning 0).
Use pointer shenanigans instead of an unnecessary bounce buffer when the
caller of get_ucall() provides a valid pointer.
Reviewed-by: Andrew Jones <[email protected]>
Tested-by: Peter Gonda <[email protected]>
Signed-off-by: Sean Christopherson <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Diffstat (limited to 'tools/testing/selftests/kvm/lib/ucall_common.c')
| -rw-r--r-- | tools/testing/selftests/kvm/lib/ucall_common.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c b/tools/testing/selftests/kvm/lib/ucall_common.c index 2395c7f1d543..ced480860746 100644 --- a/tools/testing/selftests/kvm/lib/ucall_common.c +++ b/tools/testing/selftests/kvm/lib/ucall_common.c @@ -18,3 +18,22 @@ void ucall(uint64_t cmd, int nargs, ...) ucall_arch_do_ucall((vm_vaddr_t)&uc); } + +uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) +{ + struct ucall ucall; + void *addr; + + if (!uc) + uc = &ucall; + + addr = ucall_arch_get_ucall(vcpu); + if (addr) { + memcpy(uc, addr, sizeof(*uc)); + vcpu_run_complete_io(vcpu); + } else { + memset(uc, 0, sizeof(*uc)); + } + + return uc->cmd; +} |