nmi.c 9.4 KB

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