s390mach.c 13 KB

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