[PATCH 1/3] KVM: selftests: Add support for per-VM ucall ops on x86
From: Sean Christopherson
Date: Fri Aug 28 2026 - 09:46:51 EST
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 hardwirte to the common
x86 ucall functions.
Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
.../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 e7dd5791959b..444d0f0ba138 100644
--- a/tools/testing/selftests/kvm/lib/x86/ucall.c
+++ b/tools/testing/selftests/kvm/lib/x86/ucall.c
@@ -8,7 +8,7 @@
#define UCALL_PIO_PORT ((u16)0x1000)
-void ucall_arch_do_ucall(gva_t uc)
+static void ucall_x86_do_ucall(gva_t uc)
{
/*
* FIXME: Revert this hack (the entire commit that added it) once nVMX
@@ -42,7 +42,7 @@ void ucall_arch_do_ucall(gva_t uc)
HORRIFIC_L2_UCALL_CLOBBER_HACK);
}
-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;
@@ -54,3 +54,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);
+}
base-commit: 8ab7454faa8be2d6c1fc29c857b9f9611ddb174b
--
2.55.0.897.gb25b4bd76c-goog
--D8ScZ73OZF7fi6Cd
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename=0002-KVM-selftests-Add-support-for-TDX-ucalls-via-TDVMCAL.patch