[PATCH v4 5/9] KVM: TDX: Update exit_reason on wait_for_sept_zap return

From: Xiaoyao Li

Date: Wed Aug 19 2026 - 06:02:41 EST


Update exit_reason to a value with bit[31:16] cleared and bit[15:0]
set to TDX_INVALID_EXIT_REASON when it needs to return early due to
wait_for_sept_zap in tdx_vcpu_run(). This avoids the stale exit_reason
of the previous Exit being consumed twice.

Fixes: 4b2abc49712b ("KVM: TDX: Kick off vCPUs when SEAMCALL is busy during TD page removal")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Xiaoyao Li <xiaoyao.li@xxxxxxxxx>
---
Changes in v4:
- new patch;
---
arch/x86/kvm/vmx/tdx.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
index 987092283955..014710945e8a 100644
--- a/arch/x86/kvm/vmx/tdx.c
+++ b/arch/x86/kvm/vmx/tdx.c
@@ -1088,8 +1088,21 @@ fastpath_t tdx_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags)
* allowing vCPU entry to avoid contention with tdh_vp_enter() and
* TDCALLs.
*/
- if (unlikely(READ_ONCE(to_kvm_tdx(vcpu->kvm)->wait_for_sept_zap)))
+ if (unlikely(READ_ONCE(to_kvm_tdx(vcpu->kvm)->wait_for_sept_zap))) {
+ /*
+ * The vCPU never entered the guest, but this looks like a
+ * handled exit to the caller. Synthesize an invalid exit
+ * reason so the previous exit's stale value isn't consumed
+ * a second time.
+ *
+ * Make it super clear that bit[31:16] is cleared to 0 and only
+ * basic exit reason (bit[15:0]) is set to the synthesized
+ * invalid exit reason.
+ */
+ vt->exit_reason.full = 0;
+ vt->exit_reason.basic = TDX_INVALID_EXIT_REASON;
return EXIT_FASTPATH_EXIT_HANDLED;
+ }

trace_kvm_entry(vcpu, run_flags & KVM_RUN_FORCE_IMMEDIATE_EXIT);

--
2.43.0