s390mach.c 13 KB

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