mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Xiaoyao Li <xiaoyao.li@intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Kiryl Shutsemau <kas@kernel.org>,
	 Rick Edgecombe <rick.p.edgecombe@intel.com>,
	kvm@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-coco@lists.linux.dev,  nik.borisov@suse.com
Subject: Re: [PATCH v4 3/9] KVM: TDX: Set bits 31:16 to 0 for the synthesized Exit Reason
Date: Mon, 21 Sep 2026 16:54:18 -0700	[thread overview]
Message-ID: <arHDqhdvgvH8HsvO@google.com> (raw)
In-Reply-To: <20260819094903.3060020-4-xiaoyao.li@intel.com>

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@vger.kernel.org
> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
> Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
> ---
> 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;
        }

  parent reply	other threads:[~2026-09-21 23:54 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-19  9:48 [PATCH v4 0/9] KVM: TDX: Enable VM-DoS Prevention Features for TDX Xiaoyao Li
2026-08-19  9:48 ` [PATCH v4 1/9] KVM: TDX: Enable Notify VM exit Xiaoyao Li
2026-08-20  8:48   ` Binbin Wu
2026-08-19  9:48 ` [PATCH v4 2/9] KVM: TDX: Check if there is valid exit infos based on vp_enter_ret Xiaoyao Li
2026-08-19 16:39   ` Edgecombe, Rick P
2026-08-20  1:53     ` Xiaoyao Li
2026-08-20  9:11   ` Binbin Wu
2026-08-19  9:48 ` [PATCH v4 3/9] KVM: TDX: Set bits 31:16 to 0 for the synthesized Exit Reason Xiaoyao Li
2026-08-20  9:16   ` Binbin Wu
2026-09-21 23:54   ` Sean Christopherson [this message]
2026-08-19  9:48 ` [PATCH v4 4/9] KVM: TDX: Don't assume exit_reason[31:16] is all-0 in tdx_to_vmx_exit_reason() Xiaoyao Li
2026-08-19  9:48 ` [PATCH v4 5/9] KVM: TDX: Update exit_reason on wait_for_sept_zap return Xiaoyao Li
2026-08-19 19:08   ` Edgecombe, Rick P
2026-08-19  9:49 ` [PATCH v4 6/9] KVM: VMX: Preserve negative return value in vmx_handle_exit() with bus lock detected Xiaoyao Li
2026-08-19  9:49 ` [PATCH v4 7/9] KVM: VMX: Make handle_bus_lock_vmexit() a shared helper Xiaoyao Li
2026-08-26 10:38   ` Nikolay Borisov
2026-08-19  9:49 ` [PATCH v4 8/9] KVM: TDX: Enable Bus Lock VM exit Xiaoyao Li
2026-08-26 10:38   ` Nikolay Borisov
2026-08-19  9:49 ` [PATCH v4 9/9] KVM: VMX: Consolidate the exit handler for VMX and TDX Xiaoyao Li
2026-08-26  9:51   ` Nikolay Borisov
2026-08-26 10:03   ` Nikolay Borisov
2026-08-26 10:43     ` Xiaoyao Li
2026-08-26 11:03       ` Nikolay Borisov
2026-08-26 13:59         ` Sean Christopherson
2026-08-19 22:57 ` [PATCH v4 0/9] KVM: TDX: Enable VM-DoS Prevention Features for TDX Edgecombe, Rick P
2026-08-19 23:03   ` Sean Christopherson
2026-08-19 23:08     ` Edgecombe, Rick P
2026-08-21 13:14       ` Sean Christopherson
2026-09-19  0:27 ` Vishal Annapurve
2026-09-21 14:44 ` Xiaoyao Li
2026-09-21 23:51   ` Sean Christopherson
2026-09-22  2:02     ` Xiaoyao Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=arHDqhdvgvH8HsvO@google.com \
    --to=seanjc@google.com \
    --cc=kas@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nik.borisov@suse.com \
    --cc=pbonzini@redhat.com \
    --cc=rick.p.edgecombe@intel.com \
    --cc=xiaoyao.li@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®