mce-severity.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. static struct severity {
  32. u64 mask;
  33. u64 result;
  34. unsigned char sev;
  35. unsigned char mcgmask;
  36. unsigned char mcgres;
  37. unsigned char ser;
  38. unsigned char context;
  39. unsigned char covered;
  40. char *msg;
  41. } severities[] = {
  42. #define MCESEV(s, m, c...) { .sev = MCE_ ## s ## _SEVERITY, .msg = m, ## c }
  43. #define KERNEL .context = IN_KERNEL
  44. #define USER .context = IN_USER
  45. #define SER .ser = SER_REQUIRED
  46. #define NOSER .ser = NO_SER
  47. #define BITCLR(x) .mask = x, .result = 0
  48. #define BITSET(x) .mask = x, .result = x
  49. #define MCGMASK(x, y) .mcgmask = x, .mcgres = y
  50. #define MASK(x, y) .mask = x, .result = y
  51. #define MCI_UC_S (MCI_STATUS_UC|MCI_STATUS_S)
  52. #define MCI_UC_SAR (MCI_STATUS_UC|MCI_STATUS_S|MCI_STATUS_AR)
  53. #define MCI_ADDR (MCI_STATUS_ADDRV|MCI_STATUS_MISCV)
  54. MCESEV(
  55. NO, "Invalid",
  56. BITCLR(MCI_STATUS_VAL)
  57. ),
  58. MCESEV(
  59. NO, "Not enabled",
  60. BITCLR(MCI_STATUS_EN)
  61. ),
  62. MCESEV(
  63. PANIC, "Processor context corrupt",
  64. BITSET(MCI_STATUS_PCC)
  65. ),
  66. /* When MCIP is not set something is very confused */
  67. MCESEV(
  68. PANIC, "MCIP not set in MCA handler",
  69. MCGMASK(MCG_STATUS_MCIP, 0)
  70. ),
  71. /* Neither return not error IP -- no chance to recover -> PANIC */
  72. MCESEV(
  73. PANIC, "Neither restart nor error IP",
  74. MCGMASK(MCG_STATUS_RIPV|MCG_STATUS_EIPV, 0)
  75. ),
  76. MCESEV(
  77. PANIC, "In kernel and no restart IP",
  78. KERNEL, MCGMASK(MCG_STATUS_RIPV, 0)
  79. ),
  80. MCESEV(
  81. KEEP, "Corrected error",
  82. NOSER, BITCLR(MCI_STATUS_UC)
  83. ),
  84. /* ignore OVER for UCNA */
  85. MCESEV(
  86. KEEP, "Uncorrected no action required",
  87. SER, MASK(MCI_UC_SAR, MCI_STATUS_UC)
  88. ),
  89. MCESEV(
  90. PANIC, "Illegal combination (UCNA with AR=1)",
  91. SER,
  92. MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_STATUS_UC|MCI_STATUS_AR)
  93. ),
  94. MCESEV(
  95. KEEP, "Non signalled machine check",
  96. SER, BITCLR(MCI_STATUS_S)
  97. ),
  98. MCESEV(
  99. PANIC, "Action required with lost events",
  100. SER, BITSET(MCI_STATUS_OVER|MCI_UC_SAR)
  101. ),
  102. /* known AR MCACODs: */
  103. #ifdef CONFIG_MEMORY_FAILURE
  104. MCESEV(
  105. KEEP, "HT thread notices Action required: data load error",
  106. SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCI_ADDR|MCACOD, MCI_UC_SAR|MCI_ADDR|MCACOD_DATA),
  107. MCGMASK(MCG_STATUS_EIPV, 0)
  108. ),
  109. MCESEV(
  110. AR, "Action required: data load error",
  111. SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCI_ADDR|MCACOD, MCI_UC_SAR|MCI_ADDR|MCACOD_DATA),
  112. USER
  113. ),
  114. MCESEV(
  115. KEEP, "HT thread notices Action required: instruction fetch error",
  116. SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCI_ADDR|MCACOD, MCI_UC_SAR|MCI_ADDR|MCACOD_INSTR),
  117. MCGMASK(MCG_STATUS_EIPV, 0)
  118. ),
  119. MCESEV(
  120. AR, "Action required: instruction fetch error",
  121. SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCI_ADDR|MCACOD, MCI_UC_SAR|MCI_ADDR|MCACOD_INSTR),
  122. USER
  123. ),
  124. #endif
  125. MCESEV(
  126. PANIC, "Action required: unknown MCACOD",
  127. SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_UC_SAR)
  128. ),
  129. /* known AO MCACODs: */
  130. MCESEV(
  131. AO, "Action optional: memory scrubbing error",
  132. SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCACOD_SCRUBMSK, MCI_UC_S|MCACOD_SCRUB)
  133. ),
  134. MCESEV(
  135. AO, "Action optional: last level cache writeback error",
  136. SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCACOD, MCI_UC_S|MCACOD_L3WB)
  137. ),
  138. MCESEV(
  139. SOME, "Action optional: unknown MCACOD",
  140. SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_UC_S)
  141. ),
  142. MCESEV(
  143. SOME, "Action optional with lost events",
  144. SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR, MCI_STATUS_OVER|MCI_UC_S)
  145. ),
  146. MCESEV(
  147. PANIC, "Overflowed uncorrected",
  148. BITSET(MCI_STATUS_OVER|MCI_STATUS_UC)
  149. ),
  150. MCESEV(
  151. UC, "Uncorrected",
  152. BITSET(MCI_STATUS_UC)
  153. ),
  154. MCESEV(
  155. SOME, "No match",
  156. BITSET(0)
  157. ) /* always matches. keep at end */
  158. };
  159. /*
  160. * If mcgstatus indicated that ip/cs on the stack were
  161. * no good, then "m->cs" will be zero and we will have
  162. * to assume the worst case (IN_KERNEL) as we actually
  163. * have no idea what we were executing when the machine
  164. * check hit.
  165. * If we do have a good "m->cs" (or a faked one in the
  166. * case we were executing in VM86 mode) we can use it to
  167. * distinguish an exception taken in user from from one
  168. * taken in the kernel.
  169. */
  170. static int error_context(struct mce *m)
  171. {
  172. return ((m->cs & 3) == 3) ? IN_USER : IN_KERNEL;
  173. }
  174. int mce_severity(struct mce *m, int tolerant, char **msg)
  175. {
  176. enum context ctx = error_context(m);
  177. struct severity *s;
  178. for (s = severities;; s++) {
  179. if ((m->status & s->mask) != s->result)
  180. continue;
  181. if ((m->mcgstatus & s->mcgmask) != s->mcgres)
  182. continue;
  183. if (s->ser == SER_REQUIRED && !mce_ser)
  184. continue;
  185. if (s->ser == NO_SER && mce_ser)
  186. continue;
  187. if (s->context && ctx != s->context)
  188. continue;
  189. if (msg)
  190. *msg = s->msg;
  191. s->covered = 1;
  192. if (s->sev >= MCE_UC_SEVERITY && ctx == IN_KERNEL) {
  193. if (panic_on_oops || tolerant < 1)
  194. return MCE_PANIC_SEVERITY;
  195. }
  196. return s->sev;
  197. }
  198. }
  199. #ifdef CONFIG_DEBUG_FS
  200. static void *s_start(struct seq_file *f, loff_t *pos)
  201. {
  202. if (*pos >= ARRAY_SIZE(severities))
  203. return NULL;
  204. return &severities[*pos];
  205. }
  206. static void *s_next(struct seq_file *f, void *data, loff_t *pos)
  207. {
  208. if (++(*pos) >= ARRAY_SIZE(severities))
  209. return NULL;
  210. return &severities[*pos];
  211. }
  212. static void s_stop(struct seq_file *f, void *data)
  213. {
  214. }
  215. static int s_show(struct seq_file *f, void *data)
  216. {
  217. struct severity *ser = data;
  218. seq_printf(f, "%d\t%s\n", ser->covered, ser->msg);
  219. return 0;
  220. }
  221. static const struct seq_operations severities_seq_ops = {
  222. .start = s_start,
  223. .next = s_next,
  224. .stop = s_stop,
  225. .show = s_show,
  226. };
  227. static int severities_coverage_open(struct inode *inode, struct file *file)
  228. {
  229. return seq_open(file, &severities_seq_ops);
  230. }
  231. static ssize_t severities_coverage_write(struct file *file,
  232. const char __user *ubuf,
  233. size_t count, loff_t *ppos)
  234. {
  235. int i;
  236. for (i = 0; i < ARRAY_SIZE(severities); i++)
  237. severities[i].covered = 0;
  238. return count;
  239. }
  240. static const struct file_operations severities_coverage_fops = {
  241. .open = severities_coverage_open,
  242. .release = seq_release,
  243. .read = seq_read,
  244. .write = severities_coverage_write,
  245. .llseek = seq_lseek,
  246. };
  247. static int __init severities_debugfs_init(void)
  248. {
  249. struct dentry *dmce, *fsev;
  250. dmce = mce_get_debugfs_dir();
  251. if (!dmce)
  252. goto err_out;
  253. fsev = debugfs_create_file("severities-coverage", 0444, dmce, NULL,
  254. &severities_coverage_fops);
  255. if (!fsev)
  256. goto err_out;
  257. return 0;
  258. err_out:
  259. return -ENOMEM;
  260. }
  261. late_initcall(severities_debugfs_init);
  262. #endif /* CONFIG_DEBUG_FS */