nmi.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. fpt_save_area = &S390_lowcore.floating_pt_save_area;
  110. fpt_creg_save_area = &S390_lowcore.fpt_creg_save_area;
  111. if (!mci->fc) {
  112. /*
  113. * Floating point control register can't be restored.
  114. * Task will be terminated.
  115. */
  116. asm volatile("lfpc 0(%0)" : : "a" (&zero), "m" (zero));
  117. kill_task = 1;
  118. } else
  119. asm volatile("lfpc 0(%0)" : : "a" (fpt_creg_save_area));
  120. asm volatile(
  121. " ld 0,0(%0)\n"
  122. " ld 1,8(%0)\n"
  123. " ld 2,16(%0)\n"
  124. " ld 3,24(%0)\n"
  125. " ld 4,32(%0)\n"
  126. " ld 5,40(%0)\n"
  127. " ld 6,48(%0)\n"
  128. " ld 7,56(%0)\n"
  129. " ld 8,64(%0)\n"
  130. " ld 9,72(%0)\n"
  131. " ld 10,80(%0)\n"
  132. " ld 11,88(%0)\n"
  133. " ld 12,96(%0)\n"
  134. " ld 13,104(%0)\n"
  135. " ld 14,112(%0)\n"
  136. " ld 15,120(%0)\n"
  137. : : "a" (fpt_save_area));
  138. /* Revalidate vector registers */
  139. if (MACHINE_HAS_VX && current->thread.vxrs) {
  140. if (!mci->vr) {
  141. /*
  142. * Vector registers can't be restored and therefore
  143. * the process needs to be terminated.
  144. */
  145. kill_task = 1;
  146. }
  147. restore_vx_regs((__vector128 *)
  148. S390_lowcore.vector_save_area_addr);
  149. }
  150. /* Revalidate access registers */
  151. asm volatile(
  152. " lam 0,15,0(%0)"
  153. : : "a" (&S390_lowcore.access_regs_save_area));
  154. if (!mci->ar) {
  155. /*
  156. * Access registers have unknown contents.
  157. * Terminating task.
  158. */
  159. kill_task = 1;
  160. }
  161. /* Revalidate control registers */
  162. if (!mci->cr) {
  163. /*
  164. * Control registers have unknown contents.
  165. * Can't recover and therefore stopping machine.
  166. */
  167. s390_handle_damage("invalid control registers.");
  168. } else {
  169. asm volatile(
  170. " lctlg 0,15,0(%0)"
  171. : : "a" (&S390_lowcore.cregs_save_area));
  172. }
  173. /*
  174. * We don't even try to revalidate the TOD register, since we simply
  175. * can't write something sensible into that register.
  176. */
  177. /*
  178. * See if we can revalidate the TOD programmable register with its
  179. * old contents (should be zero) otherwise set it to zero.
  180. */
  181. if (!mci->pr)
  182. asm volatile(
  183. " sr 0,0\n"
  184. " sckpf"
  185. : : : "0", "cc");
  186. else
  187. asm volatile(
  188. " l 0,0(%0)\n"
  189. " sckpf"
  190. : : "a" (&S390_lowcore.tod_progreg_save_area)
  191. : "0", "cc");
  192. /* Revalidate clock comparator register */
  193. set_clock_comparator(S390_lowcore.clock_comparator);
  194. /* Check if old PSW is valid */
  195. if (!mci->wp)
  196. /*
  197. * Can't tell if we come from user or kernel mode
  198. * -> stopping machine.
  199. */
  200. s390_handle_damage("old psw invalid.");
  201. if (!mci->ms || !mci->pm || !mci->ia)
  202. kill_task = 1;
  203. return kill_task;
  204. }
  205. #define MAX_IPD_COUNT 29
  206. #define MAX_IPD_TIME (5 * 60 * USEC_PER_SEC) /* 5 minutes */
  207. #define ED_STP_ISLAND 6 /* External damage STP island check */
  208. #define ED_STP_SYNC 7 /* External damage STP sync check */
  209. #define ED_ETR_SYNC 12 /* External damage ETR sync check */
  210. #define ED_ETR_SWITCH 13 /* External damage ETR switch to local */
  211. /*
  212. * machine check handler.
  213. */
  214. void notrace s390_do_machine_check(struct pt_regs *regs)
  215. {
  216. static int ipd_count;
  217. static DEFINE_SPINLOCK(ipd_lock);
  218. static unsigned long long last_ipd;
  219. struct mcck_struct *mcck;
  220. unsigned long long tmp;
  221. struct mci *mci;
  222. int umode;
  223. nmi_enter();
  224. inc_irq_stat(NMI_NMI);
  225. mci = (struct mci *) &S390_lowcore.mcck_interruption_code;
  226. mcck = this_cpu_ptr(&cpu_mcck);
  227. umode = user_mode(regs);
  228. if (mci->sd) {
  229. /* System damage -> stopping machine */
  230. s390_handle_damage("received system damage machine check.");
  231. }
  232. if (mci->pd) {
  233. if (mci->b) {
  234. /* Processing backup -> verify if we can survive this */
  235. u64 z_mcic, o_mcic, t_mcic;
  236. z_mcic = (1ULL<<63 | 1ULL<<59 | 1ULL<<29);
  237. o_mcic = (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
  238. 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
  239. 1ULL<<30 | 1ULL<<21 | 1ULL<<20 | 1ULL<<17 |
  240. 1ULL<<16);
  241. t_mcic = *(u64 *)mci;
  242. if (((t_mcic & z_mcic) != 0) ||
  243. ((t_mcic & o_mcic) != o_mcic)) {
  244. s390_handle_damage("processing backup machine "
  245. "check with damage.");
  246. }
  247. /*
  248. * Nullifying exigent condition, therefore we might
  249. * retry this instruction.
  250. */
  251. spin_lock(&ipd_lock);
  252. tmp = get_tod_clock();
  253. if (((tmp - last_ipd) >> 12) < MAX_IPD_TIME)
  254. ipd_count++;
  255. else
  256. ipd_count = 1;
  257. last_ipd = tmp;
  258. if (ipd_count == MAX_IPD_COUNT)
  259. s390_handle_damage("too many ipd retries.");
  260. spin_unlock(&ipd_lock);
  261. } else {
  262. /* Processing damage -> stopping machine */
  263. s390_handle_damage("received instruction processing "
  264. "damage machine check.");
  265. }
  266. }
  267. if (s390_revalidate_registers(mci)) {
  268. if (umode) {
  269. /*
  270. * Couldn't restore all register contents while in
  271. * user mode -> mark task for termination.
  272. */
  273. mcck->kill_task = 1;
  274. mcck->mcck_code = *(unsigned long long *) mci;
  275. set_cpu_flag(CIF_MCCK_PENDING);
  276. } else {
  277. /*
  278. * Couldn't restore all register contents while in
  279. * kernel mode -> stopping machine.
  280. */
  281. s390_handle_damage("unable to revalidate registers.");
  282. }
  283. }
  284. if (mci->cd) {
  285. /* Timing facility damage */
  286. s390_handle_damage("TOD clock damaged");
  287. }
  288. if (mci->ed && mci->ec) {
  289. /* External damage */
  290. if (S390_lowcore.external_damage_code & (1U << ED_ETR_SYNC))
  291. etr_sync_check();
  292. if (S390_lowcore.external_damage_code & (1U << ED_ETR_SWITCH))
  293. etr_switch_to_local();
  294. if (S390_lowcore.external_damage_code & (1U << ED_STP_SYNC))
  295. stp_sync_check();
  296. if (S390_lowcore.external_damage_code & (1U << ED_STP_ISLAND))
  297. stp_island_check();
  298. }
  299. if (mci->se)
  300. /* Storage error uncorrected */
  301. s390_handle_damage("received storage error uncorrected "
  302. "machine check.");
  303. if (mci->ke)
  304. /* Storage key-error uncorrected */
  305. s390_handle_damage("received storage key-error uncorrected "
  306. "machine check.");
  307. if (mci->ds && mci->fa)
  308. /* Storage degradation */
  309. s390_handle_damage("received storage degradation machine "
  310. "check.");
  311. if (mci->cp) {
  312. /* Channel report word pending */
  313. mcck->channel_report = 1;
  314. set_cpu_flag(CIF_MCCK_PENDING);
  315. }
  316. if (mci->w) {
  317. /* Warning pending */
  318. mcck->warning = 1;
  319. set_cpu_flag(CIF_MCCK_PENDING);
  320. }
  321. nmi_exit();
  322. }
  323. static int __init machine_check_init(void)
  324. {
  325. ctl_set_bit(14, 25); /* enable external damage MCH */
  326. ctl_set_bit(14, 27); /* enable system recovery MCH */
  327. ctl_set_bit(14, 24); /* enable warning MCH */
  328. return 0;
  329. }
  330. arch_initcall(machine_check_init);