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

Xiaoyao Li <[email protected]>
Newsgroups dev.linux.lists.linux-coco,org.kernel.vger.kvm,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
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: [email protected]
Signed-off-by: Xiaoyao Li <[email protected]>
---
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.