nmi.c 9.7 KB

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