x86/hotplug: Silence APIC only after all irq's are migrated
Subsystems (2)
PATCH v3 1/1 x86/hotplug: Silence APIC only after all irq's are migrated
There is a race when taking a CPU offline. Current code looks like this:
native_cpu_disable()
{
...
apic_soft_disable();
/*
* Any existing set bits for pending interrupt to
* this CPU are preserved and will be sent via IPI
* to another CPU by fixup_irqs().
*/
cpu_disable_common();
{
....
/*
* Race window happens here. Once local APIC has been
* disabled any new interrupts from the device to
* the old CPU are lost
*/
fixup_irqs(); // Too late to capture anything in IRR.
...
}
}The fix is to disable the APIC *after* cpu_disable_common().
Testing was done with a USB NIC that provided a source of frequent interrupts. A script migrated interrupts to a specific CPU and then took that CPU offline.
---
v3:
Fix commit message and comments per Thomas.
https://lore.kernel.org/lkml/[email protected]/
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]
Cc: [email protected]
--- arch/x86/kernel/smpboot.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
arch/x86/kernel/smpboot.c +20 -6
@@ -1594,14 +1594,28 @@ int native_cpu_disable(void)if (ret)return ret; -/* -* Disable the local APIC. Otherwise IPI broadcasts will reach -* it. It still responds normally to INIT, NMI, SMI, and SIPI -* messages. -*/ -apic_soft_disable ();cpu_disable_common (); +/* +* 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. +*/ +apic_soft_disable (); +return 0 ; }
Signature · 1 line
2.7.4
[tip: x86/urgent] x86/hotplug: Silence APIC only after all interrupts are migrated
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 52d6b926aabc47643cd910c85edb262b7f44c168 Gitweb: https://git.kernel.org/tip/52d6b926aabc47643cd910c85edb262b7f44c168 Author: Ashok Raj <[email protected]> AuthorDate: Wed, 26 Aug 2020 21:12:10 -07:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 27 Aug 2020 09:29:23 +02:00
x86/hotplug: Silence APIC only after all interrupts are migrated
There is a race when taking a CPU offline. Current code looks like this:
native_cpu_disable()
{
...
apic_soft_disable();
/*
* Any existing set bits for pending interrupt to
* this CPU are preserved and will be sent via IPI
* to another CPU by fixup_irqs().
*/
cpu_disable_common();
{
....
/*
* Race window happens here. Once local APIC has been
* disabled any new interrupts from the device to
* the old CPU are lost
*/
fixup_irqs(); // Too late to capture anything in IRR.
...
}
}The fix is to disable the APIC *after* cpu_disable_common().
Testing was done with a USB NIC that provided a source of frequent interrupts. A script migrated interrupts to a specific CPU and then took that CPU offline.
--- arch/x86/kernel/smpboot.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
arch/x86/kernel/smpboot.c +20 -6
@@ -1594,14 +1594,28 @@ int native_cpu_disable(void)if (ret)return ret; -/* -* Disable the local APIC. Otherwise IPI broadcasts will reach -* it. It still responds normally to INIT, NMI, SMI, and SIPI -* messages. -*/ -apic_soft_disable ();cpu_disable_common (); +/* +* 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. +*/ +apic_soft_disable (); +return 0 ; }