Path: blob/master/arch/x86/kernel/cpu/mcheck/mce-severity.c
10775 views
/*1* MCE grading rules.2* Copyright 2008, 2009 Intel Corporation.3*4* This program is free software; you can redistribute it and/or5* modify it under the terms of the GNU General Public License6* as published by the Free Software Foundation; version 27* of the License.8*9* Author: Andi Kleen10*/11#include <linux/kernel.h>12#include <linux/seq_file.h>13#include <linux/init.h>14#include <linux/debugfs.h>15#include <asm/mce.h>1617#include "mce-internal.h"1819/*20* Grade an mce by severity. In general the most severe ones are processed21* first. Since there are quite a lot of combinations test the bits in a22* table-driven way. The rules are simply processed in order, first23* match wins.24*25* Note this is only used for machine check exceptions, the corrected26* errors use much simpler rules. The exceptions still check for the corrected27* errors, but only to leave them alone for the CMCI handler (except for28* panic situations)29*/3031enum context { IN_KERNEL = 1, IN_USER = 2 };32enum ser { SER_REQUIRED = 1, NO_SER = 2 };3334static struct severity {35u64 mask;36u64 result;37unsigned char sev;38unsigned char mcgmask;39unsigned char mcgres;40unsigned char ser;41unsigned char context;42unsigned char covered;43char *msg;44} severities[] = {45#define KERNEL .context = IN_KERNEL46#define USER .context = IN_USER47#define SER .ser = SER_REQUIRED48#define NOSER .ser = NO_SER49#define SEV(s) .sev = MCE_ ## s ## _SEVERITY50#define BITCLR(x, s, m, r...) { .mask = x, .result = 0, SEV(s), .msg = m, ## r }51#define BITSET(x, s, m, r...) { .mask = x, .result = x, SEV(s), .msg = m, ## r }52#define MCGMASK(x, res, s, m, r...) \53{ .mcgmask = x, .mcgres = res, SEV(s), .msg = m, ## r }54#define MASK(x, y, s, m, r...) \55{ .mask = x, .result = y, SEV(s), .msg = m, ## r }56#define MCI_UC_S (MCI_STATUS_UC|MCI_STATUS_S)57#define MCI_UC_SAR (MCI_STATUS_UC|MCI_STATUS_S|MCI_STATUS_AR)58#define MCACOD 0xffff5960BITCLR(MCI_STATUS_VAL, NO, "Invalid"),61BITCLR(MCI_STATUS_EN, NO, "Not enabled"),62BITSET(MCI_STATUS_PCC, PANIC, "Processor context corrupt"),63/* When MCIP is not set something is very confused */64MCGMASK(MCG_STATUS_MCIP, 0, PANIC, "MCIP not set in MCA handler"),65/* Neither return not error IP -- no chance to recover -> PANIC */66MCGMASK(MCG_STATUS_RIPV|MCG_STATUS_EIPV, 0, PANIC,67"Neither restart nor error IP"),68MCGMASK(MCG_STATUS_RIPV, 0, PANIC, "In kernel and no restart IP",69KERNEL),70BITCLR(MCI_STATUS_UC, KEEP, "Corrected error", NOSER),71MASK(MCI_STATUS_OVER|MCI_STATUS_UC|MCI_STATUS_EN, MCI_STATUS_UC, SOME,72"Spurious not enabled", SER),7374/* ignore OVER for UCNA */75MASK(MCI_UC_SAR, MCI_STATUS_UC, KEEP,76"Uncorrected no action required", SER),77MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_STATUS_UC|MCI_STATUS_AR, PANIC,78"Illegal combination (UCNA with AR=1)", SER),79MASK(MCI_STATUS_S, 0, KEEP, "Non signalled machine check", SER),8081/* AR add known MCACODs here */82MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_STATUS_OVER|MCI_UC_SAR, PANIC,83"Action required with lost events", SER),84MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCACOD, MCI_UC_SAR, PANIC,85"Action required; unknown MCACOD", SER),8687/* known AO MCACODs: */88MASK(MCI_UC_SAR|MCI_STATUS_OVER|0xfff0, MCI_UC_S|0xc0, AO,89"Action optional: memory scrubbing error", SER),90MASK(MCI_UC_SAR|MCI_STATUS_OVER|MCACOD, MCI_UC_S|0x17a, AO,91"Action optional: last level cache writeback error", SER),9293MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_UC_S, SOME,94"Action optional unknown MCACOD", SER),95MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_UC_S|MCI_STATUS_OVER, SOME,96"Action optional with lost events", SER),97BITSET(MCI_STATUS_UC|MCI_STATUS_OVER, PANIC, "Overflowed uncorrected"),98BITSET(MCI_STATUS_UC, UC, "Uncorrected"),99BITSET(0, SOME, "No match") /* always matches. keep at end */100};101102/*103* If the EIPV bit is set, it means the saved IP is the104* instruction which caused the MCE.105*/106static int error_context(struct mce *m)107{108if (m->mcgstatus & MCG_STATUS_EIPV)109return (m->ip && (m->cs & 3) == 3) ? IN_USER : IN_KERNEL;110/* Unknown, assume kernel */111return IN_KERNEL;112}113114int mce_severity(struct mce *a, int tolerant, char **msg)115{116enum context ctx = error_context(a);117struct severity *s;118119for (s = severities;; s++) {120if ((a->status & s->mask) != s->result)121continue;122if ((a->mcgstatus & s->mcgmask) != s->mcgres)123continue;124if (s->ser == SER_REQUIRED && !mce_ser)125continue;126if (s->ser == NO_SER && mce_ser)127continue;128if (s->context && ctx != s->context)129continue;130if (msg)131*msg = s->msg;132s->covered = 1;133if (s->sev >= MCE_UC_SEVERITY && ctx == IN_KERNEL) {134if (panic_on_oops || tolerant < 1)135return MCE_PANIC_SEVERITY;136}137return s->sev;138}139}140141#ifdef CONFIG_DEBUG_FS142static void *s_start(struct seq_file *f, loff_t *pos)143{144if (*pos >= ARRAY_SIZE(severities))145return NULL;146return &severities[*pos];147}148149static void *s_next(struct seq_file *f, void *data, loff_t *pos)150{151if (++(*pos) >= ARRAY_SIZE(severities))152return NULL;153return &severities[*pos];154}155156static void s_stop(struct seq_file *f, void *data)157{158}159160static int s_show(struct seq_file *f, void *data)161{162struct severity *ser = data;163seq_printf(f, "%d\t%s\n", ser->covered, ser->msg);164return 0;165}166167static const struct seq_operations severities_seq_ops = {168.start = s_start,169.next = s_next,170.stop = s_stop,171.show = s_show,172};173174static int severities_coverage_open(struct inode *inode, struct file *file)175{176return seq_open(file, &severities_seq_ops);177}178179static ssize_t severities_coverage_write(struct file *file,180const char __user *ubuf,181size_t count, loff_t *ppos)182{183int i;184for (i = 0; i < ARRAY_SIZE(severities); i++)185severities[i].covered = 0;186return count;187}188189static const struct file_operations severities_coverage_fops = {190.open = severities_coverage_open,191.release = seq_release,192.read = seq_read,193.write = severities_coverage_write,194.llseek = seq_lseek,195};196197static int __init severities_debugfs_init(void)198{199struct dentry *dmce = NULL, *fseverities_coverage = NULL;200201dmce = mce_get_debugfs_dir();202if (dmce == NULL)203goto err_out;204fseverities_coverage = debugfs_create_file("severities-coverage",2050444, dmce, NULL,206&severities_coverage_fops);207if (fseverities_coverage == NULL)208goto err_out;209210return 0;211212err_out:213return -ENOMEM;214}215late_initcall(severities_debugfs_init);216#endif217218219