x86/hotplug: Silence APIC only after all irq's are migrated
Subsystems (2)
PATCH v2 1/1 x86/hotplug: Silence APIC only after all irq's are migrated
When offlining CPUs, fixup_irqs() migrates all interrupts away from the outgoing CPU to an online CPU. It's always possible the device sent an interrupt to the previous CPU destination. Pending interrupt bit in IRR in LAPIC identifies such interrupts. apic_soft_disable() will not capture any new interrupts in IRR. This causes interrupts from device to be lost during CPU offline. The issue was found when explicitly setting MSI affinity to a CPU and immediately offlining it. It was simple to recreate with a USB ethernet device and doing I/O to it while the CPU is offlined. Lost interrupts happen even when Interrupt Remapping is enabled.
Current code does apic_soft_disable() before migrating interrupts.
native_cpu_disable()
{
...
apic_soft_disable();
cpu_disable_common();
--> fixup_irqs(); // Too late to capture anything in IRR.
}Just flipping the above call sequence seems to hit the IRR checks and the lost interrupt is fixed for both legacy MSI and when interrupt remapping is enabled.
---
v2:
- Typos and fixes suggested by Randy Dunlap
To: [email protected]
To: Thomas Gleixner <[email protected]>
Cc: Sukumar Ghorai <[email protected]>
Cc: Srikanth Nandamuri <[email protected]>
Cc: Evan Green <[email protected]>
Cc: Mathias Nyman <[email protected]>
Cc: Bjorn Helgaas <[email protected]>
Cc: [email protected]
--- arch/x86/kernel/smpboot.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
arch/x86/kernel/smpboot.c +9 -2
@@ -1594,13 +1594,20 @@ int native_cpu_disable(void)if (ret)return ret; +cpu_disable_common ();/* * Disable the local APIC. Otherwise IPI broadcasts will reach * it. It still responds normally to INIT, NMI, SMI, and SIPI -* messages. +* messages. It's important to do apic_soft_disable() after +* fixup_irqs(), because fixup_irqs() called from cpu_disable_common() +* depends on IRR being set. After apic_soft_disable() CPU preserves +* currently set IRR/ISR but new interrupts will not set IRR. +* This causes interrupts sent to outgoing CPU before completion +* of IRQ migration to be lost. Check SDM Vol 3 "10.4.7.2 Local +* APIC State after It Has been Software Disabled" section for more +* details. */ apic_soft_disable (); -cpu_disable_common ();return 0 ; }
Signature · 1 line
2.7.4
Quoted 31 lines · Ashok Raj
When offlining CPUs,
fixup_irqs()migrates all interrupts away from the outgoing CPU to an online CPU. It's always possible the device sent an interrupt to the previous CPU destination. Pending interrupt bit in IRR in LAPIC identifies such interrupts.apic_soft_disable()will not capture any new interrupts in IRR. This causes interrupts from device to be lost during CPU offline. The issue was found when explicitly setting MSI affinity to a CPU and immediately offlining it. It was simple to recreate with a USB ethernet device and doing I/O to it while the CPU is offlined. Lost interrupts happen even when Interrupt Remapping is enabled.Current code does
apic_soft_disable()before migrating interrupts.
native_cpu_disable(){ ... apic_soft_disable(); cpu_disable_common(); --> fixup_irqs(); // Too late to capture anything in IRR. }Just flipping the above call sequence seems to hit the IRR checks and the lost interrupt is fixed for both legacy MSI and when interrupt remapping is enabled.
Fixes 60dcaad5736f ("x86/hotplug: Silence APIC and NMI when CPU is dead")Reported-by Evan Green <[email protected]>Tested-by Mathias Nyman <[email protected]>Tested-by Evan Green <[email protected]>Reviewed-by Evan Green <[email protected]>Signed-off-by Ashok Raj <[email protected]>
Quoted 3 lines
---
v2:
- Typos and fixes suggested by Randy Dunlap
Those all look good now. Thanks for the update.
Quoted 11 lines
To: [email protected]
To: Thomas Gleixner <[email protected]>
Cc: Sukumar Ghorai <[email protected]>
Cc: Srikanth Nandamuri <[email protected]>
Cc: Evan Green <[email protected]>
Cc: Mathias Nyman <[email protected]>
Cc: Bjorn Helgaas <[email protected]>
Cc: [email protected]--- arch/x86/kernel/smpboot.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
Signature · 1 line
~Randy
Hi Thomas,
I was wondering if you got a chance to take a look at this fix?
I had some mail issues recently and they showed up at lore after 2 days. I wasn't sure if you got the original mail, or maybe it didn't make it.
If you had a different way to fix it, we can try those out.
Quoted 20 lines · Ashok Raj
When offlining CPUs,
fixup_irqs()migrates all interrupts away from the outgoing CPU to an online CPU. It's always possible the device sent an interrupt to the previous CPU destination. Pending interrupt bit in IRR in LAPIC identifies such interrupts.apic_soft_disable()will not capture any new interrupts in IRR. This causes interrupts from device to be lost during CPU offline. The issue was found when explicitly setting MSI affinity to a CPU and immediately offlining it. It was simple to recreate with a USB ethernet device and doing I/O to it while the CPU is offlined. Lost interrupts happen even when Interrupt Remapping is enabled.Current code does
apic_soft_disable()before migrating interrupts.
native_cpu_disable(){ ... apic_soft_disable(); cpu_disable_common(); --> fixup_irqs(); // Too late to capture anything in IRR. }
Quoted 3 lines
Just flipping the above call sequence seems to hit the IRR checks and the lost interrupt is fixed for both legacy MSI and when interrupt remapping is enabled.
On another note, we have tested both with and without the read after write when programming MSI addr/data on the device. It didn't seem to change the results. But I think its a useful one to add for correctness.
https://lore.kernel.org/lkml/[email protected]/
This bug been eluding for a while. Looking for your feedback.
Quoted 54 lines
Fixes 60dcaad5736f ("x86/hotplug: Silence APIC and NMI when CPU is dead")Reported-by Evan Green <[email protected]>Tested-by Mathias Nyman <[email protected]>Tested-by Evan Green <[email protected]>Reviewed-by Evan Green <[email protected]>Signed-off-by Ashok Raj <[email protected]>---
v2:
- Typos and fixes suggested by Randy DunlapTo: [email protected]
To: Thomas Gleixner <[email protected]>
Cc: Sukumar Ghorai <[email protected]>
Cc: Srikanth Nandamuri <[email protected]>
Cc: Evan Green <[email protected]>
Cc: Mathias Nyman <[email protected]>
Cc: Bjorn Helgaas <[email protected]>
Cc: [email protected]--- arch/x86/kernel/smpboot.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)arch/x86/kernel/smpboot.c +9
-2@@ -1594,13 +1594,20 @@ int native_cpu_disable(void)if (ret)return ret; +cpu_disable_common ();/* * Disable the local APIC. Otherwise IPI broadcasts will reach * it. It still responds normally to INIT, NMI, SMI, and SIPI -* messages. +* messages. It's important to do apic_soft_disable() after +* fixup_irqs(), because fixup_irqs() called from cpu_disable_common() +* depends on IRR being set. After apic_soft_disable() CPU preserves +* currently set IRR/ISR but new interrupts will not set IRR. +* This causes interrupts sent to outgoing CPU before completion +* of IRQ migration to be lost. Check SDM Vol 3 "10.4.7.2 Local +* APIC State after It Has been Software Disabled" section for more +* details. */ apic_soft_disable (); -cpu_disable_common ();return 0 ; }Signature · 1 line
2.7.4
Ashok,
Quoted 9 lines · Ashok Raj
When offlining CPUs,
fixup_irqs()migrates all interrupts away from the outgoing CPU to an online CPU. It's always possible the device sent an interrupt to the previous CPU destination. Pending interrupt bit in IRR in LAPIC identifies such interrupts.apic_soft_disable()will not capture any new interrupts in IRR. This causes interrupts from device to be lost during CPU offline. The issue was found when explicitly setting MSI affinity to a CPU and immediately offlining it. It was simple to recreate with a USB ethernet device and doing I/O to it while the CPU is offlined. Lost interrupts happen even when Interrupt Remapping is enabled.
New lines exist for a reason. They help to structure information. For the content, please see below.
Quoted 10 lines
Current code does
apic_soft_disable()before migrating interrupts.
native_cpu_disable(){ ... apic_soft_disable(); cpu_disable_common(); --> fixup_irqs(); // Too late to capture anything in IRR. }
Quoted 3 lines
Just flipping the above call sequence seems to hit the IRR checks and the lost interrupt is fixed for both legacy MSI and when interrupt remapping is enabled.
Seems to hit? Come on, we really want changelogs which are based on facts and not on assumptions.
Aside of that, yes that's a really subtle one and thanks for tracking it down! For some reason I never looked at that ordering, but now that you stick it in front of me, it's pretty clear that this is the root cause.
arch/x86/kernel/smpboot.c int native_cpu_disable(void)
Quoted 7 lines
arch/x86/kernel/smpboot.c +3
-1/* * Disable the local APIC. Otherwise IPI broadcasts will reach * it. It still responds normally to INIT, NMI, SMI, and SIPI -* messages. +* messages. It's important to do apic_soft_disable() after +* fixup_irqs(), because fixup_irqs() called from cpu_disable_common() +* depends on IRR being set.
That sentence does not make sense to me.
Review
Quoted 2 lines
(quoted diff) +2
-0+ .... After apic_soft_disable() CPU preserves + * currently set IRR/ISR but new interrupts will not set IRR.
I agree with the IRR part, but ISR is simply impossible to be set in this situation.
arch/x86/kernel/smpboot.c int native_cpu_disable(void) · line 1608
Quoted 4 lines
arch/x86/kernel/smpboot.c +4
-0+* This causes interrupts sent to outgoing CPU before completion +* of IRQ migration to be lost. Check SDM Vol 3 "10.4.7.2 Local +* APIC State after It Has been Software Disabled" section for more +* details.
Please do not use the SDM chapter number of today. It's going to be a different one with the next version.
Something like this perhaps?
/*
* Disable the local APIC. Otherwise IPI broadcasts will reach
* it. It still responds normally to INIT, NMI, SMI, and SIPI
* messages.
*
* Disabling the APIC must happen after cpu_disable_common()
* which invokes fixup_irqs().
*
* Disabling the APIC preserves already set bits in IRR, but
* an interrupt arriving after disabling the local APIC does not
* set the corresponding IRR bit.
*
* fixup_irqs() scans IRR for set bits so it can raise a not
* yet handled interrupt on the new destination CPU via an IPI
* but obviously it can't do so for IRR bits which are not set.
* IOW, interrupts arriving after disabling the local APIC will
* be lost.
*/
Hmm?
The changelog wants to have a corresponding update.
Thanks,
tglx
Hi Thomas,
Quoted 13 lines · Thomas Gleixner
Ashok,
Quoted 9 lines · Ashok Raj
When offlining CPUs,
fixup_irqs()migrates all interrupts away from the outgoing CPU to an online CPU. It's always possible the device sent an interrupt to the previous CPU destination. Pending interrupt bit in IRR in LAPIC identifies such interrupts.apic_soft_disable()will not capture any new interrupts in IRR. This causes interrupts from device to be lost during CPU offline. The issue was found when explicitly setting MSI affinity to a CPU and immediately offlining it. It was simple to recreate with a USB ethernet device and doing I/O to it while the CPU is offlined. Lost interrupts happen even when Interrupt Remapping is enabled.
Quoted 2 lines
New lines exist for a reason. They help to structure information. For the content, please see below.
Will work on that :-)
Quoted 11 lines
Quoted 11 lines
Current code does
apic_soft_disable()before migrating interrupts.
native_cpu_disable(){ ... apic_soft_disable(); cpu_disable_common(); --> fixup_irqs(); // Too late to capture anything in IRR. }
Quoted 6 lines
Quoted 3 lines
Just flipping the above call sequence seems to hit the IRR checks and the lost interrupt is fixed for both legacy MSI and when interrupt remapping is enabled.
Seems to hit? Come on, we really want changelogs which are based on facts and not on assumptions.
What I intended to convay was by placing a debug trace_printk() at fixup_irqs(), it was *indeed* observed. Before the change I never noticed that path being covered.
Just my Inglish (Indian English) tricking you :-). Will make them sensible in the next update.
Quoted 5 lines
Aside of that, yes that's a really subtle one and thanks for tracking it down! For some reason I never looked at that ordering, but now that you stick it in front of me, it's pretty clear that this is the root cause.
Quoted 9 lines
arch/x86/kernel/smpboot.c int native_cpu_disable(void)
Quoted 7 lines
arch/x86/kernel/smpboot.c +3
-1/* * Disable the local APIC. Otherwise IPI broadcasts will reach * it. It still responds normally to INIT, NMI, SMI, and SIPI -* messages. +* messages. It's important to do apic_soft_disable() after +* fixup_irqs(), because fixup_irqs() called from cpu_disable_common() +* depends on IRR being set. That sentence does not make sense to me.
Right, I was just stating the obvious. Since fixup_irqs() isn't called right in that function, it was suggested to make that connection explicit.
Your writeup below is crystal.. so will replace with what you have below.
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ .... After apic_soft_disable() CPU preserves + * currently set IRR/ISR but new interrupts will not set IRR.I agree with the IRR part, but ISR is simply impossible to be set in this situation.
You are correct. I was trying to convey what the SDM said, but its probably irrelavant for this discussion.
Quoted 30 lines
arch/x86/kernel/smpboot.c int native_cpu_disable(void) · line 1608
Quoted 5 lines
arch/x86/kernel/smpboot.c +4
-0+* This causes interrupts sent to outgoing CPU before completion +* of IRQ migration to be lost. Check SDM Vol 3 "10.4.7.2 Local +* APIC State after It Has been Software Disabled" section for more +* details. Please do not use the SDM chapter number of today. It's going to be a different one with the next version.
Something like this perhaps?
/*
* Disable the local APIC. Otherwise IPI broadcasts will reach
* it. It still responds normally to INIT, NMI, SMI, and SIPI
* messages.
*
* Disabling the APIC must happen aftercpu_disable_common()
* which invokesfixup_irqs().
*
* Disabling the APIC preserves already set bits in IRR, but
* an interrupt arriving after disabling the local APIC does not
* set the corresponding IRR bit.
*
*fixup_irqs()scans IRR for set bits so it can raise a not
* yet handled interrupt on the new destination CPU via an IPI
* but obviously it can't do so for IRR bits which are not set.
* IOW, interrupts arriving after disabling the local APIC will
* be lost.
*/
Quoted 3 lines
Hmm?
The changelog wants to have a corresponding update.
Will do ...
Cheers,
Ashok