s390mach.c 11 KB

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