mce-severity.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. int mce_severity(struct mce *m, int tolerant, char **msg, bool is_excp)
  178. {
  179. enum exception excp = (is_excp ? EXCP_CONTEXT : NO_EXCP);
  180. enum context ctx = error_context(m);
  181. struct severity *s;
  182. for (s = severities;; s++) {
  183. if ((m->status & s->mask) != s->result)
  184. continue;
  185. if ((m->mcgstatus & s->mcgmask) != s->mcgres)
  186. continue;
  187. if (s->ser == SER_REQUIRED && !mca_cfg.ser)
  188. continue;
  189. if (s->ser == NO_SER && mca_cfg.ser)
  190. continue;
  191. if (s->context && ctx != s->context)
  192. continue;
  193. if (s->excp && excp != s->excp)
  194. continue;
  195. if (msg)
  196. *msg = s->msg;
  197. s->covered = 1;
  198. if (s->sev >= MCE_UC_SEVERITY && ctx == IN_KERNEL) {
  199. if (panic_on_oops || tolerant < 1)
  200. return MCE_PANIC_SEVERITY;
  201. }
  202. return s->sev;
  203. }
  204. }
  205. #ifdef CONFIG_DEBUG_FS
  206. static void *s_start(struct seq_file *f, loff_t *pos)
  207. {
  208. if (*pos >= ARRAY_SIZE(severities))
  209. return NULL;
  210. return &severities[*pos];
  211. }
  212. static void *s_next(struct seq_file *f, void *data, loff_t *pos)
  213. {
  214. if (++(*pos) >= ARRAY_SIZE(severities))
  215. return NULL;
  216. return &severities[*pos];
  217. }
  218. static void s_stop(struct seq_file *f, void *data)
  219. {
  220. }
  221. static int s_show(struct seq_file *f, void *data)
  222. {
  223. struct severity *ser = data;
  224. seq_printf(f, "%d\t%s\n", ser->covered, ser->msg);
  225. return 0;
  226. }
  227. static const struct seq_operations severities_seq_ops = {
  228. .start = s_start,
  229. .next = s_next,
  230. .stop = s_stop,
  231. .show = s_show,
  232. };
  233. static int severities_coverage_open(struct inode *inode, struct file *file)
  234. {
  235. return seq_open(file, &severities_seq_ops);
  236. }
  237. static ssize_t severities_coverage_write(struct file *file,
  238. const char __user *ubuf,
  239. size_t count, loff_t *ppos)
  240. {
  241. int i;
  242. for (i = 0; i < ARRAY_SIZE(severities); i++)
  243. severities[i].covered = 0;
  244. return count;
  245. }
  246. static const struct file_operations severities_coverage_fops = {
  247. .open = severities_coverage_open,
  248. .release = seq_release,
  249. .read = seq_read,
  250. .write = severities_coverage_write,
  251. .llseek = seq_lseek,
  252. };
  253. static int __init severities_debugfs_init(void)
  254. {
  255. struct dentry *dmce, *fsev;
  256. dmce = mce_get_debugfs_dir();
  257. if (!dmce)
  258. goto err_out;
  259. fsev = debugfs_create_file("severities-coverage", 0444, dmce, NULL,
  260. &severities_coverage_fops);
  261. if (!fsev)
  262. goto err_out;
  263. return 0;
  264. err_out:
  265. return -ENOMEM;
  266. }
  267. late_initcall(severities_debugfs_init);
  268. #endif /* CONFIG_DEBUG_FS */