Re: [PATCH] KVM: x86: Reevaluate pending interrupts when enabling ExtINT through LVT0
From: Matthew Leach
Date: Mon Nov 23 2026 - 06:28:45 EST
Hi Jiaming,
"Jiaming Fan" <fan.jiaming@xxxxxxxxxxx> writes:
> On Wed, Nov 04, 2026, Sean Christopherson wrote:
>> Ahh, but there's nowhere for edge-triggered events to be latched, so this only
>> affects level-triggered events. Which means, this?
>>
>> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
>> index d6e5fbc3c58c..b72930a8516d 100644
>> --- a/arch/x86/kvm/lapic.c
>> +++ b/arch/x86/kvm/lapic.c
>> @@ -2554,6 +2554,8 @@ static int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
>> val |= APIC_LVT_MASKED;
>> val &= apic_lvt_mask[index];
>> kvm_lapic_set_reg(apic, reg, val);
>> + if (!(val & APIC_LVT_MASKED) && (val & APIC_LVT_LEVEL_TRIGGER))
>> + kvm_make_request(KVM_REQ_EVENT, apic->vcpu);
>> break;
>> }
>
> The trigger mode check doesn't catch the case Matthew hit. Linux's
> setup_local_APIC() writes LVT0 as plain APIC_DM_EXTINT, without
> APIC_LVT_LEVEL_TRIGGER, so no request is made and the "noapic" hang
> remains.
That's right, this version of the patch wouldn't fix the issue.
> For ExtINT the pending interrupt is latched in the 8259A, whose output
> stays asserted until the guest acks it, not in the LVT entry, so the
> trigger mode bit doesn't tell whether anything is pending. Your first
> version (any unmasked LVT) does work for LVT0.
That matches my understanding. I think the right approach is Sean's
first suggestion (any unmasked LVT).
> There is a second path with the same problem that neither version
> covers: hardware-disabling the APIC through IA32_APIC_BASE. With the
> APIC disabled, kvm_apic_accept_pic_intr() returns true, so an ExtINT
> latched while LVT0 was masked becomes deliverable, but
> __kvm_apic_set_base() doesn't request KVM_REQ_EVENT either:
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -2825,6 +2825,7 @@ static void __kvm_apic_set_base(struct kvm_vcpu *vcpu, u64 value)
> } else {
> static_branch_inc(&apic_hw_disabled.key);
> atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
> + kvm_make_request(KVM_REQ_EVENT, vcpu);
> }
> }
Nice catch! Looks like a very similar problem.
[...]
> Matthew, are you planning a v2? If so, I'm happy to hand over the
> selftest and the APIC_BASE fix. Otherwise I can post a series with
> your patch (reworked per Sean's first suggestion) followed by the
> APIC_BASE fix and the selftest.
Looks like you've done much more digging into this than I have, so
please go ahead and fold my patch into your series.
Regards,
--
Matt