mce.c 31 KB

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