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