mce.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060
  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/interrupt.h>
  14. #include <linux/ratelimit.h>
  15. #include <linux/kallsyms.h>
  16. #include <linux/rcupdate.h>
  17. #include <linux/kobject.h>
  18. #include <linux/uaccess.h>
  19. #include <linux/kdebug.h>
  20. #include <linux/kernel.h>
  21. #include <linux/percpu.h>
  22. #include <linux/string.h>
  23. #include <linux/sysdev.h>
  24. #include <linux/delay.h>
  25. #include <linux/ctype.h>
  26. #include <linux/sched.h>
  27. #include <linux/sysfs.h>
  28. #include <linux/types.h>
  29. #include <linux/init.h>
  30. #include <linux/kmod.h>
  31. #include <linux/poll.h>
  32. #include <linux/nmi.h>
  33. #include <linux/cpu.h>
  34. #include <linux/smp.h>
  35. #include <linux/fs.h>
  36. #include <linux/mm.h>
  37. #include <asm/processor.h>
  38. #include <asm/hw_irq.h>
  39. #include <asm/apic.h>
  40. #include <asm/idle.h>
  41. #include <asm/ipi.h>
  42. #include <asm/mce.h>
  43. #include <asm/msr.h>
  44. #include "mce-internal.h"
  45. /* Handle unconfigured int18 (should never happen) */
  46. static void unexpected_machine_check(struct pt_regs *regs, long error_code)
  47. {
  48. printk(KERN_ERR "CPU#%d: Unexpected int18 (Machine Check).\n",
  49. smp_processor_id());
  50. }
  51. /* Call the installed machine check handler for this CPU setup. */
  52. void (*machine_check_vector)(struct pt_regs *, long error_code) =
  53. unexpected_machine_check;
  54. int mce_disabled __read_mostly;
  55. #ifdef CONFIG_X86_NEW_MCE
  56. #define MISC_MCELOG_MINOR 227
  57. #define SPINUNIT 100 /* 100ns */
  58. atomic_t mce_entry;
  59. DEFINE_PER_CPU(unsigned, mce_exception_count);
  60. /*
  61. * Tolerant levels:
  62. * 0: always panic on uncorrected errors, log corrected errors
  63. * 1: panic or SIGBUS on uncorrected errors, log corrected errors
  64. * 2: SIGBUS or log uncorrected errors (if possible), log corrected errors
  65. * 3: never panic or SIGBUS, log all errors (for testing only)
  66. */
  67. static int tolerant __read_mostly = 1;
  68. static int banks __read_mostly;
  69. static u64 *bank __read_mostly;
  70. static int rip_msr __read_mostly;
  71. static int mce_bootlog __read_mostly = -1;
  72. static int monarch_timeout __read_mostly = -1;
  73. static int mce_panic_timeout __read_mostly;
  74. static int mce_dont_log_ce __read_mostly;
  75. int mce_cmci_disabled __read_mostly;
  76. int mce_ignore_ce __read_mostly;
  77. int mce_ser __read_mostly;
  78. /* User mode helper program triggered by machine check event */
  79. static unsigned long mce_need_notify;
  80. static char mce_helper[128];
  81. static char *mce_helper_argv[2] = { mce_helper, NULL };
  82. static unsigned long dont_init_banks;
  83. static DECLARE_WAIT_QUEUE_HEAD(mce_wait);
  84. static DEFINE_PER_CPU(struct mce, mces_seen);
  85. static int cpu_missing;
  86. /* MCA banks polled by the period polling timer for corrected events */
  87. DEFINE_PER_CPU(mce_banks_t, mce_poll_banks) = {
  88. [0 ... BITS_TO_LONGS(MAX_NR_BANKS)-1] = ~0UL
  89. };
  90. static inline int skip_bank_init(int i)
  91. {
  92. return i < BITS_PER_LONG && test_bit(i, &dont_init_banks);
  93. }
  94. static DEFINE_PER_CPU(struct work_struct, mce_work);
  95. /* Do initial initialization of a struct mce */
  96. void mce_setup(struct mce *m)
  97. {
  98. memset(m, 0, sizeof(struct mce));
  99. m->cpu = m->extcpu = smp_processor_id();
  100. rdtscll(m->tsc);
  101. /* We hope get_seconds stays lockless */
  102. m->time = get_seconds();
  103. m->cpuvendor = boot_cpu_data.x86_vendor;
  104. m->cpuid = cpuid_eax(1);
  105. #ifdef CONFIG_SMP
  106. m->socketid = cpu_data(m->extcpu).phys_proc_id;
  107. #endif
  108. m->apicid = cpu_data(m->extcpu).initial_apicid;
  109. rdmsrl(MSR_IA32_MCG_CAP, m->mcgcap);
  110. }
  111. DEFINE_PER_CPU(struct mce, injectm);
  112. EXPORT_PER_CPU_SYMBOL_GPL(injectm);
  113. /*
  114. * Lockless MCE logging infrastructure.
  115. * This avoids deadlocks on printk locks without having to break locks. Also
  116. * separate MCEs from kernel messages to avoid bogus bug reports.
  117. */
  118. static struct mce_log mcelog = {
  119. .signature = MCE_LOG_SIGNATURE,
  120. .len = MCE_LOG_LEN,
  121. .recordlen = sizeof(struct mce),
  122. };
  123. void mce_log(struct mce *mce)
  124. {
  125. unsigned next, entry;
  126. mce->finished = 0;
  127. wmb();
  128. for (;;) {
  129. entry = rcu_dereference(mcelog.next);
  130. for (;;) {
  131. /*
  132. * When the buffer fills up discard new entries.
  133. * Assume that the earlier errors are the more
  134. * interesting ones:
  135. */
  136. if (entry >= MCE_LOG_LEN) {
  137. set_bit(MCE_OVERFLOW,
  138. (unsigned long *)&mcelog.flags);
  139. return;
  140. }
  141. /* Old left over entry. Skip: */
  142. if (mcelog.entry[entry].finished) {
  143. entry++;
  144. continue;
  145. }
  146. break;
  147. }
  148. smp_rmb();
  149. next = entry + 1;
  150. if (cmpxchg(&mcelog.next, entry, next) == entry)
  151. break;
  152. }
  153. memcpy(mcelog.entry + entry, mce, sizeof(struct mce));
  154. wmb();
  155. mcelog.entry[entry].finished = 1;
  156. wmb();
  157. mce->finished = 1;
  158. set_bit(0, &mce_need_notify);
  159. }
  160. static void print_mce(struct mce *m)
  161. {
  162. printk(KERN_EMERG
  163. "CPU %d: Machine Check Exception: %16Lx Bank %d: %016Lx\n",
  164. m->extcpu, m->mcgstatus, m->bank, m->status);
  165. if (m->ip) {
  166. printk(KERN_EMERG "RIP%s %02x:<%016Lx> ",
  167. !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
  168. m->cs, m->ip);
  169. if (m->cs == __KERNEL_CS)
  170. print_symbol("{%s}", m->ip);
  171. printk(KERN_CONT "\n");
  172. }
  173. printk(KERN_EMERG "TSC %llx ", m->tsc);
  174. if (m->addr)
  175. printk(KERN_CONT "ADDR %llx ", m->addr);
  176. if (m->misc)
  177. printk(KERN_CONT "MISC %llx ", m->misc);
  178. printk(KERN_CONT "\n");
  179. printk(KERN_EMERG "PROCESSOR %u:%x TIME %llu SOCKET %u APIC %x\n",
  180. m->cpuvendor, m->cpuid, m->time, m->socketid,
  181. m->apicid);
  182. }
  183. static void print_mce_head(void)
  184. {
  185. printk(KERN_EMERG "\nHARDWARE ERROR\n");
  186. }
  187. static void print_mce_tail(void)
  188. {
  189. printk(KERN_EMERG "This is not a software problem!\n"
  190. "Run through mcelog --ascii to decode and contact your hardware vendor\n");
  191. }
  192. #define PANIC_TIMEOUT 5 /* 5 seconds */
  193. static atomic_t mce_paniced;
  194. /* Panic in progress. Enable interrupts and wait for final IPI */
  195. static void wait_for_panic(void)
  196. {
  197. long timeout = PANIC_TIMEOUT*USEC_PER_SEC;
  198. preempt_disable();
  199. local_irq_enable();
  200. while (timeout-- > 0)
  201. udelay(1);
  202. if (panic_timeout == 0)
  203. panic_timeout = mce_panic_timeout;
  204. panic("Panicing machine check CPU died");
  205. }
  206. static void mce_panic(char *msg, struct mce *final, char *exp)
  207. {
  208. int i;
  209. /*
  210. * Make sure only one CPU runs in machine check panic
  211. */
  212. if (atomic_add_return(1, &mce_paniced) > 1)
  213. wait_for_panic();
  214. barrier();
  215. bust_spinlocks(1);
  216. console_verbose();
  217. print_mce_head();
  218. /* First print corrected ones that are still unlogged */
  219. for (i = 0; i < MCE_LOG_LEN; i++) {
  220. struct mce *m = &mcelog.entry[i];
  221. if (!(m->status & MCI_STATUS_VAL))
  222. continue;
  223. if (!(m->status & MCI_STATUS_UC))
  224. print_mce(m);
  225. }
  226. /* Now print uncorrected but with the final one last */
  227. for (i = 0; i < MCE_LOG_LEN; i++) {
  228. struct mce *m = &mcelog.entry[i];
  229. if (!(m->status & MCI_STATUS_VAL))
  230. continue;
  231. if (!(m->status & MCI_STATUS_UC))
  232. continue;
  233. if (!final || memcmp(m, final, sizeof(struct mce)))
  234. print_mce(m);
  235. }
  236. if (final)
  237. print_mce(final);
  238. if (cpu_missing)
  239. printk(KERN_EMERG "Some CPUs didn't answer in synchronization\n");
  240. print_mce_tail();
  241. if (exp)
  242. printk(KERN_EMERG "Machine check: %s\n", exp);
  243. if (panic_timeout == 0)
  244. panic_timeout = mce_panic_timeout;
  245. panic(msg);
  246. }
  247. /* Support code for software error injection */
  248. static int msr_to_offset(u32 msr)
  249. {
  250. unsigned bank = __get_cpu_var(injectm.bank);
  251. if (msr == rip_msr)
  252. return offsetof(struct mce, ip);
  253. if (msr == MSR_IA32_MC0_STATUS + bank*4)
  254. return offsetof(struct mce, status);
  255. if (msr == MSR_IA32_MC0_ADDR + bank*4)
  256. return offsetof(struct mce, addr);
  257. if (msr == MSR_IA32_MC0_MISC + bank*4)
  258. return offsetof(struct mce, misc);
  259. if (msr == MSR_IA32_MCG_STATUS)
  260. return offsetof(struct mce, mcgstatus);
  261. return -1;
  262. }
  263. /* MSR access wrappers used for error injection */
  264. static u64 mce_rdmsrl(u32 msr)
  265. {
  266. u64 v;
  267. if (__get_cpu_var(injectm).finished) {
  268. int offset = msr_to_offset(msr);
  269. if (offset < 0)
  270. return 0;
  271. return *(u64 *)((char *)&__get_cpu_var(injectm) + offset);
  272. }
  273. rdmsrl(msr, v);
  274. return v;
  275. }
  276. static void mce_wrmsrl(u32 msr, u64 v)
  277. {
  278. if (__get_cpu_var(injectm).finished) {
  279. int offset = msr_to_offset(msr);
  280. if (offset >= 0)
  281. *(u64 *)((char *)&__get_cpu_var(injectm) + offset) = v;
  282. return;
  283. }
  284. wrmsrl(msr, v);
  285. }
  286. /*
  287. * Simple lockless ring to communicate PFNs from the exception handler with the
  288. * process context work function. This is vastly simplified because there's
  289. * only a single reader and a single writer.
  290. */
  291. #define MCE_RING_SIZE 16 /* we use one entry less */
  292. struct mce_ring {
  293. unsigned short start;
  294. unsigned short end;
  295. unsigned long ring[MCE_RING_SIZE];
  296. };
  297. static DEFINE_PER_CPU(struct mce_ring, mce_ring);
  298. /* Runs with CPU affinity in workqueue */
  299. static int mce_ring_empty(void)
  300. {
  301. struct mce_ring *r = &__get_cpu_var(mce_ring);
  302. return r->start == r->end;
  303. }
  304. static int mce_ring_get(unsigned long *pfn)
  305. {
  306. struct mce_ring *r;
  307. int ret = 0;
  308. *pfn = 0;
  309. get_cpu();
  310. r = &__get_cpu_var(mce_ring);
  311. if (r->start == r->end)
  312. goto out;
  313. *pfn = r->ring[r->start];
  314. r->start = (r->start + 1) % MCE_RING_SIZE;
  315. ret = 1;
  316. out:
  317. put_cpu();
  318. return ret;
  319. }
  320. /* Always runs in MCE context with preempt off */
  321. static int mce_ring_add(unsigned long pfn)
  322. {
  323. struct mce_ring *r = &__get_cpu_var(mce_ring);
  324. unsigned next;
  325. next = (r->end + 1) % MCE_RING_SIZE;
  326. if (next == r->start)
  327. return -1;
  328. r->ring[r->end] = pfn;
  329. wmb();
  330. r->end = next;
  331. return 0;
  332. }
  333. int mce_available(struct cpuinfo_x86 *c)
  334. {
  335. if (mce_disabled)
  336. return 0;
  337. return cpu_has(c, X86_FEATURE_MCE) && cpu_has(c, X86_FEATURE_MCA);
  338. }
  339. static void mce_schedule_work(void)
  340. {
  341. if (!mce_ring_empty()) {
  342. struct work_struct *work = &__get_cpu_var(mce_work);
  343. if (!work_pending(work))
  344. schedule_work(work);
  345. }
  346. }
  347. /*
  348. * Get the address of the instruction at the time of the machine check
  349. * error.
  350. */
  351. static inline void mce_get_rip(struct mce *m, struct pt_regs *regs)
  352. {
  353. if (regs && (m->mcgstatus & (MCG_STATUS_RIPV|MCG_STATUS_EIPV))) {
  354. m->ip = regs->ip;
  355. m->cs = regs->cs;
  356. } else {
  357. m->ip = 0;
  358. m->cs = 0;
  359. }
  360. if (rip_msr)
  361. m->ip = mce_rdmsrl(rip_msr);
  362. }
  363. #ifdef CONFIG_X86_LOCAL_APIC
  364. /*
  365. * Called after interrupts have been reenabled again
  366. * when a MCE happened during an interrupts off region
  367. * in the kernel.
  368. */
  369. asmlinkage void smp_mce_self_interrupt(struct pt_regs *regs)
  370. {
  371. ack_APIC_irq();
  372. exit_idle();
  373. irq_enter();
  374. mce_notify_irq();
  375. mce_schedule_work();
  376. irq_exit();
  377. }
  378. #endif
  379. static void mce_report_event(struct pt_regs *regs)
  380. {
  381. if (regs->flags & (X86_VM_MASK|X86_EFLAGS_IF)) {
  382. mce_notify_irq();
  383. /*
  384. * Triggering the work queue here is just an insurance
  385. * policy in case the syscall exit notify handler
  386. * doesn't run soon enough or ends up running on the
  387. * wrong CPU (can happen when audit sleeps)
  388. */
  389. mce_schedule_work();
  390. return;
  391. }
  392. #ifdef CONFIG_X86_LOCAL_APIC
  393. /*
  394. * Without APIC do not notify. The event will be picked
  395. * up eventually.
  396. */
  397. if (!cpu_has_apic)
  398. return;
  399. /*
  400. * When interrupts are disabled we cannot use
  401. * kernel services safely. Trigger an self interrupt
  402. * through the APIC to instead do the notification
  403. * after interrupts are reenabled again.
  404. */
  405. apic->send_IPI_self(MCE_SELF_VECTOR);
  406. /*
  407. * Wait for idle afterwards again so that we don't leave the
  408. * APIC in a non idle state because the normal APIC writes
  409. * cannot exclude us.
  410. */
  411. apic_wait_icr_idle();
  412. #endif
  413. }
  414. DEFINE_PER_CPU(unsigned, mce_poll_count);
  415. /*
  416. * Poll for corrected events or events that happened before reset.
  417. * Those are just logged through /dev/mcelog.
  418. *
  419. * This is executed in standard interrupt context.
  420. *
  421. * Note: spec recommends to panic for fatal unsignalled
  422. * errors here. However this would be quite problematic --
  423. * we would need to reimplement the Monarch handling and
  424. * it would mess up the exclusion between exception handler
  425. * and poll hander -- * so we skip this for now.
  426. * These cases should not happen anyways, or only when the CPU
  427. * is already totally * confused. In this case it's likely it will
  428. * not fully execute the machine check handler either.
  429. */
  430. void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)
  431. {
  432. struct mce m;
  433. int i;
  434. __get_cpu_var(mce_poll_count)++;
  435. mce_setup(&m);
  436. m.mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS);
  437. for (i = 0; i < banks; i++) {
  438. if (!bank[i] || !test_bit(i, *b))
  439. continue;
  440. m.misc = 0;
  441. m.addr = 0;
  442. m.bank = i;
  443. m.tsc = 0;
  444. barrier();
  445. m.status = mce_rdmsrl(MSR_IA32_MC0_STATUS + i*4);
  446. if (!(m.status & MCI_STATUS_VAL))
  447. continue;
  448. /*
  449. * Uncorrected or signalled events are handled by the exception
  450. * handler when it is enabled, so don't process those here.
  451. *
  452. * TBD do the same check for MCI_STATUS_EN here?
  453. */
  454. if (!(flags & MCP_UC) &&
  455. (m.status & (mce_ser ? MCI_STATUS_S : MCI_STATUS_UC)))
  456. continue;
  457. if (m.status & MCI_STATUS_MISCV)
  458. m.misc = mce_rdmsrl(MSR_IA32_MC0_MISC + i*4);
  459. if (m.status & MCI_STATUS_ADDRV)
  460. m.addr = mce_rdmsrl(MSR_IA32_MC0_ADDR + i*4);
  461. if (!(flags & MCP_TIMESTAMP))
  462. m.tsc = 0;
  463. /*
  464. * Don't get the IP here because it's unlikely to
  465. * have anything to do with the actual error location.
  466. */
  467. if (!(flags & MCP_DONTLOG) && !mce_dont_log_ce) {
  468. mce_log(&m);
  469. add_taint(TAINT_MACHINE_CHECK);
  470. }
  471. /*
  472. * Clear state for this bank.
  473. */
  474. mce_wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
  475. }
  476. /*
  477. * Don't clear MCG_STATUS here because it's only defined for
  478. * exceptions.
  479. */
  480. sync_core();
  481. }
  482. EXPORT_SYMBOL_GPL(machine_check_poll);
  483. /*
  484. * Do a quick check if any of the events requires a panic.
  485. * This decides if we keep the events around or clear them.
  486. */
  487. static int mce_no_way_out(struct mce *m, char **msg)
  488. {
  489. int i;
  490. for (i = 0; i < banks; i++) {
  491. m->status = mce_rdmsrl(MSR_IA32_MC0_STATUS + i*4);
  492. if (mce_severity(m, tolerant, msg) >= MCE_PANIC_SEVERITY)
  493. return 1;
  494. }
  495. return 0;
  496. }
  497. /*
  498. * Variable to establish order between CPUs while scanning.
  499. * Each CPU spins initially until executing is equal its number.
  500. */
  501. static atomic_t mce_executing;
  502. /*
  503. * Defines order of CPUs on entry. First CPU becomes Monarch.
  504. */
  505. static atomic_t mce_callin;
  506. /*
  507. * Check if a timeout waiting for other CPUs happened.
  508. */
  509. static int mce_timed_out(u64 *t)
  510. {
  511. /*
  512. * The others already did panic for some reason.
  513. * Bail out like in a timeout.
  514. * rmb() to tell the compiler that system_state
  515. * might have been modified by someone else.
  516. */
  517. rmb();
  518. if (atomic_read(&mce_paniced))
  519. wait_for_panic();
  520. if (!monarch_timeout)
  521. goto out;
  522. if ((s64)*t < SPINUNIT) {
  523. /* CHECKME: Make panic default for 1 too? */
  524. if (tolerant < 1)
  525. mce_panic("Timeout synchronizing machine check over CPUs",
  526. NULL, NULL);
  527. cpu_missing = 1;
  528. return 1;
  529. }
  530. *t -= SPINUNIT;
  531. out:
  532. touch_nmi_watchdog();
  533. return 0;
  534. }
  535. /*
  536. * The Monarch's reign. The Monarch is the CPU who entered
  537. * the machine check handler first. It waits for the others to
  538. * raise the exception too and then grades them. When any
  539. * error is fatal panic. Only then let the others continue.
  540. *
  541. * The other CPUs entering the MCE handler will be controlled by the
  542. * Monarch. They are called Subjects.
  543. *
  544. * This way we prevent any potential data corruption in a unrecoverable case
  545. * and also makes sure always all CPU's errors are examined.
  546. *
  547. * Also this detects the case of an machine check event coming from outer
  548. * space (not detected by any CPUs) In this case some external agent wants
  549. * us to shut down, so panic too.
  550. *
  551. * The other CPUs might still decide to panic if the handler happens
  552. * in a unrecoverable place, but in this case the system is in a semi-stable
  553. * state and won't corrupt anything by itself. It's ok to let the others
  554. * continue for a bit first.
  555. *
  556. * All the spin loops have timeouts; when a timeout happens a CPU
  557. * typically elects itself to be Monarch.
  558. */
  559. static void mce_reign(void)
  560. {
  561. int cpu;
  562. struct mce *m = NULL;
  563. int global_worst = 0;
  564. char *msg = NULL;
  565. char *nmsg = NULL;
  566. /*
  567. * This CPU is the Monarch and the other CPUs have run
  568. * through their handlers.
  569. * Grade the severity of the errors of all the CPUs.
  570. */
  571. for_each_possible_cpu(cpu) {
  572. int severity = mce_severity(&per_cpu(mces_seen, cpu), tolerant,
  573. &nmsg);
  574. if (severity > global_worst) {
  575. msg = nmsg;
  576. global_worst = severity;
  577. m = &per_cpu(mces_seen, cpu);
  578. }
  579. }
  580. /*
  581. * Cannot recover? Panic here then.
  582. * This dumps all the mces in the log buffer and stops the
  583. * other CPUs.
  584. */
  585. if (m && global_worst >= MCE_PANIC_SEVERITY && tolerant < 3)
  586. mce_panic("Fatal Machine check", m, msg);
  587. /*
  588. * For UC somewhere we let the CPU who detects it handle it.
  589. * Also must let continue the others, otherwise the handling
  590. * CPU could deadlock on a lock.
  591. */
  592. /*
  593. * No machine check event found. Must be some external
  594. * source or one CPU is hung. Panic.
  595. */
  596. if (!m && tolerant < 3)
  597. mce_panic("Machine check from unknown source", NULL, NULL);
  598. /*
  599. * Now clear all the mces_seen so that they don't reappear on
  600. * the next mce.
  601. */
  602. for_each_possible_cpu(cpu)
  603. memset(&per_cpu(mces_seen, cpu), 0, sizeof(struct mce));
  604. }
  605. static atomic_t global_nwo;
  606. /*
  607. * Start of Monarch synchronization. This waits until all CPUs have
  608. * entered the exception handler and then determines if any of them
  609. * saw a fatal event that requires panic. Then it executes them
  610. * in the entry order.
  611. * TBD double check parallel CPU hotunplug
  612. */
  613. static int mce_start(int *no_way_out)
  614. {
  615. int order;
  616. int cpus = num_online_cpus();
  617. u64 timeout = (u64)monarch_timeout * NSEC_PER_USEC;
  618. if (!timeout)
  619. return -1;
  620. atomic_add(*no_way_out, &global_nwo);
  621. /*
  622. * global_nwo should be updated before mce_callin
  623. */
  624. smp_wmb();
  625. order = atomic_add_return(1, &mce_callin);
  626. /*
  627. * Wait for everyone.
  628. */
  629. while (atomic_read(&mce_callin) != cpus) {
  630. if (mce_timed_out(&timeout)) {
  631. atomic_set(&global_nwo, 0);
  632. return -1;
  633. }
  634. ndelay(SPINUNIT);
  635. }
  636. /*
  637. * mce_callin should be read before global_nwo
  638. */
  639. smp_rmb();
  640. if (order == 1) {
  641. /*
  642. * Monarch: Starts executing now, the others wait.
  643. */
  644. atomic_set(&mce_executing, 1);
  645. } else {
  646. /*
  647. * Subject: Now start the scanning loop one by one in
  648. * the original callin order.
  649. * This way when there are any shared banks it will be
  650. * only seen by one CPU before cleared, avoiding duplicates.
  651. */
  652. while (atomic_read(&mce_executing) < order) {
  653. if (mce_timed_out(&timeout)) {
  654. atomic_set(&global_nwo, 0);
  655. return -1;
  656. }
  657. ndelay(SPINUNIT);
  658. }
  659. }
  660. /*
  661. * Cache the global no_way_out state.
  662. */
  663. *no_way_out = atomic_read(&global_nwo);
  664. return order;
  665. }
  666. /*
  667. * Synchronize between CPUs after main scanning loop.
  668. * This invokes the bulk of the Monarch processing.
  669. */
  670. static int mce_end(int order)
  671. {
  672. int ret = -1;
  673. u64 timeout = (u64)monarch_timeout * NSEC_PER_USEC;
  674. if (!timeout)
  675. goto reset;
  676. if (order < 0)
  677. goto reset;
  678. /*
  679. * Allow others to run.
  680. */
  681. atomic_inc(&mce_executing);
  682. if (order == 1) {
  683. /* CHECKME: Can this race with a parallel hotplug? */
  684. int cpus = num_online_cpus();
  685. /*
  686. * Monarch: Wait for everyone to go through their scanning
  687. * loops.
  688. */
  689. while (atomic_read(&mce_executing) <= cpus) {
  690. if (mce_timed_out(&timeout))
  691. goto reset;
  692. ndelay(SPINUNIT);
  693. }
  694. mce_reign();
  695. barrier();
  696. ret = 0;
  697. } else {
  698. /*
  699. * Subject: Wait for Monarch to finish.
  700. */
  701. while (atomic_read(&mce_executing) != 0) {
  702. if (mce_timed_out(&timeout))
  703. goto reset;
  704. ndelay(SPINUNIT);
  705. }
  706. /*
  707. * Don't reset anything. That's done by the Monarch.
  708. */
  709. return 0;
  710. }
  711. /*
  712. * Reset all global state.
  713. */
  714. reset:
  715. atomic_set(&global_nwo, 0);
  716. atomic_set(&mce_callin, 0);
  717. barrier();
  718. /*
  719. * Let others run again.
  720. */
  721. atomic_set(&mce_executing, 0);
  722. return ret;
  723. }
  724. /*
  725. * Check if the address reported by the CPU is in a format we can parse.
  726. * It would be possible to add code for most other cases, but all would
  727. * be somewhat complicated (e.g. segment offset would require an instruction
  728. * parser). So only support physical addresses upto page granuality for now.
  729. */
  730. static int mce_usable_address(struct mce *m)
  731. {
  732. if (!(m->status & MCI_STATUS_MISCV) || !(m->status & MCI_STATUS_ADDRV))
  733. return 0;
  734. if ((m->misc & 0x3f) > PAGE_SHIFT)
  735. return 0;
  736. if (((m->misc >> 6) & 7) != MCM_ADDR_PHYS)
  737. return 0;
  738. return 1;
  739. }
  740. static void mce_clear_state(unsigned long *toclear)
  741. {
  742. int i;
  743. for (i = 0; i < banks; i++) {
  744. if (test_bit(i, toclear))
  745. mce_wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
  746. }
  747. }
  748. /*
  749. * The actual machine check handler. This only handles real
  750. * exceptions when something got corrupted coming in through int 18.
  751. *
  752. * This is executed in NMI context not subject to normal locking rules. This
  753. * implies that most kernel services cannot be safely used. Don't even
  754. * think about putting a printk in there!
  755. *
  756. * On Intel systems this is entered on all CPUs in parallel through
  757. * MCE broadcast. However some CPUs might be broken beyond repair,
  758. * so be always careful when synchronizing with others.
  759. */
  760. void do_machine_check(struct pt_regs *regs, long error_code)
  761. {
  762. struct mce m, *final;
  763. int i;
  764. int worst = 0;
  765. int severity;
  766. /*
  767. * Establish sequential order between the CPUs entering the machine
  768. * check handler.
  769. */
  770. int order;
  771. /*
  772. * If no_way_out gets set, there is no safe way to recover from this
  773. * MCE. If tolerant is cranked up, we'll try anyway.
  774. */
  775. int no_way_out = 0;
  776. /*
  777. * If kill_it gets set, there might be a way to recover from this
  778. * error.
  779. */
  780. int kill_it = 0;
  781. DECLARE_BITMAP(toclear, MAX_NR_BANKS);
  782. char *msg = "Unknown";
  783. atomic_inc(&mce_entry);
  784. __get_cpu_var(mce_exception_count)++;
  785. if (notify_die(DIE_NMI, "machine check", regs, error_code,
  786. 18, SIGKILL) == NOTIFY_STOP)
  787. goto out;
  788. if (!banks)
  789. goto out;
  790. mce_setup(&m);
  791. m.mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS);
  792. no_way_out = mce_no_way_out(&m, &msg);
  793. final = &__get_cpu_var(mces_seen);
  794. *final = m;
  795. barrier();
  796. /*
  797. * When no restart IP must always kill or panic.
  798. */
  799. if (!(m.mcgstatus & MCG_STATUS_RIPV))
  800. kill_it = 1;
  801. /*
  802. * Go through all the banks in exclusion of the other CPUs.
  803. * This way we don't report duplicated events on shared banks
  804. * because the first one to see it will clear it.
  805. */
  806. order = mce_start(&no_way_out);
  807. for (i = 0; i < banks; i++) {
  808. __clear_bit(i, toclear);
  809. if (!bank[i])
  810. continue;
  811. m.misc = 0;
  812. m.addr = 0;
  813. m.bank = i;
  814. m.status = mce_rdmsrl(MSR_IA32_MC0_STATUS + i*4);
  815. if ((m.status & MCI_STATUS_VAL) == 0)
  816. continue;
  817. /*
  818. * Non uncorrected or non signaled errors are handled by
  819. * machine_check_poll. Leave them alone, unless this panics.
  820. */
  821. if (!(m.status & (mce_ser ? MCI_STATUS_S : MCI_STATUS_UC)) &&
  822. !no_way_out)
  823. continue;
  824. /*
  825. * Set taint even when machine check was not enabled.
  826. */
  827. add_taint(TAINT_MACHINE_CHECK);
  828. severity = mce_severity(&m, tolerant, NULL);
  829. /*
  830. * When machine check was for corrected handler don't touch,
  831. * unless we're panicing.
  832. */
  833. if (severity == MCE_KEEP_SEVERITY && !no_way_out)
  834. continue;
  835. __set_bit(i, toclear);
  836. if (severity == MCE_NO_SEVERITY) {
  837. /*
  838. * Machine check event was not enabled. Clear, but
  839. * ignore.
  840. */
  841. continue;
  842. }
  843. /*
  844. * Kill on action required.
  845. */
  846. if (severity == MCE_AR_SEVERITY)
  847. kill_it = 1;
  848. if (m.status & MCI_STATUS_MISCV)
  849. m.misc = mce_rdmsrl(MSR_IA32_MC0_MISC + i*4);
  850. if (m.status & MCI_STATUS_ADDRV)
  851. m.addr = mce_rdmsrl(MSR_IA32_MC0_ADDR + i*4);
  852. /*
  853. * Action optional error. Queue address for later processing.
  854. * When the ring overflows we just ignore the AO error.
  855. * RED-PEN add some logging mechanism when
  856. * usable_address or mce_add_ring fails.
  857. * RED-PEN don't ignore overflow for tolerant == 0
  858. */
  859. if (severity == MCE_AO_SEVERITY && mce_usable_address(&m))
  860. mce_ring_add(m.addr >> PAGE_SHIFT);
  861. mce_get_rip(&m, regs);
  862. mce_log(&m);
  863. if (severity > worst) {
  864. *final = m;
  865. worst = severity;
  866. }
  867. }
  868. if (!no_way_out)
  869. mce_clear_state(toclear);
  870. /*
  871. * Do most of the synchronization with other CPUs.
  872. * When there's any problem use only local no_way_out state.
  873. */
  874. if (mce_end(order) < 0)
  875. no_way_out = worst >= MCE_PANIC_SEVERITY;
  876. /*
  877. * If we have decided that we just CAN'T continue, and the user
  878. * has not set tolerant to an insane level, give up and die.
  879. *
  880. * This is mainly used in the case when the system doesn't
  881. * support MCE broadcasting or it has been disabled.
  882. */
  883. if (no_way_out && tolerant < 3)
  884. mce_panic("Fatal machine check on current CPU", final, msg);
  885. /*
  886. * If the error seems to be unrecoverable, something should be
  887. * done. Try to kill as little as possible. If we can kill just
  888. * one task, do that. If the user has set the tolerance very
  889. * high, don't try to do anything at all.
  890. */
  891. if (kill_it && tolerant < 3)
  892. force_sig(SIGBUS, current);
  893. /* notify userspace ASAP */
  894. set_thread_flag(TIF_MCE_NOTIFY);
  895. if (worst > 0)
  896. mce_report_event(regs);
  897. mce_wrmsrl(MSR_IA32_MCG_STATUS, 0);
  898. out:
  899. atomic_dec(&mce_entry);
  900. sync_core();
  901. }
  902. EXPORT_SYMBOL_GPL(do_machine_check);
  903. /* dummy to break dependency. actual code is in mm/memory-failure.c */
  904. void __attribute__((weak)) memory_failure(unsigned long pfn, int vector)
  905. {
  906. printk(KERN_ERR "Action optional memory failure at %lx ignored\n", pfn);
  907. }
  908. /*
  909. * Called after mce notification in process context. This code
  910. * is allowed to sleep. Call the high level VM handler to process
  911. * any corrupted pages.
  912. * Assume that the work queue code only calls this one at a time
  913. * per CPU.
  914. * Note we don't disable preemption, so this code might run on the wrong
  915. * CPU. In this case the event is picked up by the scheduled work queue.
  916. * This is merely a fast path to expedite processing in some common
  917. * cases.
  918. */
  919. void mce_notify_process(void)
  920. {
  921. unsigned long pfn;
  922. mce_notify_irq();
  923. while (mce_ring_get(&pfn))
  924. memory_failure(pfn, MCE_VECTOR);
  925. }
  926. static void mce_process_work(struct work_struct *dummy)
  927. {
  928. mce_notify_process();
  929. }
  930. #ifdef CONFIG_X86_MCE_INTEL
  931. /***
  932. * mce_log_therm_throt_event - Logs the thermal throttling event to mcelog
  933. * @cpu: The CPU on which the event occurred.
  934. * @status: Event status information
  935. *
  936. * This function should be called by the thermal interrupt after the
  937. * event has been processed and the decision was made to log the event
  938. * further.
  939. *
  940. * The status parameter will be saved to the 'status' field of 'struct mce'
  941. * and historically has been the register value of the
  942. * MSR_IA32_THERMAL_STATUS (Intel) msr.
  943. */
  944. void mce_log_therm_throt_event(__u64 status)
  945. {
  946. struct mce m;
  947. mce_setup(&m);
  948. m.bank = MCE_THERMAL_BANK;
  949. m.status = status;
  950. mce_log(&m);
  951. }
  952. #endif /* CONFIG_X86_MCE_INTEL */
  953. /*
  954. * Periodic polling timer for "silent" machine check errors. If the
  955. * poller finds an MCE, poll 2x faster. When the poller finds no more
  956. * errors, poll 2x slower (up to check_interval seconds).
  957. */
  958. static int check_interval = 5 * 60; /* 5 minutes */
  959. static DEFINE_PER_CPU(int, next_interval); /* in jiffies */
  960. static DEFINE_PER_CPU(struct timer_list, mce_timer);
  961. static void mcheck_timer(unsigned long data)
  962. {
  963. struct timer_list *t = &per_cpu(mce_timer, data);
  964. int *n;
  965. WARN_ON(smp_processor_id() != data);
  966. if (mce_available(&current_cpu_data)) {
  967. machine_check_poll(MCP_TIMESTAMP,
  968. &__get_cpu_var(mce_poll_banks));
  969. }
  970. /*
  971. * Alert userspace if needed. If we logged an MCE, reduce the
  972. * polling interval, otherwise increase the polling interval.
  973. */
  974. n = &__get_cpu_var(next_interval);
  975. if (mce_notify_irq())
  976. *n = max(*n/2, HZ/100);
  977. else
  978. *n = min(*n*2, (int)round_jiffies_relative(check_interval*HZ));
  979. t->expires = jiffies + *n;
  980. add_timer_on(t, smp_processor_id());
  981. }
  982. static void mce_do_trigger(struct work_struct *work)
  983. {
  984. call_usermodehelper(mce_helper, mce_helper_argv, NULL, UMH_NO_WAIT);
  985. }
  986. static DECLARE_WORK(mce_trigger_work, mce_do_trigger);
  987. /*
  988. * Notify the user(s) about new machine check events.
  989. * Can be called from interrupt context, but not from machine check/NMI
  990. * context.
  991. */
  992. int mce_notify_irq(void)
  993. {
  994. /* Not more than two messages every minute */
  995. static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
  996. clear_thread_flag(TIF_MCE_NOTIFY);
  997. if (test_and_clear_bit(0, &mce_need_notify)) {
  998. wake_up_interruptible(&mce_wait);
  999. /*
  1000. * There is no risk of missing notifications because
  1001. * work_pending is always cleared before the function is
  1002. * executed.
  1003. */
  1004. if (mce_helper[0] && !work_pending(&mce_trigger_work))
  1005. schedule_work(&mce_trigger_work);
  1006. if (__ratelimit(&ratelimit))
  1007. printk(KERN_INFO "Machine check events logged\n");
  1008. return 1;
  1009. }
  1010. return 0;
  1011. }
  1012. EXPORT_SYMBOL_GPL(mce_notify_irq);
  1013. /*
  1014. * Initialize Machine Checks for a CPU.
  1015. */
  1016. static int mce_cap_init(void)
  1017. {
  1018. unsigned b;
  1019. u64 cap;
  1020. rdmsrl(MSR_IA32_MCG_CAP, cap);
  1021. b = cap & MCG_BANKCNT_MASK;
  1022. printk(KERN_INFO "mce: CPU supports %d MCE banks\n", b);
  1023. if (b > MAX_NR_BANKS) {
  1024. printk(KERN_WARNING
  1025. "MCE: Using only %u machine check banks out of %u\n",
  1026. MAX_NR_BANKS, b);
  1027. b = MAX_NR_BANKS;
  1028. }
  1029. /* Don't support asymmetric configurations today */
  1030. WARN_ON(banks != 0 && b != banks);
  1031. banks = b;
  1032. if (!bank) {
  1033. bank = kmalloc(banks * sizeof(u64), GFP_KERNEL);
  1034. if (!bank)
  1035. return -ENOMEM;
  1036. memset(bank, 0xff, banks * sizeof(u64));
  1037. }
  1038. /* Use accurate RIP reporting if available. */
  1039. if ((cap & MCG_EXT_P) && MCG_EXT_CNT(cap) >= 9)
  1040. rip_msr = MSR_IA32_MCG_EIP;
  1041. if (cap & MCG_SER_P)
  1042. mce_ser = 1;
  1043. return 0;
  1044. }
  1045. static void mce_init(void)
  1046. {
  1047. mce_banks_t all_banks;
  1048. u64 cap;
  1049. int i;
  1050. /*
  1051. * Log the machine checks left over from the previous reset.
  1052. */
  1053. bitmap_fill(all_banks, MAX_NR_BANKS);
  1054. machine_check_poll(MCP_UC|(!mce_bootlog ? MCP_DONTLOG : 0), &all_banks);
  1055. set_in_cr4(X86_CR4_MCE);
  1056. rdmsrl(MSR_IA32_MCG_CAP, cap);
  1057. if (cap & MCG_CTL_P)
  1058. wrmsr(MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
  1059. for (i = 0; i < banks; i++) {
  1060. if (skip_bank_init(i))
  1061. continue;
  1062. wrmsrl(MSR_IA32_MC0_CTL+4*i, bank[i]);
  1063. wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
  1064. }
  1065. }
  1066. /* Add per CPU specific workarounds here */
  1067. static int mce_cpu_quirks(struct cpuinfo_x86 *c)
  1068. {
  1069. if (c->x86_vendor == X86_VENDOR_UNKNOWN) {
  1070. pr_info("MCE: unknown CPU type - not enabling MCE support.\n");
  1071. return -EOPNOTSUPP;
  1072. }
  1073. /* This should be disabled by the BIOS, but isn't always */
  1074. if (c->x86_vendor == X86_VENDOR_AMD) {
  1075. if (c->x86 == 15 && banks > 4) {
  1076. /*
  1077. * disable GART TBL walk error reporting, which
  1078. * trips off incorrectly with the IOMMU & 3ware
  1079. * & Cerberus:
  1080. */
  1081. clear_bit(10, (unsigned long *)&bank[4]);
  1082. }
  1083. if (c->x86 <= 17 && mce_bootlog < 0) {
  1084. /*
  1085. * Lots of broken BIOS around that don't clear them
  1086. * by default and leave crap in there. Don't log:
  1087. */
  1088. mce_bootlog = 0;
  1089. }
  1090. /*
  1091. * Various K7s with broken bank 0 around. Always disable
  1092. * by default.
  1093. */
  1094. if (c->x86 == 6 && banks > 0)
  1095. bank[0] = 0;
  1096. }
  1097. if (c->x86_vendor == X86_VENDOR_INTEL) {
  1098. /*
  1099. * SDM documents that on family 6 bank 0 should not be written
  1100. * because it aliases to another special BIOS controlled
  1101. * register.
  1102. * But it's not aliased anymore on model 0x1a+
  1103. * Don't ignore bank 0 completely because there could be a
  1104. * valid event later, merely don't write CTL0.
  1105. */
  1106. if (c->x86 == 6 && c->x86_model < 0x1A)
  1107. __set_bit(0, &dont_init_banks);
  1108. /*
  1109. * All newer Intel systems support MCE broadcasting. Enable
  1110. * synchronization with a one second timeout.
  1111. */
  1112. if ((c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xe)) &&
  1113. monarch_timeout < 0)
  1114. monarch_timeout = USEC_PER_SEC;
  1115. /*
  1116. * There are also broken BIOSes on some Pentium M and
  1117. * earlier systems:
  1118. */
  1119. if (c->x86 == 6 && c->x86_model <= 13 && mce_bootlog < 0)
  1120. mce_bootlog = 0;
  1121. }
  1122. if (monarch_timeout < 0)
  1123. monarch_timeout = 0;
  1124. if (mce_bootlog != 0)
  1125. mce_panic_timeout = 30;
  1126. return 0;
  1127. }
  1128. static void __cpuinit mce_ancient_init(struct cpuinfo_x86 *c)
  1129. {
  1130. if (c->x86 != 5)
  1131. return;
  1132. switch (c->x86_vendor) {
  1133. case X86_VENDOR_INTEL:
  1134. intel_p5_mcheck_init(c);
  1135. break;
  1136. case X86_VENDOR_CENTAUR:
  1137. winchip_mcheck_init(c);
  1138. break;
  1139. }
  1140. }
  1141. static void mce_cpu_features(struct cpuinfo_x86 *c)
  1142. {
  1143. switch (c->x86_vendor) {
  1144. case X86_VENDOR_INTEL:
  1145. mce_intel_feature_init(c);
  1146. break;
  1147. case X86_VENDOR_AMD:
  1148. mce_amd_feature_init(c);
  1149. break;
  1150. default:
  1151. break;
  1152. }
  1153. }
  1154. static void mce_init_timer(void)
  1155. {
  1156. struct timer_list *t = &__get_cpu_var(mce_timer);
  1157. int *n = &__get_cpu_var(next_interval);
  1158. if (mce_ignore_ce)
  1159. return;
  1160. *n = check_interval * HZ;
  1161. if (!*n)
  1162. return;
  1163. setup_timer(t, mcheck_timer, smp_processor_id());
  1164. t->expires = round_jiffies(jiffies + *n);
  1165. add_timer_on(t, smp_processor_id());
  1166. }
  1167. /*
  1168. * Called for each booted CPU to set up machine checks.
  1169. * Must be called with preempt off:
  1170. */
  1171. void __cpuinit mcheck_init(struct cpuinfo_x86 *c)
  1172. {
  1173. if (mce_disabled)
  1174. return;
  1175. mce_ancient_init(c);
  1176. if (!mce_available(c))
  1177. return;
  1178. if (mce_cap_init() < 0 || mce_cpu_quirks(c) < 0) {
  1179. mce_disabled = 1;
  1180. return;
  1181. }
  1182. machine_check_vector = do_machine_check;
  1183. mce_init();
  1184. mce_cpu_features(c);
  1185. mce_init_timer();
  1186. INIT_WORK(&__get_cpu_var(mce_work), mce_process_work);
  1187. }
  1188. /*
  1189. * Character device to read and clear the MCE log.
  1190. */
  1191. static DEFINE_SPINLOCK(mce_state_lock);
  1192. static int open_count; /* #times opened */
  1193. static int open_exclu; /* already open exclusive? */
  1194. static int mce_open(struct inode *inode, struct file *file)
  1195. {
  1196. spin_lock(&mce_state_lock);
  1197. if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
  1198. spin_unlock(&mce_state_lock);
  1199. return -EBUSY;
  1200. }
  1201. if (file->f_flags & O_EXCL)
  1202. open_exclu = 1;
  1203. open_count++;
  1204. spin_unlock(&mce_state_lock);
  1205. return nonseekable_open(inode, file);
  1206. }
  1207. static int mce_release(struct inode *inode, struct file *file)
  1208. {
  1209. spin_lock(&mce_state_lock);
  1210. open_count--;
  1211. open_exclu = 0;
  1212. spin_unlock(&mce_state_lock);
  1213. return 0;
  1214. }
  1215. static void collect_tscs(void *data)
  1216. {
  1217. unsigned long *cpu_tsc = (unsigned long *)data;
  1218. rdtscll(cpu_tsc[smp_processor_id()]);
  1219. }
  1220. static DEFINE_MUTEX(mce_read_mutex);
  1221. static ssize_t mce_read(struct file *filp, char __user *ubuf, size_t usize,
  1222. loff_t *off)
  1223. {
  1224. char __user *buf = ubuf;
  1225. unsigned long *cpu_tsc;
  1226. unsigned prev, next;
  1227. int i, err;
  1228. cpu_tsc = kmalloc(nr_cpu_ids * sizeof(long), GFP_KERNEL);
  1229. if (!cpu_tsc)
  1230. return -ENOMEM;
  1231. mutex_lock(&mce_read_mutex);
  1232. next = rcu_dereference(mcelog.next);
  1233. /* Only supports full reads right now */
  1234. if (*off != 0 || usize < MCE_LOG_LEN*sizeof(struct mce)) {
  1235. mutex_unlock(&mce_read_mutex);
  1236. kfree(cpu_tsc);
  1237. return -EINVAL;
  1238. }
  1239. err = 0;
  1240. prev = 0;
  1241. do {
  1242. for (i = prev; i < next; i++) {
  1243. unsigned long start = jiffies;
  1244. while (!mcelog.entry[i].finished) {
  1245. if (time_after_eq(jiffies, start + 2)) {
  1246. memset(mcelog.entry + i, 0,
  1247. sizeof(struct mce));
  1248. goto timeout;
  1249. }
  1250. cpu_relax();
  1251. }
  1252. smp_rmb();
  1253. err |= copy_to_user(buf, mcelog.entry + i,
  1254. sizeof(struct mce));
  1255. buf += sizeof(struct mce);
  1256. timeout:
  1257. ;
  1258. }
  1259. memset(mcelog.entry + prev, 0,
  1260. (next - prev) * sizeof(struct mce));
  1261. prev = next;
  1262. next = cmpxchg(&mcelog.next, prev, 0);
  1263. } while (next != prev);
  1264. synchronize_sched();
  1265. /*
  1266. * Collect entries that were still getting written before the
  1267. * synchronize.
  1268. */
  1269. on_each_cpu(collect_tscs, cpu_tsc, 1);
  1270. for (i = next; i < MCE_LOG_LEN; i++) {
  1271. if (mcelog.entry[i].finished &&
  1272. mcelog.entry[i].tsc < cpu_tsc[mcelog.entry[i].cpu]) {
  1273. err |= copy_to_user(buf, mcelog.entry+i,
  1274. sizeof(struct mce));
  1275. smp_rmb();
  1276. buf += sizeof(struct mce);
  1277. memset(&mcelog.entry[i], 0, sizeof(struct mce));
  1278. }
  1279. }
  1280. mutex_unlock(&mce_read_mutex);
  1281. kfree(cpu_tsc);
  1282. return err ? -EFAULT : buf - ubuf;
  1283. }
  1284. static unsigned int mce_poll(struct file *file, poll_table *wait)
  1285. {
  1286. poll_wait(file, &mce_wait, wait);
  1287. if (rcu_dereference(mcelog.next))
  1288. return POLLIN | POLLRDNORM;
  1289. return 0;
  1290. }
  1291. static long mce_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
  1292. {
  1293. int __user *p = (int __user *)arg;
  1294. if (!capable(CAP_SYS_ADMIN))
  1295. return -EPERM;
  1296. switch (cmd) {
  1297. case MCE_GET_RECORD_LEN:
  1298. return put_user(sizeof(struct mce), p);
  1299. case MCE_GET_LOG_LEN:
  1300. return put_user(MCE_LOG_LEN, p);
  1301. case MCE_GETCLEAR_FLAGS: {
  1302. unsigned flags;
  1303. do {
  1304. flags = mcelog.flags;
  1305. } while (cmpxchg(&mcelog.flags, flags, 0) != flags);
  1306. return put_user(flags, p);
  1307. }
  1308. default:
  1309. return -ENOTTY;
  1310. }
  1311. }
  1312. /* Modified in mce-inject.c, so not static or const */
  1313. struct file_operations mce_chrdev_ops = {
  1314. .open = mce_open,
  1315. .release = mce_release,
  1316. .read = mce_read,
  1317. .poll = mce_poll,
  1318. .unlocked_ioctl = mce_ioctl,
  1319. };
  1320. EXPORT_SYMBOL_GPL(mce_chrdev_ops);
  1321. static struct miscdevice mce_log_device = {
  1322. MISC_MCELOG_MINOR,
  1323. "mcelog",
  1324. &mce_chrdev_ops,
  1325. };
  1326. /*
  1327. * mce=off Disables machine check
  1328. * mce=no_cmci Disables CMCI
  1329. * mce=dont_log_ce Clears corrected events silently, no log created for CEs.
  1330. * mce=ignore_ce Disables polling and CMCI, corrected events are not cleared.
  1331. * mce=TOLERANCELEVEL[,monarchtimeout] (number, see above)
  1332. * monarchtimeout is how long to wait for other CPUs on machine
  1333. * check, or 0 to not wait
  1334. * mce=bootlog Log MCEs from before booting. Disabled by default on AMD.
  1335. * mce=nobootlog Don't log MCEs from before booting.
  1336. */
  1337. static int __init mcheck_enable(char *str)
  1338. {
  1339. if (*str == 0)
  1340. enable_p5_mce();
  1341. if (*str == '=')
  1342. str++;
  1343. if (!strcmp(str, "off"))
  1344. mce_disabled = 1;
  1345. else if (!strcmp(str, "no_cmci"))
  1346. mce_cmci_disabled = 1;
  1347. else if (!strcmp(str, "dont_log_ce"))
  1348. mce_dont_log_ce = 1;
  1349. else if (!strcmp(str, "ignore_ce"))
  1350. mce_ignore_ce = 1;
  1351. else if (!strcmp(str, "bootlog") || !strcmp(str, "nobootlog"))
  1352. mce_bootlog = (str[0] == 'b');
  1353. else if (isdigit(str[0])) {
  1354. get_option(&str, &tolerant);
  1355. if (*str == ',') {
  1356. ++str;
  1357. get_option(&str, &monarch_timeout);
  1358. }
  1359. } else {
  1360. printk(KERN_INFO "mce argument %s ignored. Please use /sys\n",
  1361. str);
  1362. return 0;
  1363. }
  1364. return 1;
  1365. }
  1366. __setup("mce", mcheck_enable);
  1367. /*
  1368. * Sysfs support
  1369. */
  1370. /*
  1371. * Disable machine checks on suspend and shutdown. We can't really handle
  1372. * them later.
  1373. */
  1374. static int mce_disable(void)
  1375. {
  1376. int i;
  1377. for (i = 0; i < banks; i++) {
  1378. if (!skip_bank_init(i))
  1379. wrmsrl(MSR_IA32_MC0_CTL + i*4, 0);
  1380. }
  1381. return 0;
  1382. }
  1383. static int mce_suspend(struct sys_device *dev, pm_message_t state)
  1384. {
  1385. return mce_disable();
  1386. }
  1387. static int mce_shutdown(struct sys_device *dev)
  1388. {
  1389. return mce_disable();
  1390. }
  1391. /*
  1392. * On resume clear all MCE state. Don't want to see leftovers from the BIOS.
  1393. * Only one CPU is active at this time, the others get re-added later using
  1394. * CPU hotplug:
  1395. */
  1396. static int mce_resume(struct sys_device *dev)
  1397. {
  1398. mce_init();
  1399. mce_cpu_features(&current_cpu_data);
  1400. return 0;
  1401. }
  1402. static void mce_cpu_restart(void *data)
  1403. {
  1404. del_timer_sync(&__get_cpu_var(mce_timer));
  1405. if (!mce_available(&current_cpu_data))
  1406. return;
  1407. mce_init();
  1408. mce_init_timer();
  1409. }
  1410. /* Reinit MCEs after user configuration changes */
  1411. static void mce_restart(void)
  1412. {
  1413. on_each_cpu(mce_cpu_restart, NULL, 1);
  1414. }
  1415. /* Toggle features for corrected errors */
  1416. static void mce_disable_ce(void *all)
  1417. {
  1418. if (!mce_available(&current_cpu_data))
  1419. return;
  1420. if (all)
  1421. del_timer_sync(&__get_cpu_var(mce_timer));
  1422. cmci_clear();
  1423. }
  1424. static void mce_enable_ce(void *all)
  1425. {
  1426. if (!mce_available(&current_cpu_data))
  1427. return;
  1428. cmci_reenable();
  1429. cmci_recheck();
  1430. if (all)
  1431. mce_init_timer();
  1432. }
  1433. static struct sysdev_class mce_sysclass = {
  1434. .suspend = mce_suspend,
  1435. .shutdown = mce_shutdown,
  1436. .resume = mce_resume,
  1437. .name = "machinecheck",
  1438. };
  1439. DEFINE_PER_CPU(struct sys_device, mce_dev);
  1440. __cpuinitdata
  1441. void (*threshold_cpu_callback)(unsigned long action, unsigned int cpu);
  1442. static struct sysdev_attribute *bank_attrs;
  1443. static ssize_t show_bank(struct sys_device *s, struct sysdev_attribute *attr,
  1444. char *buf)
  1445. {
  1446. u64 b = bank[attr - bank_attrs];
  1447. return sprintf(buf, "%llx\n", b);
  1448. }
  1449. static ssize_t set_bank(struct sys_device *s, struct sysdev_attribute *attr,
  1450. const char *buf, size_t size)
  1451. {
  1452. u64 new;
  1453. if (strict_strtoull(buf, 0, &new) < 0)
  1454. return -EINVAL;
  1455. bank[attr - bank_attrs] = new;
  1456. mce_restart();
  1457. return size;
  1458. }
  1459. static ssize_t
  1460. show_trigger(struct sys_device *s, struct sysdev_attribute *attr, char *buf)
  1461. {
  1462. strcpy(buf, mce_helper);
  1463. strcat(buf, "\n");
  1464. return strlen(mce_helper) + 1;
  1465. }
  1466. static ssize_t set_trigger(struct sys_device *s, struct sysdev_attribute *attr,
  1467. const char *buf, size_t siz)
  1468. {
  1469. char *p;
  1470. strncpy(mce_helper, buf, sizeof(mce_helper));
  1471. mce_helper[sizeof(mce_helper)-1] = 0;
  1472. p = strchr(mce_helper, '\n');
  1473. if (p)
  1474. *p = 0;
  1475. return strlen(mce_helper) + !!p;
  1476. }
  1477. static ssize_t set_ignore_ce(struct sys_device *s,
  1478. struct sysdev_attribute *attr,
  1479. const char *buf, size_t size)
  1480. {
  1481. u64 new;
  1482. if (strict_strtoull(buf, 0, &new) < 0)
  1483. return -EINVAL;
  1484. if (mce_ignore_ce ^ !!new) {
  1485. if (new) {
  1486. /* disable ce features */
  1487. on_each_cpu(mce_disable_ce, (void *)1, 1);
  1488. mce_ignore_ce = 1;
  1489. } else {
  1490. /* enable ce features */
  1491. mce_ignore_ce = 0;
  1492. on_each_cpu(mce_enable_ce, (void *)1, 1);
  1493. }
  1494. }
  1495. return size;
  1496. }
  1497. static ssize_t set_cmci_disabled(struct sys_device *s,
  1498. struct sysdev_attribute *attr,
  1499. const char *buf, size_t size)
  1500. {
  1501. u64 new;
  1502. if (strict_strtoull(buf, 0, &new) < 0)
  1503. return -EINVAL;
  1504. if (mce_cmci_disabled ^ !!new) {
  1505. if (new) {
  1506. /* disable cmci */
  1507. on_each_cpu(mce_disable_ce, NULL, 1);
  1508. mce_cmci_disabled = 1;
  1509. } else {
  1510. /* enable cmci */
  1511. mce_cmci_disabled = 0;
  1512. on_each_cpu(mce_enable_ce, NULL, 1);
  1513. }
  1514. }
  1515. return size;
  1516. }
  1517. static ssize_t store_int_with_restart(struct sys_device *s,
  1518. struct sysdev_attribute *attr,
  1519. const char *buf, size_t size)
  1520. {
  1521. ssize_t ret = sysdev_store_int(s, attr, buf, size);
  1522. mce_restart();
  1523. return ret;
  1524. }
  1525. static SYSDEV_ATTR(trigger, 0644, show_trigger, set_trigger);
  1526. static SYSDEV_INT_ATTR(tolerant, 0644, tolerant);
  1527. static SYSDEV_INT_ATTR(monarch_timeout, 0644, monarch_timeout);
  1528. static SYSDEV_INT_ATTR(dont_log_ce, 0644, mce_dont_log_ce);
  1529. static struct sysdev_ext_attribute attr_check_interval = {
  1530. _SYSDEV_ATTR(check_interval, 0644, sysdev_show_int,
  1531. store_int_with_restart),
  1532. &check_interval
  1533. };
  1534. static struct sysdev_ext_attribute attr_ignore_ce = {
  1535. _SYSDEV_ATTR(ignore_ce, 0644, sysdev_show_int, set_ignore_ce),
  1536. &mce_ignore_ce
  1537. };
  1538. static struct sysdev_ext_attribute attr_cmci_disabled = {
  1539. _SYSDEV_ATTR(cmci_disabled, 0644, sysdev_show_int, set_cmci_disabled),
  1540. &mce_cmci_disabled
  1541. };
  1542. static struct sysdev_attribute *mce_attrs[] = {
  1543. &attr_tolerant.attr,
  1544. &attr_check_interval.attr,
  1545. &attr_trigger,
  1546. &attr_monarch_timeout.attr,
  1547. &attr_dont_log_ce.attr,
  1548. &attr_ignore_ce.attr,
  1549. &attr_cmci_disabled.attr,
  1550. NULL
  1551. };
  1552. static cpumask_var_t mce_dev_initialized;
  1553. /* Per cpu sysdev init. All of the cpus still share the same ctrl bank: */
  1554. static __cpuinit int mce_create_device(unsigned int cpu)
  1555. {
  1556. int err;
  1557. int i, j;
  1558. if (!mce_available(&boot_cpu_data))
  1559. return -EIO;
  1560. memset(&per_cpu(mce_dev, cpu).kobj, 0, sizeof(struct kobject));
  1561. per_cpu(mce_dev, cpu).id = cpu;
  1562. per_cpu(mce_dev, cpu).cls = &mce_sysclass;
  1563. err = sysdev_register(&per_cpu(mce_dev, cpu));
  1564. if (err)
  1565. return err;
  1566. for (i = 0; mce_attrs[i]; i++) {
  1567. err = sysdev_create_file(&per_cpu(mce_dev, cpu), mce_attrs[i]);
  1568. if (err)
  1569. goto error;
  1570. }
  1571. for (j = 0; j < banks; j++) {
  1572. err = sysdev_create_file(&per_cpu(mce_dev, cpu),
  1573. &bank_attrs[j]);
  1574. if (err)
  1575. goto error2;
  1576. }
  1577. cpumask_set_cpu(cpu, mce_dev_initialized);
  1578. return 0;
  1579. error2:
  1580. while (--j >= 0)
  1581. sysdev_remove_file(&per_cpu(mce_dev, cpu), &bank_attrs[j]);
  1582. error:
  1583. while (--i >= 0)
  1584. sysdev_remove_file(&per_cpu(mce_dev, cpu), mce_attrs[i]);
  1585. sysdev_unregister(&per_cpu(mce_dev, cpu));
  1586. return err;
  1587. }
  1588. static __cpuinit void mce_remove_device(unsigned int cpu)
  1589. {
  1590. int i;
  1591. if (!cpumask_test_cpu(cpu, mce_dev_initialized))
  1592. return;
  1593. for (i = 0; mce_attrs[i]; i++)
  1594. sysdev_remove_file(&per_cpu(mce_dev, cpu), mce_attrs[i]);
  1595. for (i = 0; i < banks; i++)
  1596. sysdev_remove_file(&per_cpu(mce_dev, cpu), &bank_attrs[i]);
  1597. sysdev_unregister(&per_cpu(mce_dev, cpu));
  1598. cpumask_clear_cpu(cpu, mce_dev_initialized);
  1599. }
  1600. /* Make sure there are no machine checks on offlined CPUs. */
  1601. static void mce_disable_cpu(void *h)
  1602. {
  1603. unsigned long action = *(unsigned long *)h;
  1604. int i;
  1605. if (!mce_available(&current_cpu_data))
  1606. return;
  1607. if (!(action & CPU_TASKS_FROZEN))
  1608. cmci_clear();
  1609. for (i = 0; i < banks; i++) {
  1610. if (!skip_bank_init(i))
  1611. wrmsrl(MSR_IA32_MC0_CTL + i*4, 0);
  1612. }
  1613. }
  1614. static void mce_reenable_cpu(void *h)
  1615. {
  1616. unsigned long action = *(unsigned long *)h;
  1617. int i;
  1618. if (!mce_available(&current_cpu_data))
  1619. return;
  1620. if (!(action & CPU_TASKS_FROZEN))
  1621. cmci_reenable();
  1622. for (i = 0; i < banks; i++) {
  1623. if (!skip_bank_init(i))
  1624. wrmsrl(MSR_IA32_MC0_CTL + i*4, bank[i]);
  1625. }
  1626. }
  1627. /* Get notified when a cpu comes on/off. Be hotplug friendly. */
  1628. static int __cpuinit
  1629. mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
  1630. {
  1631. unsigned int cpu = (unsigned long)hcpu;
  1632. struct timer_list *t = &per_cpu(mce_timer, cpu);
  1633. switch (action) {
  1634. case CPU_ONLINE:
  1635. case CPU_ONLINE_FROZEN:
  1636. mce_create_device(cpu);
  1637. if (threshold_cpu_callback)
  1638. threshold_cpu_callback(action, cpu);
  1639. break;
  1640. case CPU_DEAD:
  1641. case CPU_DEAD_FROZEN:
  1642. if (threshold_cpu_callback)
  1643. threshold_cpu_callback(action, cpu);
  1644. mce_remove_device(cpu);
  1645. break;
  1646. case CPU_DOWN_PREPARE:
  1647. case CPU_DOWN_PREPARE_FROZEN:
  1648. del_timer_sync(t);
  1649. smp_call_function_single(cpu, mce_disable_cpu, &action, 1);
  1650. break;
  1651. case CPU_DOWN_FAILED:
  1652. case CPU_DOWN_FAILED_FROZEN:
  1653. t->expires = round_jiffies(jiffies +
  1654. __get_cpu_var(next_interval));
  1655. add_timer_on(t, cpu);
  1656. smp_call_function_single(cpu, mce_reenable_cpu, &action, 1);
  1657. break;
  1658. case CPU_POST_DEAD:
  1659. /* intentionally ignoring frozen here */
  1660. cmci_rediscover(cpu);
  1661. break;
  1662. }
  1663. return NOTIFY_OK;
  1664. }
  1665. static struct notifier_block mce_cpu_notifier __cpuinitdata = {
  1666. .notifier_call = mce_cpu_callback,
  1667. };
  1668. static __init int mce_init_banks(void)
  1669. {
  1670. int i;
  1671. bank_attrs = kzalloc(sizeof(struct sysdev_attribute) * banks,
  1672. GFP_KERNEL);
  1673. if (!bank_attrs)
  1674. return -ENOMEM;
  1675. for (i = 0; i < banks; i++) {
  1676. struct sysdev_attribute *a = &bank_attrs[i];
  1677. a->attr.name = kasprintf(GFP_KERNEL, "bank%d", i);
  1678. if (!a->attr.name)
  1679. goto nomem;
  1680. a->attr.mode = 0644;
  1681. a->show = show_bank;
  1682. a->store = set_bank;
  1683. }
  1684. return 0;
  1685. nomem:
  1686. while (--i >= 0)
  1687. kfree(bank_attrs[i].attr.name);
  1688. kfree(bank_attrs);
  1689. bank_attrs = NULL;
  1690. return -ENOMEM;
  1691. }
  1692. static __init int mce_init_device(void)
  1693. {
  1694. int err;
  1695. int i = 0;
  1696. if (!mce_available(&boot_cpu_data))
  1697. return -EIO;
  1698. zalloc_cpumask_var(&mce_dev_initialized, GFP_KERNEL);
  1699. err = mce_init_banks();
  1700. if (err)
  1701. return err;
  1702. err = sysdev_class_register(&mce_sysclass);
  1703. if (err)
  1704. return err;
  1705. for_each_online_cpu(i) {
  1706. err = mce_create_device(i);
  1707. if (err)
  1708. return err;
  1709. }
  1710. register_hotcpu_notifier(&mce_cpu_notifier);
  1711. misc_register(&mce_log_device);
  1712. return err;
  1713. }
  1714. device_initcall(mce_init_device);
  1715. #else /* CONFIG_X86_OLD_MCE: */
  1716. int nr_mce_banks;
  1717. EXPORT_SYMBOL_GPL(nr_mce_banks); /* non-fatal.o */
  1718. /* This has to be run for each processor */
  1719. void mcheck_init(struct cpuinfo_x86 *c)
  1720. {
  1721. if (mce_disabled)
  1722. return;
  1723. switch (c->x86_vendor) {
  1724. case X86_VENDOR_AMD:
  1725. amd_mcheck_init(c);
  1726. break;
  1727. case X86_VENDOR_INTEL:
  1728. if (c->x86 == 5)
  1729. intel_p5_mcheck_init(c);
  1730. if (c->x86 == 6)
  1731. intel_p6_mcheck_init(c);
  1732. if (c->x86 == 15)
  1733. intel_p4_mcheck_init(c);
  1734. break;
  1735. case X86_VENDOR_CENTAUR:
  1736. if (c->x86 == 5)
  1737. winchip_mcheck_init(c);
  1738. break;
  1739. default:
  1740. break;
  1741. }
  1742. printk(KERN_INFO "mce: CPU supports %d MCE banks\n", nr_mce_banks);
  1743. }
  1744. static int __init mcheck_enable(char *str)
  1745. {
  1746. mce_p5_enabled = 1;
  1747. return 1;
  1748. }
  1749. __setup("mce", mcheck_enable);
  1750. #endif /* CONFIG_X86_OLD_MCE */
  1751. /*
  1752. * Old style boot options parsing. Only for compatibility.
  1753. */
  1754. static int __init mcheck_disable(char *str)
  1755. {
  1756. mce_disabled = 1;
  1757. return 1;
  1758. }
  1759. __setup("nomce", mcheck_disable);