mce.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403
  1. /*
  2. * Machine check handler.
  3. *
  4. * K8 parts Copyright 2002,2003 Andi Kleen, SuSE Labs.
  5. * Rest from unknown author(s).
  6. * 2004 Andi Kleen. Rewrote most of it.
  7. * Copyright 2008 Intel Corporation
  8. * Author: Andi Kleen
  9. */
  10. #include <linux/thread_info.h>
  11. #include <linux/capability.h>
  12. #include <linux/miscdevice.h>
  13. #include <linux/ratelimit.h>
  14. #include <linux/kallsyms.h>
  15. #include <linux/rcupdate.h>
  16. #include <linux/kobject.h>
  17. #include <linux/uaccess.h>
  18. #include <linux/kdebug.h>
  19. #include <linux/kernel.h>
  20. #include <linux/percpu.h>
  21. #include <linux/string.h>
  22. #include <linux/sysdev.h>
  23. #include <linux/ctype.h>
  24. #include <linux/sched.h>
  25. #include <linux/sysfs.h>
  26. #include <linux/types.h>
  27. #include <linux/init.h>
  28. #include <linux/kmod.h>
  29. #include <linux/poll.h>
  30. #include <linux/cpu.h>
  31. #include <linux/smp.h>
  32. #include <linux/fs.h>
  33. #include <asm/processor.h>
  34. #include <asm/idle.h>
  35. #include <asm/mce.h>
  36. #include <asm/msr.h>
  37. #include "mce.h"
  38. /* Handle unconfigured int18 (should never happen) */
  39. static void unexpected_machine_check(struct pt_regs *regs, long error_code)
  40. {
  41. printk(KERN_ERR "CPU#%d: Unexpected int18 (Machine Check).\n",
  42. smp_processor_id());
  43. }
  44. /* Call the installed machine check handler for this CPU setup. */
  45. void (*machine_check_vector)(struct pt_regs *, long error_code) =
  46. unexpected_machine_check;
  47. int mce_disabled;
  48. #ifdef CONFIG_X86_NEW_MCE
  49. #define MISC_MCELOG_MINOR 227
  50. atomic_t mce_entry;
  51. DEFINE_PER_CPU(unsigned, mce_exception_count);
  52. /*
  53. * Tolerant levels:
  54. * 0: always panic on uncorrected errors, log corrected errors
  55. * 1: panic or SIGBUS on uncorrected errors, log corrected errors
  56. * 2: SIGBUS or log uncorrected errors (if possible), log corrected errors
  57. * 3: never panic or SIGBUS, log all errors (for testing only)
  58. */
  59. static int tolerant = 1;
  60. static int banks;
  61. static u64 *bank;
  62. static unsigned long notify_user;
  63. static int rip_msr;
  64. static int mce_bootlog = -1;
  65. static char trigger[128];
  66. static char *trigger_argv[2] = { trigger, NULL };
  67. static unsigned long dont_init_banks;
  68. static DECLARE_WAIT_QUEUE_HEAD(mce_wait);
  69. /* MCA banks polled by the period polling timer for corrected events */
  70. DEFINE_PER_CPU(mce_banks_t, mce_poll_banks) = {
  71. [0 ... BITS_TO_LONGS(MAX_NR_BANKS)-1] = ~0UL
  72. };
  73. static inline int skip_bank_init(int i)
  74. {
  75. return i < BITS_PER_LONG && test_bit(i, &dont_init_banks);
  76. }
  77. /* Do initial initialization of a struct mce */
  78. void mce_setup(struct mce *m)
  79. {
  80. memset(m, 0, sizeof(struct mce));
  81. m->cpu = m->extcpu = smp_processor_id();
  82. rdtscll(m->tsc);
  83. /* We hope get_seconds stays lockless */
  84. m->time = get_seconds();
  85. m->cpuvendor = boot_cpu_data.x86_vendor;
  86. m->cpuid = cpuid_eax(1);
  87. #ifdef CONFIG_SMP
  88. m->socketid = cpu_data(m->extcpu).phys_proc_id;
  89. #endif
  90. m->apicid = cpu_data(m->extcpu).initial_apicid;
  91. rdmsrl(MSR_IA32_MCG_CAP, m->mcgcap);
  92. }
  93. DEFINE_PER_CPU(struct mce, injectm);
  94. EXPORT_PER_CPU_SYMBOL_GPL(injectm);
  95. /*
  96. * Lockless MCE logging infrastructure.
  97. * This avoids deadlocks on printk locks without having to break locks. Also
  98. * separate MCEs from kernel messages to avoid bogus bug reports.
  99. */
  100. static struct mce_log mcelog = {
  101. .signature = MCE_LOG_SIGNATURE,
  102. .len = MCE_LOG_LEN,
  103. .recordlen = sizeof(struct mce),
  104. };
  105. void mce_log(struct mce *mce)
  106. {
  107. unsigned next, entry;
  108. mce->finished = 0;
  109. wmb();
  110. for (;;) {
  111. entry = rcu_dereference(mcelog.next);
  112. for (;;) {
  113. /*
  114. * When the buffer fills up discard new entries.
  115. * Assume that the earlier errors are the more
  116. * interesting ones:
  117. */
  118. if (entry >= MCE_LOG_LEN) {
  119. set_bit(MCE_OVERFLOW,
  120. (unsigned long *)&mcelog.flags);
  121. return;
  122. }
  123. /* Old left over entry. Skip: */
  124. if (mcelog.entry[entry].finished) {
  125. entry++;
  126. continue;
  127. }
  128. break;
  129. }
  130. smp_rmb();
  131. next = entry + 1;
  132. if (cmpxchg(&mcelog.next, entry, next) == entry)
  133. break;
  134. }
  135. memcpy(mcelog.entry + entry, mce, sizeof(struct mce));
  136. wmb();
  137. mcelog.entry[entry].finished = 1;
  138. wmb();
  139. mce->finished = 1;
  140. set_bit(0, &notify_user);
  141. }
  142. static void print_mce(struct mce *m)
  143. {
  144. printk(KERN_EMERG "\n"
  145. KERN_EMERG "HARDWARE ERROR\n"
  146. KERN_EMERG
  147. "CPU %d: Machine Check Exception: %16Lx Bank %d: %016Lx\n",
  148. m->extcpu, m->mcgstatus, m->bank, m->status);
  149. if (m->ip) {
  150. printk(KERN_EMERG "RIP%s %02x:<%016Lx> ",
  151. !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
  152. m->cs, m->ip);
  153. if (m->cs == __KERNEL_CS)
  154. print_symbol("{%s}", m->ip);
  155. printk("\n");
  156. }
  157. printk(KERN_EMERG "TSC %llx ", m->tsc);
  158. if (m->addr)
  159. printk("ADDR %llx ", m->addr);
  160. if (m->misc)
  161. printk("MISC %llx ", m->misc);
  162. printk("\n");
  163. printk(KERN_EMERG "PROCESSOR %u:%x TIME %llu SOCKET %u APIC %x\n",
  164. m->cpuvendor, m->cpuid, m->time, m->socketid,
  165. m->apicid);
  166. printk(KERN_EMERG "This is not a software problem!\n");
  167. printk(KERN_EMERG "Run through mcelog --ascii to decode "
  168. "and contact your hardware vendor\n");
  169. }
  170. static void mce_panic(char *msg, struct mce *final)
  171. {
  172. int i;
  173. bust_spinlocks(1);
  174. console_verbose();
  175. /* First print corrected ones that are still unlogged */
  176. for (i = 0; i < MCE_LOG_LEN; i++) {
  177. struct mce *m = &mcelog.entry[i];
  178. if ((m->status & MCI_STATUS_VAL) &&
  179. !(m->status & MCI_STATUS_UC))
  180. print_mce(m);
  181. }
  182. /* Now print uncorrected but with the final one last */
  183. for (i = 0; i < MCE_LOG_LEN; i++) {
  184. struct mce *m = &mcelog.entry[i];
  185. if (!(m->status & MCI_STATUS_VAL))
  186. continue;
  187. if (!final || memcmp(m, final, sizeof(struct mce)))
  188. print_mce(m);
  189. }
  190. if (final)
  191. print_mce(final);
  192. panic(msg);
  193. }
  194. /* Support code for software error injection */
  195. static int msr_to_offset(u32 msr)
  196. {
  197. unsigned bank = __get_cpu_var(injectm.bank);
  198. if (msr == rip_msr)
  199. return offsetof(struct mce, ip);
  200. if (msr == MSR_IA32_MC0_STATUS + bank*4)
  201. return offsetof(struct mce, status);
  202. if (msr == MSR_IA32_MC0_ADDR + bank*4)
  203. return offsetof(struct mce, addr);
  204. if (msr == MSR_IA32_MC0_MISC + bank*4)
  205. return offsetof(struct mce, misc);
  206. if (msr == MSR_IA32_MCG_STATUS)
  207. return offsetof(struct mce, mcgstatus);
  208. return -1;
  209. }
  210. /* MSR access wrappers used for error injection */
  211. static u64 mce_rdmsrl(u32 msr)
  212. {
  213. u64 v;
  214. if (__get_cpu_var(injectm).finished) {
  215. int offset = msr_to_offset(msr);
  216. if (offset < 0)
  217. return 0;
  218. return *(u64 *)((char *)&__get_cpu_var(injectm) + offset);
  219. }
  220. rdmsrl(msr, v);
  221. return v;
  222. }
  223. static void mce_wrmsrl(u32 msr, u64 v)
  224. {
  225. if (__get_cpu_var(injectm).finished) {
  226. int offset = msr_to_offset(msr);
  227. if (offset >= 0)
  228. *(u64 *)((char *)&__get_cpu_var(injectm) + offset) = v;
  229. return;
  230. }
  231. wrmsrl(msr, v);
  232. }
  233. int mce_available(struct cpuinfo_x86 *c)
  234. {
  235. if (mce_disabled)
  236. return 0;
  237. return cpu_has(c, X86_FEATURE_MCE) && cpu_has(c, X86_FEATURE_MCA);
  238. }
  239. static inline void mce_get_rip(struct mce *m, struct pt_regs *regs)
  240. {
  241. if (regs && (m->mcgstatus & MCG_STATUS_RIPV)) {
  242. m->ip = regs->ip;
  243. m->cs = regs->cs;
  244. } else {
  245. m->ip = 0;
  246. m->cs = 0;
  247. }
  248. if (rip_msr) {
  249. /* Assume the RIP in the MSR is exact. Is this true? */
  250. m->mcgstatus |= MCG_STATUS_EIPV;
  251. m->ip = mce_rdmsrl(rip_msr);
  252. m->cs = 0;
  253. }
  254. }
  255. DEFINE_PER_CPU(unsigned, mce_poll_count);
  256. /*
  257. * Poll for corrected events or events that happened before reset.
  258. * Those are just logged through /dev/mcelog.
  259. *
  260. * This is executed in standard interrupt context.
  261. */
  262. void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)
  263. {
  264. struct mce m;
  265. int i;
  266. __get_cpu_var(mce_poll_count)++;
  267. mce_setup(&m);
  268. m.mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS);
  269. for (i = 0; i < banks; i++) {
  270. if (!bank[i] || !test_bit(i, *b))
  271. continue;
  272. m.misc = 0;
  273. m.addr = 0;
  274. m.bank = i;
  275. m.tsc = 0;
  276. barrier();
  277. m.status = mce_rdmsrl(MSR_IA32_MC0_STATUS + i*4);
  278. if (!(m.status & MCI_STATUS_VAL))
  279. continue;
  280. /*
  281. * Uncorrected events are handled by the exception handler
  282. * when it is enabled. But when the exception is disabled log
  283. * everything.
  284. *
  285. * TBD do the same check for MCI_STATUS_EN here?
  286. */
  287. if ((m.status & MCI_STATUS_UC) && !(flags & MCP_UC))
  288. continue;
  289. if (m.status & MCI_STATUS_MISCV)
  290. m.misc = mce_rdmsrl(MSR_IA32_MC0_MISC + i*4);
  291. if (m.status & MCI_STATUS_ADDRV)
  292. m.addr = mce_rdmsrl(MSR_IA32_MC0_ADDR + i*4);
  293. if (!(flags & MCP_TIMESTAMP))
  294. m.tsc = 0;
  295. /*
  296. * Don't get the IP here because it's unlikely to
  297. * have anything to do with the actual error location.
  298. */
  299. if (!(flags & MCP_DONTLOG)) {
  300. mce_log(&m);
  301. add_taint(TAINT_MACHINE_CHECK);
  302. }
  303. /*
  304. * Clear state for this bank.
  305. */
  306. mce_wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
  307. }
  308. /*
  309. * Don't clear MCG_STATUS here because it's only defined for
  310. * exceptions.
  311. */
  312. sync_core();
  313. }
  314. EXPORT_SYMBOL_GPL(machine_check_poll);
  315. /*
  316. * The actual machine check handler. This only handles real
  317. * exceptions when something got corrupted coming in through int 18.
  318. *
  319. * This is executed in NMI context not subject to normal locking rules. This
  320. * implies that most kernel services cannot be safely used. Don't even
  321. * think about putting a printk in there!
  322. */
  323. void do_machine_check(struct pt_regs *regs, long error_code)
  324. {
  325. struct mce m, panicm;
  326. int panicm_found = 0;
  327. int i;
  328. /*
  329. * If no_way_out gets set, there is no safe way to recover from this
  330. * MCE. If tolerant is cranked up, we'll try anyway.
  331. */
  332. int no_way_out = 0;
  333. /*
  334. * If kill_it gets set, there might be a way to recover from this
  335. * error.
  336. */
  337. int kill_it = 0;
  338. DECLARE_BITMAP(toclear, MAX_NR_BANKS);
  339. atomic_inc(&mce_entry);
  340. __get_cpu_var(mce_exception_count)++;
  341. if (notify_die(DIE_NMI, "machine check", regs, error_code,
  342. 18, SIGKILL) == NOTIFY_STOP)
  343. goto out;
  344. if (!banks)
  345. goto out;
  346. mce_setup(&m);
  347. m.mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS);
  348. /* if the restart IP is not valid, we're done for */
  349. if (!(m.mcgstatus & MCG_STATUS_RIPV))
  350. no_way_out = 1;
  351. barrier();
  352. for (i = 0; i < banks; i++) {
  353. __clear_bit(i, toclear);
  354. if (!bank[i])
  355. continue;
  356. m.misc = 0;
  357. m.addr = 0;
  358. m.bank = i;
  359. m.status = mce_rdmsrl(MSR_IA32_MC0_STATUS + i*4);
  360. if ((m.status & MCI_STATUS_VAL) == 0)
  361. continue;
  362. /*
  363. * Non uncorrected errors are handled by machine_check_poll
  364. * Leave them alone, unless this panics.
  365. */
  366. if ((m.status & MCI_STATUS_UC) == 0 && !no_way_out)
  367. continue;
  368. /*
  369. * Set taint even when machine check was not enabled.
  370. */
  371. add_taint(TAINT_MACHINE_CHECK);
  372. __set_bit(i, toclear);
  373. if (m.status & MCI_STATUS_EN) {
  374. /* if PCC was set, there's no way out */
  375. no_way_out |= !!(m.status & MCI_STATUS_PCC);
  376. /*
  377. * If this error was uncorrectable and there was
  378. * an overflow, we're in trouble. If no overflow,
  379. * we might get away with just killing a task.
  380. */
  381. if (m.status & MCI_STATUS_UC) {
  382. if (tolerant < 1 || m.status & MCI_STATUS_OVER)
  383. no_way_out = 1;
  384. kill_it = 1;
  385. }
  386. } else {
  387. /*
  388. * Machine check event was not enabled. Clear, but
  389. * ignore.
  390. */
  391. continue;
  392. }
  393. if (m.status & MCI_STATUS_MISCV)
  394. m.misc = mce_rdmsrl(MSR_IA32_MC0_MISC + i*4);
  395. if (m.status & MCI_STATUS_ADDRV)
  396. m.addr = mce_rdmsrl(MSR_IA32_MC0_ADDR + i*4);
  397. mce_get_rip(&m, regs);
  398. mce_log(&m);
  399. /*
  400. * Did this bank cause the exception?
  401. *
  402. * Assume that the bank with uncorrectable errors did it,
  403. * and that there is only a single one:
  404. */
  405. if ((m.status & MCI_STATUS_UC) &&
  406. (m.status & MCI_STATUS_EN)) {
  407. panicm = m;
  408. panicm_found = 1;
  409. }
  410. }
  411. /*
  412. * If we didn't find an uncorrectable error, pick
  413. * the last one (shouldn't happen, just being safe).
  414. */
  415. if (!panicm_found)
  416. panicm = m;
  417. /*
  418. * If we have decided that we just CAN'T continue, and the user
  419. * has not set tolerant to an insane level, give up and die.
  420. */
  421. if (no_way_out && tolerant < 3)
  422. mce_panic("Machine check", &panicm);
  423. /*
  424. * If the error seems to be unrecoverable, something should be
  425. * done. Try to kill as little as possible. If we can kill just
  426. * one task, do that. If the user has set the tolerance very
  427. * high, don't try to do anything at all.
  428. */
  429. if (kill_it && tolerant < 3) {
  430. int user_space = 0;
  431. /*
  432. * If the EIPV bit is set, it means the saved IP is the
  433. * instruction which caused the MCE.
  434. */
  435. if (m.mcgstatus & MCG_STATUS_EIPV)
  436. user_space = panicm.ip && (panicm.cs & 3);
  437. /*
  438. * If we know that the error was in user space, send a
  439. * SIGBUS. Otherwise, panic if tolerance is low.
  440. *
  441. * force_sig() takes an awful lot of locks and has a slight
  442. * risk of deadlocking.
  443. */
  444. if (user_space) {
  445. force_sig(SIGBUS, current);
  446. } else if (panic_on_oops || tolerant < 2) {
  447. mce_panic("Uncorrected machine check", &panicm);
  448. }
  449. }
  450. /* notify userspace ASAP */
  451. set_thread_flag(TIF_MCE_NOTIFY);
  452. /* the last thing we do is clear state */
  453. for (i = 0; i < banks; i++) {
  454. if (test_bit(i, toclear))
  455. mce_wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
  456. }
  457. mce_wrmsrl(MSR_IA32_MCG_STATUS, 0);
  458. out:
  459. atomic_dec(&mce_entry);
  460. sync_core();
  461. }
  462. EXPORT_SYMBOL_GPL(do_machine_check);
  463. #ifdef CONFIG_X86_MCE_INTEL
  464. /***
  465. * mce_log_therm_throt_event - Logs the thermal throttling event to mcelog
  466. * @cpu: The CPU on which the event occurred.
  467. * @status: Event status information
  468. *
  469. * This function should be called by the thermal interrupt after the
  470. * event has been processed and the decision was made to log the event
  471. * further.
  472. *
  473. * The status parameter will be saved to the 'status' field of 'struct mce'
  474. * and historically has been the register value of the
  475. * MSR_IA32_THERMAL_STATUS (Intel) msr.
  476. */
  477. void mce_log_therm_throt_event(__u64 status)
  478. {
  479. struct mce m;
  480. mce_setup(&m);
  481. m.bank = MCE_THERMAL_BANK;
  482. m.status = status;
  483. mce_log(&m);
  484. }
  485. #endif /* CONFIG_X86_MCE_INTEL */
  486. /*
  487. * Periodic polling timer for "silent" machine check errors. If the
  488. * poller finds an MCE, poll 2x faster. When the poller finds no more
  489. * errors, poll 2x slower (up to check_interval seconds).
  490. */
  491. static int check_interval = 5 * 60; /* 5 minutes */
  492. static DEFINE_PER_CPU(int, next_interval); /* in jiffies */
  493. static DEFINE_PER_CPU(struct timer_list, mce_timer);
  494. static void mcheck_timer(unsigned long data)
  495. {
  496. struct timer_list *t = &per_cpu(mce_timer, data);
  497. int *n;
  498. WARN_ON(smp_processor_id() != data);
  499. if (mce_available(&current_cpu_data)) {
  500. machine_check_poll(MCP_TIMESTAMP,
  501. &__get_cpu_var(mce_poll_banks));
  502. }
  503. /*
  504. * Alert userspace if needed. If we logged an MCE, reduce the
  505. * polling interval, otherwise increase the polling interval.
  506. */
  507. n = &__get_cpu_var(next_interval);
  508. if (mce_notify_user())
  509. *n = max(*n/2, HZ/100);
  510. else
  511. *n = min(*n*2, (int)round_jiffies_relative(check_interval*HZ));
  512. t->expires = jiffies + *n;
  513. add_timer(t);
  514. }
  515. static void mce_do_trigger(struct work_struct *work)
  516. {
  517. call_usermodehelper(trigger, trigger_argv, NULL, UMH_NO_WAIT);
  518. }
  519. static DECLARE_WORK(mce_trigger_work, mce_do_trigger);
  520. /*
  521. * Notify the user(s) about new machine check events.
  522. * Can be called from interrupt context, but not from machine check/NMI
  523. * context.
  524. */
  525. int mce_notify_user(void)
  526. {
  527. /* Not more than two messages every minute */
  528. static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
  529. clear_thread_flag(TIF_MCE_NOTIFY);
  530. if (test_and_clear_bit(0, &notify_user)) {
  531. wake_up_interruptible(&mce_wait);
  532. /*
  533. * There is no risk of missing notifications because
  534. * work_pending is always cleared before the function is
  535. * executed.
  536. */
  537. if (trigger[0] && !work_pending(&mce_trigger_work))
  538. schedule_work(&mce_trigger_work);
  539. if (__ratelimit(&ratelimit))
  540. printk(KERN_INFO "Machine check events logged\n");
  541. return 1;
  542. }
  543. return 0;
  544. }
  545. EXPORT_SYMBOL_GPL(mce_notify_user);
  546. /*
  547. * Initialize Machine Checks for a CPU.
  548. */
  549. static int mce_cap_init(void)
  550. {
  551. unsigned b;
  552. u64 cap;
  553. rdmsrl(MSR_IA32_MCG_CAP, cap);
  554. b = cap & MCG_BANKCNT_MASK;
  555. printk(KERN_INFO "mce: CPU supports %d MCE banks\n", b);
  556. if (b > MAX_NR_BANKS) {
  557. printk(KERN_WARNING
  558. "MCE: Using only %u machine check banks out of %u\n",
  559. MAX_NR_BANKS, b);
  560. b = MAX_NR_BANKS;
  561. }
  562. /* Don't support asymmetric configurations today */
  563. WARN_ON(banks != 0 && b != banks);
  564. banks = b;
  565. if (!bank) {
  566. bank = kmalloc(banks * sizeof(u64), GFP_KERNEL);
  567. if (!bank)
  568. return -ENOMEM;
  569. memset(bank, 0xff, banks * sizeof(u64));
  570. }
  571. /* Use accurate RIP reporting if available. */
  572. if ((cap & MCG_EXT_P) && MCG_EXT_CNT(cap) >= 9)
  573. rip_msr = MSR_IA32_MCG_EIP;
  574. return 0;
  575. }
  576. static void mce_init(void)
  577. {
  578. mce_banks_t all_banks;
  579. u64 cap;
  580. int i;
  581. /*
  582. * Log the machine checks left over from the previous reset.
  583. */
  584. bitmap_fill(all_banks, MAX_NR_BANKS);
  585. machine_check_poll(MCP_UC|(!mce_bootlog ? MCP_DONTLOG : 0), &all_banks);
  586. set_in_cr4(X86_CR4_MCE);
  587. rdmsrl(MSR_IA32_MCG_CAP, cap);
  588. if (cap & MCG_CTL_P)
  589. wrmsr(MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
  590. for (i = 0; i < banks; i++) {
  591. if (skip_bank_init(i))
  592. continue;
  593. wrmsrl(MSR_IA32_MC0_CTL+4*i, bank[i]);
  594. wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
  595. }
  596. }
  597. /* Add per CPU specific workarounds here */
  598. static void mce_cpu_quirks(struct cpuinfo_x86 *c)
  599. {
  600. /* This should be disabled by the BIOS, but isn't always */
  601. if (c->x86_vendor == X86_VENDOR_AMD) {
  602. if (c->x86 == 15 && banks > 4) {
  603. /*
  604. * disable GART TBL walk error reporting, which
  605. * trips off incorrectly with the IOMMU & 3ware
  606. * & Cerberus:
  607. */
  608. clear_bit(10, (unsigned long *)&bank[4]);
  609. }
  610. if (c->x86 <= 17 && mce_bootlog < 0) {
  611. /*
  612. * Lots of broken BIOS around that don't clear them
  613. * by default and leave crap in there. Don't log:
  614. */
  615. mce_bootlog = 0;
  616. }
  617. /*
  618. * Various K7s with broken bank 0 around. Always disable
  619. * by default.
  620. */
  621. if (c->x86 == 6)
  622. bank[0] = 0;
  623. }
  624. if (c->x86_vendor == X86_VENDOR_INTEL) {
  625. /*
  626. * SDM documents that on family 6 bank 0 should not be written
  627. * because it aliases to another special BIOS controlled
  628. * register.
  629. * But it's not aliased anymore on model 0x1a+
  630. * Don't ignore bank 0 completely because there could be a
  631. * valid event later, merely don't write CTL0.
  632. */
  633. if (c->x86 == 6 && c->x86_model < 0x1A)
  634. __set_bit(0, &dont_init_banks);
  635. }
  636. }
  637. static void __cpuinit mce_ancient_init(struct cpuinfo_x86 *c)
  638. {
  639. if (c->x86 != 5)
  640. return;
  641. switch (c->x86_vendor) {
  642. case X86_VENDOR_INTEL:
  643. if (mce_p5_enabled())
  644. intel_p5_mcheck_init(c);
  645. break;
  646. case X86_VENDOR_CENTAUR:
  647. winchip_mcheck_init(c);
  648. break;
  649. }
  650. }
  651. static void mce_cpu_features(struct cpuinfo_x86 *c)
  652. {
  653. switch (c->x86_vendor) {
  654. case X86_VENDOR_INTEL:
  655. mce_intel_feature_init(c);
  656. break;
  657. case X86_VENDOR_AMD:
  658. mce_amd_feature_init(c);
  659. break;
  660. default:
  661. break;
  662. }
  663. }
  664. static void mce_init_timer(void)
  665. {
  666. struct timer_list *t = &__get_cpu_var(mce_timer);
  667. int *n = &__get_cpu_var(next_interval);
  668. *n = check_interval * HZ;
  669. if (!*n)
  670. return;
  671. setup_timer(t, mcheck_timer, smp_processor_id());
  672. t->expires = round_jiffies(jiffies + *n);
  673. add_timer(t);
  674. }
  675. /*
  676. * Called for each booted CPU to set up machine checks.
  677. * Must be called with preempt off:
  678. */
  679. void __cpuinit mcheck_init(struct cpuinfo_x86 *c)
  680. {
  681. if (mce_disabled)
  682. return;
  683. mce_ancient_init(c);
  684. if (!mce_available(c))
  685. return;
  686. if (mce_cap_init() < 0) {
  687. mce_disabled = 1;
  688. return;
  689. }
  690. mce_cpu_quirks(c);
  691. machine_check_vector = do_machine_check;
  692. mce_init();
  693. mce_cpu_features(c);
  694. mce_init_timer();
  695. }
  696. /*
  697. * Character device to read and clear the MCE log.
  698. */
  699. static DEFINE_SPINLOCK(mce_state_lock);
  700. static int open_count; /* #times opened */
  701. static int open_exclu; /* already open exclusive? */
  702. static int mce_open(struct inode *inode, struct file *file)
  703. {
  704. spin_lock(&mce_state_lock);
  705. if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
  706. spin_unlock(&mce_state_lock);
  707. return -EBUSY;
  708. }
  709. if (file->f_flags & O_EXCL)
  710. open_exclu = 1;
  711. open_count++;
  712. spin_unlock(&mce_state_lock);
  713. return nonseekable_open(inode, file);
  714. }
  715. static int mce_release(struct inode *inode, struct file *file)
  716. {
  717. spin_lock(&mce_state_lock);
  718. open_count--;
  719. open_exclu = 0;
  720. spin_unlock(&mce_state_lock);
  721. return 0;
  722. }
  723. static void collect_tscs(void *data)
  724. {
  725. unsigned long *cpu_tsc = (unsigned long *)data;
  726. rdtscll(cpu_tsc[smp_processor_id()]);
  727. }
  728. static DEFINE_MUTEX(mce_read_mutex);
  729. static ssize_t mce_read(struct file *filp, char __user *ubuf, size_t usize,
  730. loff_t *off)
  731. {
  732. char __user *buf = ubuf;
  733. unsigned long *cpu_tsc;
  734. unsigned prev, next;
  735. int i, err;
  736. cpu_tsc = kmalloc(nr_cpu_ids * sizeof(long), GFP_KERNEL);
  737. if (!cpu_tsc)
  738. return -ENOMEM;
  739. mutex_lock(&mce_read_mutex);
  740. next = rcu_dereference(mcelog.next);
  741. /* Only supports full reads right now */
  742. if (*off != 0 || usize < MCE_LOG_LEN*sizeof(struct mce)) {
  743. mutex_unlock(&mce_read_mutex);
  744. kfree(cpu_tsc);
  745. return -EINVAL;
  746. }
  747. err = 0;
  748. prev = 0;
  749. do {
  750. for (i = prev; i < next; i++) {
  751. unsigned long start = jiffies;
  752. while (!mcelog.entry[i].finished) {
  753. if (time_after_eq(jiffies, start + 2)) {
  754. memset(mcelog.entry + i, 0,
  755. sizeof(struct mce));
  756. goto timeout;
  757. }
  758. cpu_relax();
  759. }
  760. smp_rmb();
  761. err |= copy_to_user(buf, mcelog.entry + i,
  762. sizeof(struct mce));
  763. buf += sizeof(struct mce);
  764. timeout:
  765. ;
  766. }
  767. memset(mcelog.entry + prev, 0,
  768. (next - prev) * sizeof(struct mce));
  769. prev = next;
  770. next = cmpxchg(&mcelog.next, prev, 0);
  771. } while (next != prev);
  772. synchronize_sched();
  773. /*
  774. * Collect entries that were still getting written before the
  775. * synchronize.
  776. */
  777. on_each_cpu(collect_tscs, cpu_tsc, 1);
  778. for (i = next; i < MCE_LOG_LEN; i++) {
  779. if (mcelog.entry[i].finished &&
  780. mcelog.entry[i].tsc < cpu_tsc[mcelog.entry[i].cpu]) {
  781. err |= copy_to_user(buf, mcelog.entry+i,
  782. sizeof(struct mce));
  783. smp_rmb();
  784. buf += sizeof(struct mce);
  785. memset(&mcelog.entry[i], 0, sizeof(struct mce));
  786. }
  787. }
  788. mutex_unlock(&mce_read_mutex);
  789. kfree(cpu_tsc);
  790. return err ? -EFAULT : buf - ubuf;
  791. }
  792. static unsigned int mce_poll(struct file *file, poll_table *wait)
  793. {
  794. poll_wait(file, &mce_wait, wait);
  795. if (rcu_dereference(mcelog.next))
  796. return POLLIN | POLLRDNORM;
  797. return 0;
  798. }
  799. static long mce_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
  800. {
  801. int __user *p = (int __user *)arg;
  802. if (!capable(CAP_SYS_ADMIN))
  803. return -EPERM;
  804. switch (cmd) {
  805. case MCE_GET_RECORD_LEN:
  806. return put_user(sizeof(struct mce), p);
  807. case MCE_GET_LOG_LEN:
  808. return put_user(MCE_LOG_LEN, p);
  809. case MCE_GETCLEAR_FLAGS: {
  810. unsigned flags;
  811. do {
  812. flags = mcelog.flags;
  813. } while (cmpxchg(&mcelog.flags, flags, 0) != flags);
  814. return put_user(flags, p);
  815. }
  816. default:
  817. return -ENOTTY;
  818. }
  819. }
  820. /* Modified in mce-inject.c, so not static or const */
  821. struct file_operations mce_chrdev_ops = {
  822. .open = mce_open,
  823. .release = mce_release,
  824. .read = mce_read,
  825. .poll = mce_poll,
  826. .unlocked_ioctl = mce_ioctl,
  827. };
  828. EXPORT_SYMBOL_GPL(mce_chrdev_ops);
  829. static struct miscdevice mce_log_device = {
  830. MISC_MCELOG_MINOR,
  831. "mcelog",
  832. &mce_chrdev_ops,
  833. };
  834. /*
  835. * mce=off disables machine check
  836. * mce=TOLERANCELEVEL (number, see above)
  837. * mce=bootlog Log MCEs from before booting. Disabled by default on AMD.
  838. * mce=nobootlog Don't log MCEs from before booting.
  839. */
  840. static int __init mcheck_enable(char *str)
  841. {
  842. if (*str == 0)
  843. enable_p5_mce();
  844. if (*str == '=')
  845. str++;
  846. if (!strcmp(str, "off"))
  847. mce_disabled = 1;
  848. else if (!strcmp(str, "bootlog") || !strcmp(str, "nobootlog"))
  849. mce_bootlog = (str[0] == 'b');
  850. else if (isdigit(str[0]))
  851. get_option(&str, &tolerant);
  852. else {
  853. printk(KERN_INFO "mce argument %s ignored. Please use /sys\n",
  854. str);
  855. return 0;
  856. }
  857. return 1;
  858. }
  859. __setup("mce", mcheck_enable);
  860. /*
  861. * Sysfs support
  862. */
  863. /*
  864. * Disable machine checks on suspend and shutdown. We can't really handle
  865. * them later.
  866. */
  867. static int mce_disable(void)
  868. {
  869. int i;
  870. for (i = 0; i < banks; i++) {
  871. if (!skip_bank_init(i))
  872. wrmsrl(MSR_IA32_MC0_CTL + i*4, 0);
  873. }
  874. return 0;
  875. }
  876. static int mce_suspend(struct sys_device *dev, pm_message_t state)
  877. {
  878. return mce_disable();
  879. }
  880. static int mce_shutdown(struct sys_device *dev)
  881. {
  882. return mce_disable();
  883. }
  884. /*
  885. * On resume clear all MCE state. Don't want to see leftovers from the BIOS.
  886. * Only one CPU is active at this time, the others get re-added later using
  887. * CPU hotplug:
  888. */
  889. static int mce_resume(struct sys_device *dev)
  890. {
  891. mce_init();
  892. mce_cpu_features(&current_cpu_data);
  893. return 0;
  894. }
  895. static void mce_cpu_restart(void *data)
  896. {
  897. del_timer_sync(&__get_cpu_var(mce_timer));
  898. if (mce_available(&current_cpu_data))
  899. mce_init();
  900. mce_init_timer();
  901. }
  902. /* Reinit MCEs after user configuration changes */
  903. static void mce_restart(void)
  904. {
  905. on_each_cpu(mce_cpu_restart, NULL, 1);
  906. }
  907. static struct sysdev_class mce_sysclass = {
  908. .suspend = mce_suspend,
  909. .shutdown = mce_shutdown,
  910. .resume = mce_resume,
  911. .name = "machinecheck",
  912. };
  913. DEFINE_PER_CPU(struct sys_device, mce_dev);
  914. __cpuinitdata
  915. void (*threshold_cpu_callback)(unsigned long action, unsigned int cpu);
  916. static struct sysdev_attribute *bank_attrs;
  917. static ssize_t show_bank(struct sys_device *s, struct sysdev_attribute *attr,
  918. char *buf)
  919. {
  920. u64 b = bank[attr - bank_attrs];
  921. return sprintf(buf, "%llx\n", b);
  922. }
  923. static ssize_t set_bank(struct sys_device *s, struct sysdev_attribute *attr,
  924. const char *buf, size_t size)
  925. {
  926. u64 new;
  927. if (strict_strtoull(buf, 0, &new) < 0)
  928. return -EINVAL;
  929. bank[attr - bank_attrs] = new;
  930. mce_restart();
  931. return size;
  932. }
  933. static ssize_t
  934. show_trigger(struct sys_device *s, struct sysdev_attribute *attr, char *buf)
  935. {
  936. strcpy(buf, trigger);
  937. strcat(buf, "\n");
  938. return strlen(trigger) + 1;
  939. }
  940. static ssize_t set_trigger(struct sys_device *s, struct sysdev_attribute *attr,
  941. const char *buf, size_t siz)
  942. {
  943. char *p;
  944. int len;
  945. strncpy(trigger, buf, sizeof(trigger));
  946. trigger[sizeof(trigger)-1] = 0;
  947. len = strlen(trigger);
  948. p = strchr(trigger, '\n');
  949. if (*p)
  950. *p = 0;
  951. return len;
  952. }
  953. static ssize_t store_int_with_restart(struct sys_device *s,
  954. struct sysdev_attribute *attr,
  955. const char *buf, size_t size)
  956. {
  957. ssize_t ret = sysdev_store_int(s, attr, buf, size);
  958. mce_restart();
  959. return ret;
  960. }
  961. static SYSDEV_ATTR(trigger, 0644, show_trigger, set_trigger);
  962. static SYSDEV_INT_ATTR(tolerant, 0644, tolerant);
  963. static struct sysdev_ext_attribute attr_check_interval = {
  964. _SYSDEV_ATTR(check_interval, 0644, sysdev_show_int,
  965. store_int_with_restart),
  966. &check_interval
  967. };
  968. static struct sysdev_attribute *mce_attrs[] = {
  969. &attr_tolerant.attr, &attr_check_interval.attr, &attr_trigger,
  970. NULL
  971. };
  972. static cpumask_var_t mce_dev_initialized;
  973. /* Per cpu sysdev init. All of the cpus still share the same ctrl bank: */
  974. static __cpuinit int mce_create_device(unsigned int cpu)
  975. {
  976. int err;
  977. int i;
  978. if (!mce_available(&boot_cpu_data))
  979. return -EIO;
  980. memset(&per_cpu(mce_dev, cpu).kobj, 0, sizeof(struct kobject));
  981. per_cpu(mce_dev, cpu).id = cpu;
  982. per_cpu(mce_dev, cpu).cls = &mce_sysclass;
  983. err = sysdev_register(&per_cpu(mce_dev, cpu));
  984. if (err)
  985. return err;
  986. for (i = 0; mce_attrs[i]; i++) {
  987. err = sysdev_create_file(&per_cpu(mce_dev, cpu), mce_attrs[i]);
  988. if (err)
  989. goto error;
  990. }
  991. for (i = 0; i < banks; i++) {
  992. err = sysdev_create_file(&per_cpu(mce_dev, cpu),
  993. &bank_attrs[i]);
  994. if (err)
  995. goto error2;
  996. }
  997. cpumask_set_cpu(cpu, mce_dev_initialized);
  998. return 0;
  999. error2:
  1000. while (--i >= 0)
  1001. sysdev_remove_file(&per_cpu(mce_dev, cpu), &bank_attrs[i]);
  1002. error:
  1003. while (--i >= 0)
  1004. sysdev_remove_file(&per_cpu(mce_dev, cpu), mce_attrs[i]);
  1005. sysdev_unregister(&per_cpu(mce_dev, cpu));
  1006. return err;
  1007. }
  1008. static __cpuinit void mce_remove_device(unsigned int cpu)
  1009. {
  1010. int i;
  1011. if (!cpumask_test_cpu(cpu, mce_dev_initialized))
  1012. return;
  1013. for (i = 0; mce_attrs[i]; i++)
  1014. sysdev_remove_file(&per_cpu(mce_dev, cpu), mce_attrs[i]);
  1015. for (i = 0; i < banks; i++)
  1016. sysdev_remove_file(&per_cpu(mce_dev, cpu), &bank_attrs[i]);
  1017. sysdev_unregister(&per_cpu(mce_dev, cpu));
  1018. cpumask_clear_cpu(cpu, mce_dev_initialized);
  1019. }
  1020. /* Make sure there are no machine checks on offlined CPUs. */
  1021. static void mce_disable_cpu(void *h)
  1022. {
  1023. unsigned long action = *(unsigned long *)h;
  1024. int i;
  1025. if (!mce_available(&current_cpu_data))
  1026. return;
  1027. if (!(action & CPU_TASKS_FROZEN))
  1028. cmci_clear();
  1029. for (i = 0; i < banks; i++) {
  1030. if (!skip_bank_init(i))
  1031. wrmsrl(MSR_IA32_MC0_CTL + i*4, 0);
  1032. }
  1033. }
  1034. static void mce_reenable_cpu(void *h)
  1035. {
  1036. unsigned long action = *(unsigned long *)h;
  1037. int i;
  1038. if (!mce_available(&current_cpu_data))
  1039. return;
  1040. if (!(action & CPU_TASKS_FROZEN))
  1041. cmci_reenable();
  1042. for (i = 0; i < banks; i++) {
  1043. if (!skip_bank_init(i))
  1044. wrmsrl(MSR_IA32_MC0_CTL + i*4, bank[i]);
  1045. }
  1046. }
  1047. /* Get notified when a cpu comes on/off. Be hotplug friendly. */
  1048. static int __cpuinit
  1049. mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
  1050. {
  1051. unsigned int cpu = (unsigned long)hcpu;
  1052. struct timer_list *t = &per_cpu(mce_timer, cpu);
  1053. switch (action) {
  1054. case CPU_ONLINE:
  1055. case CPU_ONLINE_FROZEN:
  1056. mce_create_device(cpu);
  1057. if (threshold_cpu_callback)
  1058. threshold_cpu_callback(action, cpu);
  1059. break;
  1060. case CPU_DEAD:
  1061. case CPU_DEAD_FROZEN:
  1062. if (threshold_cpu_callback)
  1063. threshold_cpu_callback(action, cpu);
  1064. mce_remove_device(cpu);
  1065. break;
  1066. case CPU_DOWN_PREPARE:
  1067. case CPU_DOWN_PREPARE_FROZEN:
  1068. del_timer_sync(t);
  1069. smp_call_function_single(cpu, mce_disable_cpu, &action, 1);
  1070. break;
  1071. case CPU_DOWN_FAILED:
  1072. case CPU_DOWN_FAILED_FROZEN:
  1073. t->expires = round_jiffies(jiffies +
  1074. __get_cpu_var(next_interval));
  1075. add_timer_on(t, cpu);
  1076. smp_call_function_single(cpu, mce_reenable_cpu, &action, 1);
  1077. break;
  1078. case CPU_POST_DEAD:
  1079. /* intentionally ignoring frozen here */
  1080. cmci_rediscover(cpu);
  1081. break;
  1082. }
  1083. return NOTIFY_OK;
  1084. }
  1085. static struct notifier_block mce_cpu_notifier __cpuinitdata = {
  1086. .notifier_call = mce_cpu_callback,
  1087. };
  1088. static __init int mce_init_banks(void)
  1089. {
  1090. int i;
  1091. bank_attrs = kzalloc(sizeof(struct sysdev_attribute) * banks,
  1092. GFP_KERNEL);
  1093. if (!bank_attrs)
  1094. return -ENOMEM;
  1095. for (i = 0; i < banks; i++) {
  1096. struct sysdev_attribute *a = &bank_attrs[i];
  1097. a->attr.name = kasprintf(GFP_KERNEL, "bank%d", i);
  1098. if (!a->attr.name)
  1099. goto nomem;
  1100. a->attr.mode = 0644;
  1101. a->show = show_bank;
  1102. a->store = set_bank;
  1103. }
  1104. return 0;
  1105. nomem:
  1106. while (--i >= 0)
  1107. kfree(bank_attrs[i].attr.name);
  1108. kfree(bank_attrs);
  1109. bank_attrs = NULL;
  1110. return -ENOMEM;
  1111. }
  1112. static __init int mce_init_device(void)
  1113. {
  1114. int err;
  1115. int i = 0;
  1116. if (!mce_available(&boot_cpu_data))
  1117. return -EIO;
  1118. alloc_cpumask_var(&mce_dev_initialized, GFP_KERNEL);
  1119. err = mce_init_banks();
  1120. if (err)
  1121. return err;
  1122. err = sysdev_class_register(&mce_sysclass);
  1123. if (err)
  1124. return err;
  1125. for_each_online_cpu(i) {
  1126. err = mce_create_device(i);
  1127. if (err)
  1128. return err;
  1129. }
  1130. register_hotcpu_notifier(&mce_cpu_notifier);
  1131. misc_register(&mce_log_device);
  1132. return err;
  1133. }
  1134. device_initcall(mce_init_device);
  1135. #else /* CONFIG_X86_OLD_MCE: */
  1136. int nr_mce_banks;
  1137. EXPORT_SYMBOL_GPL(nr_mce_banks); /* non-fatal.o */
  1138. /* This has to be run for each processor */
  1139. void mcheck_init(struct cpuinfo_x86 *c)
  1140. {
  1141. if (mce_disabled == 1)
  1142. return;
  1143. switch (c->x86_vendor) {
  1144. case X86_VENDOR_AMD:
  1145. amd_mcheck_init(c);
  1146. break;
  1147. case X86_VENDOR_INTEL:
  1148. if (c->x86 == 5)
  1149. intel_p5_mcheck_init(c);
  1150. if (c->x86 == 6)
  1151. intel_p6_mcheck_init(c);
  1152. if (c->x86 == 15)
  1153. intel_p4_mcheck_init(c);
  1154. break;
  1155. case X86_VENDOR_CENTAUR:
  1156. if (c->x86 == 5)
  1157. winchip_mcheck_init(c);
  1158. break;
  1159. default:
  1160. break;
  1161. }
  1162. printk(KERN_INFO "mce: CPU supports %d MCE banks\n", nr_mce_banks);
  1163. }
  1164. static int __init mcheck_enable(char *str)
  1165. {
  1166. mce_disabled = -1;
  1167. return 1;
  1168. }
  1169. __setup("mce", mcheck_enable);
  1170. #endif /* CONFIG_X86_OLD_MCE */
  1171. /*
  1172. * Old style boot options parsing. Only for compatibility.
  1173. */
  1174. static int __init mcheck_disable(char *str)
  1175. {
  1176. mce_disabled = 1;
  1177. return 1;
  1178. }
  1179. __setup("nomce", mcheck_disable);