mce.c 47 KB

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