nmi.c 9.3 KB

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