]> git.hungrycats.org Git - linux/commitdiff
KVM: TDX: Set bits 31:16 to 0 and use UNDEFINED when synthesizing exit reason
authorXiaoyao Li <xiaoyao.li@intel.com>
Wed, 19 Aug 2026 09:48:57 +0000 (17:48 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Nov 2026 17:10:49 +0000 (12:10 -0500)
commit b43c520b198ab70868307a489ef2117ed6d6c4cc upstream.

Set bits 31:16 to 0 instead of all-1s when synthesizing an exit reason,
e.g. if the TDX Module never attempted VM-Enter, or when stuffing the exit
reason due to an unexpected "real" EPT Misconfig.  Opportunistically use
VMX's KVM-defined EXIT_REASON_UNDEFINED (0xdead) instead of -1u.

KVM is going to support Bus Lock VM exit for TDX, after which bit 26 of
the Exit Reason becomes meaningful and indicates that a bus lock happened.
The existing synthesized Exit Reason, -1u, will cause a false positive in
that case.  Change the synthesized Exit Reason from -1u to U16_MAX, so that
bits 31:16 are set to 0.  This also avoids the potential issues when other
bits in 31:16 become valid in the future.

As a bonus, the check for synthesized Exit Reason in tdx_failed_vmentry()
becomes unnecessary.  Just drop it.

Cc: stable@vger.kernel.org
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com>
Link: https://patch.msgid.link/20260819094903.3060020-4-xiaoyao.li@intel.com
[sean: use EXIT_REASON_UNDEFINED instead of another magic value]
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/vmx/tdx.c

index 16d030e99ac5be83aa9e6e962bc5eeb58de82a35..e8451f68948299bbe70fdf18809df0278ff3e2a9 100644 (file)
@@ -940,8 +940,13 @@ static __always_inline u32 tdx_to_vmx_exit_reason(struct kvm_vcpu *vcpu)
        struct vcpu_tdx *tdx = to_tdx(vcpu);
        u32 exit_reason;
 
+       /*
+        * Return the synthesized invalid Exit Reason, as the TDX module
+        * never attempted to run the vCPU, i.e. the Exit Reason is undefined,
+        * but this is NOT a failed VM-Enter.
+        */
        if (!tdx_is_exit_reason_valid(tdx->vp_enter_ret))
-               return -1u;
+               return EXIT_REASON_UNDEFINED;
 
        exit_reason = tdx->vp_enter_ret;
 
@@ -956,7 +961,7 @@ static __always_inline u32 tdx_to_vmx_exit_reason(struct kvm_vcpu *vcpu)
                 * Defer KVM_BUG_ON() until tdx_handle_exit() because this is in
                 * non-instrumentable code with interrupts disabled.
                 */
-               return -1u;
+               return EXIT_REASON_UNDEFINED;
        default:
                break;
        }
@@ -987,8 +992,7 @@ static noinstr void tdx_vcpu_enter_exit(struct kvm_vcpu *vcpu)
 
 static bool tdx_failed_vmentry(struct kvm_vcpu *vcpu)
 {
-       return vmx_get_exit_reason(vcpu).failed_vmentry &&
-              vmx_get_exit_reason(vcpu).full != -1u;
+       return vmx_get_exit_reason(vcpu).failed_vmentry;
 }
 
 static fastpath_t tdx_exit_handlers_fastpath(struct kvm_vcpu *vcpu)