Re: [PATCH v4 9/9] KVM: VMX: Consolidate the exit handler for VMX and TDX

From: Nikolay Borisov

Date: Wed Aug 26 2026 - 06:23:34 EST




On 8/19/26 12:49, Xiaoyao Li wrote:
The exit handlers for VMX and TDX have the similar pattern. Consolidate
them into a single vt_handle_exit() helper.

Signed-off-by: Xiaoyao Li <xiaoyao.li@xxxxxxxxx>
Changes in v4:
- new patch.
---
arch/x86/kvm/vmx/main.c | 38 ++++++++++++++++++++++++++++----------
arch/x86/kvm/vmx/tdx.c | 18 +-----------------
arch/x86/kvm/vmx/vmx.c | 21 +--------------------
3 files changed, 30 insertions(+), 47 deletions(-)

diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c
index 6a813c49ca8a..10df9667d0c0 100644
--- a/arch/x86/kvm/vmx/main.c
+++ b/arch/x86/kvm/vmx/main.c
@@ -154,15 +154,6 @@ static fastpath_t vt_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags)
return vmx_vcpu_run(vcpu, run_flags);
}
-static int vt_handle_exit(struct kvm_vcpu *vcpu,
- enum exit_fastpath_completion fastpath)
-{
- if (is_td_vcpu(vcpu))
- return tdx_handle_exit(vcpu, fastpath);
-
- return vmx_handle_exit(vcpu, fastpath);
-}
-
static bool vt_unhandleable_emulation_required(struct kvm_vcpu *vcpu)
{
if (is_td_vcpu(vcpu)) {
@@ -887,6 +878,33 @@ int vt_handle_bus_lock_vmexit(struct kvm_vcpu *vcpu)
return 1;
}
+static int vt_handle_exit(struct kvm_vcpu *vcpu,
+ enum exit_fastpath_completion fastpath)
+{
+ int ret;
+
+#ifdef CONFIG_KVM_INTEL_TDX
+ if (is_td_vcpu(vcpu))
+ ret = tdx_handle_exit(vcpu, fastpath);
+ else
+#endif
+ ret = vmx_handle_exit(vcpu, fastpath);
+
+ /*
+ * Exit to user space when bus lock detected to inform that there is
+ * a bus lock in guest.
+ */
+ if (vmx_get_exit_reason(vcpu).bus_lock_detected) {
+ if (ret > 0) {
+ vcpu->run->exit_reason = KVM_EXIT_X86_BUS_LOCK;
+ ret = 0;
+ }
+
+ vcpu->run->flags |= KVM_RUN_X86_BUS_LOCK;
+ }
+ return ret;
+}
+
#define VMX_REQUIRED_APICV_INHIBITS \
(BIT(APICV_INHIBIT_REASON_DISABLED) | \
BIT(APICV_INHIBIT_REASON_ABSENT) | \
@@ -960,7 +978,7 @@ struct kvm_x86_ops vt_x86_ops __initdata = {
.vcpu_needs_initialization = vt_op_tdx_only(vcpu_needs_initialization),
.vcpu_run = vt_op(vcpu_run),
- .handle_exit = vt_op(handle_exit),
+ .handle_exit = vt_handle_exit,

nit: Why isn't this vt_op() for the sake of consistency and introduce needless churn ?

<snip>