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