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>
13 #include <linux/seq_file.h>
14 #include <linux/init.h>
15 #include <linux/debugfs.h>
18 #include "mce-internal.h"
21 * Grade an mce by severity. In general the most severe ones are processed
22 * first. Since there are quite a lot of combinations test the bits in a
23 * table-driven way. The rules are simply processed in order, first
26 * Note this is only used for machine check exceptions, the corrected
27 * errors use much simpler rules. The exceptions still check for the corrected
28 * errors, but only to leave them alone for the CMCI handler (except for
32 enum context
{ IN_KERNEL
= 1, IN_USER
= 2 };
33 enum ser
{ SER_REQUIRED
= 1, NO_SER
= 2 };
34 enum exception
{ EXCP_CONTEXT
= 1, NO_EXCP
= 2 };
36 static struct severity
{
40 unsigned char mcgmask
;
43 unsigned char context
;
45 unsigned char covered
;
48 #define MCESEV(s, m, c...) { .sev = MCE_ ## s ## _SEVERITY, .msg = m, ## c }
49 #define KERNEL .context = IN_KERNEL
50 #define USER .context = IN_USER
51 #define SER .ser = SER_REQUIRED
52 #define NOSER .ser = NO_SER
53 #define EXCP .excp = EXCP_CONTEXT
54 #define NOEXCP .excp = NO_EXCP
55 #define BITCLR(x) .mask = x, .result = 0
56 #define BITSET(x) .mask = x, .result = x
57 #define MCGMASK(x, y) .mcgmask = x, .mcgres = y
58 #define MASK(x, y) .mask = x, .result = y
59 #define MCI_UC_S (MCI_STATUS_UC|MCI_STATUS_S)
60 #define MCI_UC_SAR (MCI_STATUS_UC|MCI_STATUS_S|MCI_STATUS_AR)
61 #define MCI_ADDR (MCI_STATUS_ADDRV|MCI_STATUS_MISCV)
65 BITCLR(MCI_STATUS_VAL
)
69 EXCP
, BITCLR(MCI_STATUS_EN
)
72 PANIC
, "Processor context corrupt",
73 BITSET(MCI_STATUS_PCC
)
75 /* When MCIP is not set something is very confused */
77 PANIC
, "MCIP not set in MCA handler",
78 EXCP
, MCGMASK(MCG_STATUS_MCIP
, 0)
80 /* Neither return not error IP -- no chance to recover -> PANIC */
82 PANIC
, "Neither restart nor error IP",
83 EXCP
, MCGMASK(MCG_STATUS_RIPV
|MCG_STATUS_EIPV
, 0)
86 PANIC
, "In kernel and no restart IP",
87 EXCP
, KERNEL
, MCGMASK(MCG_STATUS_RIPV
, 0)
90 DEFERRED
, "Deferred error",
91 NOSER
, MASK(MCI_STATUS_UC
|MCI_STATUS_DEFERRED
|MCI_STATUS_POISON
, MCI_STATUS_DEFERRED
)
94 KEEP
, "Corrected error",
95 NOSER
, BITCLR(MCI_STATUS_UC
)
98 /* ignore OVER for UCNA */
100 UCNA
, "Uncorrected no action required",
101 SER
, MASK(MCI_UC_SAR
, MCI_STATUS_UC
)
104 PANIC
, "Illegal combination (UCNA with AR=1)",
106 MASK(MCI_STATUS_OVER
|MCI_UC_SAR
, MCI_STATUS_UC
|MCI_STATUS_AR
)
109 KEEP
, "Non signalled machine check",
110 SER
, BITCLR(MCI_STATUS_S
)
114 PANIC
, "Action required with lost events",
115 SER
, BITSET(MCI_STATUS_OVER
|MCI_UC_SAR
)
118 /* known AR MCACODs: */
119 #ifdef CONFIG_MEMORY_FAILURE
121 KEEP
, "Action required but unaffected thread is continuable",
122 SER
, MASK(MCI_STATUS_OVER
|MCI_UC_SAR
|MCI_ADDR
, MCI_UC_SAR
|MCI_ADDR
),
123 MCGMASK(MCG_STATUS_RIPV
|MCG_STATUS_EIPV
, MCG_STATUS_RIPV
)
126 AR
, "Action required: data load error in a user process",
127 SER
, MASK(MCI_STATUS_OVER
|MCI_UC_SAR
|MCI_ADDR
|MCACOD
, MCI_UC_SAR
|MCI_ADDR
|MCACOD_DATA
),
131 AR
, "Action required: instruction fetch error in a user process",
132 SER
, MASK(MCI_STATUS_OVER
|MCI_UC_SAR
|MCI_ADDR
|MCACOD
, MCI_UC_SAR
|MCI_ADDR
|MCACOD_INSTR
),
137 PANIC
, "Action required: unknown MCACOD",
138 SER
, MASK(MCI_STATUS_OVER
|MCI_UC_SAR
, MCI_UC_SAR
)
141 /* known AO MCACODs: */
143 AO
, "Action optional: memory scrubbing error",
144 SER
, MASK(MCI_STATUS_OVER
|MCI_UC_SAR
|MCACOD_SCRUBMSK
, MCI_UC_S
|MCACOD_SCRUB
)
147 AO
, "Action optional: last level cache writeback error",
148 SER
, MASK(MCI_STATUS_OVER
|MCI_UC_SAR
|MCACOD
, MCI_UC_S
|MCACOD_L3WB
)
151 SOME
, "Action optional: unknown MCACOD",
152 SER
, MASK(MCI_STATUS_OVER
|MCI_UC_SAR
, MCI_UC_S
)
155 SOME
, "Action optional with lost events",
156 SER
, MASK(MCI_STATUS_OVER
|MCI_UC_SAR
, MCI_STATUS_OVER
|MCI_UC_S
)
160 PANIC
, "Overflowed uncorrected",
161 BITSET(MCI_STATUS_OVER
|MCI_STATUS_UC
)
165 BITSET(MCI_STATUS_UC
)
170 ) /* always matches. keep at end */
174 * If mcgstatus indicated that ip/cs on the stack were
175 * no good, then "m->cs" will be zero and we will have
176 * to assume the worst case (IN_KERNEL) as we actually
177 * have no idea what we were executing when the machine
179 * If we do have a good "m->cs" (or a faked one in the
180 * case we were executing in VM86 mode) we can use it to
181 * distinguish an exception taken in user from from one
182 * taken in the kernel.
184 static int error_context(struct mce
*m
)
186 return ((m
->cs
& 3) == 3) ? IN_USER
: IN_KERNEL
;
189 int mce_severity(struct mce
*m
, int tolerant
, char **msg
, bool is_excp
)
191 enum exception excp
= (is_excp
? EXCP_CONTEXT
: NO_EXCP
);
192 enum context ctx
= error_context(m
);
195 for (s
= severities
;; s
++) {
196 if ((m
->status
& s
->mask
) != s
->result
)
198 if ((m
->mcgstatus
& s
->mcgmask
) != s
->mcgres
)
200 if (s
->ser
== SER_REQUIRED
&& !mca_cfg
.ser
)
202 if (s
->ser
== NO_SER
&& mca_cfg
.ser
)
204 if (s
->context
&& ctx
!= s
->context
)
206 if (s
->excp
&& excp
!= s
->excp
)
211 if (s
->sev
>= MCE_UC_SEVERITY
&& ctx
== IN_KERNEL
) {
212 if (panic_on_oops
|| tolerant
< 1)
213 return MCE_PANIC_SEVERITY
;
219 #ifdef CONFIG_DEBUG_FS
220 static void *s_start(struct seq_file
*f
, loff_t
*pos
)
222 if (*pos
>= ARRAY_SIZE(severities
))
224 return &severities
[*pos
];
227 static void *s_next(struct seq_file
*f
, void *data
, loff_t
*pos
)
229 if (++(*pos
) >= ARRAY_SIZE(severities
))
231 return &severities
[*pos
];
234 static void s_stop(struct seq_file
*f
, void *data
)
238 static int s_show(struct seq_file
*f
, void *data
)
240 struct severity
*ser
= data
;
241 seq_printf(f
, "%d\t%s\n", ser
->covered
, ser
->msg
);
245 static const struct seq_operations severities_seq_ops
= {
252 static int severities_coverage_open(struct inode
*inode
, struct file
*file
)
254 return seq_open(file
, &severities_seq_ops
);
257 static ssize_t
severities_coverage_write(struct file
*file
,
258 const char __user
*ubuf
,
259 size_t count
, loff_t
*ppos
)
262 for (i
= 0; i
< ARRAY_SIZE(severities
); i
++)
263 severities
[i
].covered
= 0;
267 static const struct file_operations severities_coverage_fops
= {
268 .open
= severities_coverage_open
,
269 .release
= seq_release
,
271 .write
= severities_coverage_write
,
275 static int __init
severities_debugfs_init(void)
277 struct dentry
*dmce
, *fsev
;
279 dmce
= mce_get_debugfs_dir();
283 fsev
= debugfs_create_file("severities-coverage", 0444, dmce
, NULL
,
284 &severities_coverage_fops
);
293 late_initcall(severities_debugfs_init
);
294 #endif /* CONFIG_DEBUG_FS */