mce-severity.c 6.2 KB

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