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