Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Machine check handler. |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * K8 parts Copyright 2002,2003 Andi Kleen, SuSE Labs. |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 5 | * Rest from unknown author(s). |
| 6 | * 2004 Andi Kleen. Rewrote most of it. |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 7 | * Copyright 2008 Intel Corporation |
| 8 | * Author: Andi Kleen |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
Tim Hockin | e02e68d | 2007-07-21 17:10:36 +0200 | [diff] [blame] | 10 | #include <linux/thread_info.h> |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 11 | #include <linux/capability.h> |
| 12 | #include <linux/miscdevice.h> |
Andi Kleen | ccc3c31 | 2009-05-27 21:56:54 +0200 | [diff] [blame] | 13 | #include <linux/interrupt.h> |
Andi Kleen | 8457c84 | 2009-02-12 13:49:33 +0100 | [diff] [blame] | 14 | #include <linux/ratelimit.h> |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 15 | #include <linux/kallsyms.h> |
| 16 | #include <linux/rcupdate.h> |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 17 | #include <linux/kobject.h> |
Hidetoshi Seto | 14a0253 | 2009-04-30 16:04:51 +0900 | [diff] [blame] | 18 | #include <linux/uaccess.h> |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 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> |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 24 | #include <linux/delay.h> |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 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> |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 32 | #include <linux/nmi.h> |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 33 | #include <linux/cpu.h> |
Hidetoshi Seto | 14a0253 | 2009-04-30 16:04:51 +0900 | [diff] [blame] | 34 | #include <linux/smp.h> |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 35 | #include <linux/fs.h> |
Andi Kleen | 9b1beaf | 2009-05-27 21:56:59 +0200 | [diff] [blame] | 36 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 38 | #include <asm/processor.h> |
Andi Kleen | ccc3c31 | 2009-05-27 21:56:54 +0200 | [diff] [blame] | 39 | #include <asm/hw_irq.h> |
| 40 | #include <asm/apic.h> |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 41 | #include <asm/idle.h> |
Andi Kleen | ccc3c31 | 2009-05-27 21:56:54 +0200 | [diff] [blame] | 42 | #include <asm/ipi.h> |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 43 | #include <asm/mce.h> |
| 44 | #include <asm/msr.h> |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 45 | |
Andi Kleen | bd19a5e | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 46 | #include "mce-internal.h" |
Ingo Molnar | 711c2e4 | 2009-04-08 12:31:26 +0200 | [diff] [blame] | 47 | |
Andi Kleen | 5d72792 | 2009-04-27 19:25:48 +0200 | [diff] [blame] | 48 | /* Handle unconfigured int18 (should never happen) */ |
| 49 | static void unexpected_machine_check(struct pt_regs *regs, long error_code) |
| 50 | { |
| 51 | printk(KERN_ERR "CPU#%d: Unexpected int18 (Machine Check).\n", |
| 52 | smp_processor_id()); |
| 53 | } |
| 54 | |
| 55 | /* Call the installed machine check handler for this CPU setup. */ |
| 56 | void (*machine_check_vector)(struct pt_regs *, long error_code) = |
| 57 | unexpected_machine_check; |
Andi Kleen | 04b2b1a | 2009-04-28 22:50:19 +0200 | [diff] [blame] | 58 | |
Hidetoshi Seto | 4e5b3e6 | 2009-06-15 17:20:20 +0900 | [diff] [blame] | 59 | int mce_disabled __read_mostly; |
Andi Kleen | 04b2b1a | 2009-04-28 22:50:19 +0200 | [diff] [blame] | 60 | |
Andi Kleen | 4efc067 | 2009-04-28 19:07:31 +0200 | [diff] [blame] | 61 | #ifdef CONFIG_X86_NEW_MCE |
Ingo Molnar | 711c2e4 | 2009-04-08 12:31:26 +0200 | [diff] [blame] | 62 | |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 63 | #define MISC_MCELOG_MINOR 227 |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 64 | |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 65 | #define SPINUNIT 100 /* 100ns */ |
| 66 | |
Andi Kleen | 553f265 | 2006-04-07 19:49:57 +0200 | [diff] [blame] | 67 | atomic_t mce_entry; |
| 68 | |
Andi Kleen | 01ca79f | 2009-05-27 21:56:52 +0200 | [diff] [blame] | 69 | DEFINE_PER_CPU(unsigned, mce_exception_count); |
| 70 | |
Tim Hockin | bd78432 | 2007-07-21 17:10:37 +0200 | [diff] [blame] | 71 | /* |
| 72 | * Tolerant levels: |
| 73 | * 0: always panic on uncorrected errors, log corrected errors |
| 74 | * 1: panic or SIGBUS on uncorrected errors, log corrected errors |
| 75 | * 2: SIGBUS or log uncorrected errors (if possible), log corrected errors |
| 76 | * 3: never panic or SIGBUS, log all errors (for testing only) |
| 77 | */ |
Hidetoshi Seto | 4e5b3e6 | 2009-06-15 17:20:20 +0900 | [diff] [blame] | 78 | static int tolerant __read_mostly = 1; |
| 79 | static int banks __read_mostly; |
| 80 | static u64 *bank __read_mostly; |
| 81 | static int rip_msr __read_mostly; |
| 82 | static int mce_bootlog __read_mostly = -1; |
| 83 | static int monarch_timeout __read_mostly = -1; |
| 84 | static int mce_panic_timeout __read_mostly; |
| 85 | static int mce_dont_log_ce __read_mostly; |
| 86 | int mce_cmci_disabled __read_mostly; |
| 87 | int mce_ignore_ce __read_mostly; |
| 88 | int mce_ser __read_mostly; |
Andi Kleen | a98f0dd | 2007-02-13 13:26:23 +0100 | [diff] [blame] | 89 | |
Hidetoshi Seto | 1020bcb | 2009-06-15 17:20:57 +0900 | [diff] [blame] | 90 | /* User mode helper program triggered by machine check event */ |
| 91 | static unsigned long mce_need_notify; |
| 92 | static char mce_helper[128]; |
| 93 | static char *mce_helper_argv[2] = { mce_helper, NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Andi Kleen | 06b7a7a | 2009-04-27 18:37:43 +0200 | [diff] [blame] | 95 | static unsigned long dont_init_banks; |
| 96 | |
Tim Hockin | e02e68d | 2007-07-21 17:10:36 +0200 | [diff] [blame] | 97 | static DECLARE_WAIT_QUEUE_HEAD(mce_wait); |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 98 | static DEFINE_PER_CPU(struct mce, mces_seen); |
| 99 | static int cpu_missing; |
| 100 | |
Tim Hockin | e02e68d | 2007-07-21 17:10:36 +0200 | [diff] [blame] | 101 | |
Andi Kleen | ee031c3 | 2009-02-12 13:49:34 +0100 | [diff] [blame] | 102 | /* MCA banks polled by the period polling timer for corrected events */ |
| 103 | DEFINE_PER_CPU(mce_banks_t, mce_poll_banks) = { |
| 104 | [0 ... BITS_TO_LONGS(MAX_NR_BANKS)-1] = ~0UL |
| 105 | }; |
| 106 | |
Andi Kleen | 06b7a7a | 2009-04-27 18:37:43 +0200 | [diff] [blame] | 107 | static inline int skip_bank_init(int i) |
| 108 | { |
| 109 | return i < BITS_PER_LONG && test_bit(i, &dont_init_banks); |
| 110 | } |
| 111 | |
Andi Kleen | 9b1beaf | 2009-05-27 21:56:59 +0200 | [diff] [blame] | 112 | static DEFINE_PER_CPU(struct work_struct, mce_work); |
| 113 | |
Andi Kleen | b5f2fa4 | 2009-02-12 13:43:22 +0100 | [diff] [blame] | 114 | /* Do initial initialization of a struct mce */ |
| 115 | void mce_setup(struct mce *m) |
| 116 | { |
| 117 | memset(m, 0, sizeof(struct mce)); |
Andi Kleen | d620c67 | 2009-05-27 21:56:56 +0200 | [diff] [blame] | 118 | m->cpu = m->extcpu = smp_processor_id(); |
Andi Kleen | b5f2fa4 | 2009-02-12 13:43:22 +0100 | [diff] [blame] | 119 | rdtscll(m->tsc); |
Andi Kleen | 8ee0834 | 2009-05-27 21:56:56 +0200 | [diff] [blame] | 120 | /* We hope get_seconds stays lockless */ |
| 121 | m->time = get_seconds(); |
| 122 | m->cpuvendor = boot_cpu_data.x86_vendor; |
| 123 | m->cpuid = cpuid_eax(1); |
| 124 | #ifdef CONFIG_SMP |
| 125 | m->socketid = cpu_data(m->extcpu).phys_proc_id; |
| 126 | #endif |
| 127 | m->apicid = cpu_data(m->extcpu).initial_apicid; |
| 128 | rdmsrl(MSR_IA32_MCG_CAP, m->mcgcap); |
Andi Kleen | b5f2fa4 | 2009-02-12 13:43:22 +0100 | [diff] [blame] | 129 | } |
| 130 | |
Andi Kleen | ea149b3 | 2009-04-29 19:31:00 +0200 | [diff] [blame] | 131 | DEFINE_PER_CPU(struct mce, injectm); |
| 132 | EXPORT_PER_CPU_SYMBOL_GPL(injectm); |
| 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | /* |
| 135 | * Lockless MCE logging infrastructure. |
| 136 | * This avoids deadlocks on printk locks without having to break locks. Also |
| 137 | * separate MCEs from kernel messages to avoid bogus bug reports. |
| 138 | */ |
| 139 | |
Adrian Bunk | 231fd90 | 2008-01-30 13:30:30 +0100 | [diff] [blame] | 140 | static struct mce_log mcelog = { |
Andi Kleen | f6fb0ac | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 141 | .signature = MCE_LOG_SIGNATURE, |
| 142 | .len = MCE_LOG_LEN, |
| 143 | .recordlen = sizeof(struct mce), |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 144 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | void mce_log(struct mce *mce) |
| 147 | { |
| 148 | unsigned next, entry; |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | mce->finished = 0; |
Mike Waychison | 7644143 | 2005-09-30 00:01:27 +0200 | [diff] [blame] | 151 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | for (;;) { |
| 153 | entry = rcu_dereference(mcelog.next); |
Andi Kleen | 673242c | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 154 | for (;;) { |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 155 | /* |
| 156 | * When the buffer fills up discard new entries. |
| 157 | * Assume that the earlier errors are the more |
| 158 | * interesting ones: |
| 159 | */ |
Andi Kleen | 673242c | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 160 | if (entry >= MCE_LOG_LEN) { |
Hidetoshi Seto | 14a0253 | 2009-04-30 16:04:51 +0900 | [diff] [blame] | 161 | set_bit(MCE_OVERFLOW, |
| 162 | (unsigned long *)&mcelog.flags); |
Andi Kleen | 673242c | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 163 | return; |
| 164 | } |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 165 | /* Old left over entry. Skip: */ |
Andi Kleen | 673242c | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 166 | if (mcelog.entry[entry].finished) { |
| 167 | entry++; |
| 168 | continue; |
| 169 | } |
Mike Waychison | 7644143 | 2005-09-30 00:01:27 +0200 | [diff] [blame] | 170 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | smp_rmb(); |
| 173 | next = entry + 1; |
| 174 | if (cmpxchg(&mcelog.next, entry, next) == entry) |
| 175 | break; |
| 176 | } |
| 177 | memcpy(mcelog.entry + entry, mce, sizeof(struct mce)); |
Mike Waychison | 7644143 | 2005-09-30 00:01:27 +0200 | [diff] [blame] | 178 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | mcelog.entry[entry].finished = 1; |
Mike Waychison | 7644143 | 2005-09-30 00:01:27 +0200 | [diff] [blame] | 180 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Andi Kleen | a0189c7 | 2009-05-27 21:56:54 +0200 | [diff] [blame] | 182 | mce->finished = 1; |
Hidetoshi Seto | 1020bcb | 2009-06-15 17:20:57 +0900 | [diff] [blame] | 183 | set_bit(0, &mce_need_notify); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Hidetoshi Seto | 77e26cc | 2009-06-11 16:04:35 +0900 | [diff] [blame] | 186 | static void print_mce(struct mce *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { |
Andi Kleen | 8650356 | 2009-05-27 21:56:58 +0200 | [diff] [blame] | 188 | printk(KERN_EMERG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | "CPU %d: Machine Check Exception: %16Lx Bank %d: %016Lx\n", |
Andi Kleen | d620c67 | 2009-05-27 21:56:56 +0200 | [diff] [blame] | 190 | m->extcpu, m->mcgstatus, m->bank, m->status); |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 191 | if (m->ip) { |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 192 | printk(KERN_EMERG "RIP%s %02x:<%016Lx> ", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "", |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 194 | m->cs, m->ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | if (m->cs == __KERNEL_CS) |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 196 | print_symbol("{%s}", m->ip); |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 197 | printk(KERN_CONT "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | } |
H. Peter Anvin | f6d1826 | 2009-02-19 15:44:58 -0800 | [diff] [blame] | 199 | printk(KERN_EMERG "TSC %llx ", m->tsc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | if (m->addr) |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 201 | printk(KERN_CONT "ADDR %llx ", m->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | if (m->misc) |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 203 | printk(KERN_CONT "MISC %llx ", m->misc); |
| 204 | printk(KERN_CONT "\n"); |
Andi Kleen | 8ee0834 | 2009-05-27 21:56:56 +0200 | [diff] [blame] | 205 | printk(KERN_EMERG "PROCESSOR %u:%x TIME %llu SOCKET %u APIC %x\n", |
| 206 | m->cpuvendor, m->cpuid, m->time, m->socketid, |
| 207 | m->apicid); |
Andi Kleen | 8650356 | 2009-05-27 21:56:58 +0200 | [diff] [blame] | 208 | } |
| 209 | |
Hidetoshi Seto | 77e26cc | 2009-06-11 16:04:35 +0900 | [diff] [blame] | 210 | static void print_mce_head(void) |
| 211 | { |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 212 | printk(KERN_EMERG "\nHARDWARE ERROR\n"); |
Hidetoshi Seto | 77e26cc | 2009-06-11 16:04:35 +0900 | [diff] [blame] | 213 | } |
| 214 | |
Andi Kleen | 8650356 | 2009-05-27 21:56:58 +0200 | [diff] [blame] | 215 | static void print_mce_tail(void) |
| 216 | { |
| 217 | printk(KERN_EMERG "This is not a software problem!\n" |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 218 | "Run through mcelog --ascii to decode and contact your hardware vendor\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Andi Kleen | f94b61c | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 221 | #define PANIC_TIMEOUT 5 /* 5 seconds */ |
| 222 | |
| 223 | static atomic_t mce_paniced; |
| 224 | |
| 225 | /* Panic in progress. Enable interrupts and wait for final IPI */ |
| 226 | static void wait_for_panic(void) |
| 227 | { |
| 228 | long timeout = PANIC_TIMEOUT*USEC_PER_SEC; |
| 229 | preempt_disable(); |
| 230 | local_irq_enable(); |
| 231 | while (timeout-- > 0) |
| 232 | udelay(1); |
Andi Kleen | 29b0f59 | 2009-05-27 21:56:56 +0200 | [diff] [blame] | 233 | if (panic_timeout == 0) |
| 234 | panic_timeout = mce_panic_timeout; |
Andi Kleen | f94b61c | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 235 | panic("Panicing machine check CPU died"); |
| 236 | } |
| 237 | |
Andi Kleen | bd19a5e | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 238 | static void mce_panic(char *msg, struct mce *final, char *exp) |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 239 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | int i; |
Tim Hockin | e02e68d | 2007-07-21 17:10:36 +0200 | [diff] [blame] | 241 | |
Andi Kleen | f94b61c | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 242 | /* |
| 243 | * Make sure only one CPU runs in machine check panic |
| 244 | */ |
| 245 | if (atomic_add_return(1, &mce_paniced) > 1) |
| 246 | wait_for_panic(); |
| 247 | barrier(); |
| 248 | |
Andi Kleen | d896a94 | 2009-04-28 14:25:18 +0200 | [diff] [blame] | 249 | bust_spinlocks(1); |
| 250 | console_verbose(); |
Hidetoshi Seto | 77e26cc | 2009-06-11 16:04:35 +0900 | [diff] [blame] | 251 | print_mce_head(); |
Andi Kleen | a0189c7 | 2009-05-27 21:56:54 +0200 | [diff] [blame] | 252 | /* First print corrected ones that are still unlogged */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | for (i = 0; i < MCE_LOG_LEN; i++) { |
Andi Kleen | a0189c7 | 2009-05-27 21:56:54 +0200 | [diff] [blame] | 254 | struct mce *m = &mcelog.entry[i]; |
Hidetoshi Seto | 77e26cc | 2009-06-11 16:04:35 +0900 | [diff] [blame] | 255 | if (!(m->status & MCI_STATUS_VAL)) |
| 256 | continue; |
| 257 | if (!(m->status & MCI_STATUS_UC)) |
| 258 | print_mce(m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } |
Andi Kleen | a0189c7 | 2009-05-27 21:56:54 +0200 | [diff] [blame] | 260 | /* Now print uncorrected but with the final one last */ |
| 261 | for (i = 0; i < MCE_LOG_LEN; i++) { |
| 262 | struct mce *m = &mcelog.entry[i]; |
| 263 | if (!(m->status & MCI_STATUS_VAL)) |
| 264 | continue; |
Hidetoshi Seto | 77e26cc | 2009-06-11 16:04:35 +0900 | [diff] [blame] | 265 | if (!(m->status & MCI_STATUS_UC)) |
| 266 | continue; |
Andi Kleen | a0189c7 | 2009-05-27 21:56:54 +0200 | [diff] [blame] | 267 | if (!final || memcmp(m, final, sizeof(struct mce))) |
Hidetoshi Seto | 77e26cc | 2009-06-11 16:04:35 +0900 | [diff] [blame] | 268 | print_mce(m); |
Andi Kleen | a0189c7 | 2009-05-27 21:56:54 +0200 | [diff] [blame] | 269 | } |
| 270 | if (final) |
Hidetoshi Seto | 77e26cc | 2009-06-11 16:04:35 +0900 | [diff] [blame] | 271 | print_mce(final); |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 272 | if (cpu_missing) |
| 273 | printk(KERN_EMERG "Some CPUs didn't answer in synchronization\n"); |
Andi Kleen | 8650356 | 2009-05-27 21:56:58 +0200 | [diff] [blame] | 274 | print_mce_tail(); |
Andi Kleen | bd19a5e | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 275 | if (exp) |
| 276 | printk(KERN_EMERG "Machine check: %s\n", exp); |
Andi Kleen | 29b0f59 | 2009-05-27 21:56:56 +0200 | [diff] [blame] | 277 | if (panic_timeout == 0) |
| 278 | panic_timeout = mce_panic_timeout; |
Tim Hockin | e02e68d | 2007-07-21 17:10:36 +0200 | [diff] [blame] | 279 | panic(msg); |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 280 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
Andi Kleen | ea149b3 | 2009-04-29 19:31:00 +0200 | [diff] [blame] | 282 | /* Support code for software error injection */ |
| 283 | |
| 284 | static int msr_to_offset(u32 msr) |
| 285 | { |
| 286 | unsigned bank = __get_cpu_var(injectm.bank); |
| 287 | if (msr == rip_msr) |
| 288 | return offsetof(struct mce, ip); |
| 289 | if (msr == MSR_IA32_MC0_STATUS + bank*4) |
| 290 | return offsetof(struct mce, status); |
| 291 | if (msr == MSR_IA32_MC0_ADDR + bank*4) |
| 292 | return offsetof(struct mce, addr); |
| 293 | if (msr == MSR_IA32_MC0_MISC + bank*4) |
| 294 | return offsetof(struct mce, misc); |
| 295 | if (msr == MSR_IA32_MCG_STATUS) |
| 296 | return offsetof(struct mce, mcgstatus); |
| 297 | return -1; |
| 298 | } |
| 299 | |
Andi Kleen | 5f8c1a5 | 2009-04-29 19:29:12 +0200 | [diff] [blame] | 300 | /* MSR access wrappers used for error injection */ |
| 301 | static u64 mce_rdmsrl(u32 msr) |
| 302 | { |
| 303 | u64 v; |
Andi Kleen | ea149b3 | 2009-04-29 19:31:00 +0200 | [diff] [blame] | 304 | if (__get_cpu_var(injectm).finished) { |
| 305 | int offset = msr_to_offset(msr); |
| 306 | if (offset < 0) |
| 307 | return 0; |
| 308 | return *(u64 *)((char *)&__get_cpu_var(injectm) + offset); |
| 309 | } |
Andi Kleen | 5f8c1a5 | 2009-04-29 19:29:12 +0200 | [diff] [blame] | 310 | rdmsrl(msr, v); |
| 311 | return v; |
| 312 | } |
| 313 | |
| 314 | static void mce_wrmsrl(u32 msr, u64 v) |
| 315 | { |
Andi Kleen | ea149b3 | 2009-04-29 19:31:00 +0200 | [diff] [blame] | 316 | if (__get_cpu_var(injectm).finished) { |
| 317 | int offset = msr_to_offset(msr); |
| 318 | if (offset >= 0) |
| 319 | *(u64 *)((char *)&__get_cpu_var(injectm) + offset) = v; |
| 320 | return; |
| 321 | } |
Andi Kleen | 5f8c1a5 | 2009-04-29 19:29:12 +0200 | [diff] [blame] | 322 | wrmsrl(msr, v); |
| 323 | } |
| 324 | |
Andi Kleen | 9b1beaf | 2009-05-27 21:56:59 +0200 | [diff] [blame] | 325 | /* |
| 326 | * Simple lockless ring to communicate PFNs from the exception handler with the |
| 327 | * process context work function. This is vastly simplified because there's |
| 328 | * only a single reader and a single writer. |
| 329 | */ |
| 330 | #define MCE_RING_SIZE 16 /* we use one entry less */ |
| 331 | |
| 332 | struct mce_ring { |
| 333 | unsigned short start; |
| 334 | unsigned short end; |
| 335 | unsigned long ring[MCE_RING_SIZE]; |
| 336 | }; |
| 337 | static DEFINE_PER_CPU(struct mce_ring, mce_ring); |
| 338 | |
| 339 | /* Runs with CPU affinity in workqueue */ |
| 340 | static int mce_ring_empty(void) |
| 341 | { |
| 342 | struct mce_ring *r = &__get_cpu_var(mce_ring); |
| 343 | |
| 344 | return r->start == r->end; |
| 345 | } |
| 346 | |
| 347 | static int mce_ring_get(unsigned long *pfn) |
| 348 | { |
| 349 | struct mce_ring *r; |
| 350 | int ret = 0; |
| 351 | |
| 352 | *pfn = 0; |
| 353 | get_cpu(); |
| 354 | r = &__get_cpu_var(mce_ring); |
| 355 | if (r->start == r->end) |
| 356 | goto out; |
| 357 | *pfn = r->ring[r->start]; |
| 358 | r->start = (r->start + 1) % MCE_RING_SIZE; |
| 359 | ret = 1; |
| 360 | out: |
| 361 | put_cpu(); |
| 362 | return ret; |
| 363 | } |
| 364 | |
| 365 | /* Always runs in MCE context with preempt off */ |
| 366 | static int mce_ring_add(unsigned long pfn) |
| 367 | { |
| 368 | struct mce_ring *r = &__get_cpu_var(mce_ring); |
| 369 | unsigned next; |
| 370 | |
| 371 | next = (r->end + 1) % MCE_RING_SIZE; |
| 372 | if (next == r->start) |
| 373 | return -1; |
| 374 | r->ring[r->end] = pfn; |
| 375 | wmb(); |
| 376 | r->end = next; |
| 377 | return 0; |
| 378 | } |
| 379 | |
Andi Kleen | 88ccbed | 2009-02-12 13:49:36 +0100 | [diff] [blame] | 380 | int mce_available(struct cpuinfo_x86 *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | { |
Andi Kleen | 04b2b1a | 2009-04-28 22:50:19 +0200 | [diff] [blame] | 382 | if (mce_disabled) |
Andi Kleen | 5b4408f | 2009-02-12 13:39:30 +0100 | [diff] [blame] | 383 | return 0; |
Akinobu Mita | 3d1712c | 2006-03-24 03:15:11 -0800 | [diff] [blame] | 384 | return cpu_has(c, X86_FEATURE_MCE) && cpu_has(c, X86_FEATURE_MCA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Andi Kleen | 9b1beaf | 2009-05-27 21:56:59 +0200 | [diff] [blame] | 387 | static void mce_schedule_work(void) |
| 388 | { |
| 389 | if (!mce_ring_empty()) { |
| 390 | struct work_struct *work = &__get_cpu_var(mce_work); |
| 391 | if (!work_pending(work)) |
| 392 | schedule_work(work); |
| 393 | } |
| 394 | } |
| 395 | |
Huang Ying | 1b2797d | 2009-05-27 21:56:51 +0200 | [diff] [blame] | 396 | /* |
| 397 | * Get the address of the instruction at the time of the machine check |
| 398 | * error. |
| 399 | */ |
Andi Kleen | 94ad847 | 2005-04-16 15:25:09 -0700 | [diff] [blame] | 400 | static inline void mce_get_rip(struct mce *m, struct pt_regs *regs) |
| 401 | { |
Huang Ying | 1b2797d | 2009-05-27 21:56:51 +0200 | [diff] [blame] | 402 | |
| 403 | if (regs && (m->mcgstatus & (MCG_STATUS_RIPV|MCG_STATUS_EIPV))) { |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 404 | m->ip = regs->ip; |
Andi Kleen | 94ad847 | 2005-04-16 15:25:09 -0700 | [diff] [blame] | 405 | m->cs = regs->cs; |
| 406 | } else { |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 407 | m->ip = 0; |
Andi Kleen | 94ad847 | 2005-04-16 15:25:09 -0700 | [diff] [blame] | 408 | m->cs = 0; |
| 409 | } |
Huang Ying | 1b2797d | 2009-05-27 21:56:51 +0200 | [diff] [blame] | 410 | if (rip_msr) |
Andi Kleen | 5f8c1a5 | 2009-04-29 19:29:12 +0200 | [diff] [blame] | 411 | m->ip = mce_rdmsrl(rip_msr); |
Andi Kleen | 94ad847 | 2005-04-16 15:25:09 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Andi Kleen | ccc3c31 | 2009-05-27 21:56:54 +0200 | [diff] [blame] | 414 | #ifdef CONFIG_X86_LOCAL_APIC |
| 415 | /* |
| 416 | * Called after interrupts have been reenabled again |
| 417 | * when a MCE happened during an interrupts off region |
| 418 | * in the kernel. |
| 419 | */ |
| 420 | asmlinkage void smp_mce_self_interrupt(struct pt_regs *regs) |
| 421 | { |
| 422 | ack_APIC_irq(); |
| 423 | exit_idle(); |
| 424 | irq_enter(); |
Andi Kleen | 9ff36ee | 2009-05-27 21:56:58 +0200 | [diff] [blame] | 425 | mce_notify_irq(); |
Andi Kleen | 9b1beaf | 2009-05-27 21:56:59 +0200 | [diff] [blame] | 426 | mce_schedule_work(); |
Andi Kleen | ccc3c31 | 2009-05-27 21:56:54 +0200 | [diff] [blame] | 427 | irq_exit(); |
| 428 | } |
| 429 | #endif |
| 430 | |
| 431 | static void mce_report_event(struct pt_regs *regs) |
| 432 | { |
| 433 | if (regs->flags & (X86_VM_MASK|X86_EFLAGS_IF)) { |
Andi Kleen | 9ff36ee | 2009-05-27 21:56:58 +0200 | [diff] [blame] | 434 | mce_notify_irq(); |
Andi Kleen | 9b1beaf | 2009-05-27 21:56:59 +0200 | [diff] [blame] | 435 | /* |
| 436 | * Triggering the work queue here is just an insurance |
| 437 | * policy in case the syscall exit notify handler |
| 438 | * doesn't run soon enough or ends up running on the |
| 439 | * wrong CPU (can happen when audit sleeps) |
| 440 | */ |
| 441 | mce_schedule_work(); |
Andi Kleen | ccc3c31 | 2009-05-27 21:56:54 +0200 | [diff] [blame] | 442 | return; |
| 443 | } |
| 444 | |
| 445 | #ifdef CONFIG_X86_LOCAL_APIC |
| 446 | /* |
| 447 | * Without APIC do not notify. The event will be picked |
| 448 | * up eventually. |
| 449 | */ |
| 450 | if (!cpu_has_apic) |
| 451 | return; |
| 452 | |
| 453 | /* |
| 454 | * When interrupts are disabled we cannot use |
| 455 | * kernel services safely. Trigger an self interrupt |
| 456 | * through the APIC to instead do the notification |
| 457 | * after interrupts are reenabled again. |
| 458 | */ |
| 459 | apic->send_IPI_self(MCE_SELF_VECTOR); |
| 460 | |
| 461 | /* |
| 462 | * Wait for idle afterwards again so that we don't leave the |
| 463 | * APIC in a non idle state because the normal APIC writes |
| 464 | * cannot exclude us. |
| 465 | */ |
| 466 | apic_wait_icr_idle(); |
| 467 | #endif |
| 468 | } |
| 469 | |
Andi Kleen | ca84f69 | 2009-05-27 21:56:57 +0200 | [diff] [blame] | 470 | DEFINE_PER_CPU(unsigned, mce_poll_count); |
| 471 | |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 472 | /* |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 473 | * Poll for corrected events or events that happened before reset. |
| 474 | * Those are just logged through /dev/mcelog. |
| 475 | * |
| 476 | * This is executed in standard interrupt context. |
Andi Kleen | ed7290d | 2009-05-27 21:56:57 +0200 | [diff] [blame] | 477 | * |
| 478 | * Note: spec recommends to panic for fatal unsignalled |
| 479 | * errors here. However this would be quite problematic -- |
| 480 | * we would need to reimplement the Monarch handling and |
| 481 | * it would mess up the exclusion between exception handler |
| 482 | * and poll hander -- * so we skip this for now. |
| 483 | * These cases should not happen anyways, or only when the CPU |
| 484 | * is already totally * confused. In this case it's likely it will |
| 485 | * not fully execute the machine check handler either. |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 486 | */ |
Andi Kleen | ee031c3 | 2009-02-12 13:49:34 +0100 | [diff] [blame] | 487 | void machine_check_poll(enum mcp_flags flags, mce_banks_t *b) |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 488 | { |
| 489 | struct mce m; |
| 490 | int i; |
| 491 | |
Andi Kleen | ca84f69 | 2009-05-27 21:56:57 +0200 | [diff] [blame] | 492 | __get_cpu_var(mce_poll_count)++; |
| 493 | |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 494 | mce_setup(&m); |
| 495 | |
Andi Kleen | 5f8c1a5 | 2009-04-29 19:29:12 +0200 | [diff] [blame] | 496 | m.mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS); |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 497 | for (i = 0; i < banks; i++) { |
Andi Kleen | ee031c3 | 2009-02-12 13:49:34 +0100 | [diff] [blame] | 498 | if (!bank[i] || !test_bit(i, *b)) |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 499 | continue; |
| 500 | |
| 501 | m.misc = 0; |
| 502 | m.addr = 0; |
| 503 | m.bank = i; |
| 504 | m.tsc = 0; |
| 505 | |
| 506 | barrier(); |
Andi Kleen | 5f8c1a5 | 2009-04-29 19:29:12 +0200 | [diff] [blame] | 507 | m.status = mce_rdmsrl(MSR_IA32_MC0_STATUS + i*4); |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 508 | if (!(m.status & MCI_STATUS_VAL)) |
| 509 | continue; |
| 510 | |
| 511 | /* |
Andi Kleen | ed7290d | 2009-05-27 21:56:57 +0200 | [diff] [blame] | 512 | * Uncorrected or signalled events are handled by the exception |
| 513 | * handler when it is enabled, so don't process those here. |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 514 | * |
| 515 | * TBD do the same check for MCI_STATUS_EN here? |
| 516 | */ |
Andi Kleen | ed7290d | 2009-05-27 21:56:57 +0200 | [diff] [blame] | 517 | if (!(flags & MCP_UC) && |
| 518 | (m.status & (mce_ser ? MCI_STATUS_S : MCI_STATUS_UC))) |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 519 | continue; |
| 520 | |
| 521 | if (m.status & MCI_STATUS_MISCV) |
Andi Kleen | 5f8c1a5 | 2009-04-29 19:29:12 +0200 | [diff] [blame] | 522 | m.misc = mce_rdmsrl(MSR_IA32_MC0_MISC + i*4); |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 523 | if (m.status & MCI_STATUS_ADDRV) |
Andi Kleen | 5f8c1a5 | 2009-04-29 19:29:12 +0200 | [diff] [blame] | 524 | m.addr = mce_rdmsrl(MSR_IA32_MC0_ADDR + i*4); |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 525 | |
| 526 | if (!(flags & MCP_TIMESTAMP)) |
| 527 | m.tsc = 0; |
| 528 | /* |
| 529 | * Don't get the IP here because it's unlikely to |
| 530 | * have anything to do with the actual error location. |
| 531 | */ |
Hidetoshi Seto | 62fdac5 | 2009-06-11 16:06:07 +0900 | [diff] [blame] | 532 | if (!(flags & MCP_DONTLOG) && !mce_dont_log_ce) { |
Andi Kleen | 5679af4 | 2009-04-07 17:06:55 +0200 | [diff] [blame] | 533 | mce_log(&m); |
| 534 | add_taint(TAINT_MACHINE_CHECK); |
| 535 | } |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 536 | |
| 537 | /* |
| 538 | * Clear state for this bank. |
| 539 | */ |
Andi Kleen | 5f8c1a5 | 2009-04-29 19:29:12 +0200 | [diff] [blame] | 540 | mce_wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0); |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | /* |
| 544 | * Don't clear MCG_STATUS here because it's only defined for |
| 545 | * exceptions. |
| 546 | */ |
Andi Kleen | 88921be | 2009-05-27 21:56:51 +0200 | [diff] [blame] | 547 | |
| 548 | sync_core(); |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 549 | } |
Andi Kleen | ea149b3 | 2009-04-29 19:31:00 +0200 | [diff] [blame] | 550 | EXPORT_SYMBOL_GPL(machine_check_poll); |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 551 | |
| 552 | /* |
Andi Kleen | bd19a5e | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 553 | * Do a quick check if any of the events requires a panic. |
| 554 | * This decides if we keep the events around or clear them. |
| 555 | */ |
| 556 | static int mce_no_way_out(struct mce *m, char **msg) |
| 557 | { |
| 558 | int i; |
| 559 | |
| 560 | for (i = 0; i < banks; i++) { |
| 561 | m->status = mce_rdmsrl(MSR_IA32_MC0_STATUS + i*4); |
| 562 | if (mce_severity(m, tolerant, msg) >= MCE_PANIC_SEVERITY) |
| 563 | return 1; |
| 564 | } |
| 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | /* |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 569 | * Variable to establish order between CPUs while scanning. |
| 570 | * Each CPU spins initially until executing is equal its number. |
| 571 | */ |
| 572 | static atomic_t mce_executing; |
| 573 | |
| 574 | /* |
| 575 | * Defines order of CPUs on entry. First CPU becomes Monarch. |
| 576 | */ |
| 577 | static atomic_t mce_callin; |
| 578 | |
| 579 | /* |
| 580 | * Check if a timeout waiting for other CPUs happened. |
| 581 | */ |
| 582 | static int mce_timed_out(u64 *t) |
| 583 | { |
| 584 | /* |
| 585 | * The others already did panic for some reason. |
| 586 | * Bail out like in a timeout. |
| 587 | * rmb() to tell the compiler that system_state |
| 588 | * might have been modified by someone else. |
| 589 | */ |
| 590 | rmb(); |
| 591 | if (atomic_read(&mce_paniced)) |
| 592 | wait_for_panic(); |
| 593 | if (!monarch_timeout) |
| 594 | goto out; |
| 595 | if ((s64)*t < SPINUNIT) { |
| 596 | /* CHECKME: Make panic default for 1 too? */ |
| 597 | if (tolerant < 1) |
| 598 | mce_panic("Timeout synchronizing machine check over CPUs", |
| 599 | NULL, NULL); |
| 600 | cpu_missing = 1; |
| 601 | return 1; |
| 602 | } |
| 603 | *t -= SPINUNIT; |
| 604 | out: |
| 605 | touch_nmi_watchdog(); |
| 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | /* |
| 610 | * The Monarch's reign. The Monarch is the CPU who entered |
| 611 | * the machine check handler first. It waits for the others to |
| 612 | * raise the exception too and then grades them. When any |
| 613 | * error is fatal panic. Only then let the others continue. |
| 614 | * |
| 615 | * The other CPUs entering the MCE handler will be controlled by the |
| 616 | * Monarch. They are called Subjects. |
| 617 | * |
| 618 | * This way we prevent any potential data corruption in a unrecoverable case |
| 619 | * and also makes sure always all CPU's errors are examined. |
| 620 | * |
| 621 | * Also this detects the case of an machine check event coming from outer |
| 622 | * space (not detected by any CPUs) In this case some external agent wants |
| 623 | * us to shut down, so panic too. |
| 624 | * |
| 625 | * The other CPUs might still decide to panic if the handler happens |
| 626 | * in a unrecoverable place, but in this case the system is in a semi-stable |
| 627 | * state and won't corrupt anything by itself. It's ok to let the others |
| 628 | * continue for a bit first. |
| 629 | * |
| 630 | * All the spin loops have timeouts; when a timeout happens a CPU |
| 631 | * typically elects itself to be Monarch. |
| 632 | */ |
| 633 | static void mce_reign(void) |
| 634 | { |
| 635 | int cpu; |
| 636 | struct mce *m = NULL; |
| 637 | int global_worst = 0; |
| 638 | char *msg = NULL; |
| 639 | char *nmsg = NULL; |
| 640 | |
| 641 | /* |
| 642 | * This CPU is the Monarch and the other CPUs have run |
| 643 | * through their handlers. |
| 644 | * Grade the severity of the errors of all the CPUs. |
| 645 | */ |
| 646 | for_each_possible_cpu(cpu) { |
| 647 | int severity = mce_severity(&per_cpu(mces_seen, cpu), tolerant, |
| 648 | &nmsg); |
| 649 | if (severity > global_worst) { |
| 650 | msg = nmsg; |
| 651 | global_worst = severity; |
| 652 | m = &per_cpu(mces_seen, cpu); |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | /* |
| 657 | * Cannot recover? Panic here then. |
| 658 | * This dumps all the mces in the log buffer and stops the |
| 659 | * other CPUs. |
| 660 | */ |
| 661 | if (m && global_worst >= MCE_PANIC_SEVERITY && tolerant < 3) |
Andi Kleen | ac96037 | 2009-05-27 21:56:58 +0200 | [diff] [blame] | 662 | mce_panic("Fatal Machine check", m, msg); |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 663 | |
| 664 | /* |
| 665 | * For UC somewhere we let the CPU who detects it handle it. |
| 666 | * Also must let continue the others, otherwise the handling |
| 667 | * CPU could deadlock on a lock. |
| 668 | */ |
| 669 | |
| 670 | /* |
| 671 | * No machine check event found. Must be some external |
| 672 | * source or one CPU is hung. Panic. |
| 673 | */ |
| 674 | if (!m && tolerant < 3) |
| 675 | mce_panic("Machine check from unknown source", NULL, NULL); |
| 676 | |
| 677 | /* |
| 678 | * Now clear all the mces_seen so that they don't reappear on |
| 679 | * the next mce. |
| 680 | */ |
| 681 | for_each_possible_cpu(cpu) |
| 682 | memset(&per_cpu(mces_seen, cpu), 0, sizeof(struct mce)); |
| 683 | } |
| 684 | |
| 685 | static atomic_t global_nwo; |
| 686 | |
| 687 | /* |
| 688 | * Start of Monarch synchronization. This waits until all CPUs have |
| 689 | * entered the exception handler and then determines if any of them |
| 690 | * saw a fatal event that requires panic. Then it executes them |
| 691 | * in the entry order. |
| 692 | * TBD double check parallel CPU hotunplug |
| 693 | */ |
Hidetoshi Seto | 7fb06fc | 2009-06-15 18:18:43 +0900 | [diff] [blame] | 694 | static int mce_start(int *no_way_out) |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 695 | { |
Hidetoshi Seto | 7fb06fc | 2009-06-15 18:18:43 +0900 | [diff] [blame] | 696 | int order; |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 697 | int cpus = num_online_cpus(); |
| 698 | u64 timeout = (u64)monarch_timeout * NSEC_PER_USEC; |
| 699 | |
Hidetoshi Seto | 7fb06fc | 2009-06-15 18:18:43 +0900 | [diff] [blame] | 700 | if (!timeout) |
| 701 | return -1; |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 702 | |
Hidetoshi Seto | 7fb06fc | 2009-06-15 18:18:43 +0900 | [diff] [blame] | 703 | atomic_add(*no_way_out, &global_nwo); |
Huang Ying | 184e1fd | 2009-06-15 15:37:07 +0800 | [diff] [blame] | 704 | /* |
| 705 | * global_nwo should be updated before mce_callin |
| 706 | */ |
| 707 | smp_wmb(); |
Hidetoshi Seto | 7fb06fc | 2009-06-15 18:18:43 +0900 | [diff] [blame] | 708 | order = atomic_add_return(1, &mce_callin); |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 709 | |
| 710 | /* |
| 711 | * Wait for everyone. |
| 712 | */ |
| 713 | while (atomic_read(&mce_callin) != cpus) { |
| 714 | if (mce_timed_out(&timeout)) { |
| 715 | atomic_set(&global_nwo, 0); |
Hidetoshi Seto | 7fb06fc | 2009-06-15 18:18:43 +0900 | [diff] [blame] | 716 | return -1; |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 717 | } |
| 718 | ndelay(SPINUNIT); |
| 719 | } |
| 720 | |
| 721 | /* |
Huang Ying | 184e1fd | 2009-06-15 15:37:07 +0800 | [diff] [blame] | 722 | * mce_callin should be read before global_nwo |
| 723 | */ |
| 724 | smp_rmb(); |
Hidetoshi Seto | 7fb06fc | 2009-06-15 18:18:43 +0900 | [diff] [blame] | 725 | |
| 726 | if (order == 1) { |
| 727 | /* |
| 728 | * Monarch: Starts executing now, the others wait. |
| 729 | */ |
| 730 | atomic_set(&mce_executing, 1); |
| 731 | } else { |
| 732 | /* |
| 733 | * Subject: Now start the scanning loop one by one in |
| 734 | * the original callin order. |
| 735 | * This way when there are any shared banks it will be |
| 736 | * only seen by one CPU before cleared, avoiding duplicates. |
| 737 | */ |
| 738 | while (atomic_read(&mce_executing) < order) { |
| 739 | if (mce_timed_out(&timeout)) { |
| 740 | atomic_set(&global_nwo, 0); |
| 741 | return -1; |
| 742 | } |
| 743 | ndelay(SPINUNIT); |
| 744 | } |
| 745 | } |
| 746 | |
Huang Ying | 184e1fd | 2009-06-15 15:37:07 +0800 | [diff] [blame] | 747 | /* |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 748 | * Cache the global no_way_out state. |
| 749 | */ |
Hidetoshi Seto | 7fb06fc | 2009-06-15 18:18:43 +0900 | [diff] [blame] | 750 | *no_way_out = atomic_read(&global_nwo); |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 751 | |
Hidetoshi Seto | 7fb06fc | 2009-06-15 18:18:43 +0900 | [diff] [blame] | 752 | return order; |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | /* |
| 756 | * Synchronize between CPUs after main scanning loop. |
| 757 | * This invokes the bulk of the Monarch processing. |
| 758 | */ |
| 759 | static int mce_end(int order) |
| 760 | { |
| 761 | int ret = -1; |
| 762 | u64 timeout = (u64)monarch_timeout * NSEC_PER_USEC; |
| 763 | |
| 764 | if (!timeout) |
| 765 | goto reset; |
| 766 | if (order < 0) |
| 767 | goto reset; |
| 768 | |
| 769 | /* |
| 770 | * Allow others to run. |
| 771 | */ |
| 772 | atomic_inc(&mce_executing); |
| 773 | |
| 774 | if (order == 1) { |
| 775 | /* CHECKME: Can this race with a parallel hotplug? */ |
| 776 | int cpus = num_online_cpus(); |
| 777 | |
| 778 | /* |
| 779 | * Monarch: Wait for everyone to go through their scanning |
| 780 | * loops. |
| 781 | */ |
| 782 | while (atomic_read(&mce_executing) <= cpus) { |
| 783 | if (mce_timed_out(&timeout)) |
| 784 | goto reset; |
| 785 | ndelay(SPINUNIT); |
| 786 | } |
| 787 | |
| 788 | mce_reign(); |
| 789 | barrier(); |
| 790 | ret = 0; |
| 791 | } else { |
| 792 | /* |
| 793 | * Subject: Wait for Monarch to finish. |
| 794 | */ |
| 795 | while (atomic_read(&mce_executing) != 0) { |
| 796 | if (mce_timed_out(&timeout)) |
| 797 | goto reset; |
| 798 | ndelay(SPINUNIT); |
| 799 | } |
| 800 | |
| 801 | /* |
| 802 | * Don't reset anything. That's done by the Monarch. |
| 803 | */ |
| 804 | return 0; |
| 805 | } |
| 806 | |
| 807 | /* |
| 808 | * Reset all global state. |
| 809 | */ |
| 810 | reset: |
| 811 | atomic_set(&global_nwo, 0); |
| 812 | atomic_set(&mce_callin, 0); |
| 813 | barrier(); |
| 814 | |
| 815 | /* |
| 816 | * Let others run again. |
| 817 | */ |
| 818 | atomic_set(&mce_executing, 0); |
| 819 | return ret; |
| 820 | } |
| 821 | |
Andi Kleen | 9b1beaf | 2009-05-27 21:56:59 +0200 | [diff] [blame] | 822 | /* |
| 823 | * Check if the address reported by the CPU is in a format we can parse. |
| 824 | * It would be possible to add code for most other cases, but all would |
| 825 | * be somewhat complicated (e.g. segment offset would require an instruction |
| 826 | * parser). So only support physical addresses upto page granuality for now. |
| 827 | */ |
| 828 | static int mce_usable_address(struct mce *m) |
| 829 | { |
| 830 | if (!(m->status & MCI_STATUS_MISCV) || !(m->status & MCI_STATUS_ADDRV)) |
| 831 | return 0; |
| 832 | if ((m->misc & 0x3f) > PAGE_SHIFT) |
| 833 | return 0; |
| 834 | if (((m->misc >> 6) & 7) != MCM_ADDR_PHYS) |
| 835 | return 0; |
| 836 | return 1; |
| 837 | } |
| 838 | |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 839 | static void mce_clear_state(unsigned long *toclear) |
| 840 | { |
| 841 | int i; |
| 842 | |
| 843 | for (i = 0; i < banks; i++) { |
| 844 | if (test_bit(i, toclear)) |
| 845 | mce_wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0); |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | /* |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 850 | * The actual machine check handler. This only handles real |
| 851 | * exceptions when something got corrupted coming in through int 18. |
| 852 | * |
| 853 | * This is executed in NMI context not subject to normal locking rules. This |
| 854 | * implies that most kernel services cannot be safely used. Don't even |
| 855 | * think about putting a printk in there! |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 856 | * |
| 857 | * On Intel systems this is entered on all CPUs in parallel through |
| 858 | * MCE broadcast. However some CPUs might be broken beyond repair, |
| 859 | * so be always careful when synchronizing with others. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | */ |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 861 | void do_machine_check(struct pt_regs *regs, long error_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | { |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 863 | struct mce m, *final; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | int i; |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 865 | int worst = 0; |
| 866 | int severity; |
| 867 | /* |
| 868 | * Establish sequential order between the CPUs entering the machine |
| 869 | * check handler. |
| 870 | */ |
Hidetoshi Seto | 7fb06fc | 2009-06-15 18:18:43 +0900 | [diff] [blame] | 871 | int order; |
Tim Hockin | bd78432 | 2007-07-21 17:10:37 +0200 | [diff] [blame] | 872 | /* |
| 873 | * If no_way_out gets set, there is no safe way to recover from this |
| 874 | * MCE. If tolerant is cranked up, we'll try anyway. |
| 875 | */ |
| 876 | int no_way_out = 0; |
| 877 | /* |
| 878 | * If kill_it gets set, there might be a way to recover from this |
| 879 | * error. |
| 880 | */ |
| 881 | int kill_it = 0; |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 882 | DECLARE_BITMAP(toclear, MAX_NR_BANKS); |
Andi Kleen | bd19a5e | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 883 | char *msg = "Unknown"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | |
Andi Kleen | 553f265 | 2006-04-07 19:49:57 +0200 | [diff] [blame] | 885 | atomic_inc(&mce_entry); |
| 886 | |
Andi Kleen | 01ca79f | 2009-05-27 21:56:52 +0200 | [diff] [blame] | 887 | __get_cpu_var(mce_exception_count)++; |
| 888 | |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 889 | if (notify_die(DIE_NMI, "machine check", regs, error_code, |
Jan Beulich | 22f5991 | 2008-01-30 13:31:23 +0100 | [diff] [blame] | 890 | 18, SIGKILL) == NOTIFY_STOP) |
Andi Kleen | 3256169 | 2009-05-27 21:56:53 +0200 | [diff] [blame] | 891 | goto out; |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 892 | if (!banks) |
Andi Kleen | 3256169 | 2009-05-27 21:56:53 +0200 | [diff] [blame] | 893 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | |
Andi Kleen | b5f2fa4 | 2009-02-12 13:43:22 +0100 | [diff] [blame] | 895 | mce_setup(&m); |
| 896 | |
Andi Kleen | 5f8c1a5 | 2009-04-29 19:29:12 +0200 | [diff] [blame] | 897 | m.mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS); |
Andi Kleen | bd19a5e | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 898 | no_way_out = mce_no_way_out(&m, &msg); |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 899 | |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 900 | final = &__get_cpu_var(mces_seen); |
| 901 | *final = m; |
| 902 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | barrier(); |
| 904 | |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 905 | /* |
Andi Kleen | ed7290d | 2009-05-27 21:56:57 +0200 | [diff] [blame] | 906 | * When no restart IP must always kill or panic. |
| 907 | */ |
| 908 | if (!(m.mcgstatus & MCG_STATUS_RIPV)) |
| 909 | kill_it = 1; |
| 910 | |
| 911 | /* |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 912 | * Go through all the banks in exclusion of the other CPUs. |
| 913 | * This way we don't report duplicated events on shared banks |
| 914 | * because the first one to see it will clear it. |
| 915 | */ |
Hidetoshi Seto | 7fb06fc | 2009-06-15 18:18:43 +0900 | [diff] [blame] | 916 | order = mce_start(&no_way_out); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | for (i = 0; i < banks; i++) { |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 918 | __clear_bit(i, toclear); |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 919 | if (!bank[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | continue; |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 921 | |
| 922 | m.misc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | m.addr = 0; |
| 924 | m.bank = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
Andi Kleen | 5f8c1a5 | 2009-04-29 19:29:12 +0200 | [diff] [blame] | 926 | m.status = mce_rdmsrl(MSR_IA32_MC0_STATUS + i*4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | if ((m.status & MCI_STATUS_VAL) == 0) |
| 928 | continue; |
| 929 | |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 930 | /* |
Andi Kleen | ed7290d | 2009-05-27 21:56:57 +0200 | [diff] [blame] | 931 | * Non uncorrected or non signaled errors are handled by |
| 932 | * machine_check_poll. Leave them alone, unless this panics. |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 933 | */ |
Andi Kleen | ed7290d | 2009-05-27 21:56:57 +0200 | [diff] [blame] | 934 | if (!(m.status & (mce_ser ? MCI_STATUS_S : MCI_STATUS_UC)) && |
| 935 | !no_way_out) |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 936 | continue; |
| 937 | |
| 938 | /* |
| 939 | * Set taint even when machine check was not enabled. |
| 940 | */ |
| 941 | add_taint(TAINT_MACHINE_CHECK); |
| 942 | |
Andi Kleen | ed7290d | 2009-05-27 21:56:57 +0200 | [diff] [blame] | 943 | severity = mce_severity(&m, tolerant, NULL); |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 944 | |
Andi Kleen | ed7290d | 2009-05-27 21:56:57 +0200 | [diff] [blame] | 945 | /* |
| 946 | * When machine check was for corrected handler don't touch, |
| 947 | * unless we're panicing. |
| 948 | */ |
| 949 | if (severity == MCE_KEEP_SEVERITY && !no_way_out) |
| 950 | continue; |
| 951 | __set_bit(i, toclear); |
| 952 | if (severity == MCE_NO_SEVERITY) { |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 953 | /* |
| 954 | * Machine check event was not enabled. Clear, but |
| 955 | * ignore. |
| 956 | */ |
| 957 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | } |
| 959 | |
Andi Kleen | ed7290d | 2009-05-27 21:56:57 +0200 | [diff] [blame] | 960 | /* |
| 961 | * Kill on action required. |
| 962 | */ |
| 963 | if (severity == MCE_AR_SEVERITY) |
| 964 | kill_it = 1; |
| 965 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | if (m.status & MCI_STATUS_MISCV) |
Andi Kleen | 5f8c1a5 | 2009-04-29 19:29:12 +0200 | [diff] [blame] | 967 | m.misc = mce_rdmsrl(MSR_IA32_MC0_MISC + i*4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | if (m.status & MCI_STATUS_ADDRV) |
Andi Kleen | 5f8c1a5 | 2009-04-29 19:29:12 +0200 | [diff] [blame] | 969 | m.addr = mce_rdmsrl(MSR_IA32_MC0_ADDR + i*4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | |
Andi Kleen | 9b1beaf | 2009-05-27 21:56:59 +0200 | [diff] [blame] | 971 | /* |
| 972 | * Action optional error. Queue address for later processing. |
| 973 | * When the ring overflows we just ignore the AO error. |
| 974 | * RED-PEN add some logging mechanism when |
| 975 | * usable_address or mce_add_ring fails. |
| 976 | * RED-PEN don't ignore overflow for tolerant == 0 |
| 977 | */ |
| 978 | if (severity == MCE_AO_SEVERITY && mce_usable_address(&m)) |
| 979 | mce_ring_add(m.addr >> PAGE_SHIFT); |
| 980 | |
Andi Kleen | 94ad847 | 2005-04-16 15:25:09 -0700 | [diff] [blame] | 981 | mce_get_rip(&m, regs); |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 982 | mce_log(&m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 984 | if (severity > worst) { |
| 985 | *final = m; |
| 986 | worst = severity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | } |
| 989 | |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 990 | if (!no_way_out) |
| 991 | mce_clear_state(toclear); |
| 992 | |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 993 | /* |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 994 | * Do most of the synchronization with other CPUs. |
| 995 | * When there's any problem use only local no_way_out state. |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 996 | */ |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 997 | if (mce_end(order) < 0) |
| 998 | no_way_out = worst >= MCE_PANIC_SEVERITY; |
Tim Hockin | bd78432 | 2007-07-21 17:10:37 +0200 | [diff] [blame] | 999 | |
| 1000 | /* |
| 1001 | * If we have decided that we just CAN'T continue, and the user |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1002 | * has not set tolerant to an insane level, give up and die. |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 1003 | * |
| 1004 | * This is mainly used in the case when the system doesn't |
| 1005 | * support MCE broadcasting or it has been disabled. |
Tim Hockin | bd78432 | 2007-07-21 17:10:37 +0200 | [diff] [blame] | 1006 | */ |
| 1007 | if (no_way_out && tolerant < 3) |
Andi Kleen | ac96037 | 2009-05-27 21:56:58 +0200 | [diff] [blame] | 1008 | mce_panic("Fatal machine check on current CPU", final, msg); |
Tim Hockin | bd78432 | 2007-07-21 17:10:37 +0200 | [diff] [blame] | 1009 | |
| 1010 | /* |
| 1011 | * If the error seems to be unrecoverable, something should be |
| 1012 | * done. Try to kill as little as possible. If we can kill just |
| 1013 | * one task, do that. If the user has set the tolerance very |
| 1014 | * high, don't try to do anything at all. |
| 1015 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | |
Andi Kleen | ed7290d | 2009-05-27 21:56:57 +0200 | [diff] [blame] | 1017 | if (kill_it && tolerant < 3) |
| 1018 | force_sig(SIGBUS, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | |
Tim Hockin | e02e68d | 2007-07-21 17:10:36 +0200 | [diff] [blame] | 1020 | /* notify userspace ASAP */ |
| 1021 | set_thread_flag(TIF_MCE_NOTIFY); |
| 1022 | |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 1023 | if (worst > 0) |
| 1024 | mce_report_event(regs); |
Andi Kleen | 5f8c1a5 | 2009-04-29 19:29:12 +0200 | [diff] [blame] | 1025 | mce_wrmsrl(MSR_IA32_MCG_STATUS, 0); |
Andi Kleen | 3256169 | 2009-05-27 21:56:53 +0200 | [diff] [blame] | 1026 | out: |
Andi Kleen | 553f265 | 2006-04-07 19:49:57 +0200 | [diff] [blame] | 1027 | atomic_dec(&mce_entry); |
Andi Kleen | 88921be | 2009-05-27 21:56:51 +0200 | [diff] [blame] | 1028 | sync_core(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | } |
Andi Kleen | ea149b3 | 2009-04-29 19:31:00 +0200 | [diff] [blame] | 1030 | EXPORT_SYMBOL_GPL(do_machine_check); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | |
Andi Kleen | 9b1beaf | 2009-05-27 21:56:59 +0200 | [diff] [blame] | 1032 | /* dummy to break dependency. actual code is in mm/memory-failure.c */ |
| 1033 | void __attribute__((weak)) memory_failure(unsigned long pfn, int vector) |
| 1034 | { |
| 1035 | printk(KERN_ERR "Action optional memory failure at %lx ignored\n", pfn); |
| 1036 | } |
| 1037 | |
| 1038 | /* |
| 1039 | * Called after mce notification in process context. This code |
| 1040 | * is allowed to sleep. Call the high level VM handler to process |
| 1041 | * any corrupted pages. |
| 1042 | * Assume that the work queue code only calls this one at a time |
| 1043 | * per CPU. |
| 1044 | * Note we don't disable preemption, so this code might run on the wrong |
| 1045 | * CPU. In this case the event is picked up by the scheduled work queue. |
| 1046 | * This is merely a fast path to expedite processing in some common |
| 1047 | * cases. |
| 1048 | */ |
| 1049 | void mce_notify_process(void) |
| 1050 | { |
| 1051 | unsigned long pfn; |
| 1052 | mce_notify_irq(); |
| 1053 | while (mce_ring_get(&pfn)) |
| 1054 | memory_failure(pfn, MCE_VECTOR); |
| 1055 | } |
| 1056 | |
| 1057 | static void mce_process_work(struct work_struct *dummy) |
| 1058 | { |
| 1059 | mce_notify_process(); |
| 1060 | } |
| 1061 | |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 1062 | #ifdef CONFIG_X86_MCE_INTEL |
| 1063 | /*** |
| 1064 | * mce_log_therm_throt_event - Logs the thermal throttling event to mcelog |
Simon Arlott | 676b185 | 2007-10-20 01:25:36 +0200 | [diff] [blame] | 1065 | * @cpu: The CPU on which the event occurred. |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 1066 | * @status: Event status information |
| 1067 | * |
| 1068 | * This function should be called by the thermal interrupt after the |
| 1069 | * event has been processed and the decision was made to log the event |
| 1070 | * further. |
| 1071 | * |
| 1072 | * The status parameter will be saved to the 'status' field of 'struct mce' |
| 1073 | * and historically has been the register value of the |
| 1074 | * MSR_IA32_THERMAL_STATUS (Intel) msr. |
| 1075 | */ |
Andi Kleen | b5f2fa4 | 2009-02-12 13:43:22 +0100 | [diff] [blame] | 1076 | void mce_log_therm_throt_event(__u64 status) |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 1077 | { |
| 1078 | struct mce m; |
| 1079 | |
Andi Kleen | b5f2fa4 | 2009-02-12 13:43:22 +0100 | [diff] [blame] | 1080 | mce_setup(&m); |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 1081 | m.bank = MCE_THERMAL_BANK; |
| 1082 | m.status = status; |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 1083 | mce_log(&m); |
| 1084 | } |
| 1085 | #endif /* CONFIG_X86_MCE_INTEL */ |
| 1086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | /* |
Tim Hockin | 8a336b0 | 2007-05-02 19:27:19 +0200 | [diff] [blame] | 1088 | * Periodic polling timer for "silent" machine check errors. If the |
| 1089 | * poller finds an MCE, poll 2x faster. When the poller finds no more |
| 1090 | * errors, poll 2x slower (up to check_interval seconds). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | static int check_interval = 5 * 60; /* 5 minutes */ |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1093 | |
Andi Kleen | 6298c51 | 2009-04-09 12:28:22 +0200 | [diff] [blame] | 1094 | static DEFINE_PER_CPU(int, next_interval); /* in jiffies */ |
Andi Kleen | 52d168e | 2009-02-12 13:39:29 +0100 | [diff] [blame] | 1095 | static DEFINE_PER_CPU(struct timer_list, mce_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
Andi Kleen | 52d168e | 2009-02-12 13:39:29 +0100 | [diff] [blame] | 1097 | static void mcheck_timer(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | { |
Andi Kleen | 52d168e | 2009-02-12 13:39:29 +0100 | [diff] [blame] | 1099 | struct timer_list *t = &per_cpu(mce_timer, data); |
Andi Kleen | 6298c51 | 2009-04-09 12:28:22 +0200 | [diff] [blame] | 1100 | int *n; |
Andi Kleen | 52d168e | 2009-02-12 13:39:29 +0100 | [diff] [blame] | 1101 | |
| 1102 | WARN_ON(smp_processor_id() != data); |
| 1103 | |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1104 | if (mce_available(¤t_cpu_data)) { |
Andi Kleen | ee031c3 | 2009-02-12 13:49:34 +0100 | [diff] [blame] | 1105 | machine_check_poll(MCP_TIMESTAMP, |
| 1106 | &__get_cpu_var(mce_poll_banks)); |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1107 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | |
| 1109 | /* |
Tim Hockin | e02e68d | 2007-07-21 17:10:36 +0200 | [diff] [blame] | 1110 | * Alert userspace if needed. If we logged an MCE, reduce the |
| 1111 | * polling interval, otherwise increase the polling interval. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | */ |
Andi Kleen | 6298c51 | 2009-04-09 12:28:22 +0200 | [diff] [blame] | 1113 | n = &__get_cpu_var(next_interval); |
Andi Kleen | 9ff36ee | 2009-05-27 21:56:58 +0200 | [diff] [blame] | 1114 | if (mce_notify_irq()) |
Andi Kleen | 6298c51 | 2009-04-09 12:28:22 +0200 | [diff] [blame] | 1115 | *n = max(*n/2, HZ/100); |
Hidetoshi Seto | 14a0253 | 2009-04-30 16:04:51 +0900 | [diff] [blame] | 1116 | else |
Andi Kleen | 6298c51 | 2009-04-09 12:28:22 +0200 | [diff] [blame] | 1117 | *n = min(*n*2, (int)round_jiffies_relative(check_interval*HZ)); |
Tim Hockin | 8a336b0 | 2007-05-02 19:27:19 +0200 | [diff] [blame] | 1118 | |
Andi Kleen | 6298c51 | 2009-04-09 12:28:22 +0200 | [diff] [blame] | 1119 | t->expires = jiffies + *n; |
Hidetoshi Seto | 5be6066 | 2009-06-24 09:21:10 +0900 | [diff] [blame] | 1120 | add_timer_on(t, smp_processor_id()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
Andi Kleen | 9bd9840 | 2009-02-12 13:39:28 +0100 | [diff] [blame] | 1123 | static void mce_do_trigger(struct work_struct *work) |
| 1124 | { |
Hidetoshi Seto | 1020bcb | 2009-06-15 17:20:57 +0900 | [diff] [blame] | 1125 | call_usermodehelper(mce_helper, mce_helper_argv, NULL, UMH_NO_WAIT); |
Andi Kleen | 9bd9840 | 2009-02-12 13:39:28 +0100 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | static DECLARE_WORK(mce_trigger_work, mce_do_trigger); |
| 1129 | |
Tim Hockin | e02e68d | 2007-07-21 17:10:36 +0200 | [diff] [blame] | 1130 | /* |
Andi Kleen | 9bd9840 | 2009-02-12 13:39:28 +0100 | [diff] [blame] | 1131 | * Notify the user(s) about new machine check events. |
| 1132 | * Can be called from interrupt context, but not from machine check/NMI |
| 1133 | * context. |
Tim Hockin | e02e68d | 2007-07-21 17:10:36 +0200 | [diff] [blame] | 1134 | */ |
Andi Kleen | 9ff36ee | 2009-05-27 21:56:58 +0200 | [diff] [blame] | 1135 | int mce_notify_irq(void) |
Tim Hockin | e02e68d | 2007-07-21 17:10:36 +0200 | [diff] [blame] | 1136 | { |
Andi Kleen | 8457c84 | 2009-02-12 13:49:33 +0100 | [diff] [blame] | 1137 | /* Not more than two messages every minute */ |
| 1138 | static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2); |
| 1139 | |
Tim Hockin | e02e68d | 2007-07-21 17:10:36 +0200 | [diff] [blame] | 1140 | clear_thread_flag(TIF_MCE_NOTIFY); |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1141 | |
Hidetoshi Seto | 1020bcb | 2009-06-15 17:20:57 +0900 | [diff] [blame] | 1142 | if (test_and_clear_bit(0, &mce_need_notify)) { |
Tim Hockin | e02e68d | 2007-07-21 17:10:36 +0200 | [diff] [blame] | 1143 | wake_up_interruptible(&mce_wait); |
Andi Kleen | 9bd9840 | 2009-02-12 13:39:28 +0100 | [diff] [blame] | 1144 | |
| 1145 | /* |
| 1146 | * There is no risk of missing notifications because |
| 1147 | * work_pending is always cleared before the function is |
| 1148 | * executed. |
| 1149 | */ |
Hidetoshi Seto | 1020bcb | 2009-06-15 17:20:57 +0900 | [diff] [blame] | 1150 | if (mce_helper[0] && !work_pending(&mce_trigger_work)) |
Andi Kleen | 9bd9840 | 2009-02-12 13:39:28 +0100 | [diff] [blame] | 1151 | schedule_work(&mce_trigger_work); |
Tim Hockin | e02e68d | 2007-07-21 17:10:36 +0200 | [diff] [blame] | 1152 | |
Andi Kleen | 8457c84 | 2009-02-12 13:49:33 +0100 | [diff] [blame] | 1153 | if (__ratelimit(&ratelimit)) |
Tim Hockin | e02e68d | 2007-07-21 17:10:36 +0200 | [diff] [blame] | 1154 | printk(KERN_INFO "Machine check events logged\n"); |
Tim Hockin | e02e68d | 2007-07-21 17:10:36 +0200 | [diff] [blame] | 1155 | |
| 1156 | return 1; |
| 1157 | } |
| 1158 | return 0; |
| 1159 | } |
Andi Kleen | 9ff36ee | 2009-05-27 21:56:58 +0200 | [diff] [blame] | 1160 | EXPORT_SYMBOL_GPL(mce_notify_irq); |
Tim Hockin | e02e68d | 2007-07-21 17:10:36 +0200 | [diff] [blame] | 1161 | |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1162 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | * Initialize Machine Checks for a CPU. |
| 1164 | */ |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1165 | static int mce_cap_init(void) |
| 1166 | { |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1167 | unsigned b; |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1168 | u64 cap; |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1169 | |
| 1170 | rdmsrl(MSR_IA32_MCG_CAP, cap); |
Thomas Gleixner | 01c6680 | 2009-04-08 12:31:24 +0200 | [diff] [blame] | 1171 | |
| 1172 | b = cap & MCG_BANKCNT_MASK; |
Ingo Molnar | b659294 | 2009-04-08 12:31:27 +0200 | [diff] [blame] | 1173 | printk(KERN_INFO "mce: CPU supports %d MCE banks\n", b); |
| 1174 | |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1175 | if (b > MAX_NR_BANKS) { |
| 1176 | printk(KERN_WARNING |
| 1177 | "MCE: Using only %u machine check banks out of %u\n", |
| 1178 | MAX_NR_BANKS, b); |
| 1179 | b = MAX_NR_BANKS; |
| 1180 | } |
| 1181 | |
| 1182 | /* Don't support asymmetric configurations today */ |
| 1183 | WARN_ON(banks != 0 && b != banks); |
| 1184 | banks = b; |
| 1185 | if (!bank) { |
| 1186 | bank = kmalloc(banks * sizeof(u64), GFP_KERNEL); |
| 1187 | if (!bank) |
| 1188 | return -ENOMEM; |
| 1189 | memset(bank, 0xff, banks * sizeof(u64)); |
| 1190 | } |
| 1191 | |
| 1192 | /* Use accurate RIP reporting if available. */ |
Thomas Gleixner | 01c6680 | 2009-04-08 12:31:24 +0200 | [diff] [blame] | 1193 | if ((cap & MCG_EXT_P) && MCG_EXT_CNT(cap) >= 9) |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1194 | rip_msr = MSR_IA32_MCG_EIP; |
| 1195 | |
Andi Kleen | ed7290d | 2009-05-27 21:56:57 +0200 | [diff] [blame] | 1196 | if (cap & MCG_SER_P) |
| 1197 | mce_ser = 1; |
| 1198 | |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1199 | return 0; |
| 1200 | } |
| 1201 | |
Thomas Gleixner | 8be9110 | 2009-05-27 21:56:53 +0200 | [diff] [blame] | 1202 | static void mce_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | { |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1204 | mce_banks_t all_banks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | u64 cap; |
| 1206 | int i; |
| 1207 | |
Andi Kleen | b79109c | 2009-02-12 13:43:23 +0100 | [diff] [blame] | 1208 | /* |
| 1209 | * Log the machine checks left over from the previous reset. |
| 1210 | */ |
Andi Kleen | ee031c3 | 2009-02-12 13:49:34 +0100 | [diff] [blame] | 1211 | bitmap_fill(all_banks, MAX_NR_BANKS); |
Andi Kleen | 5679af4 | 2009-04-07 17:06:55 +0200 | [diff] [blame] | 1212 | machine_check_poll(MCP_UC|(!mce_bootlog ? MCP_DONTLOG : 0), &all_banks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | |
| 1214 | set_in_cr4(X86_CR4_MCE); |
| 1215 | |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1216 | rdmsrl(MSR_IA32_MCG_CAP, cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | if (cap & MCG_CTL_P) |
| 1218 | wrmsr(MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff); |
| 1219 | |
| 1220 | for (i = 0; i < banks; i++) { |
Andi Kleen | 06b7a7a | 2009-04-27 18:37:43 +0200 | [diff] [blame] | 1221 | if (skip_bank_init(i)) |
| 1222 | continue; |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1223 | wrmsrl(MSR_IA32_MC0_CTL+4*i, bank[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0); |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1225 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | /* Add per CPU specific workarounds here */ |
Ingo Molnar | e412cd2 | 2009-08-17 10:19:00 +0200 | [diff] [blame^] | 1229 | static int mce_cpu_quirks(struct cpuinfo_x86 *c) |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1230 | { |
Ingo Molnar | e412cd2 | 2009-08-17 10:19:00 +0200 | [diff] [blame^] | 1231 | if (c->x86_vendor == X86_VENDOR_UNKNOWN) { |
| 1232 | pr_info("MCE: unknown CPU type - not enabling MCE support.\n"); |
| 1233 | return -EOPNOTSUPP; |
| 1234 | } |
| 1235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | /* This should be disabled by the BIOS, but isn't always */ |
Jan Beulich | 911f6a7 | 2008-04-22 16:22:21 +0100 | [diff] [blame] | 1237 | if (c->x86_vendor == X86_VENDOR_AMD) { |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1238 | if (c->x86 == 15 && banks > 4) { |
| 1239 | /* |
| 1240 | * disable GART TBL walk error reporting, which |
| 1241 | * trips off incorrectly with the IOMMU & 3ware |
| 1242 | * & Cerberus: |
| 1243 | */ |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1244 | clear_bit(10, (unsigned long *)&bank[4]); |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1245 | } |
| 1246 | if (c->x86 <= 17 && mce_bootlog < 0) { |
| 1247 | /* |
| 1248 | * Lots of broken BIOS around that don't clear them |
| 1249 | * by default and leave crap in there. Don't log: |
| 1250 | */ |
Jan Beulich | 911f6a7 | 2008-04-22 16:22:21 +0100 | [diff] [blame] | 1251 | mce_bootlog = 0; |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1252 | } |
Andi Kleen | 2e6f694 | 2009-04-27 18:42:48 +0200 | [diff] [blame] | 1253 | /* |
| 1254 | * Various K7s with broken bank 0 around. Always disable |
| 1255 | * by default. |
| 1256 | */ |
Andi Kleen | 203abd6 | 2009-06-15 14:52:01 +0200 | [diff] [blame] | 1257 | if (c->x86 == 6 && banks > 0) |
Andi Kleen | 2e6f694 | 2009-04-27 18:42:48 +0200 | [diff] [blame] | 1258 | bank[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | } |
Andi Kleen | e583538 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 1260 | |
Andi Kleen | 06b7a7a | 2009-04-27 18:37:43 +0200 | [diff] [blame] | 1261 | if (c->x86_vendor == X86_VENDOR_INTEL) { |
| 1262 | /* |
| 1263 | * SDM documents that on family 6 bank 0 should not be written |
| 1264 | * because it aliases to another special BIOS controlled |
| 1265 | * register. |
| 1266 | * But it's not aliased anymore on model 0x1a+ |
| 1267 | * Don't ignore bank 0 completely because there could be a |
| 1268 | * valid event later, merely don't write CTL0. |
| 1269 | */ |
| 1270 | |
| 1271 | if (c->x86 == 6 && c->x86_model < 0x1A) |
| 1272 | __set_bit(0, &dont_init_banks); |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 1273 | |
| 1274 | /* |
| 1275 | * All newer Intel systems support MCE broadcasting. Enable |
| 1276 | * synchronization with a one second timeout. |
| 1277 | */ |
| 1278 | if ((c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xe)) && |
| 1279 | monarch_timeout < 0) |
| 1280 | monarch_timeout = USEC_PER_SEC; |
Bartlomiej Zolnierkiewicz | c7f6fa4 | 2009-07-28 23:52:54 +0200 | [diff] [blame] | 1281 | |
Ingo Molnar | e412cd2 | 2009-08-17 10:19:00 +0200 | [diff] [blame^] | 1282 | /* |
| 1283 | * There are also broken BIOSes on some Pentium M and |
| 1284 | * earlier systems: |
| 1285 | */ |
| 1286 | if (c->x86 == 6 && c->x86_model <= 13 && mce_bootlog < 0) |
Bartlomiej Zolnierkiewicz | c7f6fa4 | 2009-07-28 23:52:54 +0200 | [diff] [blame] | 1287 | mce_bootlog = 0; |
Andi Kleen | 06b7a7a | 2009-04-27 18:37:43 +0200 | [diff] [blame] | 1288 | } |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 1289 | if (monarch_timeout < 0) |
| 1290 | monarch_timeout = 0; |
Andi Kleen | 29b0f59 | 2009-05-27 21:56:56 +0200 | [diff] [blame] | 1291 | if (mce_bootlog != 0) |
| 1292 | mce_panic_timeout = 30; |
Ingo Molnar | e412cd2 | 2009-08-17 10:19:00 +0200 | [diff] [blame^] | 1293 | |
| 1294 | return 0; |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1295 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | |
Andi Kleen | 4efc067 | 2009-04-28 19:07:31 +0200 | [diff] [blame] | 1297 | static void __cpuinit mce_ancient_init(struct cpuinfo_x86 *c) |
| 1298 | { |
| 1299 | if (c->x86 != 5) |
| 1300 | return; |
| 1301 | switch (c->x86_vendor) { |
| 1302 | case X86_VENDOR_INTEL: |
Hidetoshi Seto | c697836 | 2009-06-15 17:22:49 +0900 | [diff] [blame] | 1303 | intel_p5_mcheck_init(c); |
Andi Kleen | 4efc067 | 2009-04-28 19:07:31 +0200 | [diff] [blame] | 1304 | break; |
| 1305 | case X86_VENDOR_CENTAUR: |
| 1306 | winchip_mcheck_init(c); |
| 1307 | break; |
| 1308 | } |
| 1309 | } |
| 1310 | |
H. Peter Anvin | cc3ca22 | 2009-02-20 23:35:51 -0800 | [diff] [blame] | 1311 | static void mce_cpu_features(struct cpuinfo_x86 *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | { |
| 1313 | switch (c->x86_vendor) { |
| 1314 | case X86_VENDOR_INTEL: |
| 1315 | mce_intel_feature_init(c); |
| 1316 | break; |
Jacob Shin | 89b831e | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 1317 | case X86_VENDOR_AMD: |
| 1318 | mce_amd_feature_init(c); |
| 1319 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | default: |
| 1321 | break; |
| 1322 | } |
| 1323 | } |
| 1324 | |
Andi Kleen | 52d168e | 2009-02-12 13:39:29 +0100 | [diff] [blame] | 1325 | static void mce_init_timer(void) |
| 1326 | { |
| 1327 | struct timer_list *t = &__get_cpu_var(mce_timer); |
Andi Kleen | 6298c51 | 2009-04-09 12:28:22 +0200 | [diff] [blame] | 1328 | int *n = &__get_cpu_var(next_interval); |
Andi Kleen | 52d168e | 2009-02-12 13:39:29 +0100 | [diff] [blame] | 1329 | |
Hidetoshi Seto | 62fdac5 | 2009-06-11 16:06:07 +0900 | [diff] [blame] | 1330 | if (mce_ignore_ce) |
| 1331 | return; |
| 1332 | |
Andi Kleen | 6298c51 | 2009-04-09 12:28:22 +0200 | [diff] [blame] | 1333 | *n = check_interval * HZ; |
| 1334 | if (!*n) |
Andi Kleen | 52d168e | 2009-02-12 13:39:29 +0100 | [diff] [blame] | 1335 | return; |
| 1336 | setup_timer(t, mcheck_timer, smp_processor_id()); |
Andi Kleen | 6298c51 | 2009-04-09 12:28:22 +0200 | [diff] [blame] | 1337 | t->expires = round_jiffies(jiffies + *n); |
Hidetoshi Seto | 5be6066 | 2009-06-24 09:21:10 +0900 | [diff] [blame] | 1338 | add_timer_on(t, smp_processor_id()); |
Andi Kleen | 52d168e | 2009-02-12 13:39:29 +0100 | [diff] [blame] | 1339 | } |
| 1340 | |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1341 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | * Called for each booted CPU to set up machine checks. |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1343 | * Must be called with preempt off: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | */ |
Ashok Raj | e6982c6 | 2005-06-25 14:54:58 -0700 | [diff] [blame] | 1345 | void __cpuinit mcheck_init(struct cpuinfo_x86 *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | { |
Andi Kleen | 4efc067 | 2009-04-28 19:07:31 +0200 | [diff] [blame] | 1347 | if (mce_disabled) |
| 1348 | return; |
| 1349 | |
| 1350 | mce_ancient_init(c); |
| 1351 | |
Andi Kleen | 5b4408f | 2009-02-12 13:39:30 +0100 | [diff] [blame] | 1352 | if (!mce_available(c)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | return; |
| 1354 | |
Ingo Molnar | e412cd2 | 2009-08-17 10:19:00 +0200 | [diff] [blame^] | 1355 | if (mce_cap_init() < 0 || mce_cpu_quirks(c) < 0) { |
Andi Kleen | 04b2b1a | 2009-04-28 22:50:19 +0200 | [diff] [blame] | 1356 | mce_disabled = 1; |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1357 | return; |
| 1358 | } |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1359 | |
Andi Kleen | 5d72792 | 2009-04-27 19:25:48 +0200 | [diff] [blame] | 1360 | machine_check_vector = do_machine_check; |
| 1361 | |
Thomas Gleixner | 8be9110 | 2009-05-27 21:56:53 +0200 | [diff] [blame] | 1362 | mce_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | mce_cpu_features(c); |
Andi Kleen | 52d168e | 2009-02-12 13:39:29 +0100 | [diff] [blame] | 1364 | mce_init_timer(); |
Andi Kleen | 9b1beaf | 2009-05-27 21:56:59 +0200 | [diff] [blame] | 1365 | INIT_WORK(&__get_cpu_var(mce_work), mce_process_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | /* |
| 1369 | * Character device to read and clear the MCE log. |
| 1370 | */ |
| 1371 | |
Tim Hockin | f528e7b | 2007-07-21 17:10:35 +0200 | [diff] [blame] | 1372 | static DEFINE_SPINLOCK(mce_state_lock); |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1373 | static int open_count; /* #times opened */ |
| 1374 | static int open_exclu; /* already open exclusive? */ |
Tim Hockin | f528e7b | 2007-07-21 17:10:35 +0200 | [diff] [blame] | 1375 | |
| 1376 | static int mce_open(struct inode *inode, struct file *file) |
| 1377 | { |
| 1378 | spin_lock(&mce_state_lock); |
| 1379 | |
| 1380 | if (open_exclu || (open_count && (file->f_flags & O_EXCL))) { |
| 1381 | spin_unlock(&mce_state_lock); |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1382 | |
Tim Hockin | f528e7b | 2007-07-21 17:10:35 +0200 | [diff] [blame] | 1383 | return -EBUSY; |
| 1384 | } |
| 1385 | |
| 1386 | if (file->f_flags & O_EXCL) |
| 1387 | open_exclu = 1; |
| 1388 | open_count++; |
| 1389 | |
| 1390 | spin_unlock(&mce_state_lock); |
| 1391 | |
Tim Hockin | bd78432 | 2007-07-21 17:10:37 +0200 | [diff] [blame] | 1392 | return nonseekable_open(inode, file); |
Tim Hockin | f528e7b | 2007-07-21 17:10:35 +0200 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | static int mce_release(struct inode *inode, struct file *file) |
| 1396 | { |
| 1397 | spin_lock(&mce_state_lock); |
| 1398 | |
| 1399 | open_count--; |
| 1400 | open_exclu = 0; |
| 1401 | |
| 1402 | spin_unlock(&mce_state_lock); |
| 1403 | |
| 1404 | return 0; |
| 1405 | } |
| 1406 | |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1407 | static void collect_tscs(void *data) |
| 1408 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | unsigned long *cpu_tsc = (unsigned long *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1411 | rdtscll(cpu_tsc[smp_processor_id()]); |
| 1412 | } |
| 1413 | |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1414 | static DEFINE_MUTEX(mce_read_mutex); |
| 1415 | |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1416 | static ssize_t mce_read(struct file *filp, char __user *ubuf, size_t usize, |
| 1417 | loff_t *off) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | char __user *buf = ubuf; |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1420 | unsigned long *cpu_tsc; |
| 1421 | unsigned prev, next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | int i, err; |
| 1423 | |
Mike Travis | 6bca67f | 2008-07-18 18:11:27 -0700 | [diff] [blame] | 1424 | cpu_tsc = kmalloc(nr_cpu_ids * sizeof(long), GFP_KERNEL); |
Andi Kleen | f0de53b | 2005-04-16 15:25:10 -0700 | [diff] [blame] | 1425 | if (!cpu_tsc) |
| 1426 | return -ENOMEM; |
| 1427 | |
Daniel Walker | 8c8b885 | 2008-01-30 13:31:17 +0100 | [diff] [blame] | 1428 | mutex_lock(&mce_read_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | next = rcu_dereference(mcelog.next); |
| 1430 | |
| 1431 | /* Only supports full reads right now */ |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1432 | if (*off != 0 || usize < MCE_LOG_LEN*sizeof(struct mce)) { |
Daniel Walker | 8c8b885 | 2008-01-30 13:31:17 +0100 | [diff] [blame] | 1433 | mutex_unlock(&mce_read_mutex); |
Andi Kleen | f0de53b | 2005-04-16 15:25:10 -0700 | [diff] [blame] | 1434 | kfree(cpu_tsc); |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | return -EINVAL; |
| 1437 | } |
| 1438 | |
| 1439 | err = 0; |
Huang Ying | ef41df434 | 2009-02-12 13:39:34 +0100 | [diff] [blame] | 1440 | prev = 0; |
| 1441 | do { |
| 1442 | for (i = prev; i < next; i++) { |
| 1443 | unsigned long start = jiffies; |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1444 | |
Huang Ying | ef41df434 | 2009-02-12 13:39:34 +0100 | [diff] [blame] | 1445 | while (!mcelog.entry[i].finished) { |
| 1446 | if (time_after_eq(jiffies, start + 2)) { |
| 1447 | memset(mcelog.entry + i, 0, |
| 1448 | sizeof(struct mce)); |
| 1449 | goto timeout; |
| 1450 | } |
| 1451 | cpu_relax(); |
Andi Kleen | 673242c | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1452 | } |
Huang Ying | ef41df434 | 2009-02-12 13:39:34 +0100 | [diff] [blame] | 1453 | smp_rmb(); |
| 1454 | err |= copy_to_user(buf, mcelog.entry + i, |
| 1455 | sizeof(struct mce)); |
| 1456 | buf += sizeof(struct mce); |
| 1457 | timeout: |
| 1458 | ; |
Andi Kleen | 673242c | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1459 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | |
Huang Ying | ef41df434 | 2009-02-12 13:39:34 +0100 | [diff] [blame] | 1461 | memset(mcelog.entry + prev, 0, |
| 1462 | (next - prev) * sizeof(struct mce)); |
| 1463 | prev = next; |
| 1464 | next = cmpxchg(&mcelog.next, prev, 0); |
| 1465 | } while (next != prev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | |
Paul E. McKenney | b2b1866 | 2005-06-25 14:55:38 -0700 | [diff] [blame] | 1467 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1469 | /* |
| 1470 | * Collect entries that were still getting written before the |
| 1471 | * synchronize. |
| 1472 | */ |
Jens Axboe | 15c8b6c | 2008-05-09 09:39:44 +0200 | [diff] [blame] | 1473 | on_each_cpu(collect_tscs, cpu_tsc, 1); |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1474 | |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1475 | for (i = next; i < MCE_LOG_LEN; i++) { |
| 1476 | if (mcelog.entry[i].finished && |
| 1477 | mcelog.entry[i].tsc < cpu_tsc[mcelog.entry[i].cpu]) { |
| 1478 | err |= copy_to_user(buf, mcelog.entry+i, |
| 1479 | sizeof(struct mce)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | smp_rmb(); |
| 1481 | buf += sizeof(struct mce); |
| 1482 | memset(&mcelog.entry[i], 0, sizeof(struct mce)); |
| 1483 | } |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1484 | } |
Daniel Walker | 8c8b885 | 2008-01-30 13:31:17 +0100 | [diff] [blame] | 1485 | mutex_unlock(&mce_read_mutex); |
Andi Kleen | f0de53b | 2005-04-16 15:25:10 -0700 | [diff] [blame] | 1486 | kfree(cpu_tsc); |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1487 | |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1488 | return err ? -EFAULT : buf - ubuf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | } |
| 1490 | |
Tim Hockin | e02e68d | 2007-07-21 17:10:36 +0200 | [diff] [blame] | 1491 | static unsigned int mce_poll(struct file *file, poll_table *wait) |
| 1492 | { |
| 1493 | poll_wait(file, &mce_wait, wait); |
| 1494 | if (rcu_dereference(mcelog.next)) |
| 1495 | return POLLIN | POLLRDNORM; |
| 1496 | return 0; |
| 1497 | } |
| 1498 | |
Nikanth Karthikesan | c68461b | 2008-01-30 13:32:59 +0100 | [diff] [blame] | 1499 | static long mce_ioctl(struct file *f, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | { |
| 1501 | int __user *p = (int __user *)arg; |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | if (!capable(CAP_SYS_ADMIN)) |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1504 | return -EPERM; |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | switch (cmd) { |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1507 | case MCE_GET_RECORD_LEN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | return put_user(sizeof(struct mce), p); |
| 1509 | case MCE_GET_LOG_LEN: |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1510 | return put_user(MCE_LOG_LEN, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | case MCE_GETCLEAR_FLAGS: { |
| 1512 | unsigned flags; |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1513 | |
| 1514 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | flags = mcelog.flags; |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1516 | } while (cmpxchg(&mcelog.flags, flags, 0) != flags); |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1517 | |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1518 | return put_user(flags, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | } |
| 1520 | default: |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1521 | return -ENOTTY; |
| 1522 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
H. Peter Anvin | a1ff41b | 2009-05-25 22:16:14 -0700 | [diff] [blame] | 1525 | /* Modified in mce-inject.c, so not static or const */ |
Andi Kleen | ea149b3 | 2009-04-29 19:31:00 +0200 | [diff] [blame] | 1526 | struct file_operations mce_chrdev_ops = { |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1527 | .open = mce_open, |
| 1528 | .release = mce_release, |
| 1529 | .read = mce_read, |
| 1530 | .poll = mce_poll, |
| 1531 | .unlocked_ioctl = mce_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | }; |
Andi Kleen | ea149b3 | 2009-04-29 19:31:00 +0200 | [diff] [blame] | 1533 | EXPORT_SYMBOL_GPL(mce_chrdev_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | |
| 1535 | static struct miscdevice mce_log_device = { |
| 1536 | MISC_MCELOG_MINOR, |
| 1537 | "mcelog", |
| 1538 | &mce_chrdev_ops, |
| 1539 | }; |
| 1540 | |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1541 | /* |
Hidetoshi Seto | 62fdac5 | 2009-06-11 16:06:07 +0900 | [diff] [blame] | 1542 | * mce=off Disables machine check |
| 1543 | * mce=no_cmci Disables CMCI |
| 1544 | * mce=dont_log_ce Clears corrected events silently, no log created for CEs. |
| 1545 | * mce=ignore_ce Disables polling and CMCI, corrected events are not cleared. |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 1546 | * mce=TOLERANCELEVEL[,monarchtimeout] (number, see above) |
| 1547 | * monarchtimeout is how long to wait for other CPUs on machine |
| 1548 | * check, or 0 to not wait |
Hidetoshi Seto | 13503fa | 2009-03-26 17:39:20 +0900 | [diff] [blame] | 1549 | * mce=bootlog Log MCEs from before booting. Disabled by default on AMD. |
| 1550 | * mce=nobootlog Don't log MCEs from before booting. |
| 1551 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | static int __init mcheck_enable(char *str) |
| 1553 | { |
Andi Kleen | 4efc067 | 2009-04-28 19:07:31 +0200 | [diff] [blame] | 1554 | if (*str == 0) |
| 1555 | enable_p5_mce(); |
| 1556 | if (*str == '=') |
| 1557 | str++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | if (!strcmp(str, "off")) |
Andi Kleen | 04b2b1a | 2009-04-28 22:50:19 +0200 | [diff] [blame] | 1559 | mce_disabled = 1; |
Hidetoshi Seto | 62fdac5 | 2009-06-11 16:06:07 +0900 | [diff] [blame] | 1560 | else if (!strcmp(str, "no_cmci")) |
| 1561 | mce_cmci_disabled = 1; |
| 1562 | else if (!strcmp(str, "dont_log_ce")) |
| 1563 | mce_dont_log_ce = 1; |
| 1564 | else if (!strcmp(str, "ignore_ce")) |
| 1565 | mce_ignore_ce = 1; |
Hidetoshi Seto | 13503fa | 2009-03-26 17:39:20 +0900 | [diff] [blame] | 1566 | else if (!strcmp(str, "bootlog") || !strcmp(str, "nobootlog")) |
| 1567 | mce_bootlog = (str[0] == 'b'); |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 1568 | else if (isdigit(str[0])) { |
Andi Kleen | 8c566ef | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1569 | get_option(&str, &tolerant); |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 1570 | if (*str == ',') { |
| 1571 | ++str; |
| 1572 | get_option(&str, &monarch_timeout); |
| 1573 | } |
| 1574 | } else { |
Andi Kleen | 4efc067 | 2009-04-28 19:07:31 +0200 | [diff] [blame] | 1575 | printk(KERN_INFO "mce argument %s ignored. Please use /sys\n", |
Hidetoshi Seto | 13503fa | 2009-03-26 17:39:20 +0900 | [diff] [blame] | 1576 | str); |
| 1577 | return 0; |
| 1578 | } |
OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 1579 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | } |
Andi Kleen | 4efc067 | 2009-04-28 19:07:31 +0200 | [diff] [blame] | 1581 | __setup("mce", mcheck_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1583 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | * Sysfs support |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1585 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | |
Andi Kleen | 973a2dd | 2009-02-12 13:39:32 +0100 | [diff] [blame] | 1587 | /* |
| 1588 | * Disable machine checks on suspend and shutdown. We can't really handle |
| 1589 | * them later. |
| 1590 | */ |
| 1591 | static int mce_disable(void) |
| 1592 | { |
| 1593 | int i; |
| 1594 | |
Andi Kleen | 06b7a7a | 2009-04-27 18:37:43 +0200 | [diff] [blame] | 1595 | for (i = 0; i < banks; i++) { |
| 1596 | if (!skip_bank_init(i)) |
| 1597 | wrmsrl(MSR_IA32_MC0_CTL + i*4, 0); |
| 1598 | } |
Andi Kleen | 973a2dd | 2009-02-12 13:39:32 +0100 | [diff] [blame] | 1599 | return 0; |
| 1600 | } |
| 1601 | |
| 1602 | static int mce_suspend(struct sys_device *dev, pm_message_t state) |
| 1603 | { |
| 1604 | return mce_disable(); |
| 1605 | } |
| 1606 | |
| 1607 | static int mce_shutdown(struct sys_device *dev) |
| 1608 | { |
| 1609 | return mce_disable(); |
| 1610 | } |
| 1611 | |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1612 | /* |
| 1613 | * On resume clear all MCE state. Don't want to see leftovers from the BIOS. |
| 1614 | * Only one CPU is active at this time, the others get re-added later using |
| 1615 | * CPU hotplug: |
| 1616 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | static int mce_resume(struct sys_device *dev) |
| 1618 | { |
Thomas Gleixner | 8be9110 | 2009-05-27 21:56:53 +0200 | [diff] [blame] | 1619 | mce_init(); |
Andi Kleen | 6ec68bf | 2009-02-12 13:39:26 +0100 | [diff] [blame] | 1620 | mce_cpu_features(¤t_cpu_data); |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | return 0; |
| 1623 | } |
| 1624 | |
Andi Kleen | 52d168e | 2009-02-12 13:39:29 +0100 | [diff] [blame] | 1625 | static void mce_cpu_restart(void *data) |
| 1626 | { |
| 1627 | del_timer_sync(&__get_cpu_var(mce_timer)); |
Hidetoshi Seto | 33edbf0 | 2009-06-15 17:18:45 +0900 | [diff] [blame] | 1628 | if (!mce_available(¤t_cpu_data)) |
| 1629 | return; |
| 1630 | mce_init(); |
Andi Kleen | 52d168e | 2009-02-12 13:39:29 +0100 | [diff] [blame] | 1631 | mce_init_timer(); |
| 1632 | } |
| 1633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | /* Reinit MCEs after user configuration changes */ |
Thomas Gleixner | d88203d | 2007-10-23 22:37:23 +0200 | [diff] [blame] | 1635 | static void mce_restart(void) |
| 1636 | { |
Andi Kleen | 52d168e | 2009-02-12 13:39:29 +0100 | [diff] [blame] | 1637 | on_each_cpu(mce_cpu_restart, NULL, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | } |
| 1639 | |
Hidetoshi Seto | 9af43b5 | 2009-06-15 17:21:36 +0900 | [diff] [blame] | 1640 | /* Toggle features for corrected errors */ |
| 1641 | static void mce_disable_ce(void *all) |
| 1642 | { |
| 1643 | if (!mce_available(¤t_cpu_data)) |
| 1644 | return; |
| 1645 | if (all) |
| 1646 | del_timer_sync(&__get_cpu_var(mce_timer)); |
| 1647 | cmci_clear(); |
| 1648 | } |
| 1649 | |
| 1650 | static void mce_enable_ce(void *all) |
| 1651 | { |
| 1652 | if (!mce_available(¤t_cpu_data)) |
| 1653 | return; |
| 1654 | cmci_reenable(); |
| 1655 | cmci_recheck(); |
| 1656 | if (all) |
| 1657 | mce_init_timer(); |
| 1658 | } |
| 1659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | static struct sysdev_class mce_sysclass = { |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1661 | .suspend = mce_suspend, |
| 1662 | .shutdown = mce_shutdown, |
| 1663 | .resume = mce_resume, |
| 1664 | .name = "machinecheck", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | }; |
| 1666 | |
Ingo Molnar | cb491fc | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1667 | DEFINE_PER_CPU(struct sys_device, mce_dev); |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1668 | |
| 1669 | __cpuinitdata |
| 1670 | void (*threshold_cpu_callback)(unsigned long action, unsigned int cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1672 | static struct sysdev_attribute *bank_attrs; |
| 1673 | |
| 1674 | static ssize_t show_bank(struct sys_device *s, struct sysdev_attribute *attr, |
| 1675 | char *buf) |
| 1676 | { |
| 1677 | u64 b = bank[attr - bank_attrs]; |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1678 | |
H. Peter Anvin | f6d1826 | 2009-02-19 15:44:58 -0800 | [diff] [blame] | 1679 | return sprintf(buf, "%llx\n", b); |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1680 | } |
| 1681 | |
| 1682 | static ssize_t set_bank(struct sys_device *s, struct sysdev_attribute *attr, |
Hidetoshi Seto | 9319cec | 2009-04-14 17:26:30 +0900 | [diff] [blame] | 1683 | const char *buf, size_t size) |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1684 | { |
Hidetoshi Seto | 9319cec | 2009-04-14 17:26:30 +0900 | [diff] [blame] | 1685 | u64 new; |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1686 | |
Hidetoshi Seto | 9319cec | 2009-04-14 17:26:30 +0900 | [diff] [blame] | 1687 | if (strict_strtoull(buf, 0, &new) < 0) |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1688 | return -EINVAL; |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1689 | |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1690 | bank[attr - bank_attrs] = new; |
| 1691 | mce_restart(); |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1692 | |
Hidetoshi Seto | 9319cec | 2009-04-14 17:26:30 +0900 | [diff] [blame] | 1693 | return size; |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1694 | } |
Andi Kleen | a98f0dd | 2007-02-13 13:26:23 +0100 | [diff] [blame] | 1695 | |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1696 | static ssize_t |
| 1697 | show_trigger(struct sys_device *s, struct sysdev_attribute *attr, char *buf) |
Andi Kleen | a98f0dd | 2007-02-13 13:26:23 +0100 | [diff] [blame] | 1698 | { |
Hidetoshi Seto | 1020bcb | 2009-06-15 17:20:57 +0900 | [diff] [blame] | 1699 | strcpy(buf, mce_helper); |
Andi Kleen | a98f0dd | 2007-02-13 13:26:23 +0100 | [diff] [blame] | 1700 | strcat(buf, "\n"); |
Hidetoshi Seto | 1020bcb | 2009-06-15 17:20:57 +0900 | [diff] [blame] | 1701 | return strlen(mce_helper) + 1; |
Andi Kleen | a98f0dd | 2007-02-13 13:26:23 +0100 | [diff] [blame] | 1702 | } |
| 1703 | |
Andi Kleen | 4a0b2b4 | 2008-07-01 18:48:41 +0200 | [diff] [blame] | 1704 | static ssize_t set_trigger(struct sys_device *s, struct sysdev_attribute *attr, |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1705 | const char *buf, size_t siz) |
Andi Kleen | a98f0dd | 2007-02-13 13:26:23 +0100 | [diff] [blame] | 1706 | { |
| 1707 | char *p; |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1708 | |
Hidetoshi Seto | 1020bcb | 2009-06-15 17:20:57 +0900 | [diff] [blame] | 1709 | strncpy(mce_helper, buf, sizeof(mce_helper)); |
| 1710 | mce_helper[sizeof(mce_helper)-1] = 0; |
Hidetoshi Seto | 1020bcb | 2009-06-15 17:20:57 +0900 | [diff] [blame] | 1711 | p = strchr(mce_helper, '\n'); |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1712 | |
Jan Beulich | e9084ec | 2009-07-16 09:45:11 +0100 | [diff] [blame] | 1713 | if (p) |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1714 | *p = 0; |
| 1715 | |
Jan Beulich | e9084ec | 2009-07-16 09:45:11 +0100 | [diff] [blame] | 1716 | return strlen(mce_helper) + !!p; |
Andi Kleen | a98f0dd | 2007-02-13 13:26:23 +0100 | [diff] [blame] | 1717 | } |
| 1718 | |
Hidetoshi Seto | 9af43b5 | 2009-06-15 17:21:36 +0900 | [diff] [blame] | 1719 | static ssize_t set_ignore_ce(struct sys_device *s, |
| 1720 | struct sysdev_attribute *attr, |
| 1721 | const char *buf, size_t size) |
| 1722 | { |
| 1723 | u64 new; |
| 1724 | |
| 1725 | if (strict_strtoull(buf, 0, &new) < 0) |
| 1726 | return -EINVAL; |
| 1727 | |
| 1728 | if (mce_ignore_ce ^ !!new) { |
| 1729 | if (new) { |
| 1730 | /* disable ce features */ |
| 1731 | on_each_cpu(mce_disable_ce, (void *)1, 1); |
| 1732 | mce_ignore_ce = 1; |
| 1733 | } else { |
| 1734 | /* enable ce features */ |
| 1735 | mce_ignore_ce = 0; |
| 1736 | on_each_cpu(mce_enable_ce, (void *)1, 1); |
| 1737 | } |
| 1738 | } |
| 1739 | return size; |
| 1740 | } |
| 1741 | |
| 1742 | static ssize_t set_cmci_disabled(struct sys_device *s, |
| 1743 | struct sysdev_attribute *attr, |
| 1744 | const char *buf, size_t size) |
| 1745 | { |
| 1746 | u64 new; |
| 1747 | |
| 1748 | if (strict_strtoull(buf, 0, &new) < 0) |
| 1749 | return -EINVAL; |
| 1750 | |
| 1751 | if (mce_cmci_disabled ^ !!new) { |
| 1752 | if (new) { |
| 1753 | /* disable cmci */ |
| 1754 | on_each_cpu(mce_disable_ce, NULL, 1); |
| 1755 | mce_cmci_disabled = 1; |
| 1756 | } else { |
| 1757 | /* enable cmci */ |
| 1758 | mce_cmci_disabled = 0; |
| 1759 | on_each_cpu(mce_enable_ce, NULL, 1); |
| 1760 | } |
| 1761 | } |
| 1762 | return size; |
| 1763 | } |
| 1764 | |
Andi Kleen | b56f642 | 2009-05-27 21:56:52 +0200 | [diff] [blame] | 1765 | static ssize_t store_int_with_restart(struct sys_device *s, |
| 1766 | struct sysdev_attribute *attr, |
| 1767 | const char *buf, size_t size) |
| 1768 | { |
| 1769 | ssize_t ret = sysdev_store_int(s, attr, buf, size); |
| 1770 | mce_restart(); |
| 1771 | return ret; |
| 1772 | } |
| 1773 | |
Andi Kleen | a98f0dd | 2007-02-13 13:26:23 +0100 | [diff] [blame] | 1774 | static SYSDEV_ATTR(trigger, 0644, show_trigger, set_trigger); |
Andi Kleen | d95d62c | 2008-07-01 18:48:43 +0200 | [diff] [blame] | 1775 | static SYSDEV_INT_ATTR(tolerant, 0644, tolerant); |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 1776 | static SYSDEV_INT_ATTR(monarch_timeout, 0644, monarch_timeout); |
Hidetoshi Seto | 9af43b5 | 2009-06-15 17:21:36 +0900 | [diff] [blame] | 1777 | static SYSDEV_INT_ATTR(dont_log_ce, 0644, mce_dont_log_ce); |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1778 | |
Andi Kleen | b56f642 | 2009-05-27 21:56:52 +0200 | [diff] [blame] | 1779 | static struct sysdev_ext_attribute attr_check_interval = { |
| 1780 | _SYSDEV_ATTR(check_interval, 0644, sysdev_show_int, |
| 1781 | store_int_with_restart), |
| 1782 | &check_interval |
| 1783 | }; |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1784 | |
Hidetoshi Seto | 9af43b5 | 2009-06-15 17:21:36 +0900 | [diff] [blame] | 1785 | static struct sysdev_ext_attribute attr_ignore_ce = { |
| 1786 | _SYSDEV_ATTR(ignore_ce, 0644, sysdev_show_int, set_ignore_ce), |
| 1787 | &mce_ignore_ce |
| 1788 | }; |
| 1789 | |
| 1790 | static struct sysdev_ext_attribute attr_cmci_disabled = { |
Yinghai Lu | 74b602c | 2009-06-17 14:43:32 -0700 | [diff] [blame] | 1791 | _SYSDEV_ATTR(cmci_disabled, 0644, sysdev_show_int, set_cmci_disabled), |
Hidetoshi Seto | 9af43b5 | 2009-06-15 17:21:36 +0900 | [diff] [blame] | 1792 | &mce_cmci_disabled |
| 1793 | }; |
| 1794 | |
Ingo Molnar | cb491fc | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1795 | static struct sysdev_attribute *mce_attrs[] = { |
Hidetoshi Seto | 9af43b5 | 2009-06-15 17:21:36 +0900 | [diff] [blame] | 1796 | &attr_tolerant.attr, |
| 1797 | &attr_check_interval.attr, |
| 1798 | &attr_trigger, |
Andi Kleen | 3c07979 | 2009-05-27 21:56:55 +0200 | [diff] [blame] | 1799 | &attr_monarch_timeout.attr, |
Hidetoshi Seto | 9af43b5 | 2009-06-15 17:21:36 +0900 | [diff] [blame] | 1800 | &attr_dont_log_ce.attr, |
| 1801 | &attr_ignore_ce.attr, |
| 1802 | &attr_cmci_disabled.attr, |
Andi Kleen | a98f0dd | 2007-02-13 13:26:23 +0100 | [diff] [blame] | 1803 | NULL |
| 1804 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | |
Ingo Molnar | cb491fc | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1806 | static cpumask_var_t mce_dev_initialized; |
Andreas Herrmann | bae19fe | 2007-11-14 17:00:44 -0800 | [diff] [blame] | 1807 | |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1808 | /* Per cpu sysdev init. All of the cpus still share the same ctrl bank: */ |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1809 | static __cpuinit int mce_create_device(unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | { |
| 1811 | int err; |
Hidetoshi Seto | b1f49f9 | 2009-06-18 14:53:24 +0900 | [diff] [blame] | 1812 | int i, j; |
Mike Travis | 92cb761 | 2007-10-19 20:35:04 +0200 | [diff] [blame] | 1813 | |
Andreas Herrmann | 9036755 | 2007-11-07 02:12:58 +0100 | [diff] [blame] | 1814 | if (!mce_available(&boot_cpu_data)) |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1815 | return -EIO; |
| 1816 | |
Ingo Molnar | cb491fc | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1817 | memset(&per_cpu(mce_dev, cpu).kobj, 0, sizeof(struct kobject)); |
| 1818 | per_cpu(mce_dev, cpu).id = cpu; |
| 1819 | per_cpu(mce_dev, cpu).cls = &mce_sysclass; |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1820 | |
Ingo Molnar | cb491fc | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1821 | err = sysdev_register(&per_cpu(mce_dev, cpu)); |
Akinobu Mita | d435d86 | 2007-10-18 03:05:15 -0700 | [diff] [blame] | 1822 | if (err) |
| 1823 | return err; |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1824 | |
Ingo Molnar | cb491fc | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1825 | for (i = 0; mce_attrs[i]; i++) { |
| 1826 | err = sysdev_create_file(&per_cpu(mce_dev, cpu), mce_attrs[i]); |
Akinobu Mita | d435d86 | 2007-10-18 03:05:15 -0700 | [diff] [blame] | 1827 | if (err) |
| 1828 | goto error; |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1829 | } |
Hidetoshi Seto | b1f49f9 | 2009-06-18 14:53:24 +0900 | [diff] [blame] | 1830 | for (j = 0; j < banks; j++) { |
Ingo Molnar | cb491fc | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1831 | err = sysdev_create_file(&per_cpu(mce_dev, cpu), |
Hidetoshi Seto | b1f49f9 | 2009-06-18 14:53:24 +0900 | [diff] [blame] | 1832 | &bank_attrs[j]); |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1833 | if (err) |
| 1834 | goto error2; |
| 1835 | } |
Ingo Molnar | cb491fc | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1836 | cpumask_set_cpu(cpu, mce_dev_initialized); |
Akinobu Mita | d435d86 | 2007-10-18 03:05:15 -0700 | [diff] [blame] | 1837 | |
| 1838 | return 0; |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1839 | error2: |
Hidetoshi Seto | b1f49f9 | 2009-06-18 14:53:24 +0900 | [diff] [blame] | 1840 | while (--j >= 0) |
| 1841 | sysdev_remove_file(&per_cpu(mce_dev, cpu), &bank_attrs[j]); |
Akinobu Mita | d435d86 | 2007-10-18 03:05:15 -0700 | [diff] [blame] | 1842 | error: |
Ingo Molnar | cb491fc | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1843 | while (--i >= 0) |
| 1844 | sysdev_remove_file(&per_cpu(mce_dev, cpu), mce_attrs[i]); |
| 1845 | |
| 1846 | sysdev_unregister(&per_cpu(mce_dev, cpu)); |
Akinobu Mita | d435d86 | 2007-10-18 03:05:15 -0700 | [diff] [blame] | 1847 | |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1848 | return err; |
| 1849 | } |
| 1850 | |
Jan Beulich | 2d9cd6c | 2008-08-29 13:15:04 +0100 | [diff] [blame] | 1851 | static __cpuinit void mce_remove_device(unsigned int cpu) |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1852 | { |
Shaohua Li | 73ca535 | 2006-01-11 22:43:06 +0100 | [diff] [blame] | 1853 | int i; |
| 1854 | |
Ingo Molnar | cb491fc | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1855 | if (!cpumask_test_cpu(cpu, mce_dev_initialized)) |
Andreas Herrmann | bae19fe | 2007-11-14 17:00:44 -0800 | [diff] [blame] | 1856 | return; |
| 1857 | |
Ingo Molnar | cb491fc | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1858 | for (i = 0; mce_attrs[i]; i++) |
| 1859 | sysdev_remove_file(&per_cpu(mce_dev, cpu), mce_attrs[i]); |
| 1860 | |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1861 | for (i = 0; i < banks; i++) |
Ingo Molnar | cb491fc | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1862 | sysdev_remove_file(&per_cpu(mce_dev, cpu), &bank_attrs[i]); |
| 1863 | |
| 1864 | sysdev_unregister(&per_cpu(mce_dev, cpu)); |
| 1865 | cpumask_clear_cpu(cpu, mce_dev_initialized); |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1866 | } |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1867 | |
Andi Kleen | d6b7558 | 2009-02-12 13:39:31 +0100 | [diff] [blame] | 1868 | /* Make sure there are no machine checks on offlined CPUs. */ |
H. Peter Anvin | ec5b3d3 | 2009-02-23 14:01:04 -0800 | [diff] [blame] | 1869 | static void mce_disable_cpu(void *h) |
Andi Kleen | d6b7558 | 2009-02-12 13:39:31 +0100 | [diff] [blame] | 1870 | { |
Andi Kleen | 88ccbed | 2009-02-12 13:49:36 +0100 | [diff] [blame] | 1871 | unsigned long action = *(unsigned long *)h; |
Ingo Molnar | cb491fc | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1872 | int i; |
Andi Kleen | d6b7558 | 2009-02-12 13:39:31 +0100 | [diff] [blame] | 1873 | |
| 1874 | if (!mce_available(¤t_cpu_data)) |
| 1875 | return; |
Andi Kleen | 88ccbed | 2009-02-12 13:49:36 +0100 | [diff] [blame] | 1876 | if (!(action & CPU_TASKS_FROZEN)) |
| 1877 | cmci_clear(); |
Andi Kleen | 06b7a7a | 2009-04-27 18:37:43 +0200 | [diff] [blame] | 1878 | for (i = 0; i < banks; i++) { |
| 1879 | if (!skip_bank_init(i)) |
| 1880 | wrmsrl(MSR_IA32_MC0_CTL + i*4, 0); |
| 1881 | } |
Andi Kleen | d6b7558 | 2009-02-12 13:39:31 +0100 | [diff] [blame] | 1882 | } |
| 1883 | |
H. Peter Anvin | ec5b3d3 | 2009-02-23 14:01:04 -0800 | [diff] [blame] | 1884 | static void mce_reenable_cpu(void *h) |
Andi Kleen | d6b7558 | 2009-02-12 13:39:31 +0100 | [diff] [blame] | 1885 | { |
Andi Kleen | 88ccbed | 2009-02-12 13:49:36 +0100 | [diff] [blame] | 1886 | unsigned long action = *(unsigned long *)h; |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1887 | int i; |
Andi Kleen | d6b7558 | 2009-02-12 13:39:31 +0100 | [diff] [blame] | 1888 | |
| 1889 | if (!mce_available(¤t_cpu_data)) |
| 1890 | return; |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1891 | |
Andi Kleen | 88ccbed | 2009-02-12 13:49:36 +0100 | [diff] [blame] | 1892 | if (!(action & CPU_TASKS_FROZEN)) |
| 1893 | cmci_reenable(); |
Andi Kleen | 06b7a7a | 2009-04-27 18:37:43 +0200 | [diff] [blame] | 1894 | for (i = 0; i < banks; i++) { |
| 1895 | if (!skip_bank_init(i)) |
| 1896 | wrmsrl(MSR_IA32_MC0_CTL + i*4, bank[i]); |
| 1897 | } |
Andi Kleen | d6b7558 | 2009-02-12 13:39:31 +0100 | [diff] [blame] | 1898 | } |
| 1899 | |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1900 | /* Get notified when a cpu comes on/off. Be hotplug friendly. */ |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1901 | static int __cpuinit |
| 1902 | mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu) |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1903 | { |
| 1904 | unsigned int cpu = (unsigned long)hcpu; |
Andi Kleen | 52d168e | 2009-02-12 13:39:29 +0100 | [diff] [blame] | 1905 | struct timer_list *t = &per_cpu(mce_timer, cpu); |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1906 | |
| 1907 | switch (action) { |
Andreas Herrmann | bae19fe | 2007-11-14 17:00:44 -0800 | [diff] [blame] | 1908 | case CPU_ONLINE: |
| 1909 | case CPU_ONLINE_FROZEN: |
| 1910 | mce_create_device(cpu); |
Rafael J. Wysocki | 8735728 | 2008-08-22 22:23:09 +0200 | [diff] [blame] | 1911 | if (threshold_cpu_callback) |
| 1912 | threshold_cpu_callback(action, cpu); |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1913 | break; |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1914 | case CPU_DEAD: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 1915 | case CPU_DEAD_FROZEN: |
Rafael J. Wysocki | 8735728 | 2008-08-22 22:23:09 +0200 | [diff] [blame] | 1916 | if (threshold_cpu_callback) |
| 1917 | threshold_cpu_callback(action, cpu); |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1918 | mce_remove_device(cpu); |
| 1919 | break; |
Andi Kleen | 52d168e | 2009-02-12 13:39:29 +0100 | [diff] [blame] | 1920 | case CPU_DOWN_PREPARE: |
| 1921 | case CPU_DOWN_PREPARE_FROZEN: |
| 1922 | del_timer_sync(t); |
Andi Kleen | 88ccbed | 2009-02-12 13:49:36 +0100 | [diff] [blame] | 1923 | smp_call_function_single(cpu, mce_disable_cpu, &action, 1); |
Andi Kleen | 52d168e | 2009-02-12 13:39:29 +0100 | [diff] [blame] | 1924 | break; |
| 1925 | case CPU_DOWN_FAILED: |
| 1926 | case CPU_DOWN_FAILED_FROZEN: |
Andi Kleen | 6298c51 | 2009-04-09 12:28:22 +0200 | [diff] [blame] | 1927 | t->expires = round_jiffies(jiffies + |
| 1928 | __get_cpu_var(next_interval)); |
Andi Kleen | 52d168e | 2009-02-12 13:39:29 +0100 | [diff] [blame] | 1929 | add_timer_on(t, cpu); |
Andi Kleen | 88ccbed | 2009-02-12 13:49:36 +0100 | [diff] [blame] | 1930 | smp_call_function_single(cpu, mce_reenable_cpu, &action, 1); |
| 1931 | break; |
| 1932 | case CPU_POST_DEAD: |
| 1933 | /* intentionally ignoring frozen here */ |
| 1934 | cmci_rediscover(cpu); |
Andi Kleen | 52d168e | 2009-02-12 13:39:29 +0100 | [diff] [blame] | 1935 | break; |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1936 | } |
Andreas Herrmann | bae19fe | 2007-11-14 17:00:44 -0800 | [diff] [blame] | 1937 | return NOTIFY_OK; |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1938 | } |
| 1939 | |
Sam Ravnborg | 1e35669 | 2008-01-30 13:33:36 +0100 | [diff] [blame] | 1940 | static struct notifier_block mce_cpu_notifier __cpuinitdata = { |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1941 | .notifier_call = mce_cpu_callback, |
| 1942 | }; |
| 1943 | |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1944 | static __init int mce_init_banks(void) |
| 1945 | { |
| 1946 | int i; |
| 1947 | |
| 1948 | bank_attrs = kzalloc(sizeof(struct sysdev_attribute) * banks, |
| 1949 | GFP_KERNEL); |
| 1950 | if (!bank_attrs) |
| 1951 | return -ENOMEM; |
| 1952 | |
| 1953 | for (i = 0; i < banks; i++) { |
| 1954 | struct sysdev_attribute *a = &bank_attrs[i]; |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1955 | |
| 1956 | a->attr.name = kasprintf(GFP_KERNEL, "bank%d", i); |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1957 | if (!a->attr.name) |
| 1958 | goto nomem; |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1959 | |
| 1960 | a->attr.mode = 0644; |
| 1961 | a->show = show_bank; |
| 1962 | a->store = set_bank; |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1963 | } |
| 1964 | return 0; |
| 1965 | |
| 1966 | nomem: |
| 1967 | while (--i >= 0) |
| 1968 | kfree(bank_attrs[i].attr.name); |
| 1969 | kfree(bank_attrs); |
| 1970 | bank_attrs = NULL; |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 1971 | |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1972 | return -ENOMEM; |
| 1973 | } |
| 1974 | |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1975 | static __init int mce_init_device(void) |
| 1976 | { |
| 1977 | int err; |
| 1978 | int i = 0; |
| 1979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | if (!mce_available(&boot_cpu_data)) |
| 1981 | return -EIO; |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1982 | |
Yinghai Lu | e92fae0 | 2009-06-17 16:21:33 -0700 | [diff] [blame] | 1983 | zalloc_cpumask_var(&mce_dev_initialized, GFP_KERNEL); |
Rusty Russell | 996867d | 2009-03-13 14:49:51 +1030 | [diff] [blame] | 1984 | |
Andi Kleen | 0d7482e3 | 2009-02-17 23:07:13 +0100 | [diff] [blame] | 1985 | err = mce_init_banks(); |
| 1986 | if (err) |
| 1987 | return err; |
| 1988 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | err = sysdev_class_register(&mce_sysclass); |
Akinobu Mita | d435d86 | 2007-10-18 03:05:15 -0700 | [diff] [blame] | 1990 | if (err) |
| 1991 | return err; |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1992 | |
| 1993 | for_each_online_cpu(i) { |
Akinobu Mita | d435d86 | 2007-10-18 03:05:15 -0700 | [diff] [blame] | 1994 | err = mce_create_device(i); |
| 1995 | if (err) |
| 1996 | return err; |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
Chandra Seetharaman | be6b5a3 | 2006-07-30 03:03:37 -0700 | [diff] [blame] | 1999 | register_hotcpu_notifier(&mce_cpu_notifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | misc_register(&mce_log_device); |
Ingo Molnar | e9eee03 | 2009-04-08 12:31:17 +0200 | [diff] [blame] | 2001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | } |
Andi Kleen | 91c6d40 | 2005-07-28 21:15:39 -0700 | [diff] [blame] | 2004 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | device_initcall(mce_init_device); |
Ingo Molnar | a988d33 | 2009-04-08 12:31:25 +0200 | [diff] [blame] | 2006 | |
Andi Kleen | 4efc067 | 2009-04-28 19:07:31 +0200 | [diff] [blame] | 2007 | #else /* CONFIG_X86_OLD_MCE: */ |
Ingo Molnar | a988d33 | 2009-04-08 12:31:25 +0200 | [diff] [blame] | 2008 | |
Ingo Molnar | a988d33 | 2009-04-08 12:31:25 +0200 | [diff] [blame] | 2009 | int nr_mce_banks; |
| 2010 | EXPORT_SYMBOL_GPL(nr_mce_banks); /* non-fatal.o */ |
| 2011 | |
Ingo Molnar | a988d33 | 2009-04-08 12:31:25 +0200 | [diff] [blame] | 2012 | /* This has to be run for each processor */ |
| 2013 | void mcheck_init(struct cpuinfo_x86 *c) |
| 2014 | { |
Hidetoshi Seto | c697836 | 2009-06-15 17:22:49 +0900 | [diff] [blame] | 2015 | if (mce_disabled) |
Ingo Molnar | a988d33 | 2009-04-08 12:31:25 +0200 | [diff] [blame] | 2016 | return; |
| 2017 | |
| 2018 | switch (c->x86_vendor) { |
| 2019 | case X86_VENDOR_AMD: |
| 2020 | amd_mcheck_init(c); |
| 2021 | break; |
| 2022 | |
| 2023 | case X86_VENDOR_INTEL: |
| 2024 | if (c->x86 == 5) |
| 2025 | intel_p5_mcheck_init(c); |
| 2026 | if (c->x86 == 6) |
| 2027 | intel_p6_mcheck_init(c); |
| 2028 | if (c->x86 == 15) |
| 2029 | intel_p4_mcheck_init(c); |
| 2030 | break; |
| 2031 | |
| 2032 | case X86_VENDOR_CENTAUR: |
| 2033 | if (c->x86 == 5) |
| 2034 | winchip_mcheck_init(c); |
| 2035 | break; |
| 2036 | |
| 2037 | default: |
| 2038 | break; |
| 2039 | } |
Ingo Molnar | b659294 | 2009-04-08 12:31:27 +0200 | [diff] [blame] | 2040 | printk(KERN_INFO "mce: CPU supports %d MCE banks\n", nr_mce_banks); |
Ingo Molnar | a988d33 | 2009-04-08 12:31:25 +0200 | [diff] [blame] | 2041 | } |
| 2042 | |
Ingo Molnar | a988d33 | 2009-04-08 12:31:25 +0200 | [diff] [blame] | 2043 | static int __init mcheck_enable(char *str) |
| 2044 | { |
Hidetoshi Seto | c697836 | 2009-06-15 17:22:49 +0900 | [diff] [blame] | 2045 | mce_p5_enabled = 1; |
Ingo Molnar | a988d33 | 2009-04-08 12:31:25 +0200 | [diff] [blame] | 2046 | return 1; |
| 2047 | } |
Ingo Molnar | a988d33 | 2009-04-08 12:31:25 +0200 | [diff] [blame] | 2048 | __setup("mce", mcheck_enable); |
| 2049 | |
Andi Kleen | d7c3c9a | 2009-04-28 23:07:25 +0200 | [diff] [blame] | 2050 | #endif /* CONFIG_X86_OLD_MCE */ |
| 2051 | |
| 2052 | /* |
| 2053 | * Old style boot options parsing. Only for compatibility. |
| 2054 | */ |
| 2055 | static int __init mcheck_disable(char *str) |
| 2056 | { |
| 2057 | mce_disabled = 1; |
| 2058 | return 1; |
| 2059 | } |
| 2060 | __setup("nomce", mcheck_disable); |