Re: [PATCH v3 4/4] KVM: TDX: Enable Bus Lock VM exit

Sean Christopherson <[email protected]>
Newsgroups dev.linux.lists.linux-coco,org.kernel.vger.kvm,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Thu, Aug 13, 2026, Xiaoyao Li wrote:
> On 8/13/2026 6:58 AM, Edgecombe, Rick P wrote:
> > On Wed, 2026-08-12 at 16:02 +0800, Xiaoyao Li wrote:
> > > -	if (unlikely(READ_ONCE(to_kvm_tdx(vcpu->kvm)->wait_for_sept_zap)))
> > > +	if (unlikely(READ_ONCE(to_kvm_tdx(vcpu->kvm)->wait_for_sept_zap))) {
> > > +		vt->exit_reason.bus_lock_detected = 0;
> > >   		return EXIT_FASTPATH_EXIT_HANDLED;
> > > +	}
> > 
> > This still feels hacky to me. It at least deserves a comment I think. If you
> > spin another version.
> 
> I spent more time on this today and I find there is an existing issue. When
> the previous Exit Reason is EXIT_REASON_EXTERNAL_INTERRUPT, the early return
> here can go to the path due to the stale exit_reason.
> 
> kvm_x86_call(handle_exit_irqoff)(vcpu)
>   vmx_handle_exit_irqoff()
>     handle_external_interrupt_irqoff()
> 
> This makes the host process the external interrupt twice, and maybe more
> times if the wait_for_sept_zap remains longer.
> 
> I think we need an separate fix to set
> 
> 	vt->exit_reasons.full = TDX_INVALID_EXIT_REASON;
> 
> so that if some patch is going to consume the stale Exit Reason, it can be
> caught by TDX_INVALID_EXIT_REASON.

The more I look at this, the more I'm against shoving garbage into vt->exit_reasons.
With tdx_is_exit_reason_valid(), this is trivially easy to handle, *and* explicitly
captures the logic instead of subtly rerouting KVM away from meaningful handling.

diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c
index 95d89d809c19..a1f5b5dc1fa3 100644
--- a/arch/x86/kvm/vmx/main.c
+++ b/arch/x86/kvm/vmx/main.c
@@ -157,6 +157,14 @@ static fastpath_t vt_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags)
        return vmx_vcpu_run(vcpu, run_flags);
 }
 
+static void vt_handle_exit_irqoff(struct kvm_vcpu *vcpu)
+{
+       if (is_td_vcpu(vcpu) && !tdx_is_exit_reason_valid(vcpu))
+               return;
+
+       vmx_handle_exit_irqoff();
+}
+
 static int vt_handle_exit(struct kvm_vcpu *vcpu,
                          enum exit_fastpath_completion fastpath)
 {
@@ -1071,7 +1079,7 @@ struct kvm_x86_ops vt_x86_ops __initdata = {
        .load_mmu_pgd = vt_op(load_mmu_pgd),
 
        .check_intercept = vmx_check_intercept,
-       .handle_exit_irqoff = vmx_handle_exit_irqoff,
+       .handle_exit_irqoff = vt_op(handle_exit_irqoff),
 
        .update_cpu_dirty_logging = vt_op(update_cpu_dirty_logging),
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.