mce-severity.c 6.3 KB

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