From: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
To: "Li, Xiaoyao" <xiaoyao.li@intel.com>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"seanjc@google.com" <seanjc@google.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-coco@lists.linux.dev" <linux-coco@lists.linux.dev>,
"kas@kernel.org" <kas@kernel.org>,
"nik.borisov@suse.com" <nik.borisov@suse.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 2/3] KVM: TDX: Fix the exit reason handling
Date: Tue, 11 Aug 2026 00:38:57 +0000 [thread overview]
Message-ID: <5dfed336a46329ba39922dcb3a8723116dae9ae4.camel@intel.com> (raw)
In-Reply-To: <20260810112200.2326727-3-xiaoyao.li@intel.com>
On Mon, 2026-08-10 at 19:21 +0800, Xiaoyao Li wrote:
> Get and check the exit reason from the low 16 bits of vp_enter_ret, and
> store the synthesized/transformed exit reason in the "basic" field.
>
> Some bits in the upper 16 bits in the exit reason have their own meanings
> and they might be 1. When handling the exit reason, only do handling on
> the lower 16 bits and keep the upper 16 bits unchanged. This change
> also helps remove the additional check in tdx_failed_vmentry().
>
> Note, due to the synthesized invalid exit reason, -1, is changed to
> assigned to the "basic" field, adjust the checking in tdx_get_exit_info()
> accordingly.
>
> Fixes: 095b71a03f49 ("KVM: TDX: Add a place holder to handle TDX VM exit")
> Fixes: c42856af8f70 ("KVM: TDX: Add a place holder for handler of TDX hypercalls (TDG.VP.VMCALL)")
> Cc: stable@vger.kernel.org
> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
> ---
> Changes in v2:
> - new patch
> ---
> arch/x86/kvm/vmx/tdx.c | 35 ++++++++++++++++++++++-------------
> 1 file changed, 22 insertions(+), 13 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
> index 7338ac0af693..a89885d550c9 100644
> --- a/arch/x86/kvm/vmx/tdx.c
> +++ b/arch/x86/kvm/vmx/tdx.c
> @@ -921,10 +921,10 @@ 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 union vmx_exit_reason tdx_to_vmx_exit_reason(struct kvm_vcpu *vcpu)
> {
> struct vcpu_tdx *tdx = to_tdx(vcpu);
> - u32 exit_reason;
> + union vmx_exit_reason exit_reason;
>
> switch (tdx->vp_enter_ret & TDX_SEAMCALL_STATUS_MASK) {
> case TDX_SUCCESS:
> @@ -934,23 +934,33 @@ static __always_inline u32 tdx_to_vmx_exit_reason(struct kvm_vcpu *vcpu)
> case TDX_NON_RECOVERABLE_TD_WRONG_APIC_MODE:
> break;
> default:
> - return -1u;
> + /*
> + * Synthesize an invalid bogus Exit Reason, as the TDX-Module
I think this blurb came from Sean, but can we standardize on "TDX module"? The
code currently uses "TDX module" and "TDX-module" and "TDX-module" used much
less. I also don't see why it needs the "-".
> + * never attempted to run the vCPU, i.e. the Exit Reason is
> + * undefined, but this is NOT a failed VM-Enter.
> + */
> + return (union vmx_exit_reason) {
> + .basic = -1,
> + };
> }
>
> - exit_reason = tdx->vp_enter_ret;
> + exit_reason.full = (u32)tdx->vp_enter_ret;
>
> - switch (exit_reason) {
> + switch (exit_reason.basic) {
> case EXIT_REASON_TDCALL:
> if (tdvmcall_exit_type(vcpu))
> - return EXIT_REASON_VMCALL;
> -
> - return tdcall_to_vmx_exit_reason(vcpu);
> + exit_reason.basic = EXIT_REASON_VMCALL;
> + else
> + exit_reason.basic = tdcall_to_vmx_exit_reason(vcpu);
> + break;
> case EXIT_REASON_EPT_MISCONFIG:
> /*
> * Defer KVM_BUG_ON() until tdx_handle_exit() because this is in
> * non-instrumentable code with interrupts disabled.
> */
> - return -1u;
> + return (union vmx_exit_reason) {
> + .basic = -1,
> + };
We could make this return instead be a goto err; that returns this. Bonus is the
comment on the other one can cover them both. What do you think?
> default:
> break;
> }
> @@ -967,7 +977,7 @@ static noinstr void tdx_vcpu_enter_exit(struct kvm_vcpu *vcpu)
>
> tdx->vp_enter_ret = tdh_vp_enter(&tdx->vp, &tdx->vp_enter_args);
>
> - vt->exit_reason.full = tdx_to_vmx_exit_reason(vcpu);
> + vt->exit_reason = tdx_to_vmx_exit_reason(vcpu);
>
> vt->exit_qualification = tdx->vp_enter_args.rcx;
> tdx->ext_exit_qualification = tdx->vp_enter_args.rdx;
> @@ -981,8 +991,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)
> @@ -2144,7 +2153,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->vt.exit_reason.basic != -1) {
> *info1 = vmx_get_exit_qual(vcpu);
> *info2 = tdx->ext_exit_qualification;
> *intr_info = vmx_get_intr_info(vcpu);
next prev parent reply other threads:[~2026-08-11 0:39 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 11:21 [PATCH v2 0/3] KVM: TDX: Enable VM-DoS Prevention Features for TDX Xiaoyao Li
2026-08-10 11:21 ` [PATCH v2 1/3] KVM: TDX: Enable Notify VM exit Xiaoyao Li
2026-08-11 0:37 ` Edgecombe, Rick P
2026-08-10 11:21 ` [PATCH v2 2/3] KVM: TDX: Fix the exit reason handling Xiaoyao Li
2026-08-10 11:39 ` sashiko-bot
2026-08-10 12:02 ` Xiaoyao Li
2026-08-10 23:57 ` Sean Christopherson
2026-08-11 0:04 ` Sean Christopherson
2026-08-11 0:19 ` Xiaoyao Li
2026-08-11 0:03 ` Sean Christopherson
2026-08-11 3:17 ` Xiaoyao Li
2026-08-11 0:38 ` Edgecombe, Rick P [this message]
2026-08-10 11:22 ` [PATCH v2 3/3] KVM: TDX: Enable Bus Lock VM exit Xiaoyao Li
2026-08-10 11:46 ` sashiko-bot
2026-08-10 12:03 ` Xiaoyao Li
2026-08-11 1:18 ` Edgecombe, Rick P
2026-08-11 1:44 ` 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=5dfed336a46329ba39922dcb3a8723116dae9ae4.camel@intel.com \
--to=rick.p.edgecombe@intel.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=seanjc@google.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