nmi.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /*
  2. * Machine check handler
  3. *
  4. * Copyright IBM Corp. 2000, 2009
  5. * Author(s): Ingo Adlung <adlung@de.ibm.com>,
  6. * Martin Schwidefsky <schwidefsky@de.ibm.com>,
  7. * Cornelia Huck <cornelia.huck@de.ibm.com>,
  8. * Heiko Carstens <heiko.carstens@de.ibm.com>,
  9. */
  10. #include <linux/kernel_stat.h>
  11. #include <linux/init.h>
  12. #include <linux/errno.h>
  13. #include <linux/hardirq.h>
  14. #include <linux/time.h>
  15. #include <linux/module.h>
  16. #include <asm/lowcore.h>
  17. #include <asm/smp.h>
  18. #include <asm/etr.h>
  19. #include <asm/cputime.h>
  20. #include <asm/nmi.h>
  21. #include <asm/crw.h>
  22. #include <asm/switch_to.h>
  23. struct mcck_struct {
  24. int kill_task;
  25. int channel_report;
  26. int warning;
  27. unsigned long long mcck_code;
  28. };
  29. static DEFINE_PER_CPU(struct mcck_struct, cpu_mcck);
  30. static void s390_handle_damage(char *msg)
  31. {
  32. smp_send_stop();
  33. disabled_wait((unsigned long) __builtin_return_address(0));
  34. while (1);
  35. }
  36. /*
  37. * Main machine check handler function. Will be called with interrupts enabled
  38. * or disabled and machine checks enabled or disabled.
  39. */
  40. void s390_handle_mcck(void)
  41. {
  42. unsigned long flags;
  43. struct mcck_struct mcck;
  44. /*
  45. * Disable machine checks and get the current state of accumulated
  46. * machine checks. Afterwards delete the old state and enable machine
  47. * checks again.
  48. */
  49. local_irq_save(flags);
  50. local_mcck_disable();
  51. mcck = *this_cpu_ptr(&cpu_mcck);
  52. memset(this_cpu_ptr(&cpu_mcck), 0, sizeof(mcck));
  53. clear_cpu_flag(CIF_MCCK_PENDING);
  54. local_mcck_enable();
  55. local_irq_restore(flags);
  56. if (mcck.channel_report)
  57. crw_handle_channel_report();
  58. /*
  59. * A warning may remain for a prolonged period on the bare iron.
  60. * (actually until the machine is powered off, or the problem is gone)
  61. * So we just stop listening for the WARNING MCH and avoid continuously
  62. * being interrupted. One caveat is however, that we must do this per
  63. * processor and cannot use the smp version of ctl_clear_bit().
  64. * On VM we only get one interrupt per virtally presented machinecheck.
  65. * Though one suffices, we may get one interrupt per (virtual) cpu.
  66. */
  67. if (mcck.warning) { /* WARNING pending ? */
  68. static int mchchk_wng_posted = 0;
  69. /* Use single cpu clear, as we cannot handle smp here. */
  70. __ctl_clear_bit(14, 24); /* Disable WARNING MCH */
  71. if (xchg(&mchchk_wng_posted, 1) == 0)
  72. kill_cad_pid(SIGPWR, 1);
  73. }
  74. if (mcck.kill_task) {
  75. local_irq_enable();
  76. printk(KERN_EMERG "mcck: Terminating task because of machine "
  77. "malfunction (code 0x%016llx).\n", mcck.mcck_code);
  78. printk(KERN_EMERG "mcck: task: %s, pid: %d.\n",
  79. current->comm, current->pid);
  80. do_exit(SIGSEGV);
  81. }
  82. }
  83. EXPORT_SYMBOL_GPL(s390_handle_mcck);
  84. /*
  85. * returns 0 if all registers could be validated
  86. * returns 1 otherwise
  87. */
  88. static int notrace s390_revalidate_registers(struct mci *mci)
  89. {
  90. int kill_task;
  91. u64 zero;
  92. void *fpt_save_area, *fpt_creg_save_area;
  93. kill_task = 0;
  94. zero = 0;
  95. if (!mci->gr) {
  96. /*
  97. * General purpose registers couldn't be restored and have
  98. * unknown contents. Process needs to be terminated.
  99. */
  100. kill_task = 1;
  101. }
  102. if (!mci->fp) {
  103. /*
  104. * Floating point registers can't be restored and
  105. * therefore the process needs to be terminated.
  106. */
  107. kill_task = 1;
  108. }
  109. #ifndef CONFIG_64BIT
  110. asm volatile(
  111. " ld 0,0(%0)\n"
  112. " ld 2,8(%0)\n"
  113. " ld 4,16(%0)\n"
  114. " ld 6,24(%0)"
  115. : : "a" (&S390_lowcore.floating_pt_save_area));
  116. #endif
  117. if (MACHINE_HAS_IEEE) {
  118. #ifdef CONFIG_64BIT
  119. fpt_save_area = &S390_lowcore.floating_pt_save_area;
  120. fpt_creg_save_area = &S390_lowcore.fpt_creg_save_area;
  121. #else
  122. fpt_save_area = (void *) S390_lowcore.extended_save_area_addr;
  123. fpt_creg_save_area = fpt_save_area + 128;
  124. #endif
  125. if (!mci->fc) {
  126. /*
  127. * Floating point control register can't be restored.
  128. * Task will be terminated.
  129. */
  130. asm volatile("lfpc 0(%0)" : : "a" (&zero), "m" (zero));
  131. kill_task = 1;
  132. } else
  133. asm volatile("lfpc 0(%0)" : : "a" (fpt_creg_save_area));
  134. asm volatile(
  135. " ld 0,0(%0)\n"
  136. " ld 1,8(%0)\n"
  137. " ld 2,16(%0)\n"
  138. " ld 3,24(%0)\n"
  139. " ld 4,32(%0)\n"
  140. " ld 5,40(%0)\n"
  141. " ld 6,48(%0)\n"
  142. " ld 7,56(%0)\n"
  143. " ld 8,64(%0)\n"
  144. " ld 9,72(%0)\n"
  145. " ld 10,80(%0)\n"
  146. " ld 11,88(%0)\n"
  147. " ld 12,96(%0)\n"
  148. " ld 13,104(%0)\n"
  149. " ld 14,112(%0)\n"
  150. " ld 15,120(%0)\n"
  151. : : "a" (fpt_save_area));
  152. }
  153. #ifdef CONFIG_64BIT
  154. /* Revalidate vector registers */
  155. if (MACHINE_HAS_VX && current->thread.vxrs) {
  156. if (!mci->vr) {
  157. /*
  158. * Vector registers can't be restored and therefore
  159. * the process needs to be terminated.
  160. */
  161. kill_task = 1;
  162. }
  163. restore_vx_regs((__vector128 *)
  164. S390_lowcore.vector_save_area_addr);
  165. }
  166. #endif
  167. /* Revalidate access registers */
  168. asm volatile(
  169. " lam 0,15,0(%0)"
  170. : : "a" (&S390_lowcore.access_regs_save_area));
  171. if (!mci->ar) {
  172. /*
  173. * Access registers have unknown contents.
  174. * Terminating task.
  175. */
  176. kill_task = 1;
  177. }
  178. /* Revalidate control registers */
  179. if (!mci->cr) {
  180. /*
  181. * Control registers have unknown contents.
  182. * Can't recover and therefore stopping machine.
  183. */
  184. s390_handle_damage("invalid control registers.");
  185. } else {
  186. #ifdef CONFIG_64BIT
  187. asm volatile(
  188. " lctlg 0,15,0(%0)"
  189. : : "a" (&S390_lowcore.cregs_save_area));
  190. #else
  191. asm volatile(
  192. " lctl 0,15,0(%0)"
  193. : : "a" (&S390_lowcore.cregs_save_area));
  194. #endif
  195. }
  196. /*
  197. * We don't even try to revalidate the TOD register, since we simply
  198. * can't write something sensible into that register.
  199. */
  200. #ifdef CONFIG_64BIT
  201. /*
  202. * See if we can revalidate the TOD programmable register with its
  203. * old contents (should be zero) otherwise set it to zero.
  204. */
  205. if (!mci->pr)
  206. asm volatile(
  207. " sr 0,0\n"
  208. " sckpf"
  209. : : : "0", "cc");
  210. else
  211. asm volatile(
  212. " l 0,0(%0)\n"
  213. " sckpf"
  214. : : "a" (&S390_lowcore.tod_progreg_save_area)
  215. : "0", "cc");
  216. #endif
  217. /* Revalidate clock comparator register */
  218. set_clock_comparator(S390_lowcore.clock_comparator);
  219. /* Check if old PSW is valid */
  220. if (!mci->wp)
  221. /*
  222. * Can't tell if we come from user or kernel mode
  223. * -> stopping machine.
  224. */
  225. s390_handle_damage("old psw invalid.");
  226. if (!mci->ms || !mci->pm || !mci->ia)
  227. kill_task = 1;
  228. return kill_task;
  229. }
  230. #define MAX_IPD_COUNT 29
  231. #define MAX_IPD_TIME (5 * 60 * USEC_PER_SEC) /* 5 minutes */
  232. #define ED_STP_ISLAND 6 /* External damage STP island check */
  233. #define ED_STP_SYNC 7 /* External damage STP sync check */
  234. #define ED_ETR_SYNC 12 /* External damage ETR sync check */
  235. #define ED_ETR_SWITCH 13 /* External damage ETR switch to local */
  236. /*
  237. * machine check handler.
  238. */
  239. void notrace s390_do_machine_check(struct pt_regs *regs)
  240. {
  241. static int ipd_count;
  242. static DEFINE_SPINLOCK(ipd_lock);
  243. static unsigned long long last_ipd;
  244. struct mcck_struct *mcck;
  245. unsigned long long tmp;
  246. struct mci *mci;
  247. int umode;
  248. nmi_enter();
  249. inc_irq_stat(NMI_NMI);
  250. mci = (struct mci *) &S390_lowcore.mcck_interruption_code;
  251. mcck = this_cpu_ptr(&cpu_mcck);
  252. umode = user_mode(regs);
  253. if (mci->sd) {
  254. /* System damage -> stopping machine */
  255. s390_handle_damage("received system damage machine check.");
  256. }
  257. if (mci->pd) {
  258. if (mci->b) {
  259. /* Processing backup -> verify if we can survive this */
  260. u64 z_mcic, o_mcic, t_mcic;
  261. #ifdef CONFIG_64BIT
  262. z_mcic = (1ULL<<63 | 1ULL<<59 | 1ULL<<29);
  263. o_mcic = (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
  264. 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
  265. 1ULL<<30 | 1ULL<<21 | 1ULL<<20 | 1ULL<<17 |
  266. 1ULL<<16);
  267. #else
  268. z_mcic = (1ULL<<63 | 1ULL<<59 | 1ULL<<57 | 1ULL<<50 |
  269. 1ULL<<29);
  270. o_mcic = (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
  271. 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
  272. 1ULL<<30 | 1ULL<<20 | 1ULL<<17 | 1ULL<<16);
  273. #endif
  274. t_mcic = *(u64 *)mci;
  275. if (((t_mcic & z_mcic) != 0) ||
  276. ((t_mcic & o_mcic) != o_mcic)) {
  277. s390_handle_damage("processing backup machine "
  278. "check with damage.");
  279. }
  280. /*
  281. * Nullifying exigent condition, therefore we might
  282. * retry this instruction.
  283. */
  284. spin_lock(&ipd_lock);
  285. tmp = get_tod_clock();
  286. if (((tmp - last_ipd) >> 12) < MAX_IPD_TIME)
  287. ipd_count++;
  288. else
  289. ipd_count = 1;
  290. last_ipd = tmp;
  291. if (ipd_count == MAX_IPD_COUNT)
  292. s390_handle_damage("too many ipd retries.");
  293. spin_unlock(&ipd_lock);
  294. } else {
  295. /* Processing damage -> stopping machine */
  296. s390_handle_damage("received instruction processing "
  297. "damage machine check.");
  298. }
  299. }
  300. if (s390_revalidate_registers(mci)) {
  301. if (umode) {
  302. /*
  303. * Couldn't restore all register contents while in
  304. * user mode -> mark task for termination.
  305. */
  306. mcck->kill_task = 1;
  307. mcck->mcck_code = *(unsigned long long *) mci;
  308. set_cpu_flag(CIF_MCCK_PENDING);
  309. } else {
  310. /*
  311. * Couldn't restore all register contents while in
  312. * kernel mode -> stopping machine.
  313. */
  314. s390_handle_damage("unable to revalidate registers.");
  315. }
  316. }
  317. if (mci->cd) {
  318. /* Timing facility damage */
  319. s390_handle_damage("TOD clock damaged");
  320. }
  321. if (mci->ed && mci->ec) {
  322. /* External damage */
  323. if (S390_lowcore.external_damage_code & (1U << ED_ETR_SYNC))
  324. etr_sync_check();
  325. if (S390_lowcore.external_damage_code & (1U << ED_ETR_SWITCH))
  326. etr_switch_to_local();
  327. if (S390_lowcore.external_damage_code & (1U << ED_STP_SYNC))
  328. stp_sync_check();
  329. if (S390_lowcore.external_damage_code & (1U << ED_STP_ISLAND))
  330. stp_island_check();
  331. }
  332. if (mci->se)
  333. /* Storage error uncorrected */
  334. s390_handle_damage("received storage error uncorrected "
  335. "machine check.");
  336. if (mci->ke)
  337. /* Storage key-error uncorrected */
  338. s390_handle_damage("received storage key-error uncorrected "
  339. "machine check.");
  340. if (mci->ds && mci->fa)
  341. /* Storage degradation */
  342. s390_handle_damage("received storage degradation machine "
  343. "check.");
  344. if (mci->cp) {
  345. /* Channel report word pending */
  346. mcck->channel_report = 1;
  347. set_cpu_flag(CIF_MCCK_PENDING);
  348. }
  349. if (mci->w) {
  350. /* Warning pending */
  351. mcck->warning = 1;
  352. set_cpu_flag(CIF_MCCK_PENDING);
  353. }
  354. nmi_exit();
  355. }
  356. static int __init machine_check_init(void)
  357. {
  358. ctl_set_bit(14, 25); /* enable external damage MCH */
  359. ctl_set_bit(14, 27); /* enable system recovery MCH */
  360. ctl_set_bit(14, 24); /* enable warning MCH */
  361. return 0;
  362. }
  363. arch_initcall(machine_check_init);