Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / x86 / kernel / cpu / mcheck / mce-severity.c
blob5bbd06f38ff68f58d1efc980db0fd9fc0af7d89a
1 /*
2 * MCE grading rules.
3 * Copyright 2008, 2009 Intel Corporation.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; version 2
8 * of the License.
10 * Author: Andi Kleen
12 #include <linux/kernel.h>
13 #include <linux/seq_file.h>
14 #include <linux/init.h>
15 #include <linux/debugfs.h>
16 #include <asm/mce.h>
17 #include <linux/uaccess.h>
19 #include "mce-internal.h"
22 * Grade an mce by severity. In general the most severe ones are processed
23 * first. Since there are quite a lot of combinations test the bits in a
24 * table-driven way. The rules are simply processed in order, first
25 * match wins.
27 * Note this is only used for machine check exceptions, the corrected
28 * errors use much simpler rules. The exceptions still check for the corrected
29 * errors, but only to leave them alone for the CMCI handler (except for
30 * panic situations)
33 enum context { IN_KERNEL = 1, IN_USER = 2, IN_KERNEL_RECOV = 3 };
34 enum ser { SER_REQUIRED = 1, NO_SER = 2 };
35 enum exception { EXCP_CONTEXT = 1, NO_EXCP = 2 };
37 static struct severity {
38 u64 mask;
39 u64 result;
40 unsigned char sev;
41 unsigned char mcgmask;
42 unsigned char mcgres;
43 unsigned char ser;
44 unsigned char context;
45 unsigned char excp;
46 unsigned char covered;
47 char *msg;
48 } severities[] = {
49 #define MCESEV(s, m, c...) { .sev = MCE_ ## s ## _SEVERITY, .msg = m, ## c }
50 #define KERNEL .context = IN_KERNEL
51 #define USER .context = IN_USER
52 #define KERNEL_RECOV .context = IN_KERNEL_RECOV
53 #define SER .ser = SER_REQUIRED
54 #define NOSER .ser = NO_SER
55 #define EXCP .excp = EXCP_CONTEXT
56 #define NOEXCP .excp = NO_EXCP
57 #define BITCLR(x) .mask = x, .result = 0
58 #define BITSET(x) .mask = x, .result = x
59 #define MCGMASK(x, y) .mcgmask = x, .mcgres = y
60 #define MASK(x, y) .mask = x, .result = y
61 #define MCI_UC_S (MCI_STATUS_UC|MCI_STATUS_S)
62 #define MCI_UC_AR (MCI_STATUS_UC|MCI_STATUS_AR)
63 #define MCI_UC_SAR (MCI_STATUS_UC|MCI_STATUS_S|MCI_STATUS_AR)
64 #define MCI_ADDR (MCI_STATUS_ADDRV|MCI_STATUS_MISCV)
66 MCESEV(
67 NO, "Invalid",
68 BITCLR(MCI_STATUS_VAL)
70 MCESEV(
71 NO, "Not enabled",
72 EXCP, BITCLR(MCI_STATUS_EN)
74 MCESEV(
75 PANIC, "Processor context corrupt",
76 BITSET(MCI_STATUS_PCC)
78 /* When MCIP is not set something is very confused */
79 MCESEV(
80 PANIC, "MCIP not set in MCA handler",
81 EXCP, MCGMASK(MCG_STATUS_MCIP, 0)
83 /* Neither return not error IP -- no chance to recover -> PANIC */
84 MCESEV(
85 PANIC, "Neither restart nor error IP",
86 EXCP, MCGMASK(MCG_STATUS_RIPV|MCG_STATUS_EIPV, 0)
88 MCESEV(
89 PANIC, "In kernel and no restart IP",
90 EXCP, KERNEL, MCGMASK(MCG_STATUS_RIPV, 0)
92 MCESEV(
93 PANIC, "In kernel and no restart IP",
94 EXCP, KERNEL_RECOV, MCGMASK(MCG_STATUS_RIPV, 0)
96 MCESEV(
97 DEFERRED, "Deferred error",
98 NOSER, MASK(MCI_STATUS_UC|MCI_STATUS_DEFERRED|MCI_STATUS_POISON, MCI_STATUS_DEFERRED)
100 MCESEV(
101 KEEP, "Corrected error",
102 NOSER, BITCLR(MCI_STATUS_UC)
106 * known AO MCACODs reported via MCE or CMC:
108 * SRAO could be signaled either via a machine check exception or
109 * CMCI with the corresponding bit S 1 or 0. So we don't need to
110 * check bit S for SRAO.
112 MCESEV(
113 AO, "Action optional: memory scrubbing error",
114 SER, MASK(MCI_STATUS_OVER|MCI_UC_AR|MCACOD_SCRUBMSK, MCI_STATUS_UC|MCACOD_SCRUB)
116 MCESEV(
117 AO, "Action optional: last level cache writeback error",
118 SER, MASK(MCI_STATUS_OVER|MCI_UC_AR|MCACOD, MCI_STATUS_UC|MCACOD_L3WB)
121 /* ignore OVER for UCNA */
122 MCESEV(
123 UCNA, "Uncorrected no action required",
124 SER, MASK(MCI_UC_SAR, MCI_STATUS_UC)
126 MCESEV(
127 PANIC, "Illegal combination (UCNA with AR=1)",
128 SER,
129 MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_STATUS_UC|MCI_STATUS_AR)
131 MCESEV(
132 KEEP, "Non signalled machine check",
133 SER, BITCLR(MCI_STATUS_S)
136 MCESEV(
137 PANIC, "Action required with lost events",
138 SER, BITSET(MCI_STATUS_OVER|MCI_UC_SAR)
141 /* known AR MCACODs: */
142 #ifdef CONFIG_MEMORY_FAILURE
143 MCESEV(
144 KEEP, "Action required but unaffected thread is continuable",
145 SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCI_ADDR, MCI_UC_SAR|MCI_ADDR),
146 MCGMASK(MCG_STATUS_RIPV|MCG_STATUS_EIPV, MCG_STATUS_RIPV)
148 MCESEV(
149 AR, "Action required: data load in error recoverable area of kernel",
150 SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCI_ADDR|MCACOD, MCI_UC_SAR|MCI_ADDR|MCACOD_DATA),
151 KERNEL_RECOV
153 MCESEV(
154 AR, "Action required: data load error in a user process",
155 SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCI_ADDR|MCACOD, MCI_UC_SAR|MCI_ADDR|MCACOD_DATA),
156 USER
158 MCESEV(
159 AR, "Action required: instruction fetch error in a user process",
160 SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCI_ADDR|MCACOD, MCI_UC_SAR|MCI_ADDR|MCACOD_INSTR),
161 USER
163 #endif
164 MCESEV(
165 PANIC, "Action required: unknown MCACOD",
166 SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_UC_SAR)
169 MCESEV(
170 SOME, "Action optional: unknown MCACOD",
171 SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_UC_S)
173 MCESEV(
174 SOME, "Action optional with lost events",
175 SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_STATUS_OVER|MCI_UC_S)
178 MCESEV(
179 PANIC, "Overflowed uncorrected",
180 BITSET(MCI_STATUS_OVER|MCI_STATUS_UC)
182 MCESEV(
183 UC, "Uncorrected",
184 BITSET(MCI_STATUS_UC)
186 MCESEV(
187 SOME, "No match",
188 BITSET(0)
189 ) /* always matches. keep at end */
192 #define mc_recoverable(mcg) (((mcg) & (MCG_STATUS_RIPV|MCG_STATUS_EIPV)) == \
193 (MCG_STATUS_RIPV|MCG_STATUS_EIPV))
196 * If mcgstatus indicated that ip/cs on the stack were
197 * no good, then "m->cs" will be zero and we will have
198 * to assume the worst case (IN_KERNEL) as we actually
199 * have no idea what we were executing when the machine
200 * check hit.
201 * If we do have a good "m->cs" (or a faked one in the
202 * case we were executing in VM86 mode) we can use it to
203 * distinguish an exception taken in user from from one
204 * taken in the kernel.
206 static int error_context(struct mce *m)
208 if ((m->cs & 3) == 3)
209 return IN_USER;
210 if (mc_recoverable(m->mcgstatus) && ex_has_fault_handler(m->ip))
211 return IN_KERNEL_RECOV;
212 return IN_KERNEL;
215 static int mce_severity_amd_smca(struct mce *m, enum context err_ctx)
217 u32 addr = MSR_AMD64_SMCA_MCx_CONFIG(m->bank);
218 u32 low, high;
221 * We need to look at the following bits:
222 * - "succor" bit (data poisoning support), and
223 * - TCC bit (Task Context Corrupt)
224 * in MCi_STATUS to determine error severity.
226 if (!mce_flags.succor)
227 return MCE_PANIC_SEVERITY;
229 if (rdmsr_safe(addr, &low, &high))
230 return MCE_PANIC_SEVERITY;
232 /* TCC (Task context corrupt). If set and if IN_KERNEL, panic. */
233 if ((low & MCI_CONFIG_MCAX) &&
234 (m->status & MCI_STATUS_TCC) &&
235 (err_ctx == IN_KERNEL))
236 return MCE_PANIC_SEVERITY;
238 /* ...otherwise invoke hwpoison handler. */
239 return MCE_AR_SEVERITY;
243 * See AMD Error Scope Hierarchy table in a newer BKDG. For example
244 * 49125_15h_Models_30h-3Fh_BKDG.pdf, section "RAS Features"
246 static int mce_severity_amd(struct mce *m, int tolerant, char **msg, bool is_excp)
248 enum context ctx = error_context(m);
250 /* Processor Context Corrupt, no need to fumble too much, die! */
251 if (m->status & MCI_STATUS_PCC)
252 return MCE_PANIC_SEVERITY;
254 if (m->status & MCI_STATUS_UC) {
256 if (ctx == IN_KERNEL)
257 return MCE_PANIC_SEVERITY;
260 * On older systems where overflow_recov flag is not present, we
261 * should simply panic if an error overflow occurs. If
262 * overflow_recov flag is present and set, then software can try
263 * to at least kill process to prolong system operation.
265 if (mce_flags.overflow_recov) {
266 if (mce_flags.smca)
267 return mce_severity_amd_smca(m, ctx);
269 /* kill current process */
270 return MCE_AR_SEVERITY;
271 } else {
272 /* at least one error was not logged */
273 if (m->status & MCI_STATUS_OVER)
274 return MCE_PANIC_SEVERITY;
278 * For any other case, return MCE_UC_SEVERITY so that we log the
279 * error and exit #MC handler.
281 return MCE_UC_SEVERITY;
285 * deferred error: poll handler catches these and adds to mce_ring so
286 * memory-failure can take recovery actions.
288 if (m->status & MCI_STATUS_DEFERRED)
289 return MCE_DEFERRED_SEVERITY;
292 * corrected error: poll handler catches these and passes responsibility
293 * of decoding the error to EDAC
295 return MCE_KEEP_SEVERITY;
298 static int mce_severity_intel(struct mce *m, int tolerant, char **msg, bool is_excp)
300 enum exception excp = (is_excp ? EXCP_CONTEXT : NO_EXCP);
301 enum context ctx = error_context(m);
302 struct severity *s;
304 for (s = severities;; s++) {
305 if ((m->status & s->mask) != s->result)
306 continue;
307 if ((m->mcgstatus & s->mcgmask) != s->mcgres)
308 continue;
309 if (s->ser == SER_REQUIRED && !mca_cfg.ser)
310 continue;
311 if (s->ser == NO_SER && mca_cfg.ser)
312 continue;
313 if (s->context && ctx != s->context)
314 continue;
315 if (s->excp && excp != s->excp)
316 continue;
317 if (msg)
318 *msg = s->msg;
319 s->covered = 1;
320 if (s->sev >= MCE_UC_SEVERITY && ctx == IN_KERNEL) {
321 if (tolerant < 1)
322 return MCE_PANIC_SEVERITY;
324 return s->sev;
328 /* Default to mce_severity_intel */
329 int (*mce_severity)(struct mce *m, int tolerant, char **msg, bool is_excp) =
330 mce_severity_intel;
332 void __init mcheck_vendor_init_severity(void)
334 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
335 mce_severity = mce_severity_amd;
338 #ifdef CONFIG_DEBUG_FS
339 static void *s_start(struct seq_file *f, loff_t *pos)
341 if (*pos >= ARRAY_SIZE(severities))
342 return NULL;
343 return &severities[*pos];
346 static void *s_next(struct seq_file *f, void *data, loff_t *pos)
348 if (++(*pos) >= ARRAY_SIZE(severities))
349 return NULL;
350 return &severities[*pos];
353 static void s_stop(struct seq_file *f, void *data)
357 static int s_show(struct seq_file *f, void *data)
359 struct severity *ser = data;
360 seq_printf(f, "%d\t%s\n", ser->covered, ser->msg);
361 return 0;
364 static const struct seq_operations severities_seq_ops = {
365 .start = s_start,
366 .next = s_next,
367 .stop = s_stop,
368 .show = s_show,
371 static int severities_coverage_open(struct inode *inode, struct file *file)
373 return seq_open(file, &severities_seq_ops);
376 static ssize_t severities_coverage_write(struct file *file,
377 const char __user *ubuf,
378 size_t count, loff_t *ppos)
380 int i;
381 for (i = 0; i < ARRAY_SIZE(severities); i++)
382 severities[i].covered = 0;
383 return count;
386 static const struct file_operations severities_coverage_fops = {
387 .open = severities_coverage_open,
388 .release = seq_release,
389 .read = seq_read,
390 .write = severities_coverage_write,
391 .llseek = seq_lseek,
394 static int __init severities_debugfs_init(void)
396 struct dentry *dmce, *fsev;
398 dmce = mce_get_debugfs_dir();
399 if (!dmce)
400 goto err_out;
402 fsev = debugfs_create_file("severities-coverage", 0444, dmce, NULL,
403 &severities_coverage_fops);
404 if (!fsev)
405 goto err_out;
407 return 0;
409 err_out:
410 return -ENOMEM;
412 late_initcall(severities_debugfs_init);
413 #endif /* CONFIG_DEBUG_FS */