s390mach.c 13 KB

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