]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
x86, mce: implement bootstrapping for machine check wakeups
authorAndi Kleen <andi@firstfloor.org>
Wed, 27 May 2009 19:56:54 +0000 (21:56 +0200)
committerH. Peter Anvin <hpa@zytor.com>
Wed, 3 Jun 2009 21:44:05 +0000 (14:44 -0700)
Machine checks support waking up the mcelog daemon quickly.

The original wake up code for this was pretty ugly, relying on
a idle notifier and a special process flag. The reason it did
it this way is that the machine check handler is not subject
to normal interrupt locking rules so it's not safe
to call wake_up().  Instead it set a process flag
and then either did the wakeup in the syscall return
or in the idle notifier.

This patch adds a new "bootstraping" method as replacement.

The idea is that the handler checks if it's in a state where
it is unsafe to call wake_up(). If it's safe it calls it directly.
When it's not safe -- that is it interrupted in a critical
section with interrupts disables -- it uses a new "self IPI" to trigger
an IPI to its own CPU. This can be done safely because IPI
triggers are atomic with some care. The IPI is raised
once the interrupts are reenabled and can then safely call
wake_up().

When APICs are disabled the event is just queued and will be picked up
eventually by the next polling timer. I think that's a reasonable
compromise, since it should only happen quite rarely.

Contains fixes from Ying Huang.

[ solve conflict on irqinit, make it work on 32bit (entry_arch.h) - HS ]

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
arch/x86/include/asm/entry_arch.h
arch/x86/include/asm/hw_irq.h
arch/x86/include/asm/irq_vectors.h
arch/x86/kernel/cpu/mcheck/mce.c
arch/x86/kernel/entry_64.S
arch/x86/kernel/irqinit.c

index b2eb9c066843f62eaab85f1caf9997b7d27a8f31..4cdcf5a3c96b42551051473236f16c2e30136e6b 100644 (file)
@@ -60,4 +60,8 @@ BUILD_INTERRUPT(thermal_interrupt,THERMAL_APIC_VECTOR)
 BUILD_INTERRUPT(threshold_interrupt,THRESHOLD_APIC_VECTOR)
 #endif
 
+#ifdef CONFIG_X86_NEW_MCE
+BUILD_INTERRUPT(mce_self_interrupt,MCE_SELF_VECTOR)
+#endif
+
 #endif
index a7d14bbae110319cc67ebe6762c0b26d92693fc4..4e59197e29bac6c12a6e7ab672de4310754f4e08 100644 (file)
@@ -32,6 +32,7 @@ extern void error_interrupt(void);
 extern void spurious_interrupt(void);
 extern void thermal_interrupt(void);
 extern void reschedule_interrupt(void);
+extern void mce_self_interrupt(void);
 
 extern void invalidate_interrupt(void);
 extern void invalidate_interrupt0(void);
index 8c46b851296a02554391297840867f8e1b93bf86..68f7cf84a33368ba3cb04790ed07ed7f841d2425 100644 (file)
  */
 #define GENERIC_INTERRUPT_VECTOR       0xed
 
+/*
+ * Self IPI vector for machine checks
+ */
+#define MCE_SELF_VECTOR                        0xeb
+
 /*
  * First APIC vector available to drivers: (vectors 0x30-0xee) we
  * start at 0x31(0x41) to spread out vectors evenly between priority
index 5031814ac9434f27f5bf0fd8b61aba6e8df644f1..1217816278584ef06e5aab3787b5a5c1f6448be2 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/thread_info.h>
 #include <linux/capability.h>
 #include <linux/miscdevice.h>
+#include <linux/interrupt.h>
 #include <linux/ratelimit.h>
 #include <linux/kallsyms.h>
 #include <linux/rcupdate.h>
 #include <linux/fs.h>
 
 #include <asm/processor.h>
+#include <asm/hw_irq.h>
+#include <asm/apic.h>
 #include <asm/idle.h>
+#include <asm/ipi.h>
 #include <asm/mce.h>
 #include <asm/msr.h>
 
@@ -287,6 +291,54 @@ static inline void mce_get_rip(struct mce *m, struct pt_regs *regs)
        }
 }
 
+#ifdef CONFIG_X86_LOCAL_APIC 
+/*
+ * Called after interrupts have been reenabled again
+ * when a MCE happened during an interrupts off region
+ * in the kernel.
+ */
+asmlinkage void smp_mce_self_interrupt(struct pt_regs *regs)
+{
+       ack_APIC_irq();
+       exit_idle();
+       irq_enter();
+       mce_notify_user();
+       irq_exit();
+}
+#endif
+
+static void mce_report_event(struct pt_regs *regs)
+{
+       if (regs->flags & (X86_VM_MASK|X86_EFLAGS_IF)) {
+               mce_notify_user();
+               return;
+       }
+
+#ifdef CONFIG_X86_LOCAL_APIC
+       /*
+        * Without APIC do not notify. The event will be picked
+        * up eventually.
+        */
+       if (!cpu_has_apic)
+               return;
+
+       /*
+        * When interrupts are disabled we cannot use
+        * kernel services safely. Trigger an self interrupt
+        * through the APIC to instead do the notification
+        * after interrupts are reenabled again.
+        */
+       apic->send_IPI_self(MCE_SELF_VECTOR);
+
+       /*
+        * Wait for idle afterwards again so that we don't leave the
+        * APIC in a non idle state because the normal APIC writes
+        * cannot exclude us.
+        */
+       apic_wait_icr_idle();
+#endif
+}
+
 DEFINE_PER_CPU(unsigned, mce_poll_count);
 
 /*
@@ -530,6 +582,8 @@ void do_machine_check(struct pt_regs *regs, long error_code)
        /* notify userspace ASAP */
        set_thread_flag(TIF_MCE_NOTIFY);
 
+       mce_report_event(regs);
+
        /* the last thing we do is clear state */
        for (i = 0; i < banks; i++) {
                if (test_bit(i, toclear))
index a31a7f29cffe0ba1ff57cadc856cdb7557fbb0ba..711c130a8411f233012fbe4d76bbd11450efa192 100644 (file)
@@ -1011,6 +1011,11 @@ apicinterrupt THRESHOLD_APIC_VECTOR \
 apicinterrupt THERMAL_APIC_VECTOR \
        thermal_interrupt smp_thermal_interrupt
 
+#ifdef CONFIG_X86_MCE
+apicinterrupt MCE_SELF_VECTOR \
+       mce_self_interrupt smp_mce_self_interrupt
+#endif
+
 #ifdef CONFIG_SMP
 apicinterrupt CALL_FUNCTION_SINGLE_VECTOR \
        call_function_single_interrupt smp_call_function_single_interrupt
index aab3d277766c4e6edca1a85f7b260aff2c5d80c8..441f6ec6e9d4228e8a1109d59b692a5aa6e5bc6a 100644 (file)
@@ -187,6 +187,9 @@ static void __init apic_intr_init(void)
 #ifdef CONFIG_X86_THRESHOLD
        alloc_intr_gate(THRESHOLD_APIC_VECTOR, threshold_interrupt);
 #endif
+#if defined(CONFIG_X86_NEW_MCE) && defined(CONFIG_X86_LOCAL_APIC)
+       alloc_intr_gate(MCE_SELF_VECTOR, mce_self_interrupt);
+#endif
 
 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_LOCAL_APIC)
        /* self generated IPI for local APIC timer */