mce-severity.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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 <linux/seq_file.h>
  14. #include <linux/init.h>
  15. #include <linux/debugfs.h>
  16. #include <asm/mce.h>
  17. #include "mce-internal.h"
  18. /*
  19. * Grade an mce by severity. In general the most severe ones are processed
  20. * first. Since there are quite a lot of combinations test the bits in a
  21. * table-driven way. The rules are simply processed in order, first
  22. * match wins.
  23. *
  24. * Note this is only used for machine check exceptions, the corrected
  25. * errors use much simpler rules. The exceptions still check for the corrected
  26. * errors, but only to leave them alone for the CMCI handler (except for
  27. * panic situations)
  28. */
  29. enum context { IN_KERNEL = 1, IN_USER = 2 };
  30. enum ser { SER_REQUIRED = 1, NO_SER = 2 };
  31. enum exception { EXCP_CONTEXT = 1, NO_EXCP = 2 };
  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. unsigned char excp;
  41. unsigned char covered;
  42. char *msg;
  43. } severities[] = {
  44. #define MCESEV(s, m, c...) { .sev = MCE_ ## s ## _SEVERITY, .msg = m, ## c }
  45. #define KERNEL .context = IN_KERNEL
  46. #define USER .context = IN_USER
  47. #define SER .ser = SER_REQUIRED
  48. #define NOSER .ser = NO_SER
  49. #define EXCP .excp = EXCP_CONTEXT
  50. #define NOEXCP .excp = NO_EXCP
  51. #define BITCLR(x) .mask = x, .result = 0
  52. #define BITSET(x) .mask = x, .result = x
  53. #define MCGMASK(x, y) .mcgmask = x, .mcgres = y
  54. #define MASK(x, y) .mask = x, .result = y
  55. #define MCI_UC_S (MCI_STATUS_UC|MCI_STATUS_S)
  56. #define MCI_UC_SAR (MCI_STATUS_UC|MCI_STATUS_S|MCI_STATUS_AR)
  57. #define MCI_ADDR (MCI_STATUS_ADDRV|MCI_STATUS_MISCV)
  58. MCESEV(
  59. NO, "Invalid",
  60. BITCLR(MCI_STATUS_VAL)
  61. ),
  62. MCESEV(
  63. NO, "Not enabled",
  64. EXCP, BITCLR(MCI_STATUS_EN)
  65. ),
  66. MCESEV(
  67. PANIC, "Processor context corrupt",
  68. BITSET(MCI_STATUS_PCC)
  69. ),
  70. /* When MCIP is not set something is very confused */
  71. MCESEV(
  72. PANIC, "MCIP not set in MCA handler",
  73. EXCP, MCGMASK(MCG_STATUS_MCIP, 0)
  74. ),
  75. /* Neither return not error IP -- no chance to recover -> PANIC */
  76. MCESEV(
  77. PANIC, "Neither restart nor error IP",
  78. EXCP, MCGMASK(MCG_STATUS_RIPV|MCG_STATUS_EIPV, 0)
  79. ),
  80. MCESEV(
  81. PANIC, "In kernel and no restart IP",
  82. EXCP, KERNEL, MCGMASK(MCG_STATUS_RIPV, 0)
  83. ),
  84. MCESEV(
  85. DEFERRED, "Deferred error",
  86. NOSER, MASK(MCI_STATUS_UC|MCI_STATUS_DEFERRED|MCI_STATUS_POISON, MCI_STATUS_DEFERRED)
  87. ),
  88. MCESEV(
  89. KEEP, "Corrected error",
  90. NOSER, BITCLR(MCI_STATUS_UC)
  91. ),
  92. /* ignore OVER for UCNA */
  93. MCESEV(
  94. UCNA, "Uncorrected no action required",
  95. SER, MASK(MCI_UC_SAR, MCI_STATUS_UC)
  96. ),
  97. MCESEV(
  98. PANIC, "Illegal combination (UCNA with AR=1)",
  99. SER,
  100. MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_STATUS_UC|MCI_STATUS_AR)
  101. ),
  102. MCESEV(
  103. KEEP, "Non signalled machine check",
  104. SER, BITCLR(MCI_STATUS_S)
  105. ),
  106. MCESEV(
  107. PANIC, "Action required with lost events",
  108. SER, BITSET(MCI_STATUS_OVER|MCI_UC_SAR)
  109. ),
  110. /* known AR MCACODs: */
  111. #ifdef CONFIG_MEMORY_FAILURE
  112. MCESEV(
  113. KEEP, "Action required but unaffected thread is continuable",
  114. SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCI_ADDR, MCI_UC_SAR|MCI_ADDR),
  115. MCGMASK(MCG_STATUS_RIPV|MCG_STATUS_EIPV, MCG_STATUS_RIPV)
  116. ),
  117. MCESEV(
  118. AR, "Action required: data load error in a user process",
  119. SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCI_ADDR|MCACOD, MCI_UC_SAR|MCI_ADDR|MCACOD_DATA),
  120. USER
  121. ),
  122. MCESEV(
  123. AR, "Action required: instruction fetch error in a user process",
  124. SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCI_ADDR|MCACOD, MCI_UC_SAR|MCI_ADDR|MCACOD_INSTR),
  125. USER
  126. ),
  127. #endif
  128. MCESEV(
  129. PANIC, "Action required: unknown MCACOD",
  130. SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_UC_SAR)
  131. ),
  132. /* known AO MCACODs: */
  133. MCESEV(
  134. AO, "Action optional: memory scrubbing error",
  135. SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCACOD_SCRUBMSK, MCI_UC_S|MCACOD_SCRUB)
  136. ),
  137. MCESEV(
  138. AO, "Action optional: last level cache writeback error",
  139. SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCACOD, MCI_UC_S|MCACOD_L3WB)
  140. ),
  141. MCESEV(
  142. SOME, "Action optional: unknown MCACOD",
  143. SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_UC_S)
  144. ),
  145. MCESEV(
  146. SOME, "Action optional with lost events",
  147. SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_STATUS_OVER|MCI_UC_S)
  148. ),
  149. MCESEV(
  150. PANIC, "Overflowed uncorrected",
  151. BITSET(MCI_STATUS_OVER|MCI_STATUS_UC)
  152. ),
  153. MCESEV(
  154. UC, "Uncorrected",
  155. BITSET(MCI_STATUS_UC)
  156. ),
  157. MCESEV(
  158. SOME, "No match",
  159. BITSET(0)
  160. ) /* always matches. keep at end */
  161. };
  162. /*
  163. * If mcgstatus indicated that ip/cs on the stack were
  164. * no good, then "m->cs" will be zero and we will have
  165. * to assume the worst case (IN_KERNEL) as we actually
  166. * have no idea what we were executing when the machine
  167. * check hit.
  168. * If we do have a good "m->cs" (or a faked one in the
  169. * case we were executing in VM86 mode) we can use it to
  170. * distinguish an exception taken in user from from one
  171. * taken in the kernel.
  172. */
  173. static int error_context(struct mce *m)
  174. {
  175. return ((m->cs & 3) == 3) ? IN_USER : IN_KERNEL;
  176. }
  177. /*
  178. * See AMD Error Scope Hierarchy table in a newer BKDG. For example
  179. * 49125_15h_Models_30h-3Fh_BKDG.pdf, section "RAS Features"
  180. */
  181. static int mce_severity_amd(struct mce *m, int tolerant, char **msg, bool is_excp)
  182. {
  183. enum context ctx = error_context(m);
  184. /* Processor Context Corrupt, no need to fumble too much, die! */
  185. if (m->status & MCI_STATUS_PCC)
  186. return MCE_PANIC_SEVERITY;
  187. if (m->status & MCI_STATUS_UC) {
  188. /*
  189. * On older systems where overflow_recov flag is not present, we
  190. * should simply panic if an error overflow occurs. If
  191. * overflow_recov flag is present and set, then software can try
  192. * to at least kill process to prolong system operation.
  193. */
  194. if (mce_flags.overflow_recov) {
  195. /* software can try to contain */
  196. if (!(m->mcgstatus & MCG_STATUS_RIPV) && (ctx == IN_KERNEL))
  197. return MCE_PANIC_SEVERITY;
  198. /* kill current process */
  199. return MCE_AR_SEVERITY;
  200. } else {
  201. /* at least one error was not logged */
  202. if (m->status & MCI_STATUS_OVER)
  203. return MCE_PANIC_SEVERITY;
  204. }
  205. /*
  206. * For any other case, return MCE_UC_SEVERITY so that we log the
  207. * error and exit #MC handler.
  208. */
  209. return MCE_UC_SEVERITY;
  210. }
  211. /*
  212. * deferred error: poll handler catches these and adds to mce_ring so
  213. * memory-failure can take recovery actions.
  214. */
  215. if (m->status & MCI_STATUS_DEFERRED)
  216. return MCE_DEFERRED_SEVERITY;
  217. /*
  218. * corrected error: poll handler catches these and passes responsibility
  219. * of decoding the error to EDAC
  220. */
  221. return MCE_KEEP_SEVERITY;
  222. }
  223. static int mce_severity_intel(struct mce *m, int tolerant, char **msg, bool is_excp)
  224. {
  225. enum exception excp = (is_excp ? EXCP_CONTEXT : NO_EXCP);
  226. enum context ctx = error_context(m);
  227. struct severity *s;
  228. for (s = severities;; s++) {
  229. if ((m->status & s->mask) != s->result)
  230. continue;
  231. if ((m->mcgstatus & s->mcgmask) != s->mcgres)
  232. continue;
  233. if (s->ser == SER_REQUIRED && !mca_cfg.ser)
  234. continue;
  235. if (s->ser == NO_SER && mca_cfg.ser)
  236. continue;
  237. if (s->context && ctx != s->context)
  238. continue;
  239. if (s->excp && excp != s->excp)
  240. continue;
  241. if (msg)
  242. *msg = s->msg;
  243. s->covered = 1;
  244. if (s->sev >= MCE_UC_SEVERITY && ctx == IN_KERNEL) {
  245. if (panic_on_oops || tolerant < 1)
  246. return MCE_PANIC_SEVERITY;
  247. }
  248. return s->sev;
  249. }
  250. }
  251. /* Default to mce_severity_intel */
  252. int (*mce_severity)(struct mce *m, int tolerant, char **msg, bool is_excp) =
  253. mce_severity_intel;
  254. void __init mcheck_vendor_init_severity(void)
  255. {
  256. if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
  257. mce_severity = mce_severity_amd;
  258. }
  259. #ifdef CONFIG_DEBUG_FS
  260. static void *s_start(struct seq_file *f, loff_t *pos)
  261. {
  262. if (*pos >= ARRAY_SIZE(severities))
  263. return NULL;
  264. return &severities[*pos];
  265. }
  266. static void *s_next(struct seq_file *f, void *data, loff_t *pos)
  267. {
  268. if (++(*pos) >= ARRAY_SIZE(severities))
  269. return NULL;
  270. return &severities[*pos];
  271. }
  272. static void s_stop(struct seq_file *f, void *data)
  273. {
  274. }
  275. static int s_show(struct seq_file *f, void *data)
  276. {
  277. struct severity *ser = data;
  278. seq_printf(f, "%d\t%s\n", ser->covered, ser->msg);
  279. return 0;
  280. }
  281. static const struct seq_operations severities_seq_ops = {
  282. .start = s_start,
  283. .next = s_next,
  284. .stop = s_stop,
  285. .show = s_show,
  286. };
  287. static int severities_coverage_open(struct inode *inode, struct file *file)
  288. {
  289. return seq_open(file, &severities_seq_ops);
  290. }
  291. static ssize_t severities_coverage_write(struct file *file,
  292. const char __user *ubuf,
  293. size_t count, loff_t *ppos)
  294. {
  295. int i;
  296. for (i = 0; i < ARRAY_SIZE(severities); i++)
  297. severities[i].covered = 0;
  298. return count;
  299. }
  300. static const struct file_operations severities_coverage_fops = {
  301. .open = severities_coverage_open,
  302. .release = seq_release,
  303. .read = seq_read,
  304. .write = severities_coverage_write,
  305. .llseek = seq_lseek,
  306. };
  307. static int __init severities_debugfs_init(void)
  308. {
  309. struct dentry *dmce, *fsev;
  310. dmce = mce_get_debugfs_dir();
  311. if (!dmce)
  312. goto err_out;
  313. fsev = debugfs_create_file("severities-coverage", 0444, dmce, NULL,
  314. &severities_coverage_fops);
  315. if (!fsev)
  316. goto err_out;
  317. return 0;
  318. err_out:
  319. return -ENOMEM;
  320. }
  321. late_initcall(severities_debugfs_init);
  322. #endif /* CONFIG_DEBUG_FS */