aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndi Kleen <andi@firstfloor.org>2009-05-27 15:56:54 -0400
committerH. Peter Anvin <hpa@zytor.com>2009-06-03 17:40:39 -0400
commit817f32d02a52dd7f5941534e0699883691e918df (patch)
treeebca6e71edd283b9c13dde01d1861368a7e2fdcf
parenta0189c70e5f17f4253dd7bc575c97469900e23d6 (diff)
x86, mce: add table driven machine check grading
The machine check grading (as in deciding what should be done for a given register value) has to be done multiple times soon and it's also getting more complicated. So it makes sense to consolidate it into a single function. To get smaller and more straight forward and possibly more extensible code I opted towards a new table driven method. The various rules are put into a table when is then executed by a very simple interpreter. The grading engine is in a new file mce-severity.c. I also added a private include file mce-internal.h, because mce.h is already a bit too cluttered. This is dead code right now, but will be used in followon patches. Signed-off-by: Andi Kleen <ak@linux.intel.com> Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--arch/x86/kernel/cpu/mcheck/Makefile1
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce-internal.h10
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce-severity.c61
3 files changed, 72 insertions, 0 deletions
diff --git a/arch/x86/kernel/cpu/mcheck/Makefile b/arch/x86/kernel/cpu/mcheck/Makefile
index 60ee182c6c52..45004faf67ea 100644
--- a/arch/x86/kernel/cpu/mcheck/Makefile
+++ b/arch/x86/kernel/cpu/mcheck/Makefile
@@ -1,5 +1,6 @@
1obj-y = mce.o therm_throt.o 1obj-y = mce.o therm_throt.o
2 2
3obj-$(CONFIG_X86_NEW_MCE) += mce-severity.o
3obj-$(CONFIG_X86_OLD_MCE) += k7.o p4.o p6.o 4obj-$(CONFIG_X86_OLD_MCE) += k7.o p4.o p6.o
4obj-$(CONFIG_X86_ANCIENT_MCE) += winchip.o p5.o 5obj-$(CONFIG_X86_ANCIENT_MCE) += winchip.o p5.o
5obj-$(CONFIG_X86_MCE_P4THERMAL) += mce_intel.o 6obj-$(CONFIG_X86_MCE_P4THERMAL) += mce_intel.o
diff --git a/arch/x86/kernel/cpu/mcheck/mce-internal.h b/arch/x86/kernel/cpu/mcheck/mce-internal.h
new file mode 100644
index 000000000000..f126b4ae7a25
--- /dev/null
+++ b/arch/x86/kernel/cpu/mcheck/mce-internal.h
@@ -0,0 +1,10 @@
1#include <asm/mce.h>
2
3enum severity_level {
4 MCE_NO_SEVERITY,
5 MCE_SOME_SEVERITY,
6 MCE_UC_SEVERITY,
7 MCE_PANIC_SEVERITY,
8};
9
10int mce_severity(struct mce *a, int tolerant, char **msg);
diff --git a/arch/x86/kernel/cpu/mcheck/mce-severity.c b/arch/x86/kernel/cpu/mcheck/mce-severity.c
new file mode 100644
index 000000000000..c189e89a89ae
--- /dev/null
+++ b/arch/x86/kernel/cpu/mcheck/mce-severity.c
@@ -0,0 +1,61 @@
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
24static struct severity {
25 u64 mask;
26 u64 result;
27 unsigned char sev;
28 unsigned char mcgmask;
29 unsigned char mcgres;
30 char *msg;
31} severities[] = {
32#define SEV(s) .sev = MCE_ ## s ## _SEVERITY
33#define BITCLR(x, s, m, r...) { .mask = x, .result = 0, SEV(s), .msg = m, ## r }
34#define BITSET(x, s, m, r...) { .mask = x, .result = x, SEV(s), .msg = m, ## r }
35#define MCGMASK(x, res, s, m, r...) \
36 { .mcgmask = x, .mcgres = res, SEV(s), .msg = m, ## r }
37 BITCLR(MCI_STATUS_VAL, NO, "Invalid"),
38 BITCLR(MCI_STATUS_EN, NO, "Not enabled"),
39 BITSET(MCI_STATUS_PCC, PANIC, "Processor context corrupt"),
40 MCGMASK(MCG_STATUS_RIPV, 0, PANIC, "No restart IP"),
41 BITSET(MCI_STATUS_UC|MCI_STATUS_OVER, PANIC, "Overflowed uncorrected"),
42 BITSET(MCI_STATUS_UC, UC, "Uncorrected"),
43 BITSET(0, SOME, "No match") /* always matches. keep at end */
44};
45
46int mce_severity(struct mce *a, int tolerant, char **msg)
47{
48 struct severity *s;
49 for (s = severities;; s++) {
50 if ((a->status & s->mask) != s->result)
51 continue;
52 if ((a->mcgstatus & s->mcgmask) != s->mcgres)
53 continue;
54 if (s->sev > MCE_NO_SEVERITY && (a->status & MCI_STATUS_UC) &&
55 tolerant < 1)
56 return MCE_PANIC_SEVERITY;
57 if (msg)
58 *msg = s->msg;
59 return s->sev;
60 }
61}