From: Sean Christopherson <[email protected]> Add a layer of indirection to x86's ucall infrastructure to allow wiring up a different set of {do,get}_ucall() operations for TDX VMs. TDX can't use port I/O (at least, not robustly), as the TDX ABI doesn't allow the guest to share arbitrary register state with the host on a PIO exit, and the PIO data payload is limited to 4 bytes, i.e. would potentially truncate the address of the per-ucall structure.
No functional change intended, as the ops are still hardwired to the common x86 ucall functions. Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Lisa Wang <[email protected]> --- tools/testing/selftests/kvm/include/x86/ucall.h | 6 +----- tools/testing/selftests/kvm/lib/x86/ucall.c | 27 +++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86/ucall.h b/tools/testing/selftests/kvm/include/x86/ucall.h index 0e4950041e3e..3639f03a4da9 100644 --- a/tools/testing/selftests/kvm/include/x86/ucall.h +++ b/tools/testing/selftests/kvm/include/x86/ucall.h @@ -2,12 +2,8 @@ #ifndef SELFTEST_KVM_UCALL_H #define SELFTEST_KVM_UCALL_H -#include "kvm_util.h" +#include "linux/kvm.h" #define UCALL_EXIT_REASON KVM_EXIT_IO -static inline void ucall_arch_init(struct kvm_vm *vm, gpa_t mmio_gpa) -{ -} - #endif diff --git a/tools/testing/selftests/kvm/lib/x86/ucall.c b/tools/testing/selftests/kvm/lib/x86/ucall.c index 38050c60a067..c003df3c7b8a 100644 --- a/tools/testing/selftests/kvm/lib/x86/ucall.c +++ b/tools/testing/selftests/kvm/lib/x86/ucall.c @@ -8,13 +8,13 @@ #define UCALL_PIO_PORT ((u16)0x1000) -void ucall_arch_do_ucall(gva_t uc) +static void ucall_x86_do_ucall(gva_t uc) { asm volatile("in %[port], %%al" : : [port] "d" (UCALL_PIO_PORT), "D" (uc) : "rax", "memory"); } -void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu) +static void *ucall_x86_get_ucall(struct kvm_vcpu *vcpu) { struct kvm_run *run = vcpu->run; @@ -26,3 +26,26 @@ void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu) } return NULL; } + +static struct { + void (*do_ucall)(gva_t uc); + void *(*get_ucall)(struct kvm_vcpu *vcpu); +} ucall_x86_ops = { + .do_ucall = ucall_x86_do_ucall, + .get_ucall = ucall_x86_get_ucall, +}; + +void ucall_arch_init(struct kvm_vm *vm, gpa_t mmio_gpa) +{ + sync_global_to_guest(vm, ucall_x86_ops); +} + +void ucall_arch_do_ucall(gva_t uc) +{ + return ucall_x86_ops.do_ucall(uc); +} + +void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu) +{ + return ucall_x86_ops.get_ucall(vcpu); +} -- 2.56.0.rc1.315.gc6ed9934b7-goog

