Skip to contentSkip to conversation

x86/hotplug: Silence APIC only after all irq's are migrated

PATCH Superseded Ashok Raj 5 participants 9 messages Aug 14, 2020 – Aug 20, 2020

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ashok Raj

author
#0 lore raw

PATCH 1/1 x86/hotplug: Silence APIC only after all irq's are migrated

When offlining CPU's, fixup_irqs() migrates all interrupts away from the outgoing CPU to an online CPU. Its 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 fliping 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")

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
index ffbd9a3d78d8..278cc9f92f2f 100644
@@ -1603,13 +1603,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. Its 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.13.6
#1 lore raw
Quoted 1 line · Ashok Raj

When offlining CPU's, fixup_irqs() migrates all interrupts away from the

CPUs,

Quoted 1 line

outgoing CPU to an online CPU. Its always possible the device sent an

It's

Quoted 2 lines

interrupt to the previous CPU destination. Pending interrupt bit in IRR in lapic identifies such interrupts. apic_soft_disable() will not capture any

LAPIC

Quoted 2 lines

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

Quoted 7 lines

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()

Quoted 8 lines
{
	...
	apic_soft_disable();
	cpu_disable_common();
	  --> fixup_irqs(); // Too late to capture anything in IRR.
}

Just fliping the above call sequence seems to hit the IRR checks

flipping

Quoted 25 lines

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")

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 +0 -0
index ffbd9a3d78d8..278cc9f92f2f 100644

arch/x86/kernel/smpboot.c int native_cpu_disable(void) · line 1610

Quoted 9 lines
arch/x86/kernel/smpboot.c +2 -1
@@ -1603,13 +1603,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. Its important to do apic_soft_disable() after

It's

arch/x86/kernel/smpboot.c int native_cpu_disable(void) · line 1614

Quoted 4 lines
arch/x86/kernel/smpboot.c +4 -0
+	 * 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

CPU

arch/x86/kernel/smpboot.c int native_cpu_disable(void) · line 1615

Quoted 1 line
arch/x86/kernel/smpboot.c +1 -0
+	 * of irq migration to be lost. Check SDM Vol 3 "10.4.7.2 Local

IRQ

arch/x86/kernel/smpboot.c int native_cpu_disable(void) · line 1622

Quoted 9 lines
arch/x86/kernel/smpboot.c +2 -1
+	 * APIC State after It Has been Software Disabled" section for more
+	 * details.
 	 */
 	apic_soft_disable();
-	cpu_disable_common();
 
 	return 0;
 }

thanks.

Signature · 1 line
~Randy
#2 lore raw

Hi Randy

For some unknown reason my previous response said its taiting to be delivered.

Quoted 4 lines · Randy Dunlap
Quoted 1 line · Ashok Raj

When offlining CPU's, fixup_irqs() migrates all interrupts away from the

CPUs,

I'll fix all these in the next rev.

Just waiting to hear back from Thomas if he has additional ones I can fix and resend v2.

Cheers,
Ashok

Quoted 95 lines
Quoted 2 lines

outgoing CPU to an online CPU. Its always possible the device sent an

It's

Quoted 2 lines

interrupt to the previous CPU destination. Pending interrupt bit in IRR in lapic identifies such interrupts. apic_soft_disable() will not capture any

LAPIC

Quoted 2 lines

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

Quoted 7 lines

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()

Quoted 8 lines
{
	...
	apic_soft_disable();
	cpu_disable_common();
	  --> fixup_irqs(); // Too late to capture anything in IRR.
}

Just fliping the above call sequence seems to hit the IRR checks

flipping

Quoted 25 lines

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")

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 +0 -0
index ffbd9a3d78d8..278cc9f92f2f 100644

arch/x86/kernel/smpboot.c int native_cpu_disable(void) · line 1610

Quoted 9 lines
arch/x86/kernel/smpboot.c +2 -1
@@ -1603,13 +1603,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. Its important to do apic_soft_disable() after

It's

arch/x86/kernel/smpboot.c int native_cpu_disable(void) · line 1614

Quoted 4 lines
arch/x86/kernel/smpboot.c +4 -0
+	 * 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

CPU

arch/x86/kernel/smpboot.c int native_cpu_disable(void) · line 1615

Quoted 1 line
arch/x86/kernel/smpboot.c +1 -0
+	 * of irq migration to be lost. Check SDM Vol 3 "10.4.7.2 Local

IRQ

arch/x86/kernel/smpboot.c int native_cpu_disable(void) · line 1622

Quoted 9 lines
arch/x86/kernel/smpboot.c +2 -1
+	 * APIC State after It Has been Software Disabled" section for more
+	 * details.
 	 */
 	apic_soft_disable();
-	cpu_disable_common();
 
 	return 0;
 }

thanks.

Signature · 1 line
~Randy
author
#3 lore raw
In reply to Randy Dunlap

Hi Randy,

Quoted 4 lines · Randy Dunlap
Quoted 1 line · Ashok Raj

When offlining CPU's, fixup_irqs() migrates all interrupts away from the

CPUs,

Thanks for catching these. I'll fix all these suggested changes in my next rev Once i get additional feedback from Thomas.

Quoted 95 lines
Quoted 2 lines

outgoing CPU to an online CPU. Its always possible the device sent an

It's

Quoted 2 lines

interrupt to the previous CPU destination. Pending interrupt bit in IRR in lapic identifies such interrupts. apic_soft_disable() will not capture any

LAPIC

Quoted 2 lines

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

Quoted 7 lines

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()

Quoted 8 lines
{
	...
	apic_soft_disable();
	cpu_disable_common();
	  --> fixup_irqs(); // Too late to capture anything in IRR.
}

Just fliping the above call sequence seems to hit the IRR checks

flipping

Quoted 25 lines

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")

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 +0 -0
index ffbd9a3d78d8..278cc9f92f2f 100644

arch/x86/kernel/smpboot.c int native_cpu_disable(void) · line 1610

Quoted 9 lines
arch/x86/kernel/smpboot.c +2 -1
@@ -1603,13 +1603,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. Its important to do apic_soft_disable() after

It's

arch/x86/kernel/smpboot.c int native_cpu_disable(void) · line 1614

Quoted 4 lines
arch/x86/kernel/smpboot.c +4 -0
+	 * 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

CPU

arch/x86/kernel/smpboot.c int native_cpu_disable(void) · line 1615

Quoted 1 line
arch/x86/kernel/smpboot.c +1 -0
+	 * of irq migration to be lost. Check SDM Vol 3 "10.4.7.2 Local

IRQ

arch/x86/kernel/smpboot.c int native_cpu_disable(void) · line 1622

Quoted 9 lines
arch/x86/kernel/smpboot.c +2 -1
+	 * APIC State after It Has been Software Disabled" section for more
+	 * details.
 	 */
 	apic_soft_disable();
-	cpu_disable_common();
 
 	return 0;
 }

thanks.

Signature · 1 line
~Randy
#4 lore raw
In reply to Ashok Raj

Hi Ashok,
Thank you, Srikanth, and Sukumar for some very impressive debugging here.

Quoted 47 lines · Ashok Raj

When offlining CPU's, fixup_irqs() migrates all interrupts away from the outgoing CPU to an online CPU. Its 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 fliping 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")

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 +0 -0
index ffbd9a3d78d8..278cc9f92f2f 100644

arch/x86/kernel/smpboot.c int native_cpu_disable(void) · line 1609

Quoted 8 lines
arch/x86/kernel/smpboot.c +1 -1
@@ -1603,13 +1603,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.

I'm slightly unclear about whether interrupts are disabled at the core by this point or not. I followed native_cpu_disable() up to __cpu_disable(), up to take_cpu_down(). This is passed into a call to stop_machine_cpuslocked(), where interrupts get disabled at the core. So unless there's another path, it seems like interrupts are always disabled at the core by this point.

If interrupts are always disabled, then the comment above is a little obsolete, since we're not expecting to receive broadcast IPIs from here on out anyway. We could clean up that comment in this change.

If there is a path to here where interrupts are still enabled at the core, then we'd need to watch out, because this change now allows broadcast IPIs to come in during cpu_disable_common(). That could be bad. But I think that's not this case, so this should be ok.

Quoted 17 lines
arch/x86/kernel/smpboot.c +8 -2
+        * messages. Its 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;
 }
--

2.13.6

author
#5 lore raw

Hi Evan

Some details below,

Quoted 54 lines · Evan Green

Hi Ashok,
Thank you, Srikanth, and Sukumar for some very impressive debugging here.

Quoted 50 lines · Ashok Raj

When offlining CPU's, fixup_irqs() migrates all interrupts away from the outgoing CPU to an online CPU. Its 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 fliping 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")

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 +0 -0
index ffbd9a3d78d8..278cc9f92f2f 100644
@@ -1603,13 +1603,20 @@ int native_cpu_disable(void)
        if (ret)
                return ret;
 
Quoted 12 lines

arch/x86/kernel/smpboot.c int native_cpu_disable(void) · line 1609

Quoted 5 lines
arch/x86/kernel/smpboot.c +1 -1
+       cpu_disable_common();
        /*
         * Disable the local APIC. Otherwise IPI broadcasts will reach
         * it. It still responds normally to INIT, NMI, SMI, and SIPI
-        * messages.

I'm slightly unclear about whether interrupts are disabled at the core by this point or not. I followed native_cpu_disable() up to __cpu_disable(), up to take_cpu_down(). This is passed into a call to stop_machine_cpuslocked(), where interrupts get disabled at the core. So unless there's another path, it seems like interrupts are always disabled at the core by this point.

local_irq_disable() just does cli() which allows interrupts to trickle in to the IRR bits, and once you do sti() things would flow back for normal interrupt processing.

Quoted 2 lines

If interrupts are always disabled, then the comment above is a little

Disable interrupts is different from disabling LAPIC. Once you do the apic_soft_disable(), there is nothing flowing into the LAPIC except for INIT, NMI, SMI and SIPI messages.

This turns off the pipe for all other interrupts to enter LAPIC. Which is different from doing a cli().

Quoted 7 lines

obsolete, since we're not expecting to receive broadcast IPIs from here on out anyway. We could clean up that comment in this change.

If there is a path to here where interrupts are still enabled at the core, then we'd need to watch out, because this change now allows broadcast IPIs to come in during cpu_disable_common(). That could be bad. But I think that's not this case, so this should be ok.

Section SDM Vol3.b 10.4.7.2 says.

* The reception of any interrupt or transmission of any IPIs that are in progress when the local APIC is disabled are completed before the local APIC enters the software-disabled state.

It doesn't actually say much about broadcast IPI's, except broadcast NMI for instance, which is still permitted when cli() is set.

Hope this helps.

Cheers,
Ashok

Tested-by on v1 1/1
#8 lore raw
In reply to Ashok Raj
Quoted 29 lines · Ashok Raj

When offlining CPU's, fixup_irqs() migrates all interrupts away from the outgoing CPU to an online CPU. Its 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 fliping 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")
Quoted 9 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]
---

This fixes the lost xhci interrupt for me.
Before this patch a msi interupt was lost after ~200 cycles of toggling CPUs offline/online under heavy usb traffic.

With this patch I ran 3x2000 cycles without any issues (Comet lake, patch on top of 5.8) Tried both with and without CONFIG_IRQ_REMAP. No issues seen.

Reviewed-by Tested-by
#6 lore raw
In reply to Raj, Ashok
Quoted 79 lines · Ashok

Hi Evan

Some details below,

Quoted 54 lines · Evan Green

Hi Ashok,
Thank you, Srikanth, and Sukumar for some very impressive debugging here.

Quoted 50 lines · Ashok Raj

When offlining CPU's, fixup_irqs() migrates all interrupts away from the outgoing CPU to an online CPU. Its 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 fliping 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")

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 +0 -0
index ffbd9a3d78d8..278cc9f92f2f 100644
@@ -1603,13 +1603,20 @@ int native_cpu_disable(void)
        if (ret)
                return ret;
 
Quoted 12 lines

arch/x86/kernel/smpboot.c int native_cpu_disable(void) · line 1609

Quoted 5 lines
arch/x86/kernel/smpboot.c +1 -1
+       cpu_disable_common();
        /*
         * Disable the local APIC. Otherwise IPI broadcasts will reach
         * it. It still responds normally to INIT, NMI, SMI, and SIPI
-        * messages.

I'm slightly unclear about whether interrupts are disabled at the core by this point or not. I followed native_cpu_disable() up to __cpu_disable(), up to take_cpu_down(). This is passed into a call to stop_machine_cpuslocked(), where interrupts get disabled at the core. So unless there's another path, it seems like interrupts are always disabled at the core by this point.

local_irq_disable() just does cli() which allows interrupts to trickle in to the IRR bits, and once you do sti() things would flow back for normal interrupt processing.

Quoted 1 line
Quoted 8 lines
Quoted 1 line

If interrupts are always disabled, then the comment above is a little

Disable interrupts is different from disabling LAPIC. Once you do the apic_soft_disable(), there is nothing flowing into the LAPIC except for INIT, NMI, SMI and SIPI messages.

This turns off the pipe for all other interrupts to enter LAPIC. Which is different from doing a cli().

I understand the distinction. I was mostly musing on the difference in behavior your change causes if this function is entered with interrupts enabled at the core (ie sti()). But I think it never is, so that thought is moot.

I could never repro the issue reliably on comet lake after Thomas' original fix. But I can still repro it easily on jasper lake. And this patch fixes the issue for me on that platform. Thanks for the fix.

author
#7 lore raw
Quoted 28 lines · Evan Green
Quoted 14 lines
Quoted 7 lines

I'm slightly unclear about whether interrupts are disabled at the core by this point or not. I followed native_cpu_disable() up to __cpu_disable(), up to take_cpu_down(). This is passed into a call to stop_machine_cpuslocked(), where interrupts get disabled at the core. So unless there's another path, it seems like interrupts are always disabled at the core by this point.

local_irq_disable() just does cli() which allows interrupts to trickle in to the IRR bits, and once you do sti() things would flow back for normal interrupt processing.

Quoted 1 line
Quoted 8 lines
Quoted 1 line

If interrupts are always disabled, then the comment above is a little

Disable interrupts is different from disabling LAPIC. Once you do the apic_soft_disable(), there is nothing flowing into the LAPIC except for INIT, NMI, SMI and SIPI messages.

This turns off the pipe for all other interrupts to enter LAPIC. Which is different from doing a cli().

I understand the distinction. I was mostly musing on the difference in behavior your change causes if this function is entered with interrupts enabled at the core (ie sti()). But I think it never is, so that thought is moot.

Quoted 6 lines

I could never repro the issue reliably on comet lake after Thomas' original fix. But I can still repro it easily on jasper lake. And this patch fixes the issue for me on that platform. Thanks for the fix.

Thanks Evan for testing. I'll wait for thomas if he finds anything else that needs to be fixed and send a final v2 after fixing the typos and others identified by Randy.

Cheers,
Ashok