Re: [PATCH RFC v2 1/1] x86/irq/i8259: Ack PIC vectors in the LAPIC ISR

From: Dongli Zhang

Date: Wed Nov 25 2026 - 04:51:50 EST


Hi Chao,

On Fri, Nov 20, 2026 12:14:31AM -0800, Chao Gao wrote:
> On Thu, Nov 12, 2026 at 05: 06: 04PM +0000, Dongli Zhang wrote: >This is to fix
> a LAPIC ISR stall that can happen in a kdump kernel, but can >also happen in
> other scenarios. > >The issue can be intermittently reproduced in a QEMU/KVM
>
> On Thu, Nov 12, 2026 at 05:06:04PM +0000, Dongli Zhang wrote:
>>This is to fix a LAPIC ISR stall that can happen in a kdump kernel, but can
>>also happen in other scenarios.
>>
>>The issue can be intermittently reproduced in a QEMU/KVM guest when there
>>are large number of VMs on the same host.
>
> Does your production kernel include commit 1b558e14f3c1 ("x86/apic: Make the
> ISR clearing sane")? If so, can you reproduce this issue with it
> reverted? It looks to me that the one-pass ISR clearing doesn't clear all
> stale ISR/IRR bits.
>
> The changelog of that commit says
>
> 2) If interrupts are enabled, then the APIC propagates the IRR bit to the
> ISR and raises the interrupt in the CPU, which means that code _cannot_
> observe the ISR bit for any of those IRR bits.
>
> Your analysis shows a case where this doesn't hold, since the 8259A
> handler doesn't EOI the local APIC and the ISR bit stays set.
>
> You can certainly still reproduce it by injecting an interrupt manually
> after the ISR clearing. But I think the multi-pass scan may be enough for
> any practical case.

This commit came to my mind at first because I thought it was a bugfix.

When we ran into the issue, the guest VM kernel didn't have commit 1b558e14f3c1
("x86/apic: Make the ISR clearing sane").

The issue was hard to reproduce at first. I added printk calls in many places in
the guest kernel to narrow down when it occurred. At many points in
setup_local_APIC(), there were no pending IRR or ISR bits.

Based on my analysis, the issue happens if the virtio-net interrupt is delivered
before legacy interrupt handling is handed over from the 8259A to the IOAPIC.
Unfortunately, apic_clear_isr() is called before setup_IO_APIC().

https://lore.kernel.org/all/e4070a8b-fa4d-4ba1-a333-e7cf72da416e@xxxxxxxxxx/

apic_bsp_setup()
-> setup_local_APIC()
-> apic_clear_isr() ---> clear pending irr/isr
-> ----> virtio-net interrupt delivered ...
-> setup_IO_APIC()

Thank you very much!

Dongli Zhang

>
>>
>>Device interrupts can use the PIC, IOAPIC, or MSI-X. Nowadays, most x86
>>device interrupts use MSI-X or the IOAPIC. However, the PIC handler does
>>not send a LAPIC EOI, even when the interrupt it handles has set a bit in
>>the LAPIC ISR.
>>
>>For example, suppose there is a QEMU/KVM guest using virtio-net.
>>
>>1. virtio-net is about to deliver vector 52 to CPU 2 (APIC ID 2), but the
>>guest suddenly panics on that CPU.
>>
>>2. The kdump kernel boots on APIC ID 2, which becomes CPU 0 in the new
>>kernel.
>>
>>3. Suppose delivery of the interrupt is delayed, so vector 52 has not
>>reached the CPU yet.
>>
>>4. On the new CPU 0, init_ISA_irqs() initially sets up the legacy IRQs to
>>use the PIC. Vector 52 maps to IRQ4, which is normally used by the serial
>>console.
>>
>>5. Before these legacy IRQs are handed over to the IOAPIC, suppose the
>>delayed vector 52 arrives through the LAPIC and sets its ISR bit.
>>
>>6. The new kernel handles it as PIC IRQ4. Since mask_and_ack_8259A()
>>does not send a LAPIC EOI, the ISR bit for vector 52 remains set.
>