nmi.c 9.6 KB

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