mce.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /*
  2. * Machine check handler.
  3. * K8 parts Copyright 2002,2003 Andi Kleen, SuSE Labs.
  4. * Rest from unknown author(s).
  5. * 2004 Andi Kleen. Rewrote most of it.
  6. */
  7. #include <linux/init.h>
  8. #include <linux/types.h>
  9. #include <linux/kernel.h>
  10. #include <linux/sched.h>
  11. #include <linux/string.h>
  12. #include <linux/rcupdate.h>
  13. #include <linux/kallsyms.h>
  14. #include <linux/sysdev.h>
  15. #include <linux/miscdevice.h>
  16. #include <linux/fs.h>
  17. #include <linux/capability.h>
  18. #include <linux/cpu.h>
  19. #include <linux/percpu.h>
  20. #include <linux/ctype.h>
  21. #include <asm/processor.h>
  22. #include <asm/msr.h>
  23. #include <asm/mce.h>
  24. #include <asm/kdebug.h>
  25. #include <asm/uaccess.h>
  26. #include <asm/smp.h>
  27. #define MISC_MCELOG_MINOR 227
  28. #define NR_BANKS 6
  29. static int mce_dont_init;
  30. /* 0: always panic, 1: panic if deadlock possible, 2: try to avoid panic,
  31. 3: never panic or exit (for testing only) */
  32. static int tolerant = 1;
  33. static int banks;
  34. static unsigned long bank[NR_BANKS] = { [0 ... NR_BANKS-1] = ~0UL };
  35. static unsigned long console_logged;
  36. static int notify_user;
  37. static int rip_msr;
  38. static int mce_bootlog = 1;
  39. /*
  40. * Lockless MCE logging infrastructure.
  41. * This avoids deadlocks on printk locks without having to break locks. Also
  42. * separate MCEs from kernel messages to avoid bogus bug reports.
  43. */
  44. struct mce_log mcelog = {
  45. MCE_LOG_SIGNATURE,
  46. MCE_LOG_LEN,
  47. };
  48. void mce_log(struct mce *mce)
  49. {
  50. unsigned next, entry;
  51. mce->finished = 0;
  52. wmb();
  53. for (;;) {
  54. entry = rcu_dereference(mcelog.next);
  55. /* The rmb forces the compiler to reload next in each
  56. iteration */
  57. rmb();
  58. for (;;) {
  59. /* When the buffer fills up discard new entries. Assume
  60. that the earlier errors are the more interesting. */
  61. if (entry >= MCE_LOG_LEN) {
  62. set_bit(MCE_OVERFLOW, &mcelog.flags);
  63. return;
  64. }
  65. /* Old left over entry. Skip. */
  66. if (mcelog.entry[entry].finished) {
  67. entry++;
  68. continue;
  69. }
  70. break;
  71. }
  72. smp_rmb();
  73. next = entry + 1;
  74. if (cmpxchg(&mcelog.next, entry, next) == entry)
  75. break;
  76. }
  77. memcpy(mcelog.entry + entry, mce, sizeof(struct mce));
  78. wmb();
  79. mcelog.entry[entry].finished = 1;
  80. wmb();
  81. if (!test_and_set_bit(0, &console_logged))
  82. notify_user = 1;
  83. }
  84. static void print_mce(struct mce *m)
  85. {
  86. printk(KERN_EMERG "\n"
  87. KERN_EMERG "HARDWARE ERROR\n"
  88. KERN_EMERG
  89. "CPU %d: Machine Check Exception: %16Lx Bank %d: %016Lx\n",
  90. m->cpu, m->mcgstatus, m->bank, m->status);
  91. if (m->rip) {
  92. printk(KERN_EMERG
  93. "RIP%s %02x:<%016Lx> ",
  94. !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
  95. m->cs, m->rip);
  96. if (m->cs == __KERNEL_CS)
  97. print_symbol("{%s}", m->rip);
  98. printk("\n");
  99. }
  100. printk(KERN_EMERG "TSC %Lx ", m->tsc);
  101. if (m->addr)
  102. printk("ADDR %Lx ", m->addr);
  103. if (m->misc)
  104. printk("MISC %Lx ", m->misc);
  105. printk("\n");
  106. printk(KERN_EMERG "This is not a software problem!\n");
  107. printk(KERN_EMERG
  108. "Run through mcelog --ascii to decode and contact your hardware vendor\n");
  109. }
  110. static void mce_panic(char *msg, struct mce *backup, unsigned long start)
  111. {
  112. int i;
  113. oops_begin();
  114. for (i = 0; i < MCE_LOG_LEN; i++) {
  115. unsigned long tsc = mcelog.entry[i].tsc;
  116. if (time_before(tsc, start))
  117. continue;
  118. print_mce(&mcelog.entry[i]);
  119. if (backup && mcelog.entry[i].tsc == backup->tsc)
  120. backup = NULL;
  121. }
  122. if (backup)
  123. print_mce(backup);
  124. if (tolerant >= 3)
  125. printk("Fake panic: %s\n", msg);
  126. else
  127. panic(msg);
  128. }
  129. static int mce_available(struct cpuinfo_x86 *c)
  130. {
  131. return test_bit(X86_FEATURE_MCE, &c->x86_capability) &&
  132. test_bit(X86_FEATURE_MCA, &c->x86_capability);
  133. }
  134. static inline void mce_get_rip(struct mce *m, struct pt_regs *regs)
  135. {
  136. if (regs && (m->mcgstatus & MCG_STATUS_RIPV)) {
  137. m->rip = regs->rip;
  138. m->cs = regs->cs;
  139. } else {
  140. m->rip = 0;
  141. m->cs = 0;
  142. }
  143. if (rip_msr) {
  144. /* Assume the RIP in the MSR is exact. Is this true? */
  145. m->mcgstatus |= MCG_STATUS_EIPV;
  146. rdmsrl(rip_msr, m->rip);
  147. m->cs = 0;
  148. }
  149. }
  150. /*
  151. * The actual machine check handler
  152. */
  153. void do_machine_check(struct pt_regs * regs, long error_code)
  154. {
  155. struct mce m, panicm;
  156. int nowayout = (tolerant < 1);
  157. int kill_it = 0;
  158. u64 mcestart = 0;
  159. int i;
  160. int panicm_found = 0;
  161. if (regs)
  162. notify_die(DIE_NMI, "machine check", regs, error_code, 18, SIGKILL);
  163. if (!banks)
  164. return;
  165. memset(&m, 0, sizeof(struct mce));
  166. m.cpu = safe_smp_processor_id();
  167. rdmsrl(MSR_IA32_MCG_STATUS, m.mcgstatus);
  168. if (!(m.mcgstatus & MCG_STATUS_RIPV))
  169. kill_it = 1;
  170. rdtscll(mcestart);
  171. barrier();
  172. for (i = 0; i < banks; i++) {
  173. if (!bank[i])
  174. continue;
  175. m.misc = 0;
  176. m.addr = 0;
  177. m.bank = i;
  178. m.tsc = 0;
  179. rdmsrl(MSR_IA32_MC0_STATUS + i*4, m.status);
  180. if ((m.status & MCI_STATUS_VAL) == 0)
  181. continue;
  182. if (m.status & MCI_STATUS_EN) {
  183. /* In theory _OVER could be a nowayout too, but
  184. assume any overflowed errors were no fatal. */
  185. nowayout |= !!(m.status & MCI_STATUS_PCC);
  186. kill_it |= !!(m.status & MCI_STATUS_UC);
  187. }
  188. if (m.status & MCI_STATUS_MISCV)
  189. rdmsrl(MSR_IA32_MC0_MISC + i*4, m.misc);
  190. if (m.status & MCI_STATUS_ADDRV)
  191. rdmsrl(MSR_IA32_MC0_ADDR + i*4, m.addr);
  192. mce_get_rip(&m, regs);
  193. if (error_code >= 0)
  194. rdtscll(m.tsc);
  195. wrmsrl(MSR_IA32_MC0_STATUS + i*4, 0);
  196. if (error_code != -2)
  197. mce_log(&m);
  198. /* Did this bank cause the exception? */
  199. /* Assume that the bank with uncorrectable errors did it,
  200. and that there is only a single one. */
  201. if ((m.status & MCI_STATUS_UC) && (m.status & MCI_STATUS_EN)) {
  202. panicm = m;
  203. panicm_found = 1;
  204. }
  205. add_taint(TAINT_MACHINE_CHECK);
  206. }
  207. /* Never do anything final in the polling timer */
  208. if (!regs)
  209. goto out;
  210. /* If we didn't find an uncorrectable error, pick
  211. the last one (shouldn't happen, just being safe). */
  212. if (!panicm_found)
  213. panicm = m;
  214. if (nowayout)
  215. mce_panic("Machine check", &panicm, mcestart);
  216. if (kill_it) {
  217. int user_space = 0;
  218. if (m.mcgstatus & MCG_STATUS_RIPV)
  219. user_space = panicm.rip && (panicm.cs & 3);
  220. /* When the machine was in user space and the CPU didn't get
  221. confused it's normally not necessary to panic, unless you
  222. are paranoid (tolerant == 0)
  223. RED-PEN could be more tolerant for MCEs in idle,
  224. but most likely they occur at boot anyways, where
  225. it is best to just halt the machine. */
  226. if ((!user_space && (panic_on_oops || tolerant < 2)) ||
  227. (unsigned)current->pid <= 1)
  228. mce_panic("Uncorrected machine check", &panicm, mcestart);
  229. /* do_exit takes an awful lot of locks and has as
  230. slight risk of deadlocking. If you don't want that
  231. don't set tolerant >= 2 */
  232. if (tolerant < 3)
  233. do_exit(SIGBUS);
  234. }
  235. out:
  236. /* Last thing done in the machine check exception to clear state. */
  237. wrmsrl(MSR_IA32_MCG_STATUS, 0);
  238. }
  239. /*
  240. * Periodic polling timer for "silent" machine check errors.
  241. */
  242. static int check_interval = 5 * 60; /* 5 minutes */
  243. static void mcheck_timer(void *data);
  244. static DECLARE_WORK(mcheck_work, mcheck_timer, NULL);
  245. static void mcheck_check_cpu(void *info)
  246. {
  247. if (mce_available(&current_cpu_data))
  248. do_machine_check(NULL, 0);
  249. }
  250. static void mcheck_timer(void *data)
  251. {
  252. on_each_cpu(mcheck_check_cpu, NULL, 1, 1);
  253. schedule_delayed_work(&mcheck_work, check_interval * HZ);
  254. /*
  255. * It's ok to read stale data here for notify_user and
  256. * console_logged as we'll simply get the updated versions
  257. * on the next mcheck_timer execution and atomic operations
  258. * on console_logged act as synchronization for notify_user
  259. * writes.
  260. */
  261. if (notify_user && console_logged) {
  262. notify_user = 0;
  263. clear_bit(0, &console_logged);
  264. printk(KERN_INFO "Machine check events logged\n");
  265. }
  266. }
  267. static __init int periodic_mcheck_init(void)
  268. {
  269. if (check_interval)
  270. schedule_delayed_work(&mcheck_work, check_interval*HZ);
  271. return 0;
  272. }
  273. __initcall(periodic_mcheck_init);
  274. /*
  275. * Initialize Machine Checks for a CPU.
  276. */
  277. static void mce_init(void *dummy)
  278. {
  279. u64 cap;
  280. int i;
  281. rdmsrl(MSR_IA32_MCG_CAP, cap);
  282. banks = cap & 0xff;
  283. if (banks > NR_BANKS) {
  284. printk(KERN_INFO "MCE: warning: using only %d banks\n", banks);
  285. banks = NR_BANKS;
  286. }
  287. /* Use accurate RIP reporting if available. */
  288. if ((cap & (1<<9)) && ((cap >> 16) & 0xff) >= 9)
  289. rip_msr = MSR_IA32_MCG_EIP;
  290. /* Log the machine checks left over from the previous reset.
  291. This also clears all registers */
  292. do_machine_check(NULL, mce_bootlog ? -1 : -2);
  293. set_in_cr4(X86_CR4_MCE);
  294. if (cap & MCG_CTL_P)
  295. wrmsr(MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
  296. for (i = 0; i < banks; i++) {
  297. wrmsrl(MSR_IA32_MC0_CTL+4*i, bank[i]);
  298. wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
  299. }
  300. }
  301. /* Add per CPU specific workarounds here */
  302. static void __cpuinit mce_cpu_quirks(struct cpuinfo_x86 *c)
  303. {
  304. /* This should be disabled by the BIOS, but isn't always */
  305. if (c->x86_vendor == X86_VENDOR_AMD && c->x86 == 15) {
  306. /* disable GART TBL walk error reporting, which trips off
  307. incorrectly with the IOMMU & 3ware & Cerberus. */
  308. clear_bit(10, &bank[4]);
  309. /* Lots of broken BIOS around that don't clear them
  310. by default and leave crap in there. Don't log. */
  311. mce_bootlog = 0;
  312. }
  313. }
  314. static void __cpuinit mce_cpu_features(struct cpuinfo_x86 *c)
  315. {
  316. switch (c->x86_vendor) {
  317. case X86_VENDOR_INTEL:
  318. mce_intel_feature_init(c);
  319. break;
  320. case X86_VENDOR_AMD:
  321. mce_amd_feature_init(c);
  322. break;
  323. default:
  324. break;
  325. }
  326. }
  327. /*
  328. * Called for each booted CPU to set up machine checks.
  329. * Must be called with preempt off.
  330. */
  331. void __cpuinit mcheck_init(struct cpuinfo_x86 *c)
  332. {
  333. static cpumask_t mce_cpus = CPU_MASK_NONE;
  334. mce_cpu_quirks(c);
  335. if (mce_dont_init ||
  336. cpu_test_and_set(smp_processor_id(), mce_cpus) ||
  337. !mce_available(c))
  338. return;
  339. mce_init(NULL);
  340. mce_cpu_features(c);
  341. }
  342. /*
  343. * Character device to read and clear the MCE log.
  344. */
  345. static void collect_tscs(void *data)
  346. {
  347. unsigned long *cpu_tsc = (unsigned long *)data;
  348. rdtscll(cpu_tsc[smp_processor_id()]);
  349. }
  350. static ssize_t mce_read(struct file *filp, char __user *ubuf, size_t usize, loff_t *off)
  351. {
  352. unsigned long *cpu_tsc;
  353. static DECLARE_MUTEX(mce_read_sem);
  354. unsigned next;
  355. char __user *buf = ubuf;
  356. int i, err;
  357. cpu_tsc = kmalloc(NR_CPUS * sizeof(long), GFP_KERNEL);
  358. if (!cpu_tsc)
  359. return -ENOMEM;
  360. down(&mce_read_sem);
  361. next = rcu_dereference(mcelog.next);
  362. /* Only supports full reads right now */
  363. if (*off != 0 || usize < MCE_LOG_LEN*sizeof(struct mce)) {
  364. up(&mce_read_sem);
  365. kfree(cpu_tsc);
  366. return -EINVAL;
  367. }
  368. err = 0;
  369. for (i = 0; i < next; i++) {
  370. unsigned long start = jiffies;
  371. while (!mcelog.entry[i].finished) {
  372. if (!time_before(jiffies, start + 2)) {
  373. memset(mcelog.entry + i,0, sizeof(struct mce));
  374. continue;
  375. }
  376. cpu_relax();
  377. }
  378. smp_rmb();
  379. err |= copy_to_user(buf, mcelog.entry + i, sizeof(struct mce));
  380. buf += sizeof(struct mce);
  381. }
  382. memset(mcelog.entry, 0, next * sizeof(struct mce));
  383. mcelog.next = 0;
  384. synchronize_sched();
  385. /* Collect entries that were still getting written before the synchronize. */
  386. on_each_cpu(collect_tscs, cpu_tsc, 1, 1);
  387. for (i = next; i < MCE_LOG_LEN; i++) {
  388. if (mcelog.entry[i].finished &&
  389. mcelog.entry[i].tsc < cpu_tsc[mcelog.entry[i].cpu]) {
  390. err |= copy_to_user(buf, mcelog.entry+i, sizeof(struct mce));
  391. smp_rmb();
  392. buf += sizeof(struct mce);
  393. memset(&mcelog.entry[i], 0, sizeof(struct mce));
  394. }
  395. }
  396. up(&mce_read_sem);
  397. kfree(cpu_tsc);
  398. return err ? -EFAULT : buf - ubuf;
  399. }
  400. static int mce_ioctl(struct inode *i, struct file *f,unsigned int cmd, unsigned long arg)
  401. {
  402. int __user *p = (int __user *)arg;
  403. if (!capable(CAP_SYS_ADMIN))
  404. return -EPERM;
  405. switch (cmd) {
  406. case MCE_GET_RECORD_LEN:
  407. return put_user(sizeof(struct mce), p);
  408. case MCE_GET_LOG_LEN:
  409. return put_user(MCE_LOG_LEN, p);
  410. case MCE_GETCLEAR_FLAGS: {
  411. unsigned flags;
  412. do {
  413. flags = mcelog.flags;
  414. } while (cmpxchg(&mcelog.flags, flags, 0) != flags);
  415. return put_user(flags, p);
  416. }
  417. default:
  418. return -ENOTTY;
  419. }
  420. }
  421. static struct file_operations mce_chrdev_ops = {
  422. .read = mce_read,
  423. .ioctl = mce_ioctl,
  424. };
  425. static struct miscdevice mce_log_device = {
  426. MISC_MCELOG_MINOR,
  427. "mcelog",
  428. &mce_chrdev_ops,
  429. };
  430. /*
  431. * Old style boot options parsing. Only for compatibility.
  432. */
  433. static int __init mcheck_disable(char *str)
  434. {
  435. mce_dont_init = 1;
  436. return 0;
  437. }
  438. /* mce=off disables machine check. Note you can reenable it later
  439. using sysfs.
  440. mce=TOLERANCELEVEL (number, see above)
  441. mce=bootlog Log MCEs from before booting. Disabled by default on AMD.
  442. mce=nobootlog Don't log MCEs from before booting. */
  443. static int __init mcheck_enable(char *str)
  444. {
  445. if (*str == '=')
  446. str++;
  447. if (!strcmp(str, "off"))
  448. mce_dont_init = 1;
  449. else if (!strcmp(str, "bootlog") || !strcmp(str,"nobootlog"))
  450. mce_bootlog = str[0] == 'b';
  451. else if (isdigit(str[0]))
  452. get_option(&str, &tolerant);
  453. else
  454. printk("mce= argument %s ignored. Please use /sys", str);
  455. return 0;
  456. }
  457. __setup("nomce", mcheck_disable);
  458. __setup("mce", mcheck_enable);
  459. /*
  460. * Sysfs support
  461. */
  462. /* On resume clear all MCE state. Don't want to see leftovers from the BIOS.
  463. Only one CPU is active at this time, the others get readded later using
  464. CPU hotplug. */
  465. static int mce_resume(struct sys_device *dev)
  466. {
  467. mce_init(NULL);
  468. return 0;
  469. }
  470. /* Reinit MCEs after user configuration changes */
  471. static void mce_restart(void)
  472. {
  473. if (check_interval)
  474. cancel_delayed_work(&mcheck_work);
  475. /* Timer race is harmless here */
  476. on_each_cpu(mce_init, NULL, 1, 1);
  477. if (check_interval)
  478. schedule_delayed_work(&mcheck_work, check_interval*HZ);
  479. }
  480. static struct sysdev_class mce_sysclass = {
  481. .resume = mce_resume,
  482. set_kset_name("machinecheck"),
  483. };
  484. static DEFINE_PER_CPU(struct sys_device, device_mce);
  485. /* Why are there no generic functions for this? */
  486. #define ACCESSOR(name, var, start) \
  487. static ssize_t show_ ## name(struct sys_device *s, char *buf) { \
  488. return sprintf(buf, "%lx\n", (unsigned long)var); \
  489. } \
  490. static ssize_t set_ ## name(struct sys_device *s,const char *buf,size_t siz) { \
  491. char *end; \
  492. unsigned long new = simple_strtoul(buf, &end, 0); \
  493. if (end == buf) return -EINVAL; \
  494. var = new; \
  495. start; \
  496. return end-buf; \
  497. } \
  498. static SYSDEV_ATTR(name, 0644, show_ ## name, set_ ## name);
  499. ACCESSOR(bank0ctl,bank[0],mce_restart())
  500. ACCESSOR(bank1ctl,bank[1],mce_restart())
  501. ACCESSOR(bank2ctl,bank[2],mce_restart())
  502. ACCESSOR(bank3ctl,bank[3],mce_restart())
  503. ACCESSOR(bank4ctl,bank[4],mce_restart())
  504. ACCESSOR(bank5ctl,bank[5],mce_restart())
  505. static struct sysdev_attribute * bank_attributes[NR_BANKS] = {
  506. &attr_bank0ctl, &attr_bank1ctl, &attr_bank2ctl,
  507. &attr_bank3ctl, &attr_bank4ctl, &attr_bank5ctl};
  508. ACCESSOR(tolerant,tolerant,)
  509. ACCESSOR(check_interval,check_interval,mce_restart())
  510. /* Per cpu sysdev init. All of the cpus still share the same ctl bank */
  511. static __cpuinit int mce_create_device(unsigned int cpu)
  512. {
  513. int err;
  514. int i;
  515. if (!mce_available(&cpu_data[cpu]))
  516. return -EIO;
  517. per_cpu(device_mce,cpu).id = cpu;
  518. per_cpu(device_mce,cpu).cls = &mce_sysclass;
  519. err = sysdev_register(&per_cpu(device_mce,cpu));
  520. if (!err) {
  521. for (i = 0; i < banks; i++)
  522. sysdev_create_file(&per_cpu(device_mce,cpu),
  523. bank_attributes[i]);
  524. sysdev_create_file(&per_cpu(device_mce,cpu), &attr_tolerant);
  525. sysdev_create_file(&per_cpu(device_mce,cpu), &attr_check_interval);
  526. }
  527. return err;
  528. }
  529. #ifdef CONFIG_HOTPLUG_CPU
  530. static __cpuinit void mce_remove_device(unsigned int cpu)
  531. {
  532. int i;
  533. for (i = 0; i < banks; i++)
  534. sysdev_remove_file(&per_cpu(device_mce,cpu),
  535. bank_attributes[i]);
  536. sysdev_remove_file(&per_cpu(device_mce,cpu), &attr_tolerant);
  537. sysdev_remove_file(&per_cpu(device_mce,cpu), &attr_check_interval);
  538. sysdev_unregister(&per_cpu(device_mce,cpu));
  539. }
  540. #endif
  541. /* Get notified when a cpu comes on/off. Be hotplug friendly. */
  542. static __cpuinit int
  543. mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
  544. {
  545. unsigned int cpu = (unsigned long)hcpu;
  546. switch (action) {
  547. case CPU_ONLINE:
  548. mce_create_device(cpu);
  549. break;
  550. #ifdef CONFIG_HOTPLUG_CPU
  551. case CPU_DEAD:
  552. mce_remove_device(cpu);
  553. break;
  554. #endif
  555. }
  556. return NOTIFY_OK;
  557. }
  558. static struct notifier_block mce_cpu_notifier = {
  559. .notifier_call = mce_cpu_callback,
  560. };
  561. static __init int mce_init_device(void)
  562. {
  563. int err;
  564. int i = 0;
  565. if (!mce_available(&boot_cpu_data))
  566. return -EIO;
  567. err = sysdev_class_register(&mce_sysclass);
  568. for_each_online_cpu(i) {
  569. mce_create_device(i);
  570. }
  571. register_cpu_notifier(&mce_cpu_notifier);
  572. misc_register(&mce_log_device);
  573. return err;
  574. }
  575. device_initcall(mce_init_device);