mce.c 31 KB

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