nmi.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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/time.h>
  13. #include <linux/module.h>
  14. #include <asm/lowcore.h>
  15. #include <asm/smp.h>
  16. #include <asm/etr.h>
  17. #include <asm/cpu.h>
  18. #include <asm/nmi.h>
  19. #include <asm/crw.h>
  20. struct mcck_struct {
  21. int kill_task;
  22. int channel_report;
  23. int warning;
  24. unsigned long long mcck_code;
  25. };
  26. static DEFINE_PER_CPU(struct mcck_struct, cpu_mcck);
  27. static NORET_TYPE void s390_handle_damage(char *msg)
  28. {
  29. smp_send_stop();
  30. disabled_wait((unsigned long) __builtin_return_address(0));
  31. while (1);
  32. }
  33. /*
  34. * Main machine check handler function. Will be called with interrupts enabled
  35. * or disabled and machine checks enabled or disabled.
  36. */
  37. void s390_handle_mcck(void)
  38. {
  39. unsigned long flags;
  40. struct mcck_struct mcck;
  41. /*
  42. * Disable machine checks and get the current state of accumulated
  43. * machine checks. Afterwards delete the old state and enable machine
  44. * checks again.
  45. */
  46. local_irq_save(flags);
  47. local_mcck_disable();
  48. mcck = __get_cpu_var(cpu_mcck);
  49. memset(&__get_cpu_var(cpu_mcck), 0, sizeof(struct mcck_struct));
  50. clear_thread_flag(TIF_MCCK_PENDING);
  51. local_mcck_enable();
  52. local_irq_restore(flags);
  53. if (mcck.channel_report)
  54. crw_handle_channel_report();
  55. #ifdef CONFIG_MACHCHK_WARNING
  56. /*
  57. * The warning may remain for a prolonged period on the bare iron.
  58. * (actually till the machine is powered off, or until the problem is gone)
  59. * So we just stop listening for the WARNING MCH and prevent 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) processor.
  64. */
  65. if (mcck.warning) { /* WARNING pending ? */
  66. static int mchchk_wng_posted = 0;
  67. /*
  68. * Use single machine clear, as we cannot handle smp right now
  69. */
  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. #endif
  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 tmpclock;
  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. #ifndef CONFIG_64BIT
  112. asm volatile(
  113. " ld 0,0(%0)\n"
  114. " ld 2,8(%0)\n"
  115. " ld 4,16(%0)\n"
  116. " ld 6,24(%0)"
  117. : : "a" (&S390_lowcore.floating_pt_save_area));
  118. #endif
  119. if (MACHINE_HAS_IEEE) {
  120. #ifdef CONFIG_64BIT
  121. fpt_save_area = &S390_lowcore.floating_pt_save_area;
  122. fpt_creg_save_area = &S390_lowcore.fpt_creg_save_area;
  123. #else
  124. fpt_save_area = (void *) S390_lowcore.extended_save_area_addr;
  125. fpt_creg_save_area = fpt_save_area + 128;
  126. #endif
  127. if (!mci->fc) {
  128. /*
  129. * Floating point control register can't be restored.
  130. * Task will be terminated.
  131. */
  132. asm volatile("lfpc 0(%0)" : : "a" (&zero), "m" (zero));
  133. kill_task = 1;
  134. } else
  135. asm volatile("lfpc 0(%0)" : : "a" (fpt_creg_save_area));
  136. asm volatile(
  137. " ld 0,0(%0)\n"
  138. " ld 1,8(%0)\n"
  139. " ld 2,16(%0)\n"
  140. " ld 3,24(%0)\n"
  141. " ld 4,32(%0)\n"
  142. " ld 5,40(%0)\n"
  143. " ld 6,48(%0)\n"
  144. " ld 7,56(%0)\n"
  145. " ld 8,64(%0)\n"
  146. " ld 9,72(%0)\n"
  147. " ld 10,80(%0)\n"
  148. " ld 11,88(%0)\n"
  149. " ld 12,96(%0)\n"
  150. " ld 13,104(%0)\n"
  151. " ld 14,112(%0)\n"
  152. " ld 15,120(%0)\n"
  153. : : "a" (fpt_save_area));
  154. }
  155. /* Revalidate access registers */
  156. asm volatile(
  157. " lam 0,15,0(%0)"
  158. : : "a" (&S390_lowcore.access_regs_save_area));
  159. if (!mci->ar) {
  160. /*
  161. * Access registers have unknown contents.
  162. * Terminating task.
  163. */
  164. kill_task = 1;
  165. }
  166. /* Revalidate control registers */
  167. if (!mci->cr) {
  168. /*
  169. * Control registers have unknown contents.
  170. * Can't recover and therefore stopping machine.
  171. */
  172. s390_handle_damage("invalid control registers.");
  173. } else {
  174. #ifdef CONFIG_64BIT
  175. asm volatile(
  176. " lctlg 0,15,0(%0)"
  177. : : "a" (&S390_lowcore.cregs_save_area));
  178. #else
  179. asm volatile(
  180. " lctl 0,15,0(%0)"
  181. : : "a" (&S390_lowcore.cregs_save_area));
  182. #endif
  183. }
  184. /*
  185. * We don't even try to revalidate the TOD register, since we simply
  186. * can't write something sensible into that register.
  187. */
  188. #ifdef CONFIG_64BIT
  189. /*
  190. * See if we can revalidate the TOD programmable register with its
  191. * old contents (should be zero) otherwise set it to zero.
  192. */
  193. if (!mci->pr)
  194. asm volatile(
  195. " sr 0,0\n"
  196. " sckpf"
  197. : : : "0", "cc");
  198. else
  199. asm volatile(
  200. " l 0,0(%0)\n"
  201. " sckpf"
  202. : : "a" (&S390_lowcore.tod_progreg_save_area)
  203. : "0", "cc");
  204. #endif
  205. /* Revalidate clock comparator register */
  206. asm volatile(
  207. " stck 0(%1)\n"
  208. " sckc 0(%1)"
  209. : "=m" (tmpclock) : "a" (&(tmpclock)) : "cc", "memory");
  210. /* Check if old PSW is valid */
  211. if (!mci->wp)
  212. /*
  213. * Can't tell if we come from user or kernel mode
  214. * -> stopping machine.
  215. */
  216. s390_handle_damage("old psw invalid.");
  217. if (!mci->ms || !mci->pm || !mci->ia)
  218. kill_task = 1;
  219. return kill_task;
  220. }
  221. #define MAX_IPD_COUNT 29
  222. #define MAX_IPD_TIME (5 * 60 * USEC_PER_SEC) /* 5 minutes */
  223. #define ED_STP_ISLAND 6 /* External damage STP island check */
  224. #define ED_STP_SYNC 7 /* External damage STP sync check */
  225. #define ED_ETR_SYNC 12 /* External damage ETR sync check */
  226. #define ED_ETR_SWITCH 13 /* External damage ETR switch to local */
  227. /*
  228. * machine check handler.
  229. */
  230. void notrace s390_do_machine_check(struct pt_regs *regs)
  231. {
  232. static int ipd_count;
  233. static DEFINE_SPINLOCK(ipd_lock);
  234. static unsigned long long last_ipd;
  235. struct mcck_struct *mcck;
  236. unsigned long long tmp;
  237. struct mci *mci;
  238. int umode;
  239. lockdep_off();
  240. s390_idle_check();
  241. mci = (struct mci *) &S390_lowcore.mcck_interruption_code;
  242. mcck = &__get_cpu_var(cpu_mcck);
  243. umode = user_mode(regs);
  244. if (mci->sd) {
  245. /* System damage -> stopping machine */
  246. s390_handle_damage("received system damage machine check.");
  247. }
  248. if (mci->pd) {
  249. if (mci->b) {
  250. /* Processing backup -> verify if we can survive this */
  251. u64 z_mcic, o_mcic, t_mcic;
  252. #ifdef CONFIG_64BIT
  253. z_mcic = (1ULL<<63 | 1ULL<<59 | 1ULL<<29);
  254. o_mcic = (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
  255. 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
  256. 1ULL<<30 | 1ULL<<21 | 1ULL<<20 | 1ULL<<17 |
  257. 1ULL<<16);
  258. #else
  259. z_mcic = (1ULL<<63 | 1ULL<<59 | 1ULL<<57 | 1ULL<<50 |
  260. 1ULL<<29);
  261. o_mcic = (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
  262. 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
  263. 1ULL<<30 | 1ULL<<20 | 1ULL<<17 | 1ULL<<16);
  264. #endif
  265. t_mcic = *(u64 *)mci;
  266. if (((t_mcic & z_mcic) != 0) ||
  267. ((t_mcic & o_mcic) != o_mcic)) {
  268. s390_handle_damage("processing backup machine "
  269. "check with damage.");
  270. }
  271. /*
  272. * Nullifying exigent condition, therefore we might
  273. * retry this instruction.
  274. */
  275. spin_lock(&ipd_lock);
  276. tmp = get_clock();
  277. if (((tmp - last_ipd) >> 12) < MAX_IPD_TIME)
  278. ipd_count++;
  279. else
  280. ipd_count = 1;
  281. last_ipd = tmp;
  282. if (ipd_count == MAX_IPD_COUNT)
  283. s390_handle_damage("too many ipd retries.");
  284. spin_unlock(&ipd_lock);
  285. } else {
  286. /* Processing damage -> stopping machine */
  287. s390_handle_damage("received instruction processing "
  288. "damage machine check.");
  289. }
  290. }
  291. if (s390_revalidate_registers(mci)) {
  292. if (umode) {
  293. /*
  294. * Couldn't restore all register contents while in
  295. * user mode -> mark task for termination.
  296. */
  297. mcck->kill_task = 1;
  298. mcck->mcck_code = *(unsigned long long *) mci;
  299. set_thread_flag(TIF_MCCK_PENDING);
  300. } else {
  301. /*
  302. * Couldn't restore all register contents while in
  303. * kernel mode -> stopping machine.
  304. */
  305. s390_handle_damage("unable to revalidate registers.");
  306. }
  307. }
  308. if (mci->cd) {
  309. /* Timing facility damage */
  310. s390_handle_damage("TOD clock damaged");
  311. }
  312. if (mci->ed && mci->ec) {
  313. /* External damage */
  314. if (S390_lowcore.external_damage_code & (1U << ED_ETR_SYNC))
  315. etr_sync_check();
  316. if (S390_lowcore.external_damage_code & (1U << ED_ETR_SWITCH))
  317. etr_switch_to_local();
  318. if (S390_lowcore.external_damage_code & (1U << ED_STP_SYNC))
  319. stp_sync_check();
  320. if (S390_lowcore.external_damage_code & (1U << ED_STP_ISLAND))
  321. stp_island_check();
  322. }
  323. if (mci->se)
  324. /* Storage error uncorrected */
  325. s390_handle_damage("received storage error uncorrected "
  326. "machine check.");
  327. if (mci->ke)
  328. /* Storage key-error uncorrected */
  329. s390_handle_damage("received storage key-error uncorrected "
  330. "machine check.");
  331. if (mci->ds && mci->fa)
  332. /* Storage degradation */
  333. s390_handle_damage("received storage degradation machine "
  334. "check.");
  335. if (mci->cp) {
  336. /* Channel report word pending */
  337. mcck->channel_report = 1;
  338. set_thread_flag(TIF_MCCK_PENDING);
  339. }
  340. if (mci->w) {
  341. /* Warning pending */
  342. mcck->warning = 1;
  343. set_thread_flag(TIF_MCCK_PENDING);
  344. }
  345. lockdep_on();
  346. }
  347. static int __init machine_check_init(void)
  348. {
  349. ctl_set_bit(14, 25); /* enable external damage MCH */
  350. ctl_set_bit(14, 27); /* enable system recovery MCH */
  351. #ifdef CONFIG_MACHCHK_WARNING
  352. ctl_set_bit(14, 24); /* enable warning MCH */
  353. #endif
  354. return 0;
  355. }
  356. arch_initcall(machine_check_init);