s390mach.c 12 KB

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