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>
23 // #define DBG(args,...) do {} while (0);
25 static struct semaphore m_sem;
27 extern int css_process_crw(int, int);
28 extern int chsc_process_crw(void);
29 extern int chp_process_crw(int, int);
30 extern void css_reiterate_subchannels(void);
32 extern struct workqueue_struct *slow_path_wq;
33 extern struct work_struct slow_path_work;
35 static NORET_TYPE void
36 s390_handle_damage(char *msg)
41 disabled_wait((unsigned long) __builtin_return_address(0));
46 * Retrieve CRWs and call function to handle event.
48 * Note : we currently process CRWs for io and chsc subchannels only
51 s390_collect_crw_info(void *param)
55 struct semaphore *sem;
58 sem = (struct semaphore *)param;
60 down_interruptible(sem);
64 if (unlikely(chain > 1)) {
67 printk(KERN_WARNING"%s: Code does not support more "
68 "than two chained crws; please report to "
69 "linux390@de.ibm.com!\n", __FUNCTION__);
70 ccode = stcrw(&tmp_crw);
71 printk(KERN_WARNING"%s: crw reports slct=%d, oflw=%d, "
72 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
73 __FUNCTION__, tmp_crw.slct, tmp_crw.oflw,
74 tmp_crw.chn, tmp_crw.rsc, tmp_crw.anc,
75 tmp_crw.erc, tmp_crw.rsid);
76 printk(KERN_WARNING"%s: This was crw number %x in the "
77 "chain\n", __FUNCTION__, chain);
80 chain = tmp_crw.chn ? chain + 1 : 0;
83 ccode = stcrw(&crw[chain]);
86 DBG(KERN_DEBUG "crw_info : CRW reports slct=%d, oflw=%d, "
87 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
88 crw[chain].slct, crw[chain].oflw, crw[chain].chn,
89 crw[chain].rsc, crw[chain].anc, crw[chain].erc,
91 /* Check for overflows. */
92 if (crw[chain].oflw) {
93 pr_debug("%s: crw overflow detected!\n", __FUNCTION__);
94 css_reiterate_subchannels();
99 switch (crw[chain].rsc) {
101 if (crw[0].chn && !chain)
103 pr_debug("source is subchannel %04X\n", crw[0].rsid);
104 ret = css_process_crw (crw[0].rsid,
105 chain ? crw[1].rsid : 0);
109 case CRW_RSC_MONITOR:
110 pr_debug("source is monitoring facility\n");
113 pr_debug("source is channel path %02X\n", crw[0].rsid);
114 switch (crw[0].erc) {
115 case CRW_ERC_IPARM: /* Path has come. */
116 ret = chp_process_crw(crw[0].rsid, 1);
118 case CRW_ERC_PERRI: /* Path has gone. */
120 ret = chp_process_crw(crw[0].rsid, 0);
123 pr_debug("Don't know how to handle erc=%x\n",
131 pr_debug("source is configuration-alert facility\n");
134 pr_debug("source is channel subsystem\n");
135 ret = chsc_process_crw();
140 pr_debug("unknown source\n");
143 /* chain is always 0 or 1 here. */
144 chain = crw[chain].chn ? chain + 1 : 0;
147 queue_work(slow_path_wq, &slow_path_work);
156 unsigned long long mcck_code;
159 static DEFINE_PER_CPU(struct mcck_struct, cpu_mcck);
162 * Main machine check handler function. Will be called with interrupts enabled
163 * or disabled and machine checks enabled or disabled.
166 s390_handle_mcck(void)
169 struct mcck_struct mcck;
172 * Disable machine checks and get the current state of accumulated
173 * machine checks. Afterwards delete the old state and enable machine
176 local_irq_save(flags);
177 local_mcck_disable();
178 mcck = __get_cpu_var(cpu_mcck);
179 memset(&__get_cpu_var(cpu_mcck), 0, sizeof(struct mcck_struct));
180 clear_thread_flag(TIF_MCCK_PENDING);
182 local_irq_restore(flags);
184 if (mcck.channel_report)
187 #ifdef CONFIG_MACHCHK_WARNING
189 * The warning may remain for a prolonged period on the bare iron.
190 * (actually till the machine is powered off, or until the problem is gone)
191 * So we just stop listening for the WARNING MCH and prevent continuously
192 * being interrupted. One caveat is however, that we must do this per
193 * processor and cannot use the smp version of ctl_clear_bit().
194 * On VM we only get one interrupt per virtally presented machinecheck.
195 * Though one suffices, we may get one interrupt per (virtual) processor.
197 if (mcck.warning) { /* WARNING pending ? */
198 static int mchchk_wng_posted = 0;
200 * Use single machine clear, as we cannot handle smp right now
202 __ctl_clear_bit(14, 24); /* Disable WARNING MCH */
203 if (xchg(&mchchk_wng_posted, 1) == 0)
204 kill_proc(1, SIGPWR, 1);
208 if (mcck.kill_task) {
210 printk(KERN_EMERG "mcck: Terminating task because of machine "
211 "malfunction (code 0x%016llx).\n", mcck.mcck_code);
212 printk(KERN_EMERG "mcck: task: %s, pid: %d.\n",
213 current->comm, current->pid);
219 * returns 0 if all registers could be validated
220 * returns 1 otherwise
223 s390_revalidate_registers(struct mci *mci)
228 void *fpt_save_area, *fpt_creg_save_area;
232 /* General purpose registers */
235 * General purpose registers couldn't be restored and have
236 * unknown contents. Process needs to be terminated.
240 /* Revalidate floating point registers */
243 * Floating point registers can't be restored and
244 * therefore the process needs to be terminated.
249 asm volatile("ld 0,0(%0)\n"
253 : : "a" (&S390_lowcore.floating_pt_save_area));
256 if (MACHINE_HAS_IEEE) {
258 fpt_save_area = &S390_lowcore.floating_pt_save_area;
259 fpt_creg_save_area = &S390_lowcore.fpt_creg_save_area;
261 fpt_save_area = (void *) S390_lowcore.extended_save_area_addr;
262 fpt_creg_save_area = fpt_save_area+128;
264 /* Floating point control register */
267 * Floating point control register can't be restored.
268 * Task will be terminated.
270 asm volatile ("lfpc 0(%0)" : : "a" (&zero), "m" (zero));
277 : : "a" (fpt_creg_save_area));
279 asm volatile("ld 0,0(%0)\n"
295 : : "a" (fpt_save_area));
298 /* Revalidate access registers */
299 asm volatile("lam 0,15,0(%0)"
300 : : "a" (&S390_lowcore.access_regs_save_area));
303 * Access registers have unknown contents.
308 /* Revalidate control registers */
311 * Control registers have unknown contents.
312 * Can't recover and therefore stopping machine.
314 s390_handle_damage("invalid control registers.");
317 asm volatile("lctlg 0,15,0(%0)"
318 : : "a" (&S390_lowcore.cregs_save_area));
320 asm volatile("lctl 0,15,0(%0)"
321 : : "a" (&S390_lowcore.cregs_save_area));
325 * We don't even try to revalidate the TOD register, since we simply
326 * can't write something sensible into that register.
331 * See if we can revalidate the TOD programmable register with its
332 * old contents (should be zero) otherwise set it to zero.
335 asm volatile("sr 0,0\n"
342 : : "a" (&S390_lowcore.tod_progreg_save_area) : "0", "cc");
345 /* Revalidate clock comparator register */
346 asm volatile ("stck 0(%1)\n"
348 : "=m" (tmpclock) : "a" (&(tmpclock)) : "cc", "memory");
350 /* Check if old PSW is valid */
353 * Can't tell if we come from user or kernel mode
354 * -> stopping machine.
356 s390_handle_damage("old psw invalid.");
358 if (!mci->ms || !mci->pm || !mci->ia)
364 #define MAX_IPD_COUNT 29
365 #define MAX_IPD_TIME (5 * 60 * USEC_PER_SEC) /* 5 minutes */
368 * machine check handler.
371 s390_do_machine_check(struct pt_regs *regs)
373 static DEFINE_SPINLOCK(ipd_lock);
374 static unsigned long long last_ipd;
375 static int ipd_count;
376 unsigned long long tmp;
378 struct mcck_struct *mcck;
381 mci = (struct mci *) &S390_lowcore.mcck_interruption_code;
382 mcck = &__get_cpu_var(cpu_mcck);
383 umode = user_mode(regs);
386 /* System damage -> stopping machine */
387 s390_handle_damage("received system damage machine check.");
391 /* Processing backup -> verify if we can survive this */
392 u64 z_mcic, o_mcic, t_mcic;
394 z_mcic = (1ULL<<63 | 1ULL<<59 | 1ULL<<29);
395 o_mcic = (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
396 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
397 1ULL<<30 | 1ULL<<21 | 1ULL<<20 | 1ULL<<17 |
400 z_mcic = (1ULL<<63 | 1ULL<<59 | 1ULL<<57 | 1ULL<<50 |
402 o_mcic = (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
403 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
404 1ULL<<30 | 1ULL<<20 | 1ULL<<17 | 1ULL<<16);
406 t_mcic = *(u64 *)mci;
408 if (((t_mcic & z_mcic) != 0) ||
409 ((t_mcic & o_mcic) != o_mcic)) {
410 s390_handle_damage("processing backup machine "
411 "check with damage.");
415 * Nullifying exigent condition, therefore we might
416 * retry this instruction.
419 spin_lock(&ipd_lock);
423 if (((tmp - last_ipd) >> 12) < MAX_IPD_TIME)
430 if (ipd_count == MAX_IPD_COUNT)
431 s390_handle_damage("too many ipd retries.");
433 spin_unlock(&ipd_lock);
436 /* Processing damage -> stopping machine */
437 s390_handle_damage("received instruction processing "
438 "damage machine check.");
441 if (s390_revalidate_registers(mci)) {
444 * Couldn't restore all register contents while in
445 * user mode -> mark task for termination.
448 mcck->mcck_code = *(unsigned long long *) mci;
449 set_thread_flag(TIF_MCCK_PENDING);
453 * Couldn't restore all register contents while in
454 * kernel mode -> stopping machine.
456 s390_handle_damage("unable to revalidate registers.");
460 /* Storage error uncorrected */
461 s390_handle_damage("received storage error uncorrected "
465 /* Storage key-error uncorrected */
466 s390_handle_damage("received storage key-error uncorrected "
469 if (mci->ds && mci->fa)
470 /* Storage degradation */
471 s390_handle_damage("received storage degradation machine "
475 /* Channel report word pending */
476 mcck->channel_report = 1;
477 set_thread_flag(TIF_MCCK_PENDING);
481 /* Warning pending */
483 set_thread_flag(TIF_MCCK_PENDING);
488 * s390_init_machine_check
490 * initialize machine check handling
493 machine_check_init(void)
495 init_MUTEX_LOCKED(&m_sem);
496 ctl_clear_bit(14, 25); /* disable external damage MCH */
497 ctl_set_bit(14, 27); /* enable system recovery MCH */
498 #ifdef CONFIG_MACHCHK_WARNING
499 ctl_set_bit(14, 24); /* enable warning MCH */
505 * Initialize the machine check handler really early to be able to
506 * catch all machine checks that happen during boot
508 arch_initcall(machine_check_init);
511 * Machine checks for the channel subsystem must be enabled
512 * after the channel subsystem is initialized
515 machine_check_crw_init (void)
517 kthread_run(s390_collect_crw_info, &m_sem, "kmcheck");
518 ctl_set_bit(14, 28); /* enable channel report MCH */
522 device_initcall (machine_check_crw_init);