ras.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. /*
  2. * Copyright (C) 2001 Dave Engebretsen IBM Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #include <linux/sched.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/irq.h>
  21. #include <linux/of.h>
  22. #include <linux/fs.h>
  23. #include <linux/reboot.h>
  24. #include <linux/irq_work.h>
  25. #include <asm/machdep.h>
  26. #include <asm/rtas.h>
  27. #include <asm/firmware.h>
  28. #include <asm/mce.h>
  29. #include "pseries.h"
  30. static unsigned char ras_log_buf[RTAS_ERROR_LOG_MAX];
  31. static DEFINE_SPINLOCK(ras_log_buf_lock);
  32. static int ras_check_exception_token;
  33. static void mce_process_errlog_event(struct irq_work *work);
  34. static struct irq_work mce_errlog_process_work = {
  35. .func = mce_process_errlog_event,
  36. };
  37. #define EPOW_SENSOR_TOKEN 9
  38. #define EPOW_SENSOR_INDEX 0
  39. /* EPOW events counter variable */
  40. static int num_epow_events;
  41. static irqreturn_t ras_hotplug_interrupt(int irq, void *dev_id);
  42. static irqreturn_t ras_epow_interrupt(int irq, void *dev_id);
  43. static irqreturn_t ras_error_interrupt(int irq, void *dev_id);
  44. /* RTAS pseries MCE errorlog section. */
  45. struct pseries_mc_errorlog {
  46. __be32 fru_id;
  47. __be32 proc_id;
  48. u8 error_type;
  49. /*
  50. * sub_err_type (1 byte). Bit fields depends on error_type
  51. *
  52. * MSB0
  53. * |
  54. * V
  55. * 01234567
  56. * XXXXXXXX
  57. *
  58. * For error_type == MC_ERROR_TYPE_UE
  59. * XXXXXXXX
  60. * X 1: Permanent or Transient UE.
  61. * X 1: Effective address provided.
  62. * X 1: Logical address provided.
  63. * XX 2: Reserved.
  64. * XXX 3: Type of UE error.
  65. *
  66. * For error_type != MC_ERROR_TYPE_UE
  67. * XXXXXXXX
  68. * X 1: Effective address provided.
  69. * XXXXX 5: Reserved.
  70. * XX 2: Type of SLB/ERAT/TLB error.
  71. */
  72. u8 sub_err_type;
  73. u8 reserved_1[6];
  74. __be64 effective_address;
  75. __be64 logical_address;
  76. } __packed;
  77. /* RTAS pseries MCE error types */
  78. #define MC_ERROR_TYPE_UE 0x00
  79. #define MC_ERROR_TYPE_SLB 0x01
  80. #define MC_ERROR_TYPE_ERAT 0x02
  81. #define MC_ERROR_TYPE_TLB 0x04
  82. #define MC_ERROR_TYPE_D_CACHE 0x05
  83. #define MC_ERROR_TYPE_I_CACHE 0x07
  84. /* RTAS pseries MCE error sub types */
  85. #define MC_ERROR_UE_INDETERMINATE 0
  86. #define MC_ERROR_UE_IFETCH 1
  87. #define MC_ERROR_UE_PAGE_TABLE_WALK_IFETCH 2
  88. #define MC_ERROR_UE_LOAD_STORE 3
  89. #define MC_ERROR_UE_PAGE_TABLE_WALK_LOAD_STORE 4
  90. #define MC_ERROR_SLB_PARITY 0
  91. #define MC_ERROR_SLB_MULTIHIT 1
  92. #define MC_ERROR_SLB_INDETERMINATE 2
  93. #define MC_ERROR_ERAT_PARITY 1
  94. #define MC_ERROR_ERAT_MULTIHIT 2
  95. #define MC_ERROR_ERAT_INDETERMINATE 3
  96. #define MC_ERROR_TLB_PARITY 1
  97. #define MC_ERROR_TLB_MULTIHIT 2
  98. #define MC_ERROR_TLB_INDETERMINATE 3
  99. static inline u8 rtas_mc_error_sub_type(const struct pseries_mc_errorlog *mlog)
  100. {
  101. switch (mlog->error_type) {
  102. case MC_ERROR_TYPE_UE:
  103. return (mlog->sub_err_type & 0x07);
  104. case MC_ERROR_TYPE_SLB:
  105. case MC_ERROR_TYPE_ERAT:
  106. case MC_ERROR_TYPE_TLB:
  107. return (mlog->sub_err_type & 0x03);
  108. default:
  109. return 0;
  110. }
  111. }
  112. static
  113. inline u64 rtas_mc_get_effective_addr(const struct pseries_mc_errorlog *mlog)
  114. {
  115. __be64 addr = 0;
  116. switch (mlog->error_type) {
  117. case MC_ERROR_TYPE_UE:
  118. if (mlog->sub_err_type & 0x40)
  119. addr = mlog->effective_address;
  120. break;
  121. case MC_ERROR_TYPE_SLB:
  122. case MC_ERROR_TYPE_ERAT:
  123. case MC_ERROR_TYPE_TLB:
  124. if (mlog->sub_err_type & 0x80)
  125. addr = mlog->effective_address;
  126. default:
  127. break;
  128. }
  129. return be64_to_cpu(addr);
  130. }
  131. /*
  132. * Enable the hotplug interrupt late because processing them may touch other
  133. * devices or systems (e.g. hugepages) that have not been initialized at the
  134. * subsys stage.
  135. */
  136. int __init init_ras_hotplug_IRQ(void)
  137. {
  138. struct device_node *np;
  139. /* Hotplug Events */
  140. np = of_find_node_by_path("/event-sources/hot-plug-events");
  141. if (np != NULL) {
  142. if (dlpar_workqueue_init() == 0)
  143. request_event_sources_irqs(np, ras_hotplug_interrupt,
  144. "RAS_HOTPLUG");
  145. of_node_put(np);
  146. }
  147. return 0;
  148. }
  149. machine_late_initcall(pseries, init_ras_hotplug_IRQ);
  150. /*
  151. * Initialize handlers for the set of interrupts caused by hardware errors
  152. * and power system events.
  153. */
  154. static int __init init_ras_IRQ(void)
  155. {
  156. struct device_node *np;
  157. ras_check_exception_token = rtas_token("check-exception");
  158. /* Internal Errors */
  159. np = of_find_node_by_path("/event-sources/internal-errors");
  160. if (np != NULL) {
  161. request_event_sources_irqs(np, ras_error_interrupt,
  162. "RAS_ERROR");
  163. of_node_put(np);
  164. }
  165. /* EPOW Events */
  166. np = of_find_node_by_path("/event-sources/epow-events");
  167. if (np != NULL) {
  168. request_event_sources_irqs(np, ras_epow_interrupt, "RAS_EPOW");
  169. of_node_put(np);
  170. }
  171. return 0;
  172. }
  173. machine_subsys_initcall(pseries, init_ras_IRQ);
  174. #define EPOW_SHUTDOWN_NORMAL 1
  175. #define EPOW_SHUTDOWN_ON_UPS 2
  176. #define EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS 3
  177. #define EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH 4
  178. static void handle_system_shutdown(char event_modifier)
  179. {
  180. switch (event_modifier) {
  181. case EPOW_SHUTDOWN_NORMAL:
  182. pr_emerg("Power off requested\n");
  183. orderly_poweroff(true);
  184. break;
  185. case EPOW_SHUTDOWN_ON_UPS:
  186. pr_emerg("Loss of system power detected. System is running on"
  187. " UPS/battery. Check RTAS error log for details\n");
  188. orderly_poweroff(true);
  189. break;
  190. case EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS:
  191. pr_emerg("Loss of system critical functions detected. Check"
  192. " RTAS error log for details\n");
  193. orderly_poweroff(true);
  194. break;
  195. case EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH:
  196. pr_emerg("High ambient temperature detected. Check RTAS"
  197. " error log for details\n");
  198. orderly_poweroff(true);
  199. break;
  200. default:
  201. pr_err("Unknown power/cooling shutdown event (modifier = %d)\n",
  202. event_modifier);
  203. }
  204. }
  205. struct epow_errorlog {
  206. unsigned char sensor_value;
  207. unsigned char event_modifier;
  208. unsigned char extended_modifier;
  209. unsigned char reserved;
  210. unsigned char platform_reason;
  211. };
  212. #define EPOW_RESET 0
  213. #define EPOW_WARN_COOLING 1
  214. #define EPOW_WARN_POWER 2
  215. #define EPOW_SYSTEM_SHUTDOWN 3
  216. #define EPOW_SYSTEM_HALT 4
  217. #define EPOW_MAIN_ENCLOSURE 5
  218. #define EPOW_POWER_OFF 7
  219. static void rtas_parse_epow_errlog(struct rtas_error_log *log)
  220. {
  221. struct pseries_errorlog *pseries_log;
  222. struct epow_errorlog *epow_log;
  223. char action_code;
  224. char modifier;
  225. pseries_log = get_pseries_errorlog(log, PSERIES_ELOG_SECT_ID_EPOW);
  226. if (pseries_log == NULL)
  227. return;
  228. epow_log = (struct epow_errorlog *)pseries_log->data;
  229. action_code = epow_log->sensor_value & 0xF; /* bottom 4 bits */
  230. modifier = epow_log->event_modifier & 0xF; /* bottom 4 bits */
  231. switch (action_code) {
  232. case EPOW_RESET:
  233. if (num_epow_events) {
  234. pr_info("Non critical power/cooling issue cleared\n");
  235. num_epow_events--;
  236. }
  237. break;
  238. case EPOW_WARN_COOLING:
  239. pr_info("Non-critical cooling issue detected. Check RTAS error"
  240. " log for details\n");
  241. break;
  242. case EPOW_WARN_POWER:
  243. pr_info("Non-critical power issue detected. Check RTAS error"
  244. " log for details\n");
  245. break;
  246. case EPOW_SYSTEM_SHUTDOWN:
  247. handle_system_shutdown(epow_log->event_modifier);
  248. break;
  249. case EPOW_SYSTEM_HALT:
  250. pr_emerg("Critical power/cooling issue detected. Check RTAS"
  251. " error log for details. Powering off.\n");
  252. orderly_poweroff(true);
  253. break;
  254. case EPOW_MAIN_ENCLOSURE:
  255. case EPOW_POWER_OFF:
  256. pr_emerg("System about to lose power. Check RTAS error log "
  257. " for details. Powering off immediately.\n");
  258. emergency_sync();
  259. kernel_power_off();
  260. break;
  261. default:
  262. pr_err("Unknown power/cooling event (action code = %d)\n",
  263. action_code);
  264. }
  265. /* Increment epow events counter variable */
  266. if (action_code != EPOW_RESET)
  267. num_epow_events++;
  268. }
  269. static irqreturn_t ras_hotplug_interrupt(int irq, void *dev_id)
  270. {
  271. struct pseries_errorlog *pseries_log;
  272. struct pseries_hp_errorlog *hp_elog;
  273. spin_lock(&ras_log_buf_lock);
  274. rtas_call(ras_check_exception_token, 6, 1, NULL,
  275. RTAS_VECTOR_EXTERNAL_INTERRUPT, virq_to_hw(irq),
  276. RTAS_HOTPLUG_EVENTS, 0, __pa(&ras_log_buf),
  277. rtas_get_error_log_max());
  278. pseries_log = get_pseries_errorlog((struct rtas_error_log *)ras_log_buf,
  279. PSERIES_ELOG_SECT_ID_HOTPLUG);
  280. hp_elog = (struct pseries_hp_errorlog *)pseries_log->data;
  281. /*
  282. * Since PCI hotplug is not currently supported on pseries, put PCI
  283. * hotplug events on the ras_log_buf to be handled by rtas_errd.
  284. */
  285. if (hp_elog->resource == PSERIES_HP_ELOG_RESOURCE_MEM ||
  286. hp_elog->resource == PSERIES_HP_ELOG_RESOURCE_CPU ||
  287. hp_elog->resource == PSERIES_HP_ELOG_RESOURCE_PMEM)
  288. queue_hotplug_event(hp_elog);
  289. else
  290. log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, 0);
  291. spin_unlock(&ras_log_buf_lock);
  292. return IRQ_HANDLED;
  293. }
  294. /* Handle environmental and power warning (EPOW) interrupts. */
  295. static irqreturn_t ras_epow_interrupt(int irq, void *dev_id)
  296. {
  297. int status;
  298. int state;
  299. int critical;
  300. status = rtas_get_sensor_fast(EPOW_SENSOR_TOKEN, EPOW_SENSOR_INDEX,
  301. &state);
  302. if (state > 3)
  303. critical = 1; /* Time Critical */
  304. else
  305. critical = 0;
  306. spin_lock(&ras_log_buf_lock);
  307. status = rtas_call(ras_check_exception_token, 6, 1, NULL,
  308. RTAS_VECTOR_EXTERNAL_INTERRUPT,
  309. virq_to_hw(irq),
  310. RTAS_EPOW_WARNING,
  311. critical, __pa(&ras_log_buf),
  312. rtas_get_error_log_max());
  313. log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, 0);
  314. rtas_parse_epow_errlog((struct rtas_error_log *)ras_log_buf);
  315. spin_unlock(&ras_log_buf_lock);
  316. return IRQ_HANDLED;
  317. }
  318. /*
  319. * Handle hardware error interrupts.
  320. *
  321. * RTAS check-exception is called to collect data on the exception. If
  322. * the error is deemed recoverable, we log a warning and return.
  323. * For nonrecoverable errors, an error is logged and we stop all processing
  324. * as quickly as possible in order to prevent propagation of the failure.
  325. */
  326. static irqreturn_t ras_error_interrupt(int irq, void *dev_id)
  327. {
  328. struct rtas_error_log *rtas_elog;
  329. int status;
  330. int fatal;
  331. spin_lock(&ras_log_buf_lock);
  332. status = rtas_call(ras_check_exception_token, 6, 1, NULL,
  333. RTAS_VECTOR_EXTERNAL_INTERRUPT,
  334. virq_to_hw(irq),
  335. RTAS_INTERNAL_ERROR, 1 /* Time Critical */,
  336. __pa(&ras_log_buf),
  337. rtas_get_error_log_max());
  338. rtas_elog = (struct rtas_error_log *)ras_log_buf;
  339. if (status == 0 &&
  340. rtas_error_severity(rtas_elog) >= RTAS_SEVERITY_ERROR_SYNC)
  341. fatal = 1;
  342. else
  343. fatal = 0;
  344. /* format and print the extended information */
  345. log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, fatal);
  346. if (fatal) {
  347. pr_emerg("Fatal hardware error detected. Check RTAS error"
  348. " log for details. Powering off immediately\n");
  349. emergency_sync();
  350. kernel_power_off();
  351. } else {
  352. pr_err("Recoverable hardware error detected\n");
  353. }
  354. spin_unlock(&ras_log_buf_lock);
  355. return IRQ_HANDLED;
  356. }
  357. /*
  358. * Some versions of FWNMI place the buffer inside the 4kB page starting at
  359. * 0x7000. Other versions place it inside the rtas buffer. We check both.
  360. */
  361. #define VALID_FWNMI_BUFFER(A) \
  362. ((((A) >= 0x7000) && ((A) < 0x7ff0)) || \
  363. (((A) >= rtas.base) && ((A) < (rtas.base + rtas.size - 16))))
  364. static inline struct rtas_error_log *fwnmi_get_errlog(void)
  365. {
  366. return (struct rtas_error_log *)local_paca->mce_data_buf;
  367. }
  368. /*
  369. * Get the error information for errors coming through the
  370. * FWNMI vectors. The pt_regs' r3 will be updated to reflect
  371. * the actual r3 if possible, and a ptr to the error log entry
  372. * will be returned if found.
  373. *
  374. * Use one buffer mce_data_buf per cpu to store RTAS error.
  375. *
  376. * The mce_data_buf does not have any locks or protection around it,
  377. * if a second machine check comes in, or a system reset is done
  378. * before we have logged the error, then we will get corruption in the
  379. * error log. This is preferable over holding off on calling
  380. * ibm,nmi-interlock which would result in us checkstopping if a
  381. * second machine check did come in.
  382. */
  383. static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs)
  384. {
  385. unsigned long *savep;
  386. struct rtas_error_log *h;
  387. /* Mask top two bits */
  388. regs->gpr[3] &= ~(0x3UL << 62);
  389. if (!VALID_FWNMI_BUFFER(regs->gpr[3])) {
  390. printk(KERN_ERR "FWNMI: corrupt r3 0x%016lx\n", regs->gpr[3]);
  391. return NULL;
  392. }
  393. savep = __va(regs->gpr[3]);
  394. regs->gpr[3] = be64_to_cpu(savep[0]); /* restore original r3 */
  395. h = (struct rtas_error_log *)&savep[1];
  396. /* Use the per cpu buffer from paca to store rtas error log */
  397. memset(local_paca->mce_data_buf, 0, RTAS_ERROR_LOG_MAX);
  398. if (!rtas_error_extended(h)) {
  399. memcpy(local_paca->mce_data_buf, h, sizeof(__u64));
  400. } else {
  401. int len, error_log_length;
  402. error_log_length = 8 + rtas_error_extended_log_length(h);
  403. len = min_t(int, error_log_length, RTAS_ERROR_LOG_MAX);
  404. memcpy(local_paca->mce_data_buf, h, len);
  405. }
  406. return (struct rtas_error_log *)local_paca->mce_data_buf;
  407. }
  408. /* Call this when done with the data returned by FWNMI_get_errinfo.
  409. * It will release the saved data area for other CPUs in the
  410. * partition to receive FWNMI errors.
  411. */
  412. static void fwnmi_release_errinfo(void)
  413. {
  414. int ret = rtas_call(rtas_token("ibm,nmi-interlock"), 0, 1, NULL);
  415. if (ret != 0)
  416. printk(KERN_ERR "FWNMI: nmi-interlock failed: %d\n", ret);
  417. }
  418. int pSeries_system_reset_exception(struct pt_regs *regs)
  419. {
  420. #ifdef __LITTLE_ENDIAN__
  421. /*
  422. * Some firmware byteswaps SRR registers and gives incorrect SRR1. Try
  423. * to detect the bad SRR1 pattern here. Flip the NIP back to correct
  424. * endian for reporting purposes. Unfortunately the MSR can't be fixed,
  425. * so clear it. It will be missing MSR_RI so we won't try to recover.
  426. */
  427. if ((be64_to_cpu(regs->msr) &
  428. (MSR_LE|MSR_RI|MSR_DR|MSR_IR|MSR_ME|MSR_PR|
  429. MSR_ILE|MSR_HV|MSR_SF)) == (MSR_DR|MSR_SF)) {
  430. regs->nip = be64_to_cpu((__be64)regs->nip);
  431. regs->msr = 0;
  432. }
  433. #endif
  434. if (fwnmi_active) {
  435. struct rtas_error_log *errhdr = fwnmi_get_errinfo(regs);
  436. if (errhdr) {
  437. /* XXX Should look at FWNMI information */
  438. }
  439. fwnmi_release_errinfo();
  440. }
  441. if (smp_handle_nmi_ipi(regs))
  442. return 1;
  443. return 0; /* need to perform reset */
  444. }
  445. #define VAL_TO_STRING(ar, val) \
  446. (((val) < ARRAY_SIZE(ar)) ? ar[(val)] : "Unknown")
  447. static void pseries_print_mce_info(struct pt_regs *regs,
  448. struct rtas_error_log *errp)
  449. {
  450. const char *level, *sevstr;
  451. struct pseries_errorlog *pseries_log;
  452. struct pseries_mc_errorlog *mce_log;
  453. u8 error_type, err_sub_type;
  454. u64 addr;
  455. u8 initiator = rtas_error_initiator(errp);
  456. int disposition = rtas_error_disposition(errp);
  457. static const char * const initiators[] = {
  458. "Unknown",
  459. "CPU",
  460. "PCI",
  461. "ISA",
  462. "Memory",
  463. "Power Mgmt",
  464. };
  465. static const char * const mc_err_types[] = {
  466. "UE",
  467. "SLB",
  468. "ERAT",
  469. "TLB",
  470. "D-Cache",
  471. "Unknown",
  472. "I-Cache",
  473. };
  474. static const char * const mc_ue_types[] = {
  475. "Indeterminate",
  476. "Instruction fetch",
  477. "Page table walk ifetch",
  478. "Load/Store",
  479. "Page table walk Load/Store",
  480. };
  481. /* SLB sub errors valid values are 0x0, 0x1, 0x2 */
  482. static const char * const mc_slb_types[] = {
  483. "Parity",
  484. "Multihit",
  485. "Indeterminate",
  486. };
  487. /* TLB and ERAT sub errors valid values are 0x1, 0x2, 0x3 */
  488. static const char * const mc_soft_types[] = {
  489. "Unknown",
  490. "Parity",
  491. "Multihit",
  492. "Indeterminate",
  493. };
  494. if (!rtas_error_extended(errp)) {
  495. pr_err("Machine check interrupt: Missing extended error log\n");
  496. return;
  497. }
  498. pseries_log = get_pseries_errorlog(errp, PSERIES_ELOG_SECT_ID_MCE);
  499. if (pseries_log == NULL)
  500. return;
  501. mce_log = (struct pseries_mc_errorlog *)pseries_log->data;
  502. error_type = mce_log->error_type;
  503. err_sub_type = rtas_mc_error_sub_type(mce_log);
  504. switch (rtas_error_severity(errp)) {
  505. case RTAS_SEVERITY_NO_ERROR:
  506. level = KERN_INFO;
  507. sevstr = "Harmless";
  508. break;
  509. case RTAS_SEVERITY_WARNING:
  510. level = KERN_WARNING;
  511. sevstr = "";
  512. break;
  513. case RTAS_SEVERITY_ERROR:
  514. case RTAS_SEVERITY_ERROR_SYNC:
  515. level = KERN_ERR;
  516. sevstr = "Severe";
  517. break;
  518. case RTAS_SEVERITY_FATAL:
  519. default:
  520. level = KERN_ERR;
  521. sevstr = "Fatal";
  522. break;
  523. }
  524. #ifdef CONFIG_PPC_BOOK3S_64
  525. /* Display faulty slb contents for SLB errors. */
  526. if (error_type == MC_ERROR_TYPE_SLB)
  527. slb_dump_contents(local_paca->mce_faulty_slbs);
  528. #endif
  529. printk("%s%s Machine check interrupt [%s]\n", level, sevstr,
  530. disposition == RTAS_DISP_FULLY_RECOVERED ?
  531. "Recovered" : "Not recovered");
  532. if (user_mode(regs)) {
  533. printk("%s NIP: [%016lx] PID: %d Comm: %s\n", level,
  534. regs->nip, current->pid, current->comm);
  535. } else {
  536. printk("%s NIP [%016lx]: %pS\n", level, regs->nip,
  537. (void *)regs->nip);
  538. }
  539. printk("%s Initiator: %s\n", level,
  540. VAL_TO_STRING(initiators, initiator));
  541. switch (error_type) {
  542. case MC_ERROR_TYPE_UE:
  543. printk("%s Error type: %s [%s]\n", level,
  544. VAL_TO_STRING(mc_err_types, error_type),
  545. VAL_TO_STRING(mc_ue_types, err_sub_type));
  546. break;
  547. case MC_ERROR_TYPE_SLB:
  548. printk("%s Error type: %s [%s]\n", level,
  549. VAL_TO_STRING(mc_err_types, error_type),
  550. VAL_TO_STRING(mc_slb_types, err_sub_type));
  551. break;
  552. case MC_ERROR_TYPE_ERAT:
  553. case MC_ERROR_TYPE_TLB:
  554. printk("%s Error type: %s [%s]\n", level,
  555. VAL_TO_STRING(mc_err_types, error_type),
  556. VAL_TO_STRING(mc_soft_types, err_sub_type));
  557. break;
  558. default:
  559. printk("%s Error type: %s\n", level,
  560. VAL_TO_STRING(mc_err_types, error_type));
  561. break;
  562. }
  563. addr = rtas_mc_get_effective_addr(mce_log);
  564. if (addr)
  565. printk("%s Effective address: %016llx\n", level, addr);
  566. }
  567. static int mce_handle_error(struct rtas_error_log *errp)
  568. {
  569. struct pseries_errorlog *pseries_log;
  570. struct pseries_mc_errorlog *mce_log;
  571. int disposition = rtas_error_disposition(errp);
  572. u8 error_type;
  573. if (!rtas_error_extended(errp))
  574. goto out;
  575. pseries_log = get_pseries_errorlog(errp, PSERIES_ELOG_SECT_ID_MCE);
  576. if (pseries_log == NULL)
  577. goto out;
  578. mce_log = (struct pseries_mc_errorlog *)pseries_log->data;
  579. error_type = mce_log->error_type;
  580. #ifdef CONFIG_PPC_BOOK3S_64
  581. if (disposition == RTAS_DISP_NOT_RECOVERED) {
  582. switch (error_type) {
  583. case MC_ERROR_TYPE_SLB:
  584. case MC_ERROR_TYPE_ERAT:
  585. /*
  586. * Store the old slb content in paca before flushing.
  587. * Print this when we go to virtual mode.
  588. * There are chances that we may hit MCE again if there
  589. * is a parity error on the SLB entry we trying to read
  590. * for saving. Hence limit the slb saving to single
  591. * level of recursion.
  592. */
  593. if (local_paca->in_mce == 1)
  594. slb_save_contents(local_paca->mce_faulty_slbs);
  595. flush_and_reload_slb();
  596. disposition = RTAS_DISP_FULLY_RECOVERED;
  597. rtas_set_disposition_recovered(errp);
  598. break;
  599. default:
  600. break;
  601. }
  602. }
  603. #endif
  604. out:
  605. return disposition;
  606. }
  607. /*
  608. * Process MCE rtas errlog event.
  609. */
  610. static void mce_process_errlog_event(struct irq_work *work)
  611. {
  612. struct rtas_error_log *err;
  613. err = fwnmi_get_errlog();
  614. log_error((char *)err, ERR_TYPE_RTAS_LOG, 0);
  615. }
  616. /*
  617. * See if we can recover from a machine check exception.
  618. * This is only called on power4 (or above) and only via
  619. * the Firmware Non-Maskable Interrupts (fwnmi) handler
  620. * which provides the error analysis for us.
  621. *
  622. * Return 1 if corrected (or delivered a signal).
  623. * Return 0 if there is nothing we can do.
  624. */
  625. static int recover_mce(struct pt_regs *regs, struct rtas_error_log *err)
  626. {
  627. int recovered = 0;
  628. int disposition = rtas_error_disposition(err);
  629. pseries_print_mce_info(regs, err);
  630. if (!(regs->msr & MSR_RI)) {
  631. /* If MSR_RI isn't set, we cannot recover */
  632. pr_err("Machine check interrupt unrecoverable: MSR(RI=0)\n");
  633. recovered = 0;
  634. } else if (disposition == RTAS_DISP_FULLY_RECOVERED) {
  635. /* Platform corrected itself */
  636. recovered = 1;
  637. } else if (disposition == RTAS_DISP_LIMITED_RECOVERY) {
  638. /* Platform corrected itself but could be degraded */
  639. printk(KERN_ERR "MCE: limited recovery, system may "
  640. "be degraded\n");
  641. recovered = 1;
  642. } else if (user_mode(regs) && !is_global_init(current) &&
  643. rtas_error_severity(err) == RTAS_SEVERITY_ERROR_SYNC) {
  644. /*
  645. * If we received a synchronous error when in userspace
  646. * kill the task. Firmware may report details of the fail
  647. * asynchronously, so we can't rely on the target and type
  648. * fields being valid here.
  649. */
  650. printk(KERN_ERR "MCE: uncorrectable error, killing task "
  651. "%s:%d\n", current->comm, current->pid);
  652. _exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip);
  653. recovered = 1;
  654. }
  655. /* Queue irq work to log this rtas event later. */
  656. irq_work_queue(&mce_errlog_process_work);
  657. return recovered;
  658. }
  659. /*
  660. * Handle a machine check.
  661. *
  662. * Note that on Power 4 and beyond Firmware Non-Maskable Interrupts (fwnmi)
  663. * should be present. If so the handler which called us tells us if the
  664. * error was recovered (never true if RI=0).
  665. *
  666. * On hardware prior to Power 4 these exceptions were asynchronous which
  667. * means we can't tell exactly where it occurred and so we can't recover.
  668. */
  669. int pSeries_machine_check_exception(struct pt_regs *regs)
  670. {
  671. struct rtas_error_log *errp;
  672. if (fwnmi_active) {
  673. fwnmi_release_errinfo();
  674. errp = fwnmi_get_errlog();
  675. if (errp && recover_mce(regs, errp))
  676. return 1;
  677. }
  678. return 0;
  679. }
  680. long pseries_machine_check_realmode(struct pt_regs *regs)
  681. {
  682. struct rtas_error_log *errp;
  683. int disposition;
  684. if (fwnmi_active) {
  685. errp = fwnmi_get_errinfo(regs);
  686. /*
  687. * Call to fwnmi_release_errinfo() in real mode causes kernel
  688. * to panic. Hence we will call it as soon as we go into
  689. * virtual mode.
  690. */
  691. disposition = mce_handle_error(errp);
  692. if (disposition == RTAS_DISP_FULLY_RECOVERED)
  693. return 1;
  694. }
  695. return 0;
  696. }