mce.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049
  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 void mce_cpu_quirks(struct cpuinfo_x86 *c)
  1068. {
  1069. /* This should be disabled by the BIOS, but isn't always */
  1070. if (c->x86_vendor == X86_VENDOR_AMD) {
  1071. if (c->x86 == 15 && banks > 4) {
  1072. /*
  1073. * disable GART TBL walk error reporting, which
  1074. * trips off incorrectly with the IOMMU & 3ware
  1075. * & Cerberus:
  1076. */
  1077. clear_bit(10, (unsigned long *)&bank[4]);
  1078. }
  1079. if (c->x86 <= 17 && mce_bootlog < 0) {
  1080. /*
  1081. * Lots of broken BIOS around that don't clear them
  1082. * by default and leave crap in there. Don't log:
  1083. */
  1084. mce_bootlog = 0;
  1085. }
  1086. /*
  1087. * Various K7s with broken bank 0 around. Always disable
  1088. * by default.
  1089. */
  1090. if (c->x86 == 6 && banks > 0)
  1091. bank[0] = 0;
  1092. }
  1093. if (c->x86_vendor == X86_VENDOR_INTEL) {
  1094. /*
  1095. * SDM documents that on family 6 bank 0 should not be written
  1096. * because it aliases to another special BIOS controlled
  1097. * register.
  1098. * But it's not aliased anymore on model 0x1a+
  1099. * Don't ignore bank 0 completely because there could be a
  1100. * valid event later, merely don't write CTL0.
  1101. */
  1102. if (c->x86 == 6 && c->x86_model < 0x1A)
  1103. __set_bit(0, &dont_init_banks);
  1104. /*
  1105. * All newer Intel systems support MCE broadcasting. Enable
  1106. * synchronization with a one second timeout.
  1107. */
  1108. if ((c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xe)) &&
  1109. monarch_timeout < 0)
  1110. monarch_timeout = USEC_PER_SEC;
  1111. }
  1112. if (monarch_timeout < 0)
  1113. monarch_timeout = 0;
  1114. if (mce_bootlog != 0)
  1115. mce_panic_timeout = 30;
  1116. }
  1117. static void __cpuinit mce_ancient_init(struct cpuinfo_x86 *c)
  1118. {
  1119. if (c->x86 != 5)
  1120. return;
  1121. switch (c->x86_vendor) {
  1122. case X86_VENDOR_INTEL:
  1123. intel_p5_mcheck_init(c);
  1124. break;
  1125. case X86_VENDOR_CENTAUR:
  1126. winchip_mcheck_init(c);
  1127. break;
  1128. }
  1129. }
  1130. static void mce_cpu_features(struct cpuinfo_x86 *c)
  1131. {
  1132. switch (c->x86_vendor) {
  1133. case X86_VENDOR_INTEL:
  1134. mce_intel_feature_init(c);
  1135. break;
  1136. case X86_VENDOR_AMD:
  1137. mce_amd_feature_init(c);
  1138. break;
  1139. default:
  1140. break;
  1141. }
  1142. }
  1143. static void mce_init_timer(void)
  1144. {
  1145. struct timer_list *t = &__get_cpu_var(mce_timer);
  1146. int *n = &__get_cpu_var(next_interval);
  1147. if (mce_ignore_ce)
  1148. return;
  1149. *n = check_interval * HZ;
  1150. if (!*n)
  1151. return;
  1152. setup_timer(t, mcheck_timer, smp_processor_id());
  1153. t->expires = round_jiffies(jiffies + *n);
  1154. add_timer_on(t, smp_processor_id());
  1155. }
  1156. /*
  1157. * Called for each booted CPU to set up machine checks.
  1158. * Must be called with preempt off:
  1159. */
  1160. void __cpuinit mcheck_init(struct cpuinfo_x86 *c)
  1161. {
  1162. if (mce_disabled)
  1163. return;
  1164. mce_ancient_init(c);
  1165. if (!mce_available(c))
  1166. return;
  1167. if (mce_cap_init() < 0) {
  1168. mce_disabled = 1;
  1169. return;
  1170. }
  1171. mce_cpu_quirks(c);
  1172. machine_check_vector = do_machine_check;
  1173. mce_init();
  1174. mce_cpu_features(c);
  1175. mce_init_timer();
  1176. INIT_WORK(&__get_cpu_var(mce_work), mce_process_work);
  1177. }
  1178. /*
  1179. * Character device to read and clear the MCE log.
  1180. */
  1181. static DEFINE_SPINLOCK(mce_state_lock);
  1182. static int open_count; /* #times opened */
  1183. static int open_exclu; /* already open exclusive? */
  1184. static int mce_open(struct inode *inode, struct file *file)
  1185. {
  1186. spin_lock(&mce_state_lock);
  1187. if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
  1188. spin_unlock(&mce_state_lock);
  1189. return -EBUSY;
  1190. }
  1191. if (file->f_flags & O_EXCL)
  1192. open_exclu = 1;
  1193. open_count++;
  1194. spin_unlock(&mce_state_lock);
  1195. return nonseekable_open(inode, file);
  1196. }
  1197. static int mce_release(struct inode *inode, struct file *file)
  1198. {
  1199. spin_lock(&mce_state_lock);
  1200. open_count--;
  1201. open_exclu = 0;
  1202. spin_unlock(&mce_state_lock);
  1203. return 0;
  1204. }
  1205. static void collect_tscs(void *data)
  1206. {
  1207. unsigned long *cpu_tsc = (unsigned long *)data;
  1208. rdtscll(cpu_tsc[smp_processor_id()]);
  1209. }
  1210. static DEFINE_MUTEX(mce_read_mutex);
  1211. static ssize_t mce_read(struct file *filp, char __user *ubuf, size_t usize,
  1212. loff_t *off)
  1213. {
  1214. char __user *buf = ubuf;
  1215. unsigned long *cpu_tsc;
  1216. unsigned prev, next;
  1217. int i, err;
  1218. cpu_tsc = kmalloc(nr_cpu_ids * sizeof(long), GFP_KERNEL);
  1219. if (!cpu_tsc)
  1220. return -ENOMEM;
  1221. mutex_lock(&mce_read_mutex);
  1222. next = rcu_dereference(mcelog.next);
  1223. /* Only supports full reads right now */
  1224. if (*off != 0 || usize < MCE_LOG_LEN*sizeof(struct mce)) {
  1225. mutex_unlock(&mce_read_mutex);
  1226. kfree(cpu_tsc);
  1227. return -EINVAL;
  1228. }
  1229. err = 0;
  1230. prev = 0;
  1231. do {
  1232. for (i = prev; i < next; i++) {
  1233. unsigned long start = jiffies;
  1234. while (!mcelog.entry[i].finished) {
  1235. if (time_after_eq(jiffies, start + 2)) {
  1236. memset(mcelog.entry + i, 0,
  1237. sizeof(struct mce));
  1238. goto timeout;
  1239. }
  1240. cpu_relax();
  1241. }
  1242. smp_rmb();
  1243. err |= copy_to_user(buf, mcelog.entry + i,
  1244. sizeof(struct mce));
  1245. buf += sizeof(struct mce);
  1246. timeout:
  1247. ;
  1248. }
  1249. memset(mcelog.entry + prev, 0,
  1250. (next - prev) * sizeof(struct mce));
  1251. prev = next;
  1252. next = cmpxchg(&mcelog.next, prev, 0);
  1253. } while (next != prev);
  1254. synchronize_sched();
  1255. /*
  1256. * Collect entries that were still getting written before the
  1257. * synchronize.
  1258. */
  1259. on_each_cpu(collect_tscs, cpu_tsc, 1);
  1260. for (i = next; i < MCE_LOG_LEN; i++) {
  1261. if (mcelog.entry[i].finished &&
  1262. mcelog.entry[i].tsc < cpu_tsc[mcelog.entry[i].cpu]) {
  1263. err |= copy_to_user(buf, mcelog.entry+i,
  1264. sizeof(struct mce));
  1265. smp_rmb();
  1266. buf += sizeof(struct mce);
  1267. memset(&mcelog.entry[i], 0, sizeof(struct mce));
  1268. }
  1269. }
  1270. mutex_unlock(&mce_read_mutex);
  1271. kfree(cpu_tsc);
  1272. return err ? -EFAULT : buf - ubuf;
  1273. }
  1274. static unsigned int mce_poll(struct file *file, poll_table *wait)
  1275. {
  1276. poll_wait(file, &mce_wait, wait);
  1277. if (rcu_dereference(mcelog.next))
  1278. return POLLIN | POLLRDNORM;
  1279. return 0;
  1280. }
  1281. static long mce_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
  1282. {
  1283. int __user *p = (int __user *)arg;
  1284. if (!capable(CAP_SYS_ADMIN))
  1285. return -EPERM;
  1286. switch (cmd) {
  1287. case MCE_GET_RECORD_LEN:
  1288. return put_user(sizeof(struct mce), p);
  1289. case MCE_GET_LOG_LEN:
  1290. return put_user(MCE_LOG_LEN, p);
  1291. case MCE_GETCLEAR_FLAGS: {
  1292. unsigned flags;
  1293. do {
  1294. flags = mcelog.flags;
  1295. } while (cmpxchg(&mcelog.flags, flags, 0) != flags);
  1296. return put_user(flags, p);
  1297. }
  1298. default:
  1299. return -ENOTTY;
  1300. }
  1301. }
  1302. /* Modified in mce-inject.c, so not static or const */
  1303. struct file_operations mce_chrdev_ops = {
  1304. .open = mce_open,
  1305. .release = mce_release,
  1306. .read = mce_read,
  1307. .poll = mce_poll,
  1308. .unlocked_ioctl = mce_ioctl,
  1309. };
  1310. EXPORT_SYMBOL_GPL(mce_chrdev_ops);
  1311. static struct miscdevice mce_log_device = {
  1312. MISC_MCELOG_MINOR,
  1313. "mcelog",
  1314. &mce_chrdev_ops,
  1315. };
  1316. /*
  1317. * mce=off Disables machine check
  1318. * mce=no_cmci Disables CMCI
  1319. * mce=dont_log_ce Clears corrected events silently, no log created for CEs.
  1320. * mce=ignore_ce Disables polling and CMCI, corrected events are not cleared.
  1321. * mce=TOLERANCELEVEL[,monarchtimeout] (number, see above)
  1322. * monarchtimeout is how long to wait for other CPUs on machine
  1323. * check, or 0 to not wait
  1324. * mce=bootlog Log MCEs from before booting. Disabled by default on AMD.
  1325. * mce=nobootlog Don't log MCEs from before booting.
  1326. */
  1327. static int __init mcheck_enable(char *str)
  1328. {
  1329. if (*str == 0)
  1330. enable_p5_mce();
  1331. if (*str == '=')
  1332. str++;
  1333. if (!strcmp(str, "off"))
  1334. mce_disabled = 1;
  1335. else if (!strcmp(str, "no_cmci"))
  1336. mce_cmci_disabled = 1;
  1337. else if (!strcmp(str, "dont_log_ce"))
  1338. mce_dont_log_ce = 1;
  1339. else if (!strcmp(str, "ignore_ce"))
  1340. mce_ignore_ce = 1;
  1341. else if (!strcmp(str, "bootlog") || !strcmp(str, "nobootlog"))
  1342. mce_bootlog = (str[0] == 'b');
  1343. else if (isdigit(str[0])) {
  1344. get_option(&str, &tolerant);
  1345. if (*str == ',') {
  1346. ++str;
  1347. get_option(&str, &monarch_timeout);
  1348. }
  1349. } else {
  1350. printk(KERN_INFO "mce argument %s ignored. Please use /sys\n",
  1351. str);
  1352. return 0;
  1353. }
  1354. return 1;
  1355. }
  1356. __setup("mce", mcheck_enable);
  1357. /*
  1358. * Sysfs support
  1359. */
  1360. /*
  1361. * Disable machine checks on suspend and shutdown. We can't really handle
  1362. * them later.
  1363. */
  1364. static int mce_disable(void)
  1365. {
  1366. int i;
  1367. for (i = 0; i < banks; i++) {
  1368. if (!skip_bank_init(i))
  1369. wrmsrl(MSR_IA32_MC0_CTL + i*4, 0);
  1370. }
  1371. return 0;
  1372. }
  1373. static int mce_suspend(struct sys_device *dev, pm_message_t state)
  1374. {
  1375. return mce_disable();
  1376. }
  1377. static int mce_shutdown(struct sys_device *dev)
  1378. {
  1379. return mce_disable();
  1380. }
  1381. /*
  1382. * On resume clear all MCE state. Don't want to see leftovers from the BIOS.
  1383. * Only one CPU is active at this time, the others get re-added later using
  1384. * CPU hotplug:
  1385. */
  1386. static int mce_resume(struct sys_device *dev)
  1387. {
  1388. mce_init();
  1389. mce_cpu_features(&current_cpu_data);
  1390. return 0;
  1391. }
  1392. static void mce_cpu_restart(void *data)
  1393. {
  1394. del_timer_sync(&__get_cpu_var(mce_timer));
  1395. if (!mce_available(&current_cpu_data))
  1396. return;
  1397. mce_init();
  1398. mce_init_timer();
  1399. }
  1400. /* Reinit MCEs after user configuration changes */
  1401. static void mce_restart(void)
  1402. {
  1403. on_each_cpu(mce_cpu_restart, NULL, 1);
  1404. }
  1405. /* Toggle features for corrected errors */
  1406. static void mce_disable_ce(void *all)
  1407. {
  1408. if (!mce_available(&current_cpu_data))
  1409. return;
  1410. if (all)
  1411. del_timer_sync(&__get_cpu_var(mce_timer));
  1412. cmci_clear();
  1413. }
  1414. static void mce_enable_ce(void *all)
  1415. {
  1416. if (!mce_available(&current_cpu_data))
  1417. return;
  1418. cmci_reenable();
  1419. cmci_recheck();
  1420. if (all)
  1421. mce_init_timer();
  1422. }
  1423. static struct sysdev_class mce_sysclass = {
  1424. .suspend = mce_suspend,
  1425. .shutdown = mce_shutdown,
  1426. .resume = mce_resume,
  1427. .name = "machinecheck",
  1428. };
  1429. DEFINE_PER_CPU(struct sys_device, mce_dev);
  1430. __cpuinitdata
  1431. void (*threshold_cpu_callback)(unsigned long action, unsigned int cpu);
  1432. static struct sysdev_attribute *bank_attrs;
  1433. static ssize_t show_bank(struct sys_device *s, struct sysdev_attribute *attr,
  1434. char *buf)
  1435. {
  1436. u64 b = bank[attr - bank_attrs];
  1437. return sprintf(buf, "%llx\n", b);
  1438. }
  1439. static ssize_t set_bank(struct sys_device *s, struct sysdev_attribute *attr,
  1440. const char *buf, size_t size)
  1441. {
  1442. u64 new;
  1443. if (strict_strtoull(buf, 0, &new) < 0)
  1444. return -EINVAL;
  1445. bank[attr - bank_attrs] = new;
  1446. mce_restart();
  1447. return size;
  1448. }
  1449. static ssize_t
  1450. show_trigger(struct sys_device *s, struct sysdev_attribute *attr, char *buf)
  1451. {
  1452. strcpy(buf, mce_helper);
  1453. strcat(buf, "\n");
  1454. return strlen(mce_helper) + 1;
  1455. }
  1456. static ssize_t set_trigger(struct sys_device *s, struct sysdev_attribute *attr,
  1457. const char *buf, size_t siz)
  1458. {
  1459. char *p;
  1460. int len;
  1461. strncpy(mce_helper, buf, sizeof(mce_helper));
  1462. mce_helper[sizeof(mce_helper)-1] = 0;
  1463. len = strlen(mce_helper);
  1464. p = strchr(mce_helper, '\n');
  1465. if (*p)
  1466. *p = 0;
  1467. return len;
  1468. }
  1469. static ssize_t set_ignore_ce(struct sys_device *s,
  1470. struct sysdev_attribute *attr,
  1471. const char *buf, size_t size)
  1472. {
  1473. u64 new;
  1474. if (strict_strtoull(buf, 0, &new) < 0)
  1475. return -EINVAL;
  1476. if (mce_ignore_ce ^ !!new) {
  1477. if (new) {
  1478. /* disable ce features */
  1479. on_each_cpu(mce_disable_ce, (void *)1, 1);
  1480. mce_ignore_ce = 1;
  1481. } else {
  1482. /* enable ce features */
  1483. mce_ignore_ce = 0;
  1484. on_each_cpu(mce_enable_ce, (void *)1, 1);
  1485. }
  1486. }
  1487. return size;
  1488. }
  1489. static ssize_t set_cmci_disabled(struct sys_device *s,
  1490. struct sysdev_attribute *attr,
  1491. const char *buf, size_t size)
  1492. {
  1493. u64 new;
  1494. if (strict_strtoull(buf, 0, &new) < 0)
  1495. return -EINVAL;
  1496. if (mce_cmci_disabled ^ !!new) {
  1497. if (new) {
  1498. /* disable cmci */
  1499. on_each_cpu(mce_disable_ce, NULL, 1);
  1500. mce_cmci_disabled = 1;
  1501. } else {
  1502. /* enable cmci */
  1503. mce_cmci_disabled = 0;
  1504. on_each_cpu(mce_enable_ce, NULL, 1);
  1505. }
  1506. }
  1507. return size;
  1508. }
  1509. static ssize_t store_int_with_restart(struct sys_device *s,
  1510. struct sysdev_attribute *attr,
  1511. const char *buf, size_t size)
  1512. {
  1513. ssize_t ret = sysdev_store_int(s, attr, buf, size);
  1514. mce_restart();
  1515. return ret;
  1516. }
  1517. static SYSDEV_ATTR(trigger, 0644, show_trigger, set_trigger);
  1518. static SYSDEV_INT_ATTR(tolerant, 0644, tolerant);
  1519. static SYSDEV_INT_ATTR(monarch_timeout, 0644, monarch_timeout);
  1520. static SYSDEV_INT_ATTR(dont_log_ce, 0644, mce_dont_log_ce);
  1521. static struct sysdev_ext_attribute attr_check_interval = {
  1522. _SYSDEV_ATTR(check_interval, 0644, sysdev_show_int,
  1523. store_int_with_restart),
  1524. &check_interval
  1525. };
  1526. static struct sysdev_ext_attribute attr_ignore_ce = {
  1527. _SYSDEV_ATTR(ignore_ce, 0644, sysdev_show_int, set_ignore_ce),
  1528. &mce_ignore_ce
  1529. };
  1530. static struct sysdev_ext_attribute attr_cmci_disabled = {
  1531. _SYSDEV_ATTR(cmci_disabled, 0644, sysdev_show_int, set_cmci_disabled),
  1532. &mce_cmci_disabled
  1533. };
  1534. static struct sysdev_attribute *mce_attrs[] = {
  1535. &attr_tolerant.attr,
  1536. &attr_check_interval.attr,
  1537. &attr_trigger,
  1538. &attr_monarch_timeout.attr,
  1539. &attr_dont_log_ce.attr,
  1540. &attr_ignore_ce.attr,
  1541. &attr_cmci_disabled.attr,
  1542. NULL
  1543. };
  1544. static cpumask_var_t mce_dev_initialized;
  1545. /* Per cpu sysdev init. All of the cpus still share the same ctrl bank: */
  1546. static __cpuinit int mce_create_device(unsigned int cpu)
  1547. {
  1548. int err;
  1549. int i, j;
  1550. if (!mce_available(&boot_cpu_data))
  1551. return -EIO;
  1552. memset(&per_cpu(mce_dev, cpu).kobj, 0, sizeof(struct kobject));
  1553. per_cpu(mce_dev, cpu).id = cpu;
  1554. per_cpu(mce_dev, cpu).cls = &mce_sysclass;
  1555. err = sysdev_register(&per_cpu(mce_dev, cpu));
  1556. if (err)
  1557. return err;
  1558. for (i = 0; mce_attrs[i]; i++) {
  1559. err = sysdev_create_file(&per_cpu(mce_dev, cpu), mce_attrs[i]);
  1560. if (err)
  1561. goto error;
  1562. }
  1563. for (j = 0; j < banks; j++) {
  1564. err = sysdev_create_file(&per_cpu(mce_dev, cpu),
  1565. &bank_attrs[j]);
  1566. if (err)
  1567. goto error2;
  1568. }
  1569. cpumask_set_cpu(cpu, mce_dev_initialized);
  1570. return 0;
  1571. error2:
  1572. while (--j >= 0)
  1573. sysdev_remove_file(&per_cpu(mce_dev, cpu), &bank_attrs[j]);
  1574. error:
  1575. while (--i >= 0)
  1576. sysdev_remove_file(&per_cpu(mce_dev, cpu), mce_attrs[i]);
  1577. sysdev_unregister(&per_cpu(mce_dev, cpu));
  1578. return err;
  1579. }
  1580. static __cpuinit void mce_remove_device(unsigned int cpu)
  1581. {
  1582. int i;
  1583. if (!cpumask_test_cpu(cpu, mce_dev_initialized))
  1584. return;
  1585. for (i = 0; mce_attrs[i]; i++)
  1586. sysdev_remove_file(&per_cpu(mce_dev, cpu), mce_attrs[i]);
  1587. for (i = 0; i < banks; i++)
  1588. sysdev_remove_file(&per_cpu(mce_dev, cpu), &bank_attrs[i]);
  1589. sysdev_unregister(&per_cpu(mce_dev, cpu));
  1590. cpumask_clear_cpu(cpu, mce_dev_initialized);
  1591. }
  1592. /* Make sure there are no machine checks on offlined CPUs. */
  1593. static void mce_disable_cpu(void *h)
  1594. {
  1595. unsigned long action = *(unsigned long *)h;
  1596. int i;
  1597. if (!mce_available(&current_cpu_data))
  1598. return;
  1599. if (!(action & CPU_TASKS_FROZEN))
  1600. cmci_clear();
  1601. for (i = 0; i < banks; i++) {
  1602. if (!skip_bank_init(i))
  1603. wrmsrl(MSR_IA32_MC0_CTL + i*4, 0);
  1604. }
  1605. }
  1606. static void mce_reenable_cpu(void *h)
  1607. {
  1608. unsigned long action = *(unsigned long *)h;
  1609. int i;
  1610. if (!mce_available(&current_cpu_data))
  1611. return;
  1612. if (!(action & CPU_TASKS_FROZEN))
  1613. cmci_reenable();
  1614. for (i = 0; i < banks; i++) {
  1615. if (!skip_bank_init(i))
  1616. wrmsrl(MSR_IA32_MC0_CTL + i*4, bank[i]);
  1617. }
  1618. }
  1619. /* Get notified when a cpu comes on/off. Be hotplug friendly. */
  1620. static int __cpuinit
  1621. mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
  1622. {
  1623. unsigned int cpu = (unsigned long)hcpu;
  1624. struct timer_list *t = &per_cpu(mce_timer, cpu);
  1625. switch (action) {
  1626. case CPU_ONLINE:
  1627. case CPU_ONLINE_FROZEN:
  1628. mce_create_device(cpu);
  1629. if (threshold_cpu_callback)
  1630. threshold_cpu_callback(action, cpu);
  1631. break;
  1632. case CPU_DEAD:
  1633. case CPU_DEAD_FROZEN:
  1634. if (threshold_cpu_callback)
  1635. threshold_cpu_callback(action, cpu);
  1636. mce_remove_device(cpu);
  1637. break;
  1638. case CPU_DOWN_PREPARE:
  1639. case CPU_DOWN_PREPARE_FROZEN:
  1640. del_timer_sync(t);
  1641. smp_call_function_single(cpu, mce_disable_cpu, &action, 1);
  1642. break;
  1643. case CPU_DOWN_FAILED:
  1644. case CPU_DOWN_FAILED_FROZEN:
  1645. t->expires = round_jiffies(jiffies +
  1646. __get_cpu_var(next_interval));
  1647. add_timer_on(t, cpu);
  1648. smp_call_function_single(cpu, mce_reenable_cpu, &action, 1);
  1649. break;
  1650. case CPU_POST_DEAD:
  1651. /* intentionally ignoring frozen here */
  1652. cmci_rediscover(cpu);
  1653. break;
  1654. }
  1655. return NOTIFY_OK;
  1656. }
  1657. static struct notifier_block mce_cpu_notifier __cpuinitdata = {
  1658. .notifier_call = mce_cpu_callback,
  1659. };
  1660. static __init int mce_init_banks(void)
  1661. {
  1662. int i;
  1663. bank_attrs = kzalloc(sizeof(struct sysdev_attribute) * banks,
  1664. GFP_KERNEL);
  1665. if (!bank_attrs)
  1666. return -ENOMEM;
  1667. for (i = 0; i < banks; i++) {
  1668. struct sysdev_attribute *a = &bank_attrs[i];
  1669. a->attr.name = kasprintf(GFP_KERNEL, "bank%d", i);
  1670. if (!a->attr.name)
  1671. goto nomem;
  1672. a->attr.mode = 0644;
  1673. a->show = show_bank;
  1674. a->store = set_bank;
  1675. }
  1676. return 0;
  1677. nomem:
  1678. while (--i >= 0)
  1679. kfree(bank_attrs[i].attr.name);
  1680. kfree(bank_attrs);
  1681. bank_attrs = NULL;
  1682. return -ENOMEM;
  1683. }
  1684. static __init int mce_init_device(void)
  1685. {
  1686. int err;
  1687. int i = 0;
  1688. if (!mce_available(&boot_cpu_data))
  1689. return -EIO;
  1690. zalloc_cpumask_var(&mce_dev_initialized, GFP_KERNEL);
  1691. err = mce_init_banks();
  1692. if (err)
  1693. return err;
  1694. err = sysdev_class_register(&mce_sysclass);
  1695. if (err)
  1696. return err;
  1697. for_each_online_cpu(i) {
  1698. err = mce_create_device(i);
  1699. if (err)
  1700. return err;
  1701. }
  1702. register_hotcpu_notifier(&mce_cpu_notifier);
  1703. misc_register(&mce_log_device);
  1704. return err;
  1705. }
  1706. device_initcall(mce_init_device);
  1707. #else /* CONFIG_X86_OLD_MCE: */
  1708. int nr_mce_banks;
  1709. EXPORT_SYMBOL_GPL(nr_mce_banks); /* non-fatal.o */
  1710. /* This has to be run for each processor */
  1711. void mcheck_init(struct cpuinfo_x86 *c)
  1712. {
  1713. if (mce_disabled)
  1714. return;
  1715. switch (c->x86_vendor) {
  1716. case X86_VENDOR_AMD:
  1717. amd_mcheck_init(c);
  1718. break;
  1719. case X86_VENDOR_INTEL:
  1720. if (c->x86 == 5)
  1721. intel_p5_mcheck_init(c);
  1722. if (c->x86 == 6)
  1723. intel_p6_mcheck_init(c);
  1724. if (c->x86 == 15)
  1725. intel_p4_mcheck_init(c);
  1726. break;
  1727. case X86_VENDOR_CENTAUR:
  1728. if (c->x86 == 5)
  1729. winchip_mcheck_init(c);
  1730. break;
  1731. default:
  1732. break;
  1733. }
  1734. printk(KERN_INFO "mce: CPU supports %d MCE banks\n", nr_mce_banks);
  1735. }
  1736. static int __init mcheck_enable(char *str)
  1737. {
  1738. mce_p5_enabled = 1;
  1739. return 1;
  1740. }
  1741. __setup("mce", mcheck_enable);
  1742. #endif /* CONFIG_X86_OLD_MCE */
  1743. /*
  1744. * Old style boot options parsing. Only for compatibility.
  1745. */
  1746. static int __init mcheck_disable(char *str)
  1747. {
  1748. mce_disabled = 1;
  1749. return 1;
  1750. }
  1751. __setup("nomce", mcheck_disable);