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>
17 #include <asm/lowcore.h>
22 // #define DBG(args,...) do {} while (0);
24 static struct semaphore m_sem
;
26 extern int css_process_crw(int);
27 extern int chsc_process_crw(void);
28 extern int chp_process_crw(int, int);
29 extern void css_reiterate_subchannels(void);
31 extern struct workqueue_struct
*slow_path_wq
;
32 extern struct work_struct slow_path_work
;
34 static NORET_TYPE
void
35 s390_handle_damage(char *msg
)
40 disabled_wait((unsigned long) __builtin_return_address(0));
45 * Retrieve CRWs and call function to handle event.
47 * Note : we currently process CRWs for io and chsc subchannels only
50 s390_collect_crw_info(void *param
)
54 struct semaphore
*sem
;
56 sem
= (struct semaphore
*)param
;
57 /* Set a nice name. */
60 down_interruptible(sem
);
66 DBG(KERN_DEBUG
"crw_info : CRW reports slct=%d, oflw=%d, "
67 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
68 crw
.slct
, crw
.oflw
, crw
.chn
, crw
.rsc
, crw
.anc
,
70 /* Check for overflows. */
72 pr_debug("%s: crw overflow detected!\n", __FUNCTION__
);
73 css_reiterate_subchannels();
79 pr_debug("source is subchannel %04X\n", crw
.rsid
);
80 ret
= css_process_crw (crw
.rsid
);
85 pr_debug("source is monitoring facility\n");
88 pr_debug("source is channel path %02X\n", crw
.rsid
);
90 case CRW_ERC_IPARM
: /* Path has come. */
91 ret
= chp_process_crw(crw
.rsid
, 1);
93 case CRW_ERC_PERRI
: /* Path has gone. */
95 ret
= chp_process_crw(crw
.rsid
, 0);
98 pr_debug("Don't know how to handle erc=%x\n",
106 pr_debug("source is configuration-alert facility\n");
109 pr_debug("source is channel subsystem\n");
110 ret
= chsc_process_crw();
115 pr_debug("unknown source\n");
120 queue_work(slow_path_wq
, &slow_path_work
);
129 unsigned long long mcck_code
;
132 static DEFINE_PER_CPU(struct mcck_struct
, cpu_mcck
);
135 * Main machine check handler function. Will be called with interrupts enabled
136 * or disabled and machine checks enabled or disabled.
139 s390_handle_mcck(void)
142 struct mcck_struct mcck
;
145 * Disable machine checks and get the current state of accumulated
146 * machine checks. Afterwards delete the old state and enable machine
149 local_irq_save(flags
);
150 local_mcck_disable();
151 mcck
= __get_cpu_var(cpu_mcck
);
152 memset(&__get_cpu_var(cpu_mcck
), 0, sizeof(struct mcck_struct
));
153 clear_thread_flag(TIF_MCCK_PENDING
);
155 local_irq_restore(flags
);
157 if (mcck
.channel_report
)
160 #ifdef CONFIG_MACHCHK_WARNING
162 * The warning may remain for a prolonged period on the bare iron.
163 * (actually till the machine is powered off, or until the problem is gone)
164 * So we just stop listening for the WARNING MCH and prevent continuously
165 * being interrupted. One caveat is however, that we must do this per
166 * processor and cannot use the smp version of ctl_clear_bit().
167 * On VM we only get one interrupt per virtally presented machinecheck.
168 * Though one suffices, we may get one interrupt per (virtual) processor.
170 if (mcck
.warning
) { /* WARNING pending ? */
171 static int mchchk_wng_posted
= 0;
173 * Use single machine clear, as we cannot handle smp right now
175 __ctl_clear_bit(14, 24); /* Disable WARNING MCH */
176 if (xchg(&mchchk_wng_posted
, 1) == 0)
177 kill_proc(1, SIGPWR
, 1);
181 if (mcck
.kill_task
) {
183 printk(KERN_EMERG
"mcck: Terminating task because of machine "
184 "malfunction (code 0x%016llx).\n", mcck
.mcck_code
);
185 printk(KERN_EMERG
"mcck: task: %s, pid: %d.\n",
186 current
->comm
, current
->pid
);
192 * returns 0 if all registers could be validated
193 * returns 1 otherwise
196 s390_revalidate_registers(struct mci
*mci
)
201 void *fpt_save_area
, *fpt_creg_save_area
;
205 /* General purpose registers */
208 * General purpose registers couldn't be restored and have
209 * unknown contents. Process needs to be terminated.
213 /* Revalidate floating point registers */
216 * Floating point registers can't be restored and
217 * therefore the process needs to be terminated.
222 asm volatile("ld 0,0(%0)\n"
226 : : "a" (&S390_lowcore
.floating_pt_save_area
));
229 if (MACHINE_HAS_IEEE
) {
231 fpt_save_area
= &S390_lowcore
.floating_pt_save_area
;
232 fpt_creg_save_area
= &S390_lowcore
.fpt_creg_save_area
;
234 fpt_save_area
= (void *) S390_lowcore
.extended_save_area_addr
;
235 fpt_creg_save_area
= fpt_save_area
+128;
237 /* Floating point control register */
240 * Floating point control register can't be restored.
241 * Task will be terminated.
243 asm volatile ("lfpc 0(%0)" : : "a" (&zero
));
250 : : "a" (fpt_creg_save_area
));
252 asm volatile("ld 0,0(%0)\n"
268 : : "a" (fpt_save_area
));
271 /* Revalidate access registers */
272 asm volatile("lam 0,15,0(%0)"
273 : : "a" (&S390_lowcore
.access_regs_save_area
));
276 * Access registers have unknown contents.
281 /* Revalidate control registers */
284 * Control registers have unknown contents.
285 * Can't recover and therefore stopping machine.
287 s390_handle_damage("invalid control registers.");
290 asm volatile("lctlg 0,15,0(%0)"
291 : : "a" (&S390_lowcore
.cregs_save_area
));
293 asm volatile("lctl 0,15,0(%0)"
294 : : "a" (&S390_lowcore
.cregs_save_area
));
298 * We don't even try to revalidate the TOD register, since we simply
299 * can't write something sensible into that register.
304 * See if we can revalidate the TOD programmable register with its
305 * old contents (should be zero) otherwise set it to zero.
308 asm volatile("sr 0,0\n"
315 : : "a" (&S390_lowcore
.tod_progreg_save_area
) : "0", "cc");
318 /* Revalidate clock comparator register */
319 asm volatile ("stck 0(%1)\n"
321 : "=m" (tmpclock
) : "a" (&(tmpclock
)) : "cc", "memory");
323 /* Check if old PSW is valid */
326 * Can't tell if we come from user or kernel mode
327 * -> stopping machine.
329 s390_handle_damage("old psw invalid.");
331 if (!mci
->ms
|| !mci
->pm
|| !mci
->ia
)
338 * machine check handler.
341 s390_do_machine_check(struct pt_regs
*regs
)
344 struct mcck_struct
*mcck
;
347 mci
= (struct mci
*) &S390_lowcore
.mcck_interruption_code
;
348 mcck
= &__get_cpu_var(cpu_mcck
);
349 umode
= user_mode(regs
);
352 /* System damage -> stopping machine */
353 s390_handle_damage("received system damage machine check.");
357 /* Processing backup -> verify if we can survive this */
358 u64 z_mcic
, o_mcic
, t_mcic
;
360 z_mcic
= (1ULL<<63 | 1ULL<<59 | 1ULL<<29);
361 o_mcic
= (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
362 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
363 1ULL<<30 | 1ULL<<21 | 1ULL<<20 | 1ULL<<17 |
366 z_mcic
= (1ULL<<63 | 1ULL<<59 | 1ULL<<57 | 1ULL<<50 |
368 o_mcic
= (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
369 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
370 1ULL<<30 | 1ULL<<20 | 1ULL<<17 | 1ULL<<16);
372 t_mcic
= *(u64
*)mci
;
374 if (((t_mcic
& z_mcic
) != 0) ||
375 ((t_mcic
& o_mcic
) != o_mcic
)) {
376 s390_handle_damage("processing backup machine "
377 "check with damage.");
380 s390_handle_damage("processing backup machine "
381 "check in kernel mode.");
383 mcck
->mcck_code
= *(unsigned long long *) mci
;
386 /* Processing damage -> stopping machine */
387 s390_handle_damage("received instruction processing "
388 "damage machine check.");
391 if (s390_revalidate_registers(mci
)) {
394 * Couldn't restore all register contents while in
395 * user mode -> mark task for termination.
398 mcck
->mcck_code
= *(unsigned long long *) mci
;
399 set_thread_flag(TIF_MCCK_PENDING
);
403 * Couldn't restore all register contents while in
404 * kernel mode -> stopping machine.
406 s390_handle_damage("unable to revalidate registers.");
410 /* Storage error uncorrected */
411 s390_handle_damage("received storage error uncorrected "
415 /* Storage key-error uncorrected */
416 s390_handle_damage("received storage key-error uncorrected "
419 if (mci
->ds
&& mci
->fa
)
420 /* Storage degradation */
421 s390_handle_damage("received storage degradation machine "
425 /* Channel report word pending */
426 mcck
->channel_report
= 1;
427 set_thread_flag(TIF_MCCK_PENDING
);
431 /* Warning pending */
433 set_thread_flag(TIF_MCCK_PENDING
);
438 * s390_init_machine_check
440 * initialize machine check handling
443 machine_check_init(void)
445 init_MUTEX_LOCKED(&m_sem
);
446 ctl_clear_bit(14, 25); /* disable external damage MCH */
447 ctl_set_bit(14, 27); /* enable system recovery MCH */
448 #ifdef CONFIG_MACHCHK_WARNING
449 ctl_set_bit(14, 24); /* enable warning MCH */
455 * Initialize the machine check handler really early to be able to
456 * catch all machine checks that happen during boot
458 arch_initcall(machine_check_init
);
461 * Machine checks for the channel subsystem must be enabled
462 * after the channel subsystem is initialized
465 machine_check_crw_init (void)
467 kernel_thread(s390_collect_crw_info
, &m_sem
, CLONE_FS
|CLONE_FILES
);
468 ctl_set_bit(14, 28); /* enable channel report MCH */
472 device_initcall (machine_check_crw_init
);