mce-severity.c 7.1 KB

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