]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
x86/hotplug: Silence APIC and NMI when CPU is dead
authorThomas Gleixner <tglx@linutronix.de>
Wed, 24 Jul 2019 15:25:52 +0000 (17:25 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Thu, 25 Jul 2019 14:11:59 +0000 (16:11 +0200)
In order to support IPI/NMI broadcasting via the shorthand mechanism side
effects of shorthands need to be mitigated:

 Shorthand IPIs and NMIs hit all CPUs including unplugged CPUs

Neither of those can be handled on unplugged CPUs for obvious reasons.

It would be trivial to just fully disable the APIC via the enable bit in
MSR_APICBASE. But that's not possible because clearing that bit on systems
based on the 3 wire APIC bus would require a hardware reset to bring it
back as the APIC would lose track of bus arbitration. On systems with FSB
delivery APICBASE could be disabled, but it has to be guaranteed that no
interrupt is sent to the APIC while in that state and it's not clear from
the SDM whether it still responds to INIT/SIPI messages.

Therefore stay on the safe side and switch the APIC into soft disabled mode
so it won't deliver any regular vector to the CPU.

NMIs are still propagated to the 'dead' CPUs. To mitigate that add a check
for the CPU being offline on early nmi entry and if so bail.

Note, this cannot use the stop/restart_nmi() magic which is used in the
alternatives code. A dead CPU cannot invoke nmi_enter() or anything else
due to RCU and other reasons.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1907241723290.1791@nanos.tec.linutronix.de
arch/x86/include/asm/apic.h
arch/x86/kernel/apic/apic.c
arch/x86/kernel/nmi.c
arch/x86/kernel/smpboot.c

index f53eda2c986bbc80236bed40dfacff739aa5a645..cae7e0d02476adc59dd971ff209b989e0aaf6e61 100644 (file)
@@ -136,6 +136,7 @@ extern int lapic_get_maxlvt(void);
 extern void clear_local_APIC(void);
 extern void disconnect_bsp_APIC(int virt_wire_setup);
 extern void disable_local_APIC(void);
+extern void apic_soft_disable(void);
 extern void lapic_shutdown(void);
 extern void sync_Arb_IDs(void);
 extern void init_bsp_APIC(void);
index fe30d1854a4e26f0181dca4be566ffa9568af197..831274e3c09f28a73fe765f2a04d2c8ff3615e2c 100644 (file)
@@ -1182,25 +1182,38 @@ void clear_local_APIC(void)
 }
 
 /**
- * disable_local_APIC - clear and disable the local APIC
+ * apic_soft_disable - Clears and software disables the local APIC on hotplug
+ *
+ * Contrary to disable_local_APIC() this does not touch the enable bit in
+ * MSR_IA32_APICBASE. Clearing that bit on systems based on the 3 wire APIC
+ * bus would require a hardware reset as the APIC would lose track of bus
+ * arbitration. On systems with FSB delivery APICBASE could be disabled,
+ * but it has to be guaranteed that no interrupt is sent to the APIC while
+ * in that state and it's not clear from the SDM whether it still responds
+ * to INIT/SIPI messages. Stay on the safe side and use software disable.
  */
-void disable_local_APIC(void)
+void apic_soft_disable(void)
 {
-       unsigned int value;
-
-       /* APIC hasn't been mapped yet */
-       if (!x2apic_mode && !apic_phys)
-               return;
+       u32 value;
 
        clear_local_APIC();
 
-       /*
-        * Disable APIC (implies clearing of registers
-        * for 82489DX!).
-        */
+       /* Soft disable APIC (implies clearing of registers for 82489DX!). */
        value = apic_read(APIC_SPIV);
        value &= ~APIC_SPIV_APIC_ENABLED;
        apic_write(APIC_SPIV, value);
+}
+
+/**
+ * disable_local_APIC - clear and disable the local APIC
+ */
+void disable_local_APIC(void)
+{
+       /* APIC hasn't been mapped yet */
+       if (!x2apic_mode && !apic_phys)
+               return;
+
+       apic_soft_disable();
 
 #ifdef CONFIG_X86_32
        /*
index 4df7705022b9d99500d3c36e8c524f00aed4dfe6..e676a9916c498225ea32822a5cae851288d6737c 100644 (file)
@@ -512,6 +512,9 @@ NOKPROBE_SYMBOL(is_debug_stack);
 dotraplinkage notrace void
 do_nmi(struct pt_regs *regs, long error_code)
 {
+       if (IS_ENABLED(CONFIG_SMP) && cpu_is_offline(smp_processor_id()))
+               return;
+
        if (this_cpu_read(nmi_state) != NMI_NOT_RUNNING) {
                this_cpu_write(nmi_state, NMI_LATCHED);
                return;
index fdbd47ceb84d45cc9db743633e42f29e18913d59..c19f8e21b7484c05c3ba5dd147dea60ec199c689 100644 (file)
@@ -1596,7 +1596,12 @@ int native_cpu_disable(void)
        if (ret)
                return ret;
 
-       clear_local_APIC();
+       /*
+        * 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();
 
        return 0;