s390mach.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /*
  2. * drivers/s390/s390mach.c
  3. * S/390 machine check handler
  4. *
  5. * S390 version
  6. * Copyright (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  7. * Author(s): Ingo Adlung (adlung@de.ibm.com)
  8. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  9. */
  10. #include <linux/init.h>
  11. #include <linux/sched.h>
  12. #include <linux/errno.h>
  13. #include <linux/workqueue.h>
  14. #include <linux/time.h>
  15. #include <linux/device.h>
  16. #include <linux/kthread.h>
  17. #include <asm/etr.h>
  18. #include <asm/lowcore.h>
  19. #include <asm/cio.h>
  20. #include "cio/cio.h"
  21. #include "cio/chsc.h"
  22. #include "cio/css.h"
  23. #include "cio/chp.h"
  24. #include "s390mach.h"
  25. static struct semaphore m_sem;
  26. static NORET_TYPE void
  27. s390_handle_damage(char *msg)
  28. {
  29. #ifdef CONFIG_SMP
  30. smp_send_stop();
  31. #endif
  32. disabled_wait((unsigned long) __builtin_return_address(0));
  33. for(;;);
  34. }
  35. /*
  36. * Retrieve CRWs and call function to handle event.
  37. *
  38. * Note : we currently process CRWs for io and chsc subchannels only
  39. */
  40. static int
  41. s390_collect_crw_info(void *param)
  42. {
  43. struct crw crw[2];
  44. int ccode, ret, slow;
  45. struct semaphore *sem;
  46. unsigned int chain;
  47. sem = (struct semaphore *)param;
  48. repeat:
  49. down_interruptible(sem);
  50. slow = 0;
  51. chain = 0;
  52. while (1) {
  53. if (unlikely(chain > 1)) {
  54. struct crw tmp_crw;
  55. printk(KERN_WARNING"%s: Code does not support more "
  56. "than two chained crws; please report to "
  57. "linux390@de.ibm.com!\n", __FUNCTION__);
  58. ccode = stcrw(&tmp_crw);
  59. printk(KERN_WARNING"%s: crw reports slct=%d, oflw=%d, "
  60. "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
  61. __FUNCTION__, tmp_crw.slct, tmp_crw.oflw,
  62. tmp_crw.chn, tmp_crw.rsc, tmp_crw.anc,
  63. tmp_crw.erc, tmp_crw.rsid);
  64. printk(KERN_WARNING"%s: This was crw number %x in the "
  65. "chain\n", __FUNCTION__, chain);
  66. if (ccode != 0)
  67. break;
  68. chain = tmp_crw.chn ? chain + 1 : 0;
  69. continue;
  70. }
  71. ccode = stcrw(&crw[chain]);
  72. if (ccode != 0)
  73. break;
  74. printk(KERN_DEBUG "crw_info : CRW reports slct=%d, oflw=%d, "
  75. "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
  76. crw[chain].slct, crw[chain].oflw, crw[chain].chn,
  77. crw[chain].rsc, crw[chain].anc, crw[chain].erc,
  78. crw[chain].rsid);
  79. /* Check for overflows. */
  80. if (crw[chain].oflw) {
  81. pr_debug("%s: crw overflow detected!\n", __FUNCTION__);
  82. css_reiterate_subchannels();
  83. chain = 0;
  84. slow = 1;
  85. continue;
  86. }
  87. switch (crw[chain].rsc) {
  88. case CRW_RSC_SCH:
  89. if (crw[0].chn && !chain)
  90. break;
  91. pr_debug("source is subchannel %04X\n", crw[0].rsid);
  92. ret = css_process_crw (crw[0].rsid,
  93. chain ? crw[1].rsid : 0);
  94. if (ret == -EAGAIN)
  95. slow = 1;
  96. break;
  97. case CRW_RSC_MONITOR:
  98. pr_debug("source is monitoring facility\n");
  99. break;
  100. case CRW_RSC_CPATH:
  101. pr_debug("source is channel path %02X\n", crw[0].rsid);
  102. /*
  103. * Check for solicited machine checks. These are
  104. * created by reset channel path and need not be
  105. * reported to the common I/O layer.
  106. */
  107. if (crw[chain].slct) {
  108. pr_debug("solicited machine check for "
  109. "channel path %02X\n", crw[0].rsid);
  110. break;
  111. }
  112. switch (crw[0].erc) {
  113. case CRW_ERC_IPARM: /* Path has come. */
  114. ret = chp_process_crw(crw[0].rsid, 1);
  115. break;
  116. case CRW_ERC_PERRI: /* Path has gone. */
  117. case CRW_ERC_PERRN:
  118. ret = chp_process_crw(crw[0].rsid, 0);
  119. break;
  120. default:
  121. pr_debug("Don't know how to handle erc=%x\n",
  122. crw[0].erc);
  123. ret = 0;
  124. }
  125. if (ret == -EAGAIN)
  126. slow = 1;
  127. break;
  128. case CRW_RSC_CONFIG:
  129. pr_debug("source is configuration-alert facility\n");
  130. break;
  131. case CRW_RSC_CSS:
  132. pr_debug("source is channel subsystem\n");
  133. ret = chsc_process_crw();
  134. if (ret == -EAGAIN)
  135. slow = 1;
  136. break;
  137. default:
  138. pr_debug("unknown source\n");
  139. break;
  140. }
  141. /* chain is always 0 or 1 here. */
  142. chain = crw[chain].chn ? chain + 1 : 0;
  143. }
  144. if (slow)
  145. queue_work(slow_path_wq, &slow_path_work);
  146. goto repeat;
  147. return 0;
  148. }
  149. struct mcck_struct {
  150. int kill_task;
  151. int channel_report;
  152. int warning;
  153. unsigned long long mcck_code;
  154. };
  155. static DEFINE_PER_CPU(struct mcck_struct, cpu_mcck);
  156. /*
  157. * Main machine check handler function. Will be called with interrupts enabled
  158. * or disabled and machine checks enabled or disabled.
  159. */
  160. void
  161. s390_handle_mcck(void)
  162. {
  163. unsigned long flags;
  164. struct mcck_struct mcck;
  165. /*
  166. * Disable machine checks and get the current state of accumulated
  167. * machine checks. Afterwards delete the old state and enable machine
  168. * checks again.
  169. */
  170. local_irq_save(flags);
  171. local_mcck_disable();
  172. mcck = __get_cpu_var(cpu_mcck);
  173. memset(&__get_cpu_var(cpu_mcck), 0, sizeof(struct mcck_struct));
  174. clear_thread_flag(TIF_MCCK_PENDING);
  175. local_mcck_enable();
  176. local_irq_restore(flags);
  177. if (mcck.channel_report)
  178. up(&m_sem);
  179. #ifdef CONFIG_MACHCHK_WARNING
  180. /*
  181. * The warning may remain for a prolonged period on the bare iron.
  182. * (actually till the machine is powered off, or until the problem is gone)
  183. * So we just stop listening for the WARNING MCH and prevent continuously
  184. * being interrupted. One caveat is however, that we must do this per
  185. * processor and cannot use the smp version of ctl_clear_bit().
  186. * On VM we only get one interrupt per virtally presented machinecheck.
  187. * Though one suffices, we may get one interrupt per (virtual) processor.
  188. */
  189. if (mcck.warning) { /* WARNING pending ? */
  190. static int mchchk_wng_posted = 0;
  191. /*
  192. * Use single machine clear, as we cannot handle smp right now
  193. */
  194. __ctl_clear_bit(14, 24); /* Disable WARNING MCH */
  195. if (xchg(&mchchk_wng_posted, 1) == 0)
  196. kill_cad_pid(SIGPWR, 1);
  197. }
  198. #endif
  199. if (mcck.kill_task) {
  200. local_irq_enable();
  201. printk(KERN_EMERG "mcck: Terminating task because of machine "
  202. "malfunction (code 0x%016llx).\n", mcck.mcck_code);
  203. printk(KERN_EMERG "mcck: task: %s, pid: %d.\n",
  204. current->comm, current->pid);
  205. do_exit(SIGSEGV);
  206. }
  207. }
  208. /*
  209. * returns 0 if all registers could be validated
  210. * returns 1 otherwise
  211. */
  212. static int
  213. s390_revalidate_registers(struct mci *mci)
  214. {
  215. int kill_task;
  216. u64 tmpclock;
  217. u64 zero;
  218. void *fpt_save_area, *fpt_creg_save_area;
  219. kill_task = 0;
  220. zero = 0;
  221. /* General purpose registers */
  222. if (!mci->gr)
  223. /*
  224. * General purpose registers couldn't be restored and have
  225. * unknown contents. Process needs to be terminated.
  226. */
  227. kill_task = 1;
  228. /* Revalidate floating point registers */
  229. if (!mci->fp)
  230. /*
  231. * Floating point registers can't be restored and
  232. * therefore the process needs to be terminated.
  233. */
  234. kill_task = 1;
  235. #ifndef CONFIG_64BIT
  236. asm volatile(
  237. " ld 0,0(%0)\n"
  238. " ld 2,8(%0)\n"
  239. " ld 4,16(%0)\n"
  240. " ld 6,24(%0)"
  241. : : "a" (&S390_lowcore.floating_pt_save_area));
  242. #endif
  243. if (MACHINE_HAS_IEEE) {
  244. #ifdef CONFIG_64BIT
  245. fpt_save_area = &S390_lowcore.floating_pt_save_area;
  246. fpt_creg_save_area = &S390_lowcore.fpt_creg_save_area;
  247. #else
  248. fpt_save_area = (void *) S390_lowcore.extended_save_area_addr;
  249. fpt_creg_save_area = fpt_save_area+128;
  250. #endif
  251. /* Floating point control register */
  252. if (!mci->fc) {
  253. /*
  254. * Floating point control register can't be restored.
  255. * Task will be terminated.
  256. */
  257. asm volatile("lfpc 0(%0)" : : "a" (&zero), "m" (zero));
  258. kill_task = 1;
  259. } else
  260. asm volatile("lfpc 0(%0)" : : "a" (fpt_creg_save_area));
  261. asm volatile(
  262. " ld 0,0(%0)\n"
  263. " ld 1,8(%0)\n"
  264. " ld 2,16(%0)\n"
  265. " ld 3,24(%0)\n"
  266. " ld 4,32(%0)\n"
  267. " ld 5,40(%0)\n"
  268. " ld 6,48(%0)\n"
  269. " ld 7,56(%0)\n"
  270. " ld 8,64(%0)\n"
  271. " ld 9,72(%0)\n"
  272. " ld 10,80(%0)\n"
  273. " ld 11,88(%0)\n"
  274. " ld 12,96(%0)\n"
  275. " ld 13,104(%0)\n"
  276. " ld 14,112(%0)\n"
  277. " ld 15,120(%0)\n"
  278. : : "a" (fpt_save_area));
  279. }
  280. /* Revalidate access registers */
  281. asm volatile(
  282. " lam 0,15,0(%0)"
  283. : : "a" (&S390_lowcore.access_regs_save_area));
  284. if (!mci->ar)
  285. /*
  286. * Access registers have unknown contents.
  287. * Terminating task.
  288. */
  289. kill_task = 1;
  290. /* Revalidate control registers */
  291. if (!mci->cr)
  292. /*
  293. * Control registers have unknown contents.
  294. * Can't recover and therefore stopping machine.
  295. */
  296. s390_handle_damage("invalid control registers.");
  297. else
  298. #ifdef CONFIG_64BIT
  299. asm volatile(
  300. " lctlg 0,15,0(%0)"
  301. : : "a" (&S390_lowcore.cregs_save_area));
  302. #else
  303. asm volatile(
  304. " lctl 0,15,0(%0)"
  305. : : "a" (&S390_lowcore.cregs_save_area));
  306. #endif
  307. /*
  308. * We don't even try to revalidate the TOD register, since we simply
  309. * can't write something sensible into that register.
  310. */
  311. #ifdef CONFIG_64BIT
  312. /*
  313. * See if we can revalidate the TOD programmable register with its
  314. * old contents (should be zero) otherwise set it to zero.
  315. */
  316. if (!mci->pr)
  317. asm volatile(
  318. " sr 0,0\n"
  319. " sckpf"
  320. : : : "0", "cc");
  321. else
  322. asm volatile(
  323. " l 0,0(%0)\n"
  324. " sckpf"
  325. : : "a" (&S390_lowcore.tod_progreg_save_area)
  326. : "0", "cc");
  327. #endif
  328. /* Revalidate clock comparator register */
  329. asm volatile(
  330. " stck 0(%1)\n"
  331. " sckc 0(%1)"
  332. : "=m" (tmpclock) : "a" (&(tmpclock)) : "cc", "memory");
  333. /* Check if old PSW is valid */
  334. if (!mci->wp)
  335. /*
  336. * Can't tell if we come from user or kernel mode
  337. * -> stopping machine.
  338. */
  339. s390_handle_damage("old psw invalid.");
  340. if (!mci->ms || !mci->pm || !mci->ia)
  341. kill_task = 1;
  342. return kill_task;
  343. }
  344. #define MAX_IPD_COUNT 29
  345. #define MAX_IPD_TIME (5 * 60 * USEC_PER_SEC) /* 5 minutes */
  346. /*
  347. * machine check handler.
  348. */
  349. void
  350. s390_do_machine_check(struct pt_regs *regs)
  351. {
  352. static DEFINE_SPINLOCK(ipd_lock);
  353. static unsigned long long last_ipd;
  354. static int ipd_count;
  355. unsigned long long tmp;
  356. struct mci *mci;
  357. struct mcck_struct *mcck;
  358. int umode;
  359. lockdep_off();
  360. mci = (struct mci *) &S390_lowcore.mcck_interruption_code;
  361. mcck = &__get_cpu_var(cpu_mcck);
  362. umode = user_mode(regs);
  363. if (mci->sd)
  364. /* System damage -> stopping machine */
  365. s390_handle_damage("received system damage machine check.");
  366. if (mci->pd) {
  367. if (mci->b) {
  368. /* Processing backup -> verify if we can survive this */
  369. u64 z_mcic, o_mcic, t_mcic;
  370. #ifdef CONFIG_64BIT
  371. z_mcic = (1ULL<<63 | 1ULL<<59 | 1ULL<<29);
  372. o_mcic = (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
  373. 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
  374. 1ULL<<30 | 1ULL<<21 | 1ULL<<20 | 1ULL<<17 |
  375. 1ULL<<16);
  376. #else
  377. z_mcic = (1ULL<<63 | 1ULL<<59 | 1ULL<<57 | 1ULL<<50 |
  378. 1ULL<<29);
  379. o_mcic = (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
  380. 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
  381. 1ULL<<30 | 1ULL<<20 | 1ULL<<17 | 1ULL<<16);
  382. #endif
  383. t_mcic = *(u64 *)mci;
  384. if (((t_mcic & z_mcic) != 0) ||
  385. ((t_mcic & o_mcic) != o_mcic)) {
  386. s390_handle_damage("processing backup machine "
  387. "check with damage.");
  388. }
  389. /*
  390. * Nullifying exigent condition, therefore we might
  391. * retry this instruction.
  392. */
  393. spin_lock(&ipd_lock);
  394. tmp = get_clock();
  395. if (((tmp - last_ipd) >> 12) < MAX_IPD_TIME)
  396. ipd_count++;
  397. else
  398. ipd_count = 1;
  399. last_ipd = tmp;
  400. if (ipd_count == MAX_IPD_COUNT)
  401. s390_handle_damage("too many ipd retries.");
  402. spin_unlock(&ipd_lock);
  403. }
  404. else {
  405. /* Processing damage -> stopping machine */
  406. s390_handle_damage("received instruction processing "
  407. "damage machine check.");
  408. }
  409. }
  410. if (s390_revalidate_registers(mci)) {
  411. if (umode) {
  412. /*
  413. * Couldn't restore all register contents while in
  414. * user mode -> mark task for termination.
  415. */
  416. mcck->kill_task = 1;
  417. mcck->mcck_code = *(unsigned long long *) mci;
  418. set_thread_flag(TIF_MCCK_PENDING);
  419. }
  420. else
  421. /*
  422. * Couldn't restore all register contents while in
  423. * kernel mode -> stopping machine.
  424. */
  425. s390_handle_damage("unable to revalidate registers.");
  426. }
  427. if (mci->cd) {
  428. /* Timing facility damage */
  429. s390_handle_damage("TOD clock damaged");
  430. }
  431. if (mci->ed && mci->ec) {
  432. /* External damage */
  433. if (S390_lowcore.external_damage_code & (1U << ED_ETR_SYNC))
  434. etr_sync_check();
  435. if (S390_lowcore.external_damage_code & (1U << ED_ETR_SWITCH))
  436. etr_switch_to_local();
  437. }
  438. if (mci->se)
  439. /* Storage error uncorrected */
  440. s390_handle_damage("received storage error uncorrected "
  441. "machine check.");
  442. if (mci->ke)
  443. /* Storage key-error uncorrected */
  444. s390_handle_damage("received storage key-error uncorrected "
  445. "machine check.");
  446. if (mci->ds && mci->fa)
  447. /* Storage degradation */
  448. s390_handle_damage("received storage degradation machine "
  449. "check.");
  450. if (mci->cp) {
  451. /* Channel report word pending */
  452. mcck->channel_report = 1;
  453. set_thread_flag(TIF_MCCK_PENDING);
  454. }
  455. if (mci->w) {
  456. /* Warning pending */
  457. mcck->warning = 1;
  458. set_thread_flag(TIF_MCCK_PENDING);
  459. }
  460. lockdep_on();
  461. }
  462. /*
  463. * s390_init_machine_check
  464. *
  465. * initialize machine check handling
  466. */
  467. static int
  468. machine_check_init(void)
  469. {
  470. init_MUTEX_LOCKED(&m_sem);
  471. ctl_set_bit(14, 25); /* enable external damage MCH */
  472. ctl_set_bit(14, 27); /* enable system recovery MCH */
  473. #ifdef CONFIG_MACHCHK_WARNING
  474. ctl_set_bit(14, 24); /* enable warning MCH */
  475. #endif
  476. return 0;
  477. }
  478. /*
  479. * Initialize the machine check handler really early to be able to
  480. * catch all machine checks that happen during boot
  481. */
  482. arch_initcall(machine_check_init);
  483. /*
  484. * Machine checks for the channel subsystem must be enabled
  485. * after the channel subsystem is initialized
  486. */
  487. static int __init
  488. machine_check_crw_init (void)
  489. {
  490. struct task_struct *task;
  491. task = kthread_run(s390_collect_crw_info, &m_sem, "kmcheck");
  492. if (IS_ERR(task))
  493. return PTR_ERR(task);
  494. ctl_set_bit(14, 28); /* enable channel report MCH */
  495. return 0;
  496. }
  497. device_initcall (machine_check_crw_init);