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

From: Binbin Wu

Date: Fri May 08 2026 - 04:56:43 EST




On 5/8/2026 4:53 PM, Peter Zijlstra wrote:
> On Fri, May 08, 2026 at 02:09:09PM +0800, Binbin Wu wrote:
>> On 5/2/2026 4:37 AM, Peter Zijlstra wrote:
>
>>> +noinstr void x86_entry_from_kvm(unsigned int event_type, unsigned int vector)
>>> +{
>>> + if (event_type == EVENT_TYPE_EXTINT) {
>>> +#ifdef CONFIG_X86_64
>>> + /*
>>> + * Use FRED dispatch, even when running IDT. The dispatch
>>> + * tables are kept in sync between FRED and IDT, and the FRED
>>> + * dispatch works well with CFI.
>>> + */
>>> + fred_entry_from_kvm(event_type, vector);
>>> +#else
>>> + idt_entry_from_kvm(vector);
>>> +#endif
>>> + return;
>>> + }
>>> +
>>> + WARN_ON_ONCE(event_type != EVENT_TYPE_NMI);
>>
>> Not sure if it's OK to use WARN_ON_ONCE() here.
>> If the warning is triggered, it could unblock NMI due to handling of #UD.
>
> If that ever triggers you've got bigger problems.

Agree. :)

>
>>> --- a/arch/x86/include/asm/desc.h
>>> +++ b/arch/x86/include/asm/desc.h
>>> @@ -438,6 +438,10 @@ extern void idt_setup_traps(void);
>>> extern void idt_setup_apic_and_irq_gates(void);
>>> extern bool idt_is_f00f_address(unsigned long address);
>>>
>>> +extern void idt_do_interrupt_irqoff(unsigned int vector);
>>
>> In idt_entry_from_kvm() below, gate_offset() returns 'unsigned long', but here
>> it uses 'unsigned int'. It's not safe since there is no guarantee that the
>> address is within 32 bits for x86_64.
>>
>
> Right you are, 'unsigned long address' it is.