x86, mce: implement new status bits
[safe/jmp/linux-2.6] / arch / x86 / kernel / cpu / mcheck / mce-severity.c
1 /*
2  * MCE grading rules.
3  * Copyright 2008, 2009 Intel Corporation.
4  *
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.
9  *
10  * Author: Andi Kleen
11  */
12 #include <linux/kernel.h>
13 #include <asm/mce.h>
14
15 #include "mce-internal.h"
16
17 /*
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
21  * match wins.
22  *
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
26  * panic situations)
27  */
28
29 enum context { IN_KERNEL = 1, IN_USER = 2 };
30 enum ser { SER_REQUIRED = 1, NO_SER = 2 };
31
32 static struct severity {
33         u64 mask;
34         u64 result;
35         unsigned char sev;
36         unsigned char mcgmask;
37         unsigned char mcgres;
38         unsigned char ser;
39         unsigned char context;
40         char *msg;
41 } severities[] = {
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)
55 #define MCACOD 0xffff
56
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",
66                 KERNEL),
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),
70
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),
77
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),
83
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),
89
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 */
97 };
98
99 /*
100  * If the EIPV bit is set, it means the saved IP is the
101  * instruction which caused the MCE.
102  */
103 static int error_context(struct mce *m)
104 {
105         if (m->mcgstatus & MCG_STATUS_EIPV)
106                 return (m->ip && (m->cs & 3) == 3) ? IN_USER : IN_KERNEL;
107         /* Unknown, assume kernel */
108         return IN_KERNEL;
109 }
110
111 int mce_severity(struct mce *a, int tolerant, char **msg)
112 {
113         enum context ctx = error_context(a);
114         struct severity *s;
115
116         for (s = severities;; s++) {
117                 if ((a->status & s->mask) != s->result)
118                         continue;
119                 if ((a->mcgstatus & s->mcgmask) != s->mcgres)
120                         continue;
121                 if (s->ser == SER_REQUIRED && !mce_ser)
122                         continue;
123                 if (s->ser == NO_SER && mce_ser)
124                         continue;
125                 if (s->context && ctx != s->context)
126                         continue;
127                 if (msg)
128                         *msg = s->msg;
129                 if (s->sev >= MCE_UC_SEVERITY && ctx == IN_KERNEL) {
130                         if (panic_on_oops || tolerant < 1)
131                                 return MCE_PANIC_SEVERITY;
132                 }
133                 return s->sev;
134         }
135 }