]> git.hungrycats.org Git - linux/commitdiff
KVM: TDX: Check if there is valid exit infos based on vp_enter_ret
authorXiaoyao Li <xiaoyao.li@intel.com>
Wed, 19 Aug 2026 09:48:56 +0000 (17:48 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Nov 2026 17:10:48 +0000 (12:10 -0500)
commit 0966c881ea13be5ec89820c185de4d55568e80ed upstream.

Check if there is valid exit info based on vp_enter_ret instead of relying
on the clobbered Exit Reason, in tdx_get_exit_info().

Current KVM uses "Exit Reason is not equal to the synthesized invalid
Exit Reason, -1u," as the condition to identify there is a real TD Exit
and valid exit infos.  However, there is one issue with this approach:
KVM updates the Exit Reason to the synthesized invalid Exit Reason for
real EPT MISCONFIG as well.  This is a false positive for real EPT
MISCONFIG, which has valid exit infos.

Though the issue can be addressed by changing the handling for real EPT
MISCONFIG to not update the Exit Reason to the synthesized one, relying
on the clobbered Exit Reason itself is brittle.  Instead, check
vp_enter_ret directly to identify if it is a valid Exit Reason.

Fixes: da407fe45908 ("KVM: TDX: Handle EPT violation/misconfig exit")
Cc: stable@vger.kernel.org
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com>
Link: https://patch.msgid.link/20260819094903.3060020-3-xiaoyao.li@intel.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/vmx/tdx.c

index 00850a3a77d66a4ac28f18a4a9d7fb37dccbe0e0..5740fc5b5ed20a9f7769f8c6b466064c8819dcf7 100644 (file)
@@ -921,21 +921,27 @@ static __always_inline u32 tdcall_to_vmx_exit_reason(struct kvm_vcpu *vcpu)
        return EXIT_REASON_TDCALL;
 }
 
-static __always_inline u32 tdx_to_vmx_exit_reason(struct kvm_vcpu *vcpu)
+static __always_inline bool tdx_is_exit_reason_valid(u64 vp_enter_ret)
 {
-       struct vcpu_tdx *tdx = to_tdx(vcpu);
-       u32 exit_reason;
-
-       switch (tdx->vp_enter_ret & TDX_SEAMCALL_STATUS_MASK) {
+       switch (vp_enter_ret & TDX_SEAMCALL_STATUS_MASK) {
        case TDX_SUCCESS:
        case TDX_NON_RECOVERABLE_VCPU:
        case TDX_NON_RECOVERABLE_TD:
        case TDX_NON_RECOVERABLE_TD_NON_ACCESSIBLE:
        case TDX_NON_RECOVERABLE_TD_WRONG_APIC_MODE:
-               break;
+               return true;
        default:
-               return -1u;
+               return false;
        }
+}
+
+static __always_inline u32 tdx_to_vmx_exit_reason(struct kvm_vcpu *vcpu)
+{
+       struct vcpu_tdx *tdx = to_tdx(vcpu);
+       u32 exit_reason;
+
+       if (!tdx_is_exit_reason_valid(tdx->vp_enter_ret))
+               return -1u;
 
        exit_reason = tdx->vp_enter_ret;
 
@@ -2141,7 +2147,7 @@ void tdx_get_exit_info(struct kvm_vcpu *vcpu, u32 *reason,
        struct vcpu_tdx *tdx = to_tdx(vcpu);
 
        *reason = tdx->vt.exit_reason.full;
-       if (*reason != -1u) {
+       if (tdx_is_exit_reason_valid(tdx->vp_enter_ret)) {
                *info1 = vmx_get_exit_qual(vcpu);
                *info2 = tdx->ext_exit_qualification;
                *intr_info = vmx_get_intr_info(vcpu);