2 * Machine check handler.
4 * K8 parts Copyright 2002,2003 Andi Kleen, SuSE Labs.
5 * Rest from unknown author(s).
6 * 2004 Andi Kleen. Rewrote most of it.
7 * Copyright 2008 Intel Corporation
10 #include <linux/thread_info.h>
11 #include <linux/capability.h>
12 #include <linux/miscdevice.h>
13 #include <linux/interrupt.h>
14 #include <linux/ratelimit.h>
15 #include <linux/kallsyms.h>
16 #include <linux/rcupdate.h>
17 #include <linux/kobject.h>
18 #include <linux/uaccess.h>
19 #include <linux/kdebug.h>
20 #include <linux/kernel.h>
21 #include <linux/percpu.h>
22 #include <linux/string.h>
23 #include <linux/sysdev.h>
24 #include <linux/delay.h>
25 #include <linux/ctype.h>
26 #include <linux/sched.h>
27 #include <linux/sysfs.h>
28 #include <linux/types.h>
29 #include <linux/init.h>
30 #include <linux/kmod.h>
31 #include <linux/poll.h>
32 #include <linux/nmi.h>
33 #include <linux/cpu.h>
34 #include <linux/smp.h>
37 #include <linux/debugfs.h>
39 #include <asm/processor.h>
40 #include <asm/hw_irq.h>
47 #include "mce-internal.h"
49 int mce_disabled __read_mostly;
51 #define MISC_MCELOG_MINOR 227
53 #define SPINUNIT 100 /* 100ns */
57 DEFINE_PER_CPU(unsigned, mce_exception_count);
61 * 0: always panic on uncorrected errors, log corrected errors
62 * 1: panic or SIGBUS on uncorrected errors, log corrected errors
63 * 2: SIGBUS or log uncorrected errors (if possible), log corrected errors
64 * 3: never panic or SIGBUS, log all errors (for testing only)
66 static int tolerant __read_mostly = 1;
67 static int banks __read_mostly;
68 static int rip_msr __read_mostly;
69 static int mce_bootlog __read_mostly = -1;
70 static int monarch_timeout __read_mostly = -1;
71 static int mce_panic_timeout __read_mostly;
72 static int mce_dont_log_ce __read_mostly;
73 int mce_cmci_disabled __read_mostly;
74 int mce_ignore_ce __read_mostly;
75 int mce_ser __read_mostly;
77 struct mce_bank *mce_banks __read_mostly;
79 /* User mode helper program triggered by machine check event */
80 static unsigned long mce_need_notify;
81 static char mce_helper[128];
82 static char *mce_helper_argv[2] = { mce_helper, NULL };
84 static DECLARE_WAIT_QUEUE_HEAD(mce_wait);
85 static DEFINE_PER_CPU(struct mce, mces_seen);
86 static int cpu_missing;
89 * CPU/chipset specific EDAC code can register a notifier call here to print
90 * MCE errors in a human-readable form.
92 ATOMIC_NOTIFIER_HEAD(x86_mce_decoder_chain);
93 EXPORT_SYMBOL_GPL(x86_mce_decoder_chain);
95 static int default_decode_mce(struct notifier_block *nb, unsigned long val,
98 pr_emerg("No human readable MCE decoding support on this CPU type.\n");
99 pr_emerg("Run the message through 'mcelog --ascii' to decode.\n");
104 static struct notifier_block mce_dec_nb = {
105 .notifier_call = default_decode_mce,
109 /* MCA banks polled by the period polling timer for corrected events */
110 DEFINE_PER_CPU(mce_banks_t, mce_poll_banks) = {
111 [0 ... BITS_TO_LONGS(MAX_NR_BANKS)-1] = ~0UL
114 static DEFINE_PER_CPU(struct work_struct, mce_work);
116 /* Do initial initialization of a struct mce */
117 void mce_setup(struct mce *m)
119 memset(m, 0, sizeof(struct mce));
120 m->cpu = m->extcpu = smp_processor_id();
122 /* We hope get_seconds stays lockless */
123 m->time = get_seconds();
124 m->cpuvendor = boot_cpu_data.x86_vendor;
125 m->cpuid = cpuid_eax(1);
127 m->socketid = cpu_data(m->extcpu).phys_proc_id;
129 m->apicid = cpu_data(m->extcpu).initial_apicid;
130 rdmsrl(MSR_IA32_MCG_CAP, m->mcgcap);
133 DEFINE_PER_CPU(struct mce, injectm);
134 EXPORT_PER_CPU_SYMBOL_GPL(injectm);
137 * Lockless MCE logging infrastructure.
138 * This avoids deadlocks on printk locks without having to break locks. Also
139 * separate MCEs from kernel messages to avoid bogus bug reports.
142 static struct mce_log mcelog = {
143 .signature = MCE_LOG_SIGNATURE,
145 .recordlen = sizeof(struct mce),
148 void mce_log(struct mce *mce)
150 unsigned next, entry;
155 entry = rcu_dereference(mcelog.next);
158 * When the buffer fills up discard new entries.
159 * Assume that the earlier errors are the more
162 if (entry >= MCE_LOG_LEN) {
163 set_bit(MCE_OVERFLOW,
164 (unsigned long *)&mcelog.flags);
167 /* Old left over entry. Skip: */
168 if (mcelog.entry[entry].finished) {
176 if (cmpxchg(&mcelog.next, entry, next) == entry)
179 memcpy(mcelog.entry + entry, mce, sizeof(struct mce));
181 mcelog.entry[entry].finished = 1;
185 set_bit(0, &mce_need_notify);
188 static void print_mce(struct mce *m)
190 pr_emerg("CPU %d: Machine Check Exception: %16Lx Bank %d: %016Lx\n",
191 m->extcpu, m->mcgstatus, m->bank, m->status);
194 pr_emerg("RIP%s %02x:<%016Lx> ",
195 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
198 if (m->cs == __KERNEL_CS)
199 print_symbol("{%s}", m->ip);
203 pr_emerg("TSC %llx ", m->tsc);
205 pr_cont("ADDR %llx ", m->addr);
207 pr_cont("MISC %llx ", m->misc);
210 pr_emerg("PROCESSOR %u:%x TIME %llu SOCKET %u APIC %x\n",
211 m->cpuvendor, m->cpuid, m->time, m->socketid, m->apicid);
214 * Print out human-readable details about the MCE error,
215 * (if the CPU has an implementation for that)
217 atomic_notifier_call_chain(&x86_mce_decoder_chain, 0, m);
220 static void print_mce_head(void)
222 pr_emerg("\nHARDWARE ERROR\n");
225 static void print_mce_tail(void)
227 pr_emerg("This is not a software problem!\n");
230 #define PANIC_TIMEOUT 5 /* 5 seconds */
232 static atomic_t mce_paniced;
234 static int fake_panic;
235 static atomic_t mce_fake_paniced;
237 /* Panic in progress. Enable interrupts and wait for final IPI */
238 static void wait_for_panic(void)
240 long timeout = PANIC_TIMEOUT*USEC_PER_SEC;
244 while (timeout-- > 0)
246 if (panic_timeout == 0)
247 panic_timeout = mce_panic_timeout;
248 panic("Panicing machine check CPU died");
251 static void mce_panic(char *msg, struct mce *final, char *exp)
257 * Make sure only one CPU runs in machine check panic
259 if (atomic_inc_return(&mce_paniced) > 1)
266 /* Don't log too much for fake panic */
267 if (atomic_inc_return(&mce_fake_paniced) > 1)
271 /* First print corrected ones that are still unlogged */
272 for (i = 0; i < MCE_LOG_LEN; i++) {
273 struct mce *m = &mcelog.entry[i];
274 if (!(m->status & MCI_STATUS_VAL))
276 if (!(m->status & MCI_STATUS_UC))
279 /* Now print uncorrected but with the final one last */
280 for (i = 0; i < MCE_LOG_LEN; i++) {
281 struct mce *m = &mcelog.entry[i];
282 if (!(m->status & MCI_STATUS_VAL))
284 if (!(m->status & MCI_STATUS_UC))
286 if (!final || memcmp(m, final, sizeof(struct mce)))
292 printk(KERN_EMERG "Some CPUs didn't answer in synchronization\n");
295 printk(KERN_EMERG "Machine check: %s\n", exp);
297 if (panic_timeout == 0)
298 panic_timeout = mce_panic_timeout;
301 printk(KERN_EMERG "Fake kernel panic: %s\n", msg);
304 /* Support code for software error injection */
306 static int msr_to_offset(u32 msr)
308 unsigned bank = __get_cpu_var(injectm.bank);
311 return offsetof(struct mce, ip);
312 if (msr == MSR_IA32_MCx_STATUS(bank))
313 return offsetof(struct mce, status);
314 if (msr == MSR_IA32_MCx_ADDR(bank))
315 return offsetof(struct mce, addr);
316 if (msr == MSR_IA32_MCx_MISC(bank))
317 return offsetof(struct mce, misc);
318 if (msr == MSR_IA32_MCG_STATUS)
319 return offsetof(struct mce, mcgstatus);
323 /* MSR access wrappers used for error injection */
324 static u64 mce_rdmsrl(u32 msr)
328 if (__get_cpu_var(injectm).finished) {
329 int offset = msr_to_offset(msr);
333 return *(u64 *)((char *)&__get_cpu_var(injectm) + offset);
336 if (rdmsrl_safe(msr, &v)) {
337 WARN_ONCE(1, "mce: Unable to read msr %d!\n", msr);
339 * Return zero in case the access faulted. This should
340 * not happen normally but can happen if the CPU does
341 * something weird, or if the code is buggy.
349 static void mce_wrmsrl(u32 msr, u64 v)
351 if (__get_cpu_var(injectm).finished) {
352 int offset = msr_to_offset(msr);
355 *(u64 *)((char *)&__get_cpu_var(injectm) + offset) = v;
362 * Simple lockless ring to communicate PFNs from the exception handler with the
363 * process context work function. This is vastly simplified because there's
364 * only a single reader and a single writer.
366 #define MCE_RING_SIZE 16 /* we use one entry less */
369 unsigned short start;
371 unsigned long ring[MCE_RING_SIZE];
373 static DEFINE_PER_CPU(struct mce_ring, mce_ring);
375 /* Runs with CPU affinity in workqueue */
376 static int mce_ring_empty(void)
378 struct mce_ring *r = &__get_cpu_var(mce_ring);
380 return r->start == r->end;
383 static int mce_ring_get(unsigned long *pfn)
390 r = &__get_cpu_var(mce_ring);
391 if (r->start == r->end)
393 *pfn = r->ring[r->start];
394 r->start = (r->start + 1) % MCE_RING_SIZE;
401 /* Always runs in MCE context with preempt off */
402 static int mce_ring_add(unsigned long pfn)
404 struct mce_ring *r = &__get_cpu_var(mce_ring);
407 next = (r->end + 1) % MCE_RING_SIZE;
408 if (next == r->start)
410 r->ring[r->end] = pfn;
416 int mce_available(struct cpuinfo_x86 *c)
420 return cpu_has(c, X86_FEATURE_MCE) && cpu_has(c, X86_FEATURE_MCA);
423 static void mce_schedule_work(void)
425 if (!mce_ring_empty()) {
426 struct work_struct *work = &__get_cpu_var(mce_work);
427 if (!work_pending(work))
433 * Get the address of the instruction at the time of the machine check
436 static inline void mce_get_rip(struct mce *m, struct pt_regs *regs)
439 if (regs && (m->mcgstatus & (MCG_STATUS_RIPV|MCG_STATUS_EIPV))) {
447 m->ip = mce_rdmsrl(rip_msr);
450 #ifdef CONFIG_X86_LOCAL_APIC
452 * Called after interrupts have been reenabled again
453 * when a MCE happened during an interrupts off region
456 asmlinkage void smp_mce_self_interrupt(struct pt_regs *regs)
467 static void mce_report_event(struct pt_regs *regs)
469 if (regs->flags & (X86_VM_MASK|X86_EFLAGS_IF)) {
472 * Triggering the work queue here is just an insurance
473 * policy in case the syscall exit notify handler
474 * doesn't run soon enough or ends up running on the
475 * wrong CPU (can happen when audit sleeps)
481 #ifdef CONFIG_X86_LOCAL_APIC
483 * Without APIC do not notify. The event will be picked
490 * When interrupts are disabled we cannot use
491 * kernel services safely. Trigger an self interrupt
492 * through the APIC to instead do the notification
493 * after interrupts are reenabled again.
495 apic->send_IPI_self(MCE_SELF_VECTOR);
498 * Wait for idle afterwards again so that we don't leave the
499 * APIC in a non idle state because the normal APIC writes
502 apic_wait_icr_idle();
506 DEFINE_PER_CPU(unsigned, mce_poll_count);
509 * Poll for corrected events or events that happened before reset.
510 * Those are just logged through /dev/mcelog.
512 * This is executed in standard interrupt context.
514 * Note: spec recommends to panic for fatal unsignalled
515 * errors here. However this would be quite problematic --
516 * we would need to reimplement the Monarch handling and
517 * it would mess up the exclusion between exception handler
518 * and poll hander -- * so we skip this for now.
519 * These cases should not happen anyways, or only when the CPU
520 * is already totally * confused. In this case it's likely it will
521 * not fully execute the machine check handler either.
523 void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)
528 __get_cpu_var(mce_poll_count)++;
532 m.mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS);
533 for (i = 0; i < banks; i++) {
534 if (!mce_banks[i].ctl || !test_bit(i, *b))
543 m.status = mce_rdmsrl(MSR_IA32_MCx_STATUS(i));
544 if (!(m.status & MCI_STATUS_VAL))
548 * Uncorrected or signalled events are handled by the exception
549 * handler when it is enabled, so don't process those here.
551 * TBD do the same check for MCI_STATUS_EN here?
553 if (!(flags & MCP_UC) &&
554 (m.status & (mce_ser ? MCI_STATUS_S : MCI_STATUS_UC)))
557 if (m.status & MCI_STATUS_MISCV)
558 m.misc = mce_rdmsrl(MSR_IA32_MCx_MISC(i));
559 if (m.status & MCI_STATUS_ADDRV)
560 m.addr = mce_rdmsrl(MSR_IA32_MCx_ADDR(i));
562 if (!(flags & MCP_TIMESTAMP))
565 * Don't get the IP here because it's unlikely to
566 * have anything to do with the actual error location.
568 if (!(flags & MCP_DONTLOG) && !mce_dont_log_ce) {
570 add_taint(TAINT_MACHINE_CHECK);
574 * Clear state for this bank.
576 mce_wrmsrl(MSR_IA32_MCx_STATUS(i), 0);
580 * Don't clear MCG_STATUS here because it's only defined for
586 EXPORT_SYMBOL_GPL(machine_check_poll);
589 * Do a quick check if any of the events requires a panic.
590 * This decides if we keep the events around or clear them.
592 static int mce_no_way_out(struct mce *m, char **msg)
596 for (i = 0; i < banks; i++) {
597 m->status = mce_rdmsrl(MSR_IA32_MCx_STATUS(i));
598 if (mce_severity(m, tolerant, msg) >= MCE_PANIC_SEVERITY)
605 * Variable to establish order between CPUs while scanning.
606 * Each CPU spins initially until executing is equal its number.
608 static atomic_t mce_executing;
611 * Defines order of CPUs on entry. First CPU becomes Monarch.
613 static atomic_t mce_callin;
616 * Check if a timeout waiting for other CPUs happened.
618 static int mce_timed_out(u64 *t)
621 * The others already did panic for some reason.
622 * Bail out like in a timeout.
623 * rmb() to tell the compiler that system_state
624 * might have been modified by someone else.
627 if (atomic_read(&mce_paniced))
629 if (!monarch_timeout)
631 if ((s64)*t < SPINUNIT) {
632 /* CHECKME: Make panic default for 1 too? */
634 mce_panic("Timeout synchronizing machine check over CPUs",
641 touch_nmi_watchdog();
646 * The Monarch's reign. The Monarch is the CPU who entered
647 * the machine check handler first. It waits for the others to
648 * raise the exception too and then grades them. When any
649 * error is fatal panic. Only then let the others continue.
651 * The other CPUs entering the MCE handler will be controlled by the
652 * Monarch. They are called Subjects.
654 * This way we prevent any potential data corruption in a unrecoverable case
655 * and also makes sure always all CPU's errors are examined.
657 * Also this detects the case of a machine check event coming from outer
658 * space (not detected by any CPUs) In this case some external agent wants
659 * us to shut down, so panic too.
661 * The other CPUs might still decide to panic if the handler happens
662 * in a unrecoverable place, but in this case the system is in a semi-stable
663 * state and won't corrupt anything by itself. It's ok to let the others
664 * continue for a bit first.
666 * All the spin loops have timeouts; when a timeout happens a CPU
667 * typically elects itself to be Monarch.
669 static void mce_reign(void)
672 struct mce *m = NULL;
673 int global_worst = 0;
678 * This CPU is the Monarch and the other CPUs have run
679 * through their handlers.
680 * Grade the severity of the errors of all the CPUs.
682 for_each_possible_cpu(cpu) {
683 int severity = mce_severity(&per_cpu(mces_seen, cpu), tolerant,
685 if (severity > global_worst) {
687 global_worst = severity;
688 m = &per_cpu(mces_seen, cpu);
693 * Cannot recover? Panic here then.
694 * This dumps all the mces in the log buffer and stops the
697 if (m && global_worst >= MCE_PANIC_SEVERITY && tolerant < 3)
698 mce_panic("Fatal Machine check", m, msg);
701 * For UC somewhere we let the CPU who detects it handle it.
702 * Also must let continue the others, otherwise the handling
703 * CPU could deadlock on a lock.
707 * No machine check event found. Must be some external
708 * source or one CPU is hung. Panic.
710 if (global_worst <= MCE_KEEP_SEVERITY && tolerant < 3)
711 mce_panic("Machine check from unknown source", NULL, NULL);
714 * Now clear all the mces_seen so that they don't reappear on
717 for_each_possible_cpu(cpu)
718 memset(&per_cpu(mces_seen, cpu), 0, sizeof(struct mce));
721 static atomic_t global_nwo;
724 * Start of Monarch synchronization. This waits until all CPUs have
725 * entered the exception handler and then determines if any of them
726 * saw a fatal event that requires panic. Then it executes them
727 * in the entry order.
728 * TBD double check parallel CPU hotunplug
730 static int mce_start(int *no_way_out)
733 int cpus = num_online_cpus();
734 u64 timeout = (u64)monarch_timeout * NSEC_PER_USEC;
739 atomic_add(*no_way_out, &global_nwo);
741 * global_nwo should be updated before mce_callin
744 order = atomic_inc_return(&mce_callin);
749 while (atomic_read(&mce_callin) != cpus) {
750 if (mce_timed_out(&timeout)) {
751 atomic_set(&global_nwo, 0);
758 * mce_callin should be read before global_nwo
764 * Monarch: Starts executing now, the others wait.
766 atomic_set(&mce_executing, 1);
769 * Subject: Now start the scanning loop one by one in
770 * the original callin order.
771 * This way when there are any shared banks it will be
772 * only seen by one CPU before cleared, avoiding duplicates.
774 while (atomic_read(&mce_executing) < order) {
775 if (mce_timed_out(&timeout)) {
776 atomic_set(&global_nwo, 0);
784 * Cache the global no_way_out state.
786 *no_way_out = atomic_read(&global_nwo);
792 * Synchronize between CPUs after main scanning loop.
793 * This invokes the bulk of the Monarch processing.
795 static int mce_end(int order)
798 u64 timeout = (u64)monarch_timeout * NSEC_PER_USEC;
806 * Allow others to run.
808 atomic_inc(&mce_executing);
811 /* CHECKME: Can this race with a parallel hotplug? */
812 int cpus = num_online_cpus();
815 * Monarch: Wait for everyone to go through their scanning
818 while (atomic_read(&mce_executing) <= cpus) {
819 if (mce_timed_out(&timeout))
829 * Subject: Wait for Monarch to finish.
831 while (atomic_read(&mce_executing) != 0) {
832 if (mce_timed_out(&timeout))
838 * Don't reset anything. That's done by the Monarch.
844 * Reset all global state.
847 atomic_set(&global_nwo, 0);
848 atomic_set(&mce_callin, 0);
852 * Let others run again.
854 atomic_set(&mce_executing, 0);
859 * Check if the address reported by the CPU is in a format we can parse.
860 * It would be possible to add code for most other cases, but all would
861 * be somewhat complicated (e.g. segment offset would require an instruction
862 * parser). So only support physical addresses upto page granuality for now.
864 static int mce_usable_address(struct mce *m)
866 if (!(m->status & MCI_STATUS_MISCV) || !(m->status & MCI_STATUS_ADDRV))
868 if ((m->misc & 0x3f) > PAGE_SHIFT)
870 if (((m->misc >> 6) & 7) != MCM_ADDR_PHYS)
875 static void mce_clear_state(unsigned long *toclear)
879 for (i = 0; i < banks; i++) {
880 if (test_bit(i, toclear))
881 mce_wrmsrl(MSR_IA32_MCx_STATUS(i), 0);
886 * The actual machine check handler. This only handles real
887 * exceptions when something got corrupted coming in through int 18.
889 * This is executed in NMI context not subject to normal locking rules. This
890 * implies that most kernel services cannot be safely used. Don't even
891 * think about putting a printk in there!
893 * On Intel systems this is entered on all CPUs in parallel through
894 * MCE broadcast. However some CPUs might be broken beyond repair,
895 * so be always careful when synchronizing with others.
897 void do_machine_check(struct pt_regs *regs, long error_code)
899 struct mce m, *final;
904 * Establish sequential order between the CPUs entering the machine
909 * If no_way_out gets set, there is no safe way to recover from this
910 * MCE. If tolerant is cranked up, we'll try anyway.
914 * If kill_it gets set, there might be a way to recover from this
918 DECLARE_BITMAP(toclear, MAX_NR_BANKS);
919 char *msg = "Unknown";
921 atomic_inc(&mce_entry);
923 __get_cpu_var(mce_exception_count)++;
925 if (notify_die(DIE_NMI, "machine check", regs, error_code,
926 18, SIGKILL) == NOTIFY_STOP)
933 m.mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS);
934 final = &__get_cpu_var(mces_seen);
937 no_way_out = mce_no_way_out(&m, &msg);
942 * When no restart IP must always kill or panic.
944 if (!(m.mcgstatus & MCG_STATUS_RIPV))
948 * Go through all the banks in exclusion of the other CPUs.
949 * This way we don't report duplicated events on shared banks
950 * because the first one to see it will clear it.
952 order = mce_start(&no_way_out);
953 for (i = 0; i < banks; i++) {
954 __clear_bit(i, toclear);
955 if (!mce_banks[i].ctl)
962 m.status = mce_rdmsrl(MSR_IA32_MCx_STATUS(i));
963 if ((m.status & MCI_STATUS_VAL) == 0)
967 * Non uncorrected or non signaled errors are handled by
968 * machine_check_poll. Leave them alone, unless this panics.
970 if (!(m.status & (mce_ser ? MCI_STATUS_S : MCI_STATUS_UC)) &&
975 * Set taint even when machine check was not enabled.
977 add_taint(TAINT_MACHINE_CHECK);
979 severity = mce_severity(&m, tolerant, NULL);
982 * When machine check was for corrected handler don't touch,
983 * unless we're panicing.
985 if (severity == MCE_KEEP_SEVERITY && !no_way_out)
987 __set_bit(i, toclear);
988 if (severity == MCE_NO_SEVERITY) {
990 * Machine check event was not enabled. Clear, but
997 * Kill on action required.
999 if (severity == MCE_AR_SEVERITY)
1002 if (m.status & MCI_STATUS_MISCV)
1003 m.misc = mce_rdmsrl(MSR_IA32_MCx_MISC(i));
1004 if (m.status & MCI_STATUS_ADDRV)
1005 m.addr = mce_rdmsrl(MSR_IA32_MCx_ADDR(i));
1008 * Action optional error. Queue address for later processing.
1009 * When the ring overflows we just ignore the AO error.
1010 * RED-PEN add some logging mechanism when
1011 * usable_address or mce_add_ring fails.
1012 * RED-PEN don't ignore overflow for tolerant == 0
1014 if (severity == MCE_AO_SEVERITY && mce_usable_address(&m))
1015 mce_ring_add(m.addr >> PAGE_SHIFT);
1017 mce_get_rip(&m, regs);
1020 if (severity > worst) {
1027 mce_clear_state(toclear);
1030 * Do most of the synchronization with other CPUs.
1031 * When there's any problem use only local no_way_out state.
1033 if (mce_end(order) < 0)
1034 no_way_out = worst >= MCE_PANIC_SEVERITY;
1037 * If we have decided that we just CAN'T continue, and the user
1038 * has not set tolerant to an insane level, give up and die.
1040 * This is mainly used in the case when the system doesn't
1041 * support MCE broadcasting or it has been disabled.
1043 if (no_way_out && tolerant < 3)
1044 mce_panic("Fatal machine check on current CPU", final, msg);
1047 * If the error seems to be unrecoverable, something should be
1048 * done. Try to kill as little as possible. If we can kill just
1049 * one task, do that. If the user has set the tolerance very
1050 * high, don't try to do anything at all.
1053 if (kill_it && tolerant < 3)
1054 force_sig(SIGBUS, current);
1056 /* notify userspace ASAP */
1057 set_thread_flag(TIF_MCE_NOTIFY);
1060 mce_report_event(regs);
1061 mce_wrmsrl(MSR_IA32_MCG_STATUS, 0);
1063 atomic_dec(&mce_entry);
1066 EXPORT_SYMBOL_GPL(do_machine_check);
1068 /* dummy to break dependency. actual code is in mm/memory-failure.c */
1069 void __attribute__((weak)) memory_failure(unsigned long pfn, int vector)
1071 printk(KERN_ERR "Action optional memory failure at %lx ignored\n", pfn);
1075 * Called after mce notification in process context. This code
1076 * is allowed to sleep. Call the high level VM handler to process
1077 * any corrupted pages.
1078 * Assume that the work queue code only calls this one at a time
1080 * Note we don't disable preemption, so this code might run on the wrong
1081 * CPU. In this case the event is picked up by the scheduled work queue.
1082 * This is merely a fast path to expedite processing in some common
1085 void mce_notify_process(void)
1089 while (mce_ring_get(&pfn))
1090 memory_failure(pfn, MCE_VECTOR);
1093 static void mce_process_work(struct work_struct *dummy)
1095 mce_notify_process();
1098 #ifdef CONFIG_X86_MCE_INTEL
1100 * mce_log_therm_throt_event - Logs the thermal throttling event to mcelog
1101 * @cpu: The CPU on which the event occurred.
1102 * @status: Event status information
1104 * This function should be called by the thermal interrupt after the
1105 * event has been processed and the decision was made to log the event
1108 * The status parameter will be saved to the 'status' field of 'struct mce'
1109 * and historically has been the register value of the
1110 * MSR_IA32_THERMAL_STATUS (Intel) msr.
1112 void mce_log_therm_throt_event(__u64 status)
1117 m.bank = MCE_THERMAL_BANK;
1121 #endif /* CONFIG_X86_MCE_INTEL */
1124 * Periodic polling timer for "silent" machine check errors. If the
1125 * poller finds an MCE, poll 2x faster. When the poller finds no more
1126 * errors, poll 2x slower (up to check_interval seconds).
1128 static int check_interval = 5 * 60; /* 5 minutes */
1130 static DEFINE_PER_CPU(int, mce_next_interval); /* in jiffies */
1131 static DEFINE_PER_CPU(struct timer_list, mce_timer);
1133 static void mcheck_timer(unsigned long data)
1135 struct timer_list *t = &per_cpu(mce_timer, data);
1138 WARN_ON(smp_processor_id() != data);
1140 if (mce_available(¤t_cpu_data)) {
1141 machine_check_poll(MCP_TIMESTAMP,
1142 &__get_cpu_var(mce_poll_banks));
1146 * Alert userspace if needed. If we logged an MCE, reduce the
1147 * polling interval, otherwise increase the polling interval.
1149 n = &__get_cpu_var(mce_next_interval);
1150 if (mce_notify_irq())
1151 *n = max(*n/2, HZ/100);
1153 *n = min(*n*2, (int)round_jiffies_relative(check_interval*HZ));
1155 t->expires = jiffies + *n;
1156 add_timer_on(t, smp_processor_id());
1159 static void mce_do_trigger(struct work_struct *work)
1161 call_usermodehelper(mce_helper, mce_helper_argv, NULL, UMH_NO_WAIT);
1164 static DECLARE_WORK(mce_trigger_work, mce_do_trigger);
1167 * Notify the user(s) about new machine check events.
1168 * Can be called from interrupt context, but not from machine check/NMI
1171 int mce_notify_irq(void)
1173 /* Not more than two messages every minute */
1174 static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
1176 clear_thread_flag(TIF_MCE_NOTIFY);
1178 if (test_and_clear_bit(0, &mce_need_notify)) {
1179 wake_up_interruptible(&mce_wait);
1182 * There is no risk of missing notifications because
1183 * work_pending is always cleared before the function is
1186 if (mce_helper[0] && !work_pending(&mce_trigger_work))
1187 schedule_work(&mce_trigger_work);
1189 if (__ratelimit(&ratelimit))
1190 printk(KERN_INFO "Machine check events logged\n");
1196 EXPORT_SYMBOL_GPL(mce_notify_irq);
1198 static int mce_banks_init(void)
1202 mce_banks = kzalloc(banks * sizeof(struct mce_bank), GFP_KERNEL);
1205 for (i = 0; i < banks; i++) {
1206 struct mce_bank *b = &mce_banks[i];
1215 * Initialize Machine Checks for a CPU.
1217 static int __cpuinit mce_cap_init(void)
1222 rdmsrl(MSR_IA32_MCG_CAP, cap);
1224 b = cap & MCG_BANKCNT_MASK;
1225 printk(KERN_INFO "mce: CPU supports %d MCE banks\n", b);
1227 if (b > MAX_NR_BANKS) {
1229 "MCE: Using only %u machine check banks out of %u\n",
1234 /* Don't support asymmetric configurations today */
1235 WARN_ON(banks != 0 && b != banks);
1238 int err = mce_banks_init();
1244 /* Use accurate RIP reporting if available. */
1245 if ((cap & MCG_EXT_P) && MCG_EXT_CNT(cap) >= 9)
1246 rip_msr = MSR_IA32_MCG_EIP;
1248 if (cap & MCG_SER_P)
1254 static void mce_init(void)
1256 mce_banks_t all_banks;
1261 * Log the machine checks left over from the previous reset.
1263 bitmap_fill(all_banks, MAX_NR_BANKS);
1264 machine_check_poll(MCP_UC|(!mce_bootlog ? MCP_DONTLOG : 0), &all_banks);
1266 set_in_cr4(X86_CR4_MCE);
1268 rdmsrl(MSR_IA32_MCG_CAP, cap);
1269 if (cap & MCG_CTL_P)
1270 wrmsr(MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
1272 for (i = 0; i < banks; i++) {
1273 struct mce_bank *b = &mce_banks[i];
1277 wrmsrl(MSR_IA32_MCx_CTL(i), b->ctl);
1278 wrmsrl(MSR_IA32_MCx_STATUS(i), 0);
1282 /* Add per CPU specific workarounds here */
1283 static int __cpuinit mce_cpu_quirks(struct cpuinfo_x86 *c)
1285 if (c->x86_vendor == X86_VENDOR_UNKNOWN) {
1286 pr_info("MCE: unknown CPU type - not enabling MCE support.\n");
1290 /* This should be disabled by the BIOS, but isn't always */
1291 if (c->x86_vendor == X86_VENDOR_AMD) {
1292 if (c->x86 == 15 && banks > 4) {
1294 * disable GART TBL walk error reporting, which
1295 * trips off incorrectly with the IOMMU & 3ware
1298 clear_bit(10, (unsigned long *)&mce_banks[4].ctl);
1300 if (c->x86 <= 17 && mce_bootlog < 0) {
1302 * Lots of broken BIOS around that don't clear them
1303 * by default and leave crap in there. Don't log:
1308 * Various K7s with broken bank 0 around. Always disable
1311 if (c->x86 == 6 && banks > 0)
1312 mce_banks[0].ctl = 0;
1315 if (c->x86_vendor == X86_VENDOR_INTEL) {
1317 * SDM documents that on family 6 bank 0 should not be written
1318 * because it aliases to another special BIOS controlled
1320 * But it's not aliased anymore on model 0x1a+
1321 * Don't ignore bank 0 completely because there could be a
1322 * valid event later, merely don't write CTL0.
1325 if (c->x86 == 6 && c->x86_model < 0x1A && banks > 0)
1326 mce_banks[0].init = 0;
1329 * All newer Intel systems support MCE broadcasting. Enable
1330 * synchronization with a one second timeout.
1332 if ((c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xe)) &&
1333 monarch_timeout < 0)
1334 monarch_timeout = USEC_PER_SEC;
1337 * There are also broken BIOSes on some Pentium M and
1340 if (c->x86 == 6 && c->x86_model <= 13 && mce_bootlog < 0)
1343 if (monarch_timeout < 0)
1344 monarch_timeout = 0;
1345 if (mce_bootlog != 0)
1346 mce_panic_timeout = 30;
1351 static void __cpuinit mce_ancient_init(struct cpuinfo_x86 *c)
1355 switch (c->x86_vendor) {
1356 case X86_VENDOR_INTEL:
1357 intel_p5_mcheck_init(c);
1359 case X86_VENDOR_CENTAUR:
1360 winchip_mcheck_init(c);
1365 static void mce_cpu_features(struct cpuinfo_x86 *c)
1367 switch (c->x86_vendor) {
1368 case X86_VENDOR_INTEL:
1369 mce_intel_feature_init(c);
1371 case X86_VENDOR_AMD:
1372 mce_amd_feature_init(c);
1379 static void mce_init_timer(void)
1381 struct timer_list *t = &__get_cpu_var(mce_timer);
1382 int *n = &__get_cpu_var(mce_next_interval);
1387 *n = check_interval * HZ;
1390 setup_timer(t, mcheck_timer, smp_processor_id());
1391 t->expires = round_jiffies(jiffies + *n);
1392 add_timer_on(t, smp_processor_id());
1395 /* Handle unconfigured int18 (should never happen) */
1396 static void unexpected_machine_check(struct pt_regs *regs, long error_code)
1398 printk(KERN_ERR "CPU#%d: Unexpected int18 (Machine Check).\n",
1399 smp_processor_id());
1402 /* Call the installed machine check handler for this CPU setup. */
1403 void (*machine_check_vector)(struct pt_regs *, long error_code) =
1404 unexpected_machine_check;
1407 * Called for each booted CPU to set up machine checks.
1408 * Must be called with preempt off:
1410 void __cpuinit mcheck_init(struct cpuinfo_x86 *c)
1415 mce_ancient_init(c);
1417 if (!mce_available(c))
1420 if (mce_cap_init() < 0 || mce_cpu_quirks(c) < 0) {
1425 machine_check_vector = do_machine_check;
1428 mce_cpu_features(c);
1430 INIT_WORK(&__get_cpu_var(mce_work), mce_process_work);
1432 if (raw_smp_processor_id() == 0)
1433 atomic_notifier_chain_register(&x86_mce_decoder_chain, &mce_dec_nb);
1437 * Character device to read and clear the MCE log.
1440 static DEFINE_SPINLOCK(mce_state_lock);
1441 static int open_count; /* #times opened */
1442 static int open_exclu; /* already open exclusive? */
1444 static int mce_open(struct inode *inode, struct file *file)
1446 spin_lock(&mce_state_lock);
1448 if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
1449 spin_unlock(&mce_state_lock);
1454 if (file->f_flags & O_EXCL)
1458 spin_unlock(&mce_state_lock);
1460 return nonseekable_open(inode, file);
1463 static int mce_release(struct inode *inode, struct file *file)
1465 spin_lock(&mce_state_lock);
1470 spin_unlock(&mce_state_lock);
1475 static void collect_tscs(void *data)
1477 unsigned long *cpu_tsc = (unsigned long *)data;
1479 rdtscll(cpu_tsc[smp_processor_id()]);
1482 static DEFINE_MUTEX(mce_read_mutex);
1484 static ssize_t mce_read(struct file *filp, char __user *ubuf, size_t usize,
1487 char __user *buf = ubuf;
1488 unsigned long *cpu_tsc;
1489 unsigned prev, next;
1492 cpu_tsc = kmalloc(nr_cpu_ids * sizeof(long), GFP_KERNEL);
1496 mutex_lock(&mce_read_mutex);
1497 next = rcu_dereference(mcelog.next);
1499 /* Only supports full reads right now */
1500 if (*off != 0 || usize < MCE_LOG_LEN*sizeof(struct mce)) {
1501 mutex_unlock(&mce_read_mutex);
1510 for (i = prev; i < next; i++) {
1511 unsigned long start = jiffies;
1513 while (!mcelog.entry[i].finished) {
1514 if (time_after_eq(jiffies, start + 2)) {
1515 memset(mcelog.entry + i, 0,
1516 sizeof(struct mce));
1522 err |= copy_to_user(buf, mcelog.entry + i,
1523 sizeof(struct mce));
1524 buf += sizeof(struct mce);
1529 memset(mcelog.entry + prev, 0,
1530 (next - prev) * sizeof(struct mce));
1532 next = cmpxchg(&mcelog.next, prev, 0);
1533 } while (next != prev);
1535 synchronize_sched();
1538 * Collect entries that were still getting written before the
1541 on_each_cpu(collect_tscs, cpu_tsc, 1);
1543 for (i = next; i < MCE_LOG_LEN; i++) {
1544 if (mcelog.entry[i].finished &&
1545 mcelog.entry[i].tsc < cpu_tsc[mcelog.entry[i].cpu]) {
1546 err |= copy_to_user(buf, mcelog.entry+i,
1547 sizeof(struct mce));
1549 buf += sizeof(struct mce);
1550 memset(&mcelog.entry[i], 0, sizeof(struct mce));
1553 mutex_unlock(&mce_read_mutex);
1556 return err ? -EFAULT : buf - ubuf;
1559 static unsigned int mce_poll(struct file *file, poll_table *wait)
1561 poll_wait(file, &mce_wait, wait);
1562 if (rcu_dereference(mcelog.next))
1563 return POLLIN | POLLRDNORM;
1567 static long mce_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
1569 int __user *p = (int __user *)arg;
1571 if (!capable(CAP_SYS_ADMIN))
1575 case MCE_GET_RECORD_LEN:
1576 return put_user(sizeof(struct mce), p);
1577 case MCE_GET_LOG_LEN:
1578 return put_user(MCE_LOG_LEN, p);
1579 case MCE_GETCLEAR_FLAGS: {
1583 flags = mcelog.flags;
1584 } while (cmpxchg(&mcelog.flags, flags, 0) != flags);
1586 return put_user(flags, p);
1593 /* Modified in mce-inject.c, so not static or const */
1594 struct file_operations mce_chrdev_ops = {
1596 .release = mce_release,
1599 .unlocked_ioctl = mce_ioctl,
1601 EXPORT_SYMBOL_GPL(mce_chrdev_ops);
1603 static struct miscdevice mce_log_device = {
1610 * mce=off Disables machine check
1611 * mce=no_cmci Disables CMCI
1612 * mce=dont_log_ce Clears corrected events silently, no log created for CEs.
1613 * mce=ignore_ce Disables polling and CMCI, corrected events are not cleared.
1614 * mce=TOLERANCELEVEL[,monarchtimeout] (number, see above)
1615 * monarchtimeout is how long to wait for other CPUs on machine
1616 * check, or 0 to not wait
1617 * mce=bootlog Log MCEs from before booting. Disabled by default on AMD.
1618 * mce=nobootlog Don't log MCEs from before booting.
1620 static int __init mcheck_enable(char *str)
1628 if (!strcmp(str, "off"))
1630 else if (!strcmp(str, "no_cmci"))
1631 mce_cmci_disabled = 1;
1632 else if (!strcmp(str, "dont_log_ce"))
1633 mce_dont_log_ce = 1;
1634 else if (!strcmp(str, "ignore_ce"))
1636 else if (!strcmp(str, "bootlog") || !strcmp(str, "nobootlog"))
1637 mce_bootlog = (str[0] == 'b');
1638 else if (isdigit(str[0])) {
1639 get_option(&str, &tolerant);
1642 get_option(&str, &monarch_timeout);
1645 printk(KERN_INFO "mce argument %s ignored. Please use /sys\n",
1651 __setup("mce", mcheck_enable);
1658 * Disable machine checks on suspend and shutdown. We can't really handle
1661 static int mce_disable(void)
1665 for (i = 0; i < banks; i++) {
1666 struct mce_bank *b = &mce_banks[i];
1669 wrmsrl(MSR_IA32_MCx_CTL(i), 0);
1674 static int mce_suspend(struct sys_device *dev, pm_message_t state)
1676 return mce_disable();
1679 static int mce_shutdown(struct sys_device *dev)
1681 return mce_disable();
1685 * On resume clear all MCE state. Don't want to see leftovers from the BIOS.
1686 * Only one CPU is active at this time, the others get re-added later using
1689 static int mce_resume(struct sys_device *dev)
1692 mce_cpu_features(¤t_cpu_data);
1697 static void mce_cpu_restart(void *data)
1699 del_timer_sync(&__get_cpu_var(mce_timer));
1700 if (!mce_available(¤t_cpu_data))
1706 /* Reinit MCEs after user configuration changes */
1707 static void mce_restart(void)
1709 on_each_cpu(mce_cpu_restart, NULL, 1);
1712 /* Toggle features for corrected errors */
1713 static void mce_disable_ce(void *all)
1715 if (!mce_available(¤t_cpu_data))
1718 del_timer_sync(&__get_cpu_var(mce_timer));
1722 static void mce_enable_ce(void *all)
1724 if (!mce_available(¤t_cpu_data))
1732 static struct sysdev_class mce_sysclass = {
1733 .suspend = mce_suspend,
1734 .shutdown = mce_shutdown,
1735 .resume = mce_resume,
1736 .name = "machinecheck",
1739 DEFINE_PER_CPU(struct sys_device, mce_dev);
1742 void (*threshold_cpu_callback)(unsigned long action, unsigned int cpu);
1744 static inline struct mce_bank *attr_to_bank(struct sysdev_attribute *attr)
1746 return container_of(attr, struct mce_bank, attr);
1749 static ssize_t show_bank(struct sys_device *s, struct sysdev_attribute *attr,
1752 return sprintf(buf, "%llx\n", attr_to_bank(attr)->ctl);
1755 static ssize_t set_bank(struct sys_device *s, struct sysdev_attribute *attr,
1756 const char *buf, size_t size)
1760 if (strict_strtoull(buf, 0, &new) < 0)
1763 attr_to_bank(attr)->ctl = new;
1770 show_trigger(struct sys_device *s, struct sysdev_attribute *attr, char *buf)
1772 strcpy(buf, mce_helper);
1774 return strlen(mce_helper) + 1;
1777 static ssize_t set_trigger(struct sys_device *s, struct sysdev_attribute *attr,
1778 const char *buf, size_t siz)
1782 strncpy(mce_helper, buf, sizeof(mce_helper));
1783 mce_helper[sizeof(mce_helper)-1] = 0;
1784 p = strchr(mce_helper, '\n');
1789 return strlen(mce_helper) + !!p;
1792 static ssize_t set_ignore_ce(struct sys_device *s,
1793 struct sysdev_attribute *attr,
1794 const char *buf, size_t size)
1798 if (strict_strtoull(buf, 0, &new) < 0)
1801 if (mce_ignore_ce ^ !!new) {
1803 /* disable ce features */
1804 on_each_cpu(mce_disable_ce, (void *)1, 1);
1807 /* enable ce features */
1809 on_each_cpu(mce_enable_ce, (void *)1, 1);
1815 static ssize_t set_cmci_disabled(struct sys_device *s,
1816 struct sysdev_attribute *attr,
1817 const char *buf, size_t size)
1821 if (strict_strtoull(buf, 0, &new) < 0)
1824 if (mce_cmci_disabled ^ !!new) {
1827 on_each_cpu(mce_disable_ce, NULL, 1);
1828 mce_cmci_disabled = 1;
1831 mce_cmci_disabled = 0;
1832 on_each_cpu(mce_enable_ce, NULL, 1);
1838 static ssize_t store_int_with_restart(struct sys_device *s,
1839 struct sysdev_attribute *attr,
1840 const char *buf, size_t size)
1842 ssize_t ret = sysdev_store_int(s, attr, buf, size);
1847 static SYSDEV_ATTR(trigger, 0644, show_trigger, set_trigger);
1848 static SYSDEV_INT_ATTR(tolerant, 0644, tolerant);
1849 static SYSDEV_INT_ATTR(monarch_timeout, 0644, monarch_timeout);
1850 static SYSDEV_INT_ATTR(dont_log_ce, 0644, mce_dont_log_ce);
1852 static struct sysdev_ext_attribute attr_check_interval = {
1853 _SYSDEV_ATTR(check_interval, 0644, sysdev_show_int,
1854 store_int_with_restart),
1858 static struct sysdev_ext_attribute attr_ignore_ce = {
1859 _SYSDEV_ATTR(ignore_ce, 0644, sysdev_show_int, set_ignore_ce),
1863 static struct sysdev_ext_attribute attr_cmci_disabled = {
1864 _SYSDEV_ATTR(cmci_disabled, 0644, sysdev_show_int, set_cmci_disabled),
1868 static struct sysdev_attribute *mce_attrs[] = {
1869 &attr_tolerant.attr,
1870 &attr_check_interval.attr,
1872 &attr_monarch_timeout.attr,
1873 &attr_dont_log_ce.attr,
1874 &attr_ignore_ce.attr,
1875 &attr_cmci_disabled.attr,
1879 static cpumask_var_t mce_dev_initialized;
1881 /* Per cpu sysdev init. All of the cpus still share the same ctrl bank: */
1882 static __cpuinit int mce_create_device(unsigned int cpu)
1887 if (!mce_available(&boot_cpu_data))
1890 memset(&per_cpu(mce_dev, cpu).kobj, 0, sizeof(struct kobject));
1891 per_cpu(mce_dev, cpu).id = cpu;
1892 per_cpu(mce_dev, cpu).cls = &mce_sysclass;
1894 err = sysdev_register(&per_cpu(mce_dev, cpu));
1898 for (i = 0; mce_attrs[i]; i++) {
1899 err = sysdev_create_file(&per_cpu(mce_dev, cpu), mce_attrs[i]);
1903 for (j = 0; j < banks; j++) {
1904 err = sysdev_create_file(&per_cpu(mce_dev, cpu),
1905 &mce_banks[j].attr);
1909 cpumask_set_cpu(cpu, mce_dev_initialized);
1914 sysdev_remove_file(&per_cpu(mce_dev, cpu), &mce_banks[j].attr);
1917 sysdev_remove_file(&per_cpu(mce_dev, cpu), &mce_banks[i].attr);
1919 sysdev_unregister(&per_cpu(mce_dev, cpu));
1924 static __cpuinit void mce_remove_device(unsigned int cpu)
1928 if (!cpumask_test_cpu(cpu, mce_dev_initialized))
1931 for (i = 0; mce_attrs[i]; i++)
1932 sysdev_remove_file(&per_cpu(mce_dev, cpu), mce_attrs[i]);
1934 for (i = 0; i < banks; i++)
1935 sysdev_remove_file(&per_cpu(mce_dev, cpu), &mce_banks[i].attr);
1937 sysdev_unregister(&per_cpu(mce_dev, cpu));
1938 cpumask_clear_cpu(cpu, mce_dev_initialized);
1941 /* Make sure there are no machine checks on offlined CPUs. */
1942 static void mce_disable_cpu(void *h)
1944 unsigned long action = *(unsigned long *)h;
1947 if (!mce_available(¤t_cpu_data))
1949 if (!(action & CPU_TASKS_FROZEN))
1951 for (i = 0; i < banks; i++) {
1952 struct mce_bank *b = &mce_banks[i];
1955 wrmsrl(MSR_IA32_MCx_CTL(i), 0);
1959 static void mce_reenable_cpu(void *h)
1961 unsigned long action = *(unsigned long *)h;
1964 if (!mce_available(¤t_cpu_data))
1967 if (!(action & CPU_TASKS_FROZEN))
1969 for (i = 0; i < banks; i++) {
1970 struct mce_bank *b = &mce_banks[i];
1973 wrmsrl(MSR_IA32_MCx_CTL(i), b->ctl);
1977 /* Get notified when a cpu comes on/off. Be hotplug friendly. */
1978 static int __cpuinit
1979 mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
1981 unsigned int cpu = (unsigned long)hcpu;
1982 struct timer_list *t = &per_cpu(mce_timer, cpu);
1986 case CPU_ONLINE_FROZEN:
1987 mce_create_device(cpu);
1988 if (threshold_cpu_callback)
1989 threshold_cpu_callback(action, cpu);
1992 case CPU_DEAD_FROZEN:
1993 if (threshold_cpu_callback)
1994 threshold_cpu_callback(action, cpu);
1995 mce_remove_device(cpu);
1997 case CPU_DOWN_PREPARE:
1998 case CPU_DOWN_PREPARE_FROZEN:
2000 smp_call_function_single(cpu, mce_disable_cpu, &action, 1);
2002 case CPU_DOWN_FAILED:
2003 case CPU_DOWN_FAILED_FROZEN:
2004 t->expires = round_jiffies(jiffies +
2005 __get_cpu_var(mce_next_interval));
2006 add_timer_on(t, cpu);
2007 smp_call_function_single(cpu, mce_reenable_cpu, &action, 1);
2010 /* intentionally ignoring frozen here */
2011 cmci_rediscover(cpu);
2017 static struct notifier_block mce_cpu_notifier __cpuinitdata = {
2018 .notifier_call = mce_cpu_callback,
2021 static __init void mce_init_banks(void)
2025 for (i = 0; i < banks; i++) {
2026 struct mce_bank *b = &mce_banks[i];
2027 struct sysdev_attribute *a = &b->attr;
2029 a->attr.name = b->attrname;
2030 snprintf(b->attrname, ATTR_LEN, "bank%d", i);
2032 a->attr.mode = 0644;
2033 a->show = show_bank;
2034 a->store = set_bank;
2038 static __init int mce_init_device(void)
2043 if (!mce_available(&boot_cpu_data))
2046 zalloc_cpumask_var(&mce_dev_initialized, GFP_KERNEL);
2050 err = sysdev_class_register(&mce_sysclass);
2054 for_each_online_cpu(i) {
2055 err = mce_create_device(i);
2060 register_hotcpu_notifier(&mce_cpu_notifier);
2061 misc_register(&mce_log_device);
2066 device_initcall(mce_init_device);
2069 * Old style boot options parsing. Only for compatibility.
2071 static int __init mcheck_disable(char *str)
2076 __setup("nomce", mcheck_disable);
2078 #ifdef CONFIG_DEBUG_FS
2079 struct dentry *mce_get_debugfs_dir(void)
2081 static struct dentry *dmce;
2084 dmce = debugfs_create_dir("mce", NULL);
2089 static void mce_reset(void)
2092 atomic_set(&mce_fake_paniced, 0);
2093 atomic_set(&mce_executing, 0);
2094 atomic_set(&mce_callin, 0);
2095 atomic_set(&global_nwo, 0);
2098 static int fake_panic_get(void *data, u64 *val)
2104 static int fake_panic_set(void *data, u64 val)
2111 DEFINE_SIMPLE_ATTRIBUTE(fake_panic_fops, fake_panic_get,
2112 fake_panic_set, "%llu\n");
2114 static int __init mce_debugfs_init(void)
2116 struct dentry *dmce, *ffake_panic;
2118 dmce = mce_get_debugfs_dir();
2121 ffake_panic = debugfs_create_file("fake_panic", 0444, dmce, NULL,
2128 late_initcall(mce_debugfs_init);