Re: [PATCH v4 3/9] KVM: TDX: Set bits 31:16 to 0 for the synthesized Exit Reason
From: Sean Christopherson
Date: Mon Sep 21 2026 - 19:54:53 EST
On Wed, Aug 19, 2026, Xiaoyao Li wrote:
> Set bits 31:16 to 0 instead of all-1s for KVM's synthesized Exit Reason.
>
> 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@xxxxxxxxxxxxxxx
> Signed-off-by: Xiaoyao Li <xiaoyao.li@xxxxxxxxx>
> Reviewed-by: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>
> ---
> Note, the checking of tdx_failed_vmentry() looks to miss the case where
> a real EPT_MISCONFIG happens with failed_vmentry being set. First, in
> practice, EPT_MISCONFIG cannot happen with failed_vmentry being set.
> Second, even if it can, this is a pre-existing issue and the next
> patch can address it.
>
> Changes in v4:
> - Collect R-b from Rick.
>
> Changes in v3:
> - split from the patch 2 in v2.
> - define a MARCO for the synthesized invalid Exit Reason.
> ---
> arch/x86/kvm/vmx/tdx.c | 15 +++++++++++----
> 1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
> index 1dead84e6077..4e275cb6927a 100644
> --- a/arch/x86/kvm/vmx/tdx.c
> +++ b/arch/x86/kvm/vmx/tdx.c
> @@ -935,13 +935,21 @@ static __always_inline bool tdx_is_exit_reason_valid(u64 vp_enter_ret)
> }
> }
>
> +/* Synthesized invalid Exit Reason */
> +#define TDX_INVALID_EXIT_REASON U16_MAX
I very strongly prefer exposing VMX's magic "0xdead", i.e. not having two different
magic values when the exit reason is undefined. I'll post a standalone patch,
and fixup this series when applying.
diff --git arch/x86/include/asm/vmx.h arch/x86/include/asm/vmx.h
index 3f1b3096ff04..e49b836c7313 100644
--- arch/x86/include/asm/vmx.h
+++ arch/x86/include/asm/vmx.h
@@ -20,6 +20,14 @@
#include <asm/trapnr.h>
#include <asm/vmxfeatures.h>
+/*
+ * UNDEFINED is a KVM-defined value used to indicate that the basic exit reason
+ * is undefined/invalid, e.g. on VM-Fail or if TDX never attempted VM-Enter.
+ * The value itself is arbitrary, it just needs to not collide with a real exit
+ * reason.
+ */
+#define EXIT_REASON_UNDEFINED 0xdead
+
struct vmcs_hdr {
u32 revision_id:31;
u32 shadow_vmcs:1;
diff --git arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.c
index 612ab07d4100..c897dbf0e954 100644
--- arch/x86/kvm/vmx/vmx.c
+++ arch/x86/kvm/vmx/vmx.c
@@ -6388,6 +6388,8 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {
static const int kvm_vmx_max_exit_handlers =
ARRAY_SIZE(kvm_vmx_exit_handlers);
+static_assert(EXIT_REASON_UNDEFINED >= ARRAY_SIZE(kvm_vmx_exit_handlers));
+
void vmx_get_exit_info(struct kvm_vcpu *vcpu, u32 *reason,
u64 *info1, u64 *info2, u32 *intr_info, u32 *error_code)
{
@@ -7474,7 +7476,7 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu,
vmx_enable_fb_clear(vmx);
if (unlikely(vmx->fail)) {
- vmx->vt.exit_reason.full = 0xdead;
+ vmx->vt.exit_reason.full = EXIT_REASON_UNDEFINED;
goto out;
}