Re: [PATCH 1/2] KVM: TDX: Enable Notify VM exit

Sean Christopherson <[email protected]>
Newsgroups org.kernel.vger.kvm,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Fri, Aug 07, 2026, Xiaoyao Li wrote:
> On 8/6/2026 9:33 PM, Nikolay Borisov wrote:
> > > diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
> > > index 545b03d9d10b..cdc0d24657ac 100644
> > > --- a/arch/x86/kvm/vmx/tdx.c
> > > +++ b/arch/x86/kvm/vmx/tdx.c
> > > @@ -2129,6 +2129,9 @@ int tdx_handle_exit(struct kvm_vcpu *vcpu,
> > > fastpath_t fastpath)
> > >            * - If it's not an MSMI, no need to do anything here.
> > >            */
> > >           return 1;
> > > +    case EXIT_REASON_NOTIFY:
> > > +        /* NMI blocking state is handled by TDX module */
> > > +        return __handle_notify(vcpu, false);
> > 
> > I'd rather there be a private handle_tdx_notify function in tdx.c than
> > exposing __handle_notify and introducing the boolean. This is needed
> > because the TDX module handles the NMI unblocking, so let's keep the
> > implementation specific to tdx.
> 
> The initial version just implemented a separate handler for TDX. It had the
> exact same code as VMX's handle_notify() except the "NMI blocking handling".
> So to eliminate the code duplication, I changed to current code.
> 
> Sean, please let me if you have a preference. Otherwise, I'll follow
> Nikolay's preference in a v2.

Handling this like __vmx_handle_ept_violation() and __vmx_deliver_posted_interrupt()
seems like the obvious answer.

diff --git a/arch/x86/kvm/vmx/common.h b/arch/x86/kvm/vmx/common.h
index 08005676702c..c179fb34c336 100644
--- a/arch/x86/kvm/vmx/common.h
+++ b/arch/x86/kvm/vmx/common.h
@@ -4,6 +4,7 @@
 
 #include <linux/kvm_host.h>
 #include <asm/posted_intr.h>
+#include <asm/vmx.h>
 
 #include "mmu.h"
 
@@ -183,6 +184,25 @@ static inline void __vmx_deliver_posted_interrupt(struct kvm_vcpu *vcpu,
        kvm_vcpu_trigger_posted_interrupt(vcpu, POSTED_INTR_VECTOR);
 }
 
+static inline int __vmx_handle_notify(struct kvm_vcpu *vcpu,
+                                     unsigned long exit_qual)
+{
+
+       bool context_invalid = exit_qual & NOTIFY_VM_CONTEXT_INVALID;
+
+       ++vcpu->stat.notify_window_exits;
+
+       if (vcpu->kvm->arch.notify_vmexit_flags & KVM_X86_NOTIFY_VMEXIT_USER ||
+           context_invalid) {
+               vcpu->run->exit_reason = KVM_EXIT_NOTIFY;
+               vcpu->run->notify.flags = context_invalid ?
+                                         KVM_NOTIFY_CONTEXT_INVALID : 0;
+               return 0;
+       }
+
+       return 1;
+}
+
 noinstr void vmx_handle_nmi(struct kvm_vcpu *vcpu);
 
 #endif /* __KVM_X86_VMX_COMMON_H */
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 9abd2ed3aeae..e77c1037e95d 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -6289,9 +6289,6 @@ static int handle_bus_lock_vmexit(struct kvm_vcpu *vcpu)
 static int handle_notify(struct kvm_vcpu *vcpu)
 {
        unsigned long exit_qual = vmx_get_exit_qual(vcpu);
-       bool context_invalid = exit_qual & NOTIFY_VM_CONTEXT_INVALID;
-
-       ++vcpu->stat.notify_window_exits;
 
        /*
         * Notify VM exit happened while executing iret from NMI,
@@ -6301,15 +6298,7 @@ static int handle_notify(struct kvm_vcpu *vcpu)
                vmcs_set_bits(GUEST_INTERRUPTIBILITY_INFO,
                              GUEST_INTR_STATE_NMI);
 
-       if (vcpu->kvm->arch.notify_vmexit_flags & KVM_X86_NOTIFY_VMEXIT_USER ||
-           context_invalid) {
-               vcpu->run->exit_reason = KVM_EXIT_NOTIFY;
-               vcpu->run->notify.flags = context_invalid ?
-                                         KVM_NOTIFY_CONTEXT_INVALID : 0;
-               return 0;
-       }
-
-       return 1;
+       return __vmx_handle_notify(vcpu, exit_qual);
 }
 
 static int vmx_get_msr_imm_reg(struct kvm_vcpu *vcpu)
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.