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/config.h>
12 #include <linux/init.h>
13 #include <linux/sched.h>
14 #include <linux/errno.h>
15 #include <linux/workqueue.h>
16 #include <linux/time.h>
17 #include <linux/kthread.h>
19 #include <asm/lowcore.h>
24 // #define DBG(args,...) do {} while (0);
26 static struct semaphore m_sem;
28 extern int css_process_crw(int, int);
29 extern int chsc_process_crw(void);
30 extern int chp_process_crw(int, int);
31 extern void css_reiterate_subchannels(void);
33 extern struct workqueue_struct *slow_path_wq;
34 extern struct work_struct slow_path_work;
36 static NORET_TYPE void
37 s390_handle_damage(char *msg)
42 disabled_wait((unsigned long) __builtin_return_address(0));
47 * Retrieve CRWs and call function to handle event.
49 * Note : we currently process CRWs for io and chsc subchannels only
52 s390_collect_crw_info(void *param)
56 struct semaphore *sem;
59 sem = (struct semaphore *)param;
61 down_interruptible(sem);
65 if (unlikely(chain > 1)) {
68 printk(KERN_WARNING"%s: Code does not support more "
69 "than two chained crws; please report to "
70 "linux390@de.ibm.com!\n", __FUNCTION__);
71 ccode = stcrw(&tmp_crw);
72 printk(KERN_WARNING"%s: crw reports slct=%d, oflw=%d, "
73 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
74 __FUNCTION__, tmp_crw.slct, tmp_crw.oflw,
75 tmp_crw.chn, tmp_crw.rsc, tmp_crw.anc,
76 tmp_crw.erc, tmp_crw.rsid);
77 printk(KERN_WARNING"%s: This was crw number %x in the "
78 "chain\n", __FUNCTION__, chain);
81 chain = tmp_crw.chn ? chain + 1 : 0;
84 ccode = stcrw(&crw[chain]);
87 DBG(KERN_DEBUG "crw_info : CRW reports slct=%d, oflw=%d, "
88 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
89 crw[chain].slct, crw[chain].oflw, crw[chain].chn,
90 crw[chain].rsc, crw[chain].anc, crw[chain].erc,
92 /* Check for overflows. */
93 if (crw[chain].oflw) {
94 pr_debug("%s: crw overflow detected!\n", __FUNCTION__);
95 css_reiterate_subchannels();
100 switch (crw[chain].rsc) {
102 if (crw[0].chn && !chain)
104 pr_debug("source is subchannel %04X\n", crw[0].rsid);
105 ret = css_process_crw (crw[0].rsid,
106 chain ? crw[1].rsid : 0);
110 case CRW_RSC_MONITOR:
111 pr_debug("source is monitoring facility\n");
114 pr_debug("source is channel path %02X\n", crw[0].rsid);
115 switch (crw[0].erc) {
116 case CRW_ERC_IPARM: /* Path has come. */
117 ret = chp_process_crw(crw[0].rsid, 1);
119 case CRW_ERC_PERRI: /* Path has gone. */
121 ret = chp_process_crw(crw[0].rsid, 0);
124 pr_debug("Don't know how to handle erc=%x\n",
132 pr_debug("source is configuration-alert facility\n");
135 pr_debug("source is channel subsystem\n");
136 ret = chsc_process_crw();
141 pr_debug("unknown source\n");
144 /* chain is always 0 or 1 here. */
145 chain = crw[chain].chn ? chain + 1 : 0;
148 queue_work(slow_path_wq, &slow_path_work);
157 unsigned long long mcck_code;
160 static DEFINE_PER_CPU(struct mcck_struct, cpu_mcck);
163 * Main machine check handler function. Will be called with interrupts enabled
164 * or disabled and machine checks enabled or disabled.
167 s390_handle_mcck(void)
170 struct mcck_struct mcck;
173 * Disable machine checks and get the current state of accumulated
174 * machine checks. Afterwards delete the old state and enable machine
177 local_irq_save(flags);
178 local_mcck_disable();
179 mcck = __get_cpu_var(cpu_mcck);
180 memset(&__get_cpu_var(cpu_mcck), 0, sizeof(struct mcck_struct));
181 clear_thread_flag(TIF_MCCK_PENDING);
183 local_irq_restore(flags);
185 if (mcck.channel_report)
188 #ifdef CONFIG_MACHCHK_WARNING
190 * The warning may remain for a prolonged period on the bare iron.
191 * (actually till the machine is powered off, or until the problem is gone)
192 * So we just stop listening for the WARNING MCH and prevent continuously
193 * being interrupted. One caveat is however, that we must do this per
194 * processor and cannot use the smp version of ctl_clear_bit().
195 * On VM we only get one interrupt per virtally presented machinecheck.
196 * Though one suffices, we may get one interrupt per (virtual) processor.
198 if (mcck.warning) { /* WARNING pending ? */
199 static int mchchk_wng_posted = 0;
201 * Use single machine clear, as we cannot handle smp right now
203 __ctl_clear_bit(14, 24); /* Disable WARNING MCH */
204 if (xchg(&mchchk_wng_posted, 1) == 0)
205 kill_proc(1, SIGPWR, 1);
209 if (mcck.kill_task) {
211 printk(KERN_EMERG "mcck: Terminating task because of machine "
212 "malfunction (code 0x%016llx).\n", mcck.mcck_code);
213 printk(KERN_EMERG "mcck: task: %s, pid: %d.\n",
214 current->comm, current->pid);
220 * returns 0 if all registers could be validated
221 * returns 1 otherwise
224 s390_revalidate_registers(struct mci *mci)
229 void *fpt_save_area, *fpt_creg_save_area;
233 /* General purpose registers */
236 * General purpose registers couldn't be restored and have
237 * unknown contents. Process needs to be terminated.
241 /* Revalidate floating point registers */
244 * Floating point registers can't be restored and
245 * therefore the process needs to be terminated.
250 asm volatile("ld 0,0(%0)\n"
254 : : "a" (&S390_lowcore.floating_pt_save_area));
257 if (MACHINE_HAS_IEEE) {
259 fpt_save_area = &S390_lowcore.floating_pt_save_area;
260 fpt_creg_save_area = &S390_lowcore.fpt_creg_save_area;
262 fpt_save_area = (void *) S390_lowcore.extended_save_area_addr;
263 fpt_creg_save_area = fpt_save_area+128;
265 /* Floating point control register */
268 * Floating point control register can't be restored.
269 * Task will be terminated.
271 asm volatile ("lfpc 0(%0)" : : "a" (&zero), "m" (zero));
278 : : "a" (fpt_creg_save_area));
280 asm volatile("ld 0,0(%0)\n"
296 : : "a" (fpt_save_area));
299 /* Revalidate access registers */
300 asm volatile("lam 0,15,0(%0)"
301 : : "a" (&S390_lowcore.access_regs_save_area));
304 * Access registers have unknown contents.
309 /* Revalidate control registers */
312 * Control registers have unknown contents.
313 * Can't recover and therefore stopping machine.
315 s390_handle_damage("invalid control registers.");
318 asm volatile("lctlg 0,15,0(%0)"
319 : : "a" (&S390_lowcore.cregs_save_area));
321 asm volatile("lctl 0,15,0(%0)"
322 : : "a" (&S390_lowcore.cregs_save_area));
326 * We don't even try to revalidate the TOD register, since we simply
327 * can't write something sensible into that register.
332 * See if we can revalidate the TOD programmable register with its
333 * old contents (should be zero) otherwise set it to zero.
336 asm volatile("sr 0,0\n"
343 : : "a" (&S390_lowcore.tod_progreg_save_area) : "0", "cc");
346 /* Revalidate clock comparator register */
347 asm volatile ("stck 0(%1)\n"
349 : "=m" (tmpclock) : "a" (&(tmpclock)) : "cc", "memory");
351 /* Check if old PSW is valid */
354 * Can't tell if we come from user or kernel mode
355 * -> stopping machine.
357 s390_handle_damage("old psw invalid.");
359 if (!mci->ms || !mci->pm || !mci->ia)
365 #define MAX_IPD_COUNT 29
366 #define MAX_IPD_TIME (5 * 60 * USEC_PER_SEC) /* 5 minutes */
369 * machine check handler.
372 s390_do_machine_check(struct pt_regs *regs)
374 static DEFINE_SPINLOCK(ipd_lock);
375 static unsigned long long last_ipd;
376 static int ipd_count;
377 unsigned long long tmp;
379 struct mcck_struct *mcck;
382 mci = (struct mci *) &S390_lowcore.mcck_interruption_code;
383 mcck = &__get_cpu_var(cpu_mcck);
384 umode = user_mode(regs);
387 /* System damage -> stopping machine */
388 s390_handle_damage("received system damage machine check.");
392 /* Processing backup -> verify if we can survive this */
393 u64 z_mcic, o_mcic, t_mcic;
395 z_mcic = (1ULL<<63 | 1ULL<<59 | 1ULL<<29);
396 o_mcic = (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
397 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
398 1ULL<<30 | 1ULL<<21 | 1ULL<<20 | 1ULL<<17 |
401 z_mcic = (1ULL<<63 | 1ULL<<59 | 1ULL<<57 | 1ULL<<50 |
403 o_mcic = (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
404 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
405 1ULL<<30 | 1ULL<<20 | 1ULL<<17 | 1ULL<<16);
407 t_mcic = *(u64 *)mci;
409 if (((t_mcic & z_mcic) != 0) ||
410 ((t_mcic & o_mcic) != o_mcic)) {
411 s390_handle_damage("processing backup machine "
412 "check with damage.");
416 * Nullifying exigent condition, therefore we might
417 * retry this instruction.
420 spin_lock(&ipd_lock);
424 if (((tmp - last_ipd) >> 12) < MAX_IPD_TIME)
431 if (ipd_count == MAX_IPD_COUNT)
432 s390_handle_damage("too many ipd retries.");
434 spin_unlock(&ipd_lock);
437 /* Processing damage -> stopping machine */
438 s390_handle_damage("received instruction processing "
439 "damage machine check.");
442 if (s390_revalidate_registers(mci)) {
445 * Couldn't restore all register contents while in
446 * user mode -> mark task for termination.
449 mcck->mcck_code = *(unsigned long long *) mci;
450 set_thread_flag(TIF_MCCK_PENDING);
454 * Couldn't restore all register contents while in
455 * kernel mode -> stopping machine.
457 s390_handle_damage("unable to revalidate registers.");
461 /* Storage error uncorrected */
462 s390_handle_damage("received storage error uncorrected "
466 /* Storage key-error uncorrected */
467 s390_handle_damage("received storage key-error uncorrected "
470 if (mci->ds && mci->fa)
471 /* Storage degradation */
472 s390_handle_damage("received storage degradation machine "
476 /* Channel report word pending */
477 mcck->channel_report = 1;
478 set_thread_flag(TIF_MCCK_PENDING);
482 /* Warning pending */
484 set_thread_flag(TIF_MCCK_PENDING);
489 * s390_init_machine_check
491 * initialize machine check handling
494 machine_check_init(void)
496 init_MUTEX_LOCKED(&m_sem);
497 ctl_clear_bit(14, 25); /* disable external damage MCH */
498 ctl_set_bit(14, 27); /* enable system recovery MCH */
499 #ifdef CONFIG_MACHCHK_WARNING
500 ctl_set_bit(14, 24); /* enable warning MCH */
506 * Initialize the machine check handler really early to be able to
507 * catch all machine checks that happen during boot
509 arch_initcall(machine_check_init);
512 * Machine checks for the channel subsystem must be enabled
513 * after the channel subsystem is initialized
516 machine_check_crw_init (void)
518 kthread_run(s390_collect_crw_info, &m_sem, "kmcheck");
519 ctl_set_bit(14, 28); /* enable channel report MCH */
523 device_initcall (machine_check_crw_init);