2 * drivers/s390/s390mach.c
3 * S/390 machine check handler
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)
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 <linux/kthread.h>
18 #include <asm/lowcore.h>
22 static struct semaphore m_sem;
24 extern int css_process_crw(int, int);
25 extern int chsc_process_crw(void);
26 extern int chp_process_crw(int, int);
27 extern void css_reiterate_subchannels(void);
29 extern struct workqueue_struct *slow_path_wq;
30 extern struct work_struct slow_path_work;
32 static NORET_TYPE void
33 s390_handle_damage(char *msg)
38 disabled_wait((unsigned long) __builtin_return_address(0));
43 * Retrieve CRWs and call function to handle event.
45 * Note : we currently process CRWs for io and chsc subchannels only
48 s390_collect_crw_info(void *param)
52 struct semaphore *sem;
55 sem = (struct semaphore *)param;
57 down_interruptible(sem);
61 if (unlikely(chain > 1)) {
64 printk(KERN_WARNING"%s: Code does not support more "
65 "than two chained crws; please report to "
66 "linux390@de.ibm.com!\n", __FUNCTION__);
67 ccode = stcrw(&tmp_crw);
68 printk(KERN_WARNING"%s: crw reports slct=%d, oflw=%d, "
69 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
70 __FUNCTION__, tmp_crw.slct, tmp_crw.oflw,
71 tmp_crw.chn, tmp_crw.rsc, tmp_crw.anc,
72 tmp_crw.erc, tmp_crw.rsid);
73 printk(KERN_WARNING"%s: This was crw number %x in the "
74 "chain\n", __FUNCTION__, chain);
77 chain = tmp_crw.chn ? chain + 1 : 0;
80 ccode = stcrw(&crw[chain]);
83 printk(KERN_DEBUG "crw_info : CRW reports slct=%d, oflw=%d, "
84 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
85 crw[chain].slct, crw[chain].oflw, crw[chain].chn,
86 crw[chain].rsc, crw[chain].anc, crw[chain].erc,
88 /* Check for overflows. */
89 if (crw[chain].oflw) {
90 pr_debug("%s: crw overflow detected!\n", __FUNCTION__);
91 css_reiterate_subchannels();
96 switch (crw[chain].rsc) {
98 if (crw[0].chn && !chain)
100 pr_debug("source is subchannel %04X\n", crw[0].rsid);
101 ret = css_process_crw (crw[0].rsid,
102 chain ? crw[1].rsid : 0);
106 case CRW_RSC_MONITOR:
107 pr_debug("source is monitoring facility\n");
110 pr_debug("source is channel path %02X\n", crw[0].rsid);
112 * Check for solicited machine checks. These are
113 * created by reset channel path and need not be
114 * reported to the common I/O layer.
116 if (crw[chain].slct) {
117 pr_debug("solicited machine check for "
118 "channel path %02X\n", crw[0].rsid);
121 switch (crw[0].erc) {
122 case CRW_ERC_IPARM: /* Path has come. */
123 ret = chp_process_crw(crw[0].rsid, 1);
125 case CRW_ERC_PERRI: /* Path has gone. */
127 ret = chp_process_crw(crw[0].rsid, 0);
130 pr_debug("Don't know how to handle erc=%x\n",
138 pr_debug("source is configuration-alert facility\n");
141 pr_debug("source is channel subsystem\n");
142 ret = chsc_process_crw();
147 pr_debug("unknown source\n");
150 /* chain is always 0 or 1 here. */
151 chain = crw[chain].chn ? chain + 1 : 0;
154 queue_work(slow_path_wq, &slow_path_work);
163 unsigned long long mcck_code;
166 static DEFINE_PER_CPU(struct mcck_struct, cpu_mcck);
169 * Main machine check handler function. Will be called with interrupts enabled
170 * or disabled and machine checks enabled or disabled.
173 s390_handle_mcck(void)
176 struct mcck_struct mcck;
179 * Disable machine checks and get the current state of accumulated
180 * machine checks. Afterwards delete the old state and enable machine
183 local_irq_save(flags);
184 local_mcck_disable();
185 mcck = __get_cpu_var(cpu_mcck);
186 memset(&__get_cpu_var(cpu_mcck), 0, sizeof(struct mcck_struct));
187 clear_thread_flag(TIF_MCCK_PENDING);
189 local_irq_restore(flags);
191 if (mcck.channel_report)
194 #ifdef CONFIG_MACHCHK_WARNING
196 * The warning may remain for a prolonged period on the bare iron.
197 * (actually till the machine is powered off, or until the problem is gone)
198 * So we just stop listening for the WARNING MCH and prevent continuously
199 * being interrupted. One caveat is however, that we must do this per
200 * processor and cannot use the smp version of ctl_clear_bit().
201 * On VM we only get one interrupt per virtally presented machinecheck.
202 * Though one suffices, we may get one interrupt per (virtual) processor.
204 if (mcck.warning) { /* WARNING pending ? */
205 static int mchchk_wng_posted = 0;
207 * Use single machine clear, as we cannot handle smp right now
209 __ctl_clear_bit(14, 24); /* Disable WARNING MCH */
210 if (xchg(&mchchk_wng_posted, 1) == 0)
211 kill_proc(1, SIGPWR, 1);
215 if (mcck.kill_task) {
217 printk(KERN_EMERG "mcck: Terminating task because of machine "
218 "malfunction (code 0x%016llx).\n", mcck.mcck_code);
219 printk(KERN_EMERG "mcck: task: %s, pid: %d.\n",
220 current->comm, current->pid);
226 * returns 0 if all registers could be validated
227 * returns 1 otherwise
230 s390_revalidate_registers(struct mci *mci)
235 void *fpt_save_area, *fpt_creg_save_area;
239 /* General purpose registers */
242 * General purpose registers couldn't be restored and have
243 * unknown contents. Process needs to be terminated.
247 /* Revalidate floating point registers */
250 * Floating point registers can't be restored and
251 * therefore the process needs to be terminated.
256 asm volatile("ld 0,0(%0)\n"
260 : : "a" (&S390_lowcore.floating_pt_save_area));
263 if (MACHINE_HAS_IEEE) {
265 fpt_save_area = &S390_lowcore.floating_pt_save_area;
266 fpt_creg_save_area = &S390_lowcore.fpt_creg_save_area;
268 fpt_save_area = (void *) S390_lowcore.extended_save_area_addr;
269 fpt_creg_save_area = fpt_save_area+128;
271 /* Floating point control register */
274 * Floating point control register can't be restored.
275 * Task will be terminated.
277 asm volatile ("lfpc 0(%0)" : : "a" (&zero), "m" (zero));
284 : : "a" (fpt_creg_save_area));
286 asm volatile("ld 0,0(%0)\n"
302 : : "a" (fpt_save_area));
305 /* Revalidate access registers */
306 asm volatile("lam 0,15,0(%0)"
307 : : "a" (&S390_lowcore.access_regs_save_area));
310 * Access registers have unknown contents.
315 /* Revalidate control registers */
318 * Control registers have unknown contents.
319 * Can't recover and therefore stopping machine.
321 s390_handle_damage("invalid control registers.");
324 asm volatile("lctlg 0,15,0(%0)"
325 : : "a" (&S390_lowcore.cregs_save_area));
327 asm volatile("lctl 0,15,0(%0)"
328 : : "a" (&S390_lowcore.cregs_save_area));
332 * We don't even try to revalidate the TOD register, since we simply
333 * can't write something sensible into that register.
338 * See if we can revalidate the TOD programmable register with its
339 * old contents (should be zero) otherwise set it to zero.
342 asm volatile("sr 0,0\n"
349 : : "a" (&S390_lowcore.tod_progreg_save_area) : "0", "cc");
352 /* Revalidate clock comparator register */
353 asm volatile ("stck 0(%1)\n"
355 : "=m" (tmpclock) : "a" (&(tmpclock)) : "cc", "memory");
357 /* Check if old PSW is valid */
360 * Can't tell if we come from user or kernel mode
361 * -> stopping machine.
363 s390_handle_damage("old psw invalid.");
365 if (!mci->ms || !mci->pm || !mci->ia)
371 #define MAX_IPD_COUNT 29
372 #define MAX_IPD_TIME (5 * 60 * USEC_PER_SEC) /* 5 minutes */
375 * machine check handler.
378 s390_do_machine_check(struct pt_regs *regs)
380 static DEFINE_SPINLOCK(ipd_lock);
381 static unsigned long long last_ipd;
382 static int ipd_count;
383 unsigned long long tmp;
385 struct mcck_struct *mcck;
390 mci = (struct mci *) &S390_lowcore.mcck_interruption_code;
391 mcck = &__get_cpu_var(cpu_mcck);
392 umode = user_mode(regs);
395 /* System damage -> stopping machine */
396 s390_handle_damage("received system damage machine check.");
400 /* Processing backup -> verify if we can survive this */
401 u64 z_mcic, o_mcic, t_mcic;
403 z_mcic = (1ULL<<63 | 1ULL<<59 | 1ULL<<29);
404 o_mcic = (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
405 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
406 1ULL<<30 | 1ULL<<21 | 1ULL<<20 | 1ULL<<17 |
409 z_mcic = (1ULL<<63 | 1ULL<<59 | 1ULL<<57 | 1ULL<<50 |
411 o_mcic = (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
412 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
413 1ULL<<30 | 1ULL<<20 | 1ULL<<17 | 1ULL<<16);
415 t_mcic = *(u64 *)mci;
417 if (((t_mcic & z_mcic) != 0) ||
418 ((t_mcic & o_mcic) != o_mcic)) {
419 s390_handle_damage("processing backup machine "
420 "check with damage.");
424 * Nullifying exigent condition, therefore we might
425 * retry this instruction.
428 spin_lock(&ipd_lock);
432 if (((tmp - last_ipd) >> 12) < MAX_IPD_TIME)
439 if (ipd_count == MAX_IPD_COUNT)
440 s390_handle_damage("too many ipd retries.");
442 spin_unlock(&ipd_lock);
445 /* Processing damage -> stopping machine */
446 s390_handle_damage("received instruction processing "
447 "damage machine check.");
450 if (s390_revalidate_registers(mci)) {
453 * Couldn't restore all register contents while in
454 * user mode -> mark task for termination.
457 mcck->mcck_code = *(unsigned long long *) mci;
458 set_thread_flag(TIF_MCCK_PENDING);
462 * Couldn't restore all register contents while in
463 * kernel mode -> stopping machine.
465 s390_handle_damage("unable to revalidate registers.");
469 /* Storage error uncorrected */
470 s390_handle_damage("received storage error uncorrected "
474 /* Storage key-error uncorrected */
475 s390_handle_damage("received storage key-error uncorrected "
478 if (mci->ds && mci->fa)
479 /* Storage degradation */
480 s390_handle_damage("received storage degradation machine "
484 /* Channel report word pending */
485 mcck->channel_report = 1;
486 set_thread_flag(TIF_MCCK_PENDING);
490 /* Warning pending */
492 set_thread_flag(TIF_MCCK_PENDING);
498 * s390_init_machine_check
500 * initialize machine check handling
503 machine_check_init(void)
505 init_MUTEX_LOCKED(&m_sem);
506 ctl_clear_bit(14, 25); /* disable external damage MCH */
507 ctl_set_bit(14, 27); /* enable system recovery MCH */
508 #ifdef CONFIG_MACHCHK_WARNING
509 ctl_set_bit(14, 24); /* enable warning MCH */
515 * Initialize the machine check handler really early to be able to
516 * catch all machine checks that happen during boot
518 arch_initcall(machine_check_init);
521 * Machine checks for the channel subsystem must be enabled
522 * after the channel subsystem is initialized
525 machine_check_crw_init (void)
527 kthread_run(s390_collect_crw_info, &m_sem, "kmcheck");
528 ctl_set_bit(14, 28); /* enable channel report MCH */
532 device_initcall (machine_check_crw_init);