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
12 #include <linux/kernel.h>
15 #include "mce-internal.h"
18 * Grade an mce by severity. In general the most severe ones are processed
19 * first. Since there are quite a lot of combinations test the bits in a
20 * table-driven way. The rules are simply processed in order, first
23 * Note this is only used for machine check exceptions, the corrected
24 * errors use much simpler rules. The exceptions still check for the corrected
25 * errors, but only to leave them alone for the CMCI handler (except for
29 enum context { IN_KERNEL = 1, IN_USER = 2 };
30 enum ser { SER_REQUIRED = 1, NO_SER = 2 };
32 static struct severity {
36 unsigned char mcgmask;
39 unsigned char context;
42 #define KERNEL .context = IN_KERNEL
43 #define USER .context = IN_USER
44 #define SER .ser = SER_REQUIRED
45 #define NOSER .ser = NO_SER
46 #define SEV(s) .sev = MCE_ ## s ## _SEVERITY
47 #define BITCLR(x, s, m, r...) { .mask = x, .result = 0, SEV(s), .msg = m, ## r }
48 #define BITSET(x, s, m, r...) { .mask = x, .result = x, SEV(s), .msg = m, ## r }
49 #define MCGMASK(x, res, s, m, r...) \
50 { .mcgmask = x, .mcgres = res, SEV(s), .msg = m, ## r }
51 #define MASK(x, y, s, m, r...) \
52 { .mask = x, .result = y, SEV(s), .msg = m, ## r }
53 #define MCI_UC_S (MCI_STATUS_UC|MCI_STATUS_S)
54 #define MCI_UC_SAR (MCI_STATUS_UC|MCI_STATUS_S|MCI_STATUS_AR)
57 BITCLR(MCI_STATUS_VAL, NO, "Invalid"),
58 BITCLR(MCI_STATUS_EN, NO, "Not enabled"),
59 BITSET(MCI_STATUS_PCC, PANIC, "Processor context corrupt"),
60 /* When MCIP is not set something is very confused */
61 MCGMASK(MCG_STATUS_MCIP, 0, PANIC, "MCIP not set in MCA handler"),
62 /* Neither return not error IP -- no chance to recover -> PANIC */
63 MCGMASK(MCG_STATUS_RIPV|MCG_STATUS_EIPV, 0, PANIC,
64 "Neither restart nor error IP"),
65 MCGMASK(MCG_STATUS_RIPV, 0, PANIC, "In kernel and no restart IP",
67 BITCLR(MCI_STATUS_UC, KEEP, "Corrected error", NOSER),
68 MASK(MCI_STATUS_OVER|MCI_STATUS_UC|MCI_STATUS_EN, MCI_STATUS_UC, SOME,
69 "Spurious not enabled", SER),
71 /* ignore OVER for UCNA */
72 MASK(MCI_UC_SAR, MCI_STATUS_UC, KEEP,
73 "Uncorrected no action required", SER),
74 MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_STATUS_UC|MCI_STATUS_AR, PANIC,
75 "Illegal combination (UCNA with AR=1)", SER),
76 MASK(MCI_STATUS_S, 0, KEEP, "Non signalled machine check", SER),
78 /* AR add known MCACODs here */
79 MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_STATUS_OVER|MCI_UC_SAR, PANIC,
80 "Action required with lost events", SER),
81 MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCACOD, MCI_UC_SAR, PANIC,
82 "Action required; unknown MCACOD", SER),
84 /* known AO MCACODs: */
85 MASK(MCI_UC_SAR|MCI_STATUS_OVER|0xfff0, MCI_UC_S|0xc0, AO,
86 "Action optional: memory scrubbing error", SER),
87 MASK(MCI_UC_SAR|MCI_STATUS_OVER|MCACOD, MCI_UC_S|0x17a, AO,
88 "Action optional: last level cache writeback error", SER),
90 MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_UC_S, SOME,
91 "Action optional unknown MCACOD", SER),
92 MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_UC_S|MCI_STATUS_OVER, SOME,
93 "Action optional with lost events", SER),
94 BITSET(MCI_STATUS_UC|MCI_STATUS_OVER, PANIC, "Overflowed uncorrected"),
95 BITSET(MCI_STATUS_UC, UC, "Uncorrected"),
96 BITSET(0, SOME, "No match") /* always matches. keep at end */
100 * If the EIPV bit is set, it means the saved IP is the
101 * instruction which caused the MCE.
103 static int error_context(struct mce *m)
105 if (m->mcgstatus & MCG_STATUS_EIPV)
106 return (m->ip && (m->cs & 3) == 3) ? IN_USER : IN_KERNEL;
107 /* Unknown, assume kernel */
111 int mce_severity(struct mce *a, int tolerant, char **msg)
113 enum context ctx = error_context(a);
116 for (s = severities;; s++) {
117 if ((a->status & s->mask) != s->result)
119 if ((a->mcgstatus & s->mcgmask) != s->mcgres)
121 if (s->ser == SER_REQUIRED && !mce_ser)
123 if (s->ser == NO_SER && mce_ser)
125 if (s->context && ctx != s->context)
129 if (s->sev >= MCE_UC_SEVERITY && ctx == IN_KERNEL) {
130 if (panic_on_oops || tolerant < 1)
131 return MCE_PANIC_SEVERITY;