Re: [PATCH 1/2] x86/kvm/vmx: Move IRQ/NMI dispatch from KVM into x86 core

From: Peter Zijlstra

Date: Fri May 01 2026 - 16:32:18 EST


On Tue, Apr 28, 2026 at 01:25:58PM +0200, Paolo Bonzini wrote:

> > > +#if IS_ENABLED(CONFIG_KVM_INTEL)
> > > +/*
> > > + * On VMX, NMIs and IRQs (as configured by KVM) are acknowledge by hardware as
> >
> > s/acknowledge/acknowledged
> > > + * part of the VM-Exit, i.e. the event itself is consumed as part the VM-Exit.
> > > + * x86_entry_from_kvm() is invoked by KVM to effectively forward NMIs and IRQs
> > > + * to the kernel for servicing. On SVM, a.k.a. AMD, the NMI/IRQ VM-Exit is
> > > + * purely a signal that an NMI/IRQ is pending, i.e. the event that triggered
> > > + * the VM-Exit is held pending until it's unblocked in the host.
> > > + */
> >
> > [...]
> >
> > > -
> > > -#if IS_ENABLED(CONFIG_KVM_INTEL)
> > > -/*
> > > - * Special entry point for VMX which invokes this on the kernel stack, even for
> > > - * 64-bit, i.e. without using an IST. asm_exc_nmi() requires an IST to work
> >
> > Although it's being removed, I guess what it says is still true?
> >
> > It says asm_exc_nmi() requires an IST to work correctly, and the new path for
> > handling NMI when FRED is disabled.
> >
> > idt_entry_from_kvm
> > idt_do_nmi_irqoff
> > IDT_DO_EVENT_IRQOFF call asm_exc_nmi
> > ...
> > call asm_exc_nmi
> >
> > It seems the stack before calling asm_exc_nmi is not an IST?
> > Does it matter?
>
> I think it does, the IST is needed because of all the stuff to detect
> recursive NMIs. So asm_exc_nmi_kvm_vmx needs to remain.
>
> By the way, here:
>
> > + /*
> > + * Notably, we must use IDT dispatch for NMI when running in IDT mode.
> > + * The FRED NMI context is significantly different and will not work
> > + * right (speficially FRED fixed the NMI recursion issue).
> > + */
>
> It's even more important to note that NMIs need an IRET in order to unblock
> further NMIs. This is even more important than the recursion issue, which
> does not affect KVM's non-IST entry into the NMI handler, and is the real
> reason to use IDT_DO_EVENT_IRQOFF to build the interrupt stack frame for
> NMIs.

Durr, I missed that: DECLARE_IDTENTRY_NMI != DECLARE_IDTENTRY_RAW

Let me go rectify that.