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/device.h>
17 #include <linux/kthread.h>
19 #include <asm/lowcore.h>
26 static struct semaphore m_sem
;
28 static NORET_TYPE
void
29 s390_handle_damage(char *msg
)
34 disabled_wait((unsigned long) __builtin_return_address(0));
39 * Retrieve CRWs and call function to handle event.
41 * Note : we currently process CRWs for io and chsc subchannels only
44 s390_collect_crw_info(void *param
)
48 struct semaphore
*sem
;
51 sem
= (struct semaphore
*)param
;
53 down_interruptible(sem
);
57 if (unlikely(chain
> 1)) {
60 printk(KERN_WARNING
"%s: Code does not support more "
61 "than two chained crws; please report to "
62 "linux390@de.ibm.com!\n", __FUNCTION__
);
63 ccode
= stcrw(&tmp_crw
);
64 printk(KERN_WARNING
"%s: crw reports slct=%d, oflw=%d, "
65 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
66 __FUNCTION__
, tmp_crw
.slct
, tmp_crw
.oflw
,
67 tmp_crw
.chn
, tmp_crw
.rsc
, tmp_crw
.anc
,
68 tmp_crw
.erc
, tmp_crw
.rsid
);
69 printk(KERN_WARNING
"%s: This was crw number %x in the "
70 "chain\n", __FUNCTION__
, chain
);
73 chain
= tmp_crw
.chn
? chain
+ 1 : 0;
76 ccode
= stcrw(&crw
[chain
]);
79 printk(KERN_DEBUG
"crw_info : CRW reports slct=%d, oflw=%d, "
80 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
81 crw
[chain
].slct
, crw
[chain
].oflw
, crw
[chain
].chn
,
82 crw
[chain
].rsc
, crw
[chain
].anc
, crw
[chain
].erc
,
84 /* Check for overflows. */
85 if (crw
[chain
].oflw
) {
86 pr_debug("%s: crw overflow detected!\n", __FUNCTION__
);
87 css_reiterate_subchannels();
92 switch (crw
[chain
].rsc
) {
94 if (crw
[0].chn
&& !chain
)
96 pr_debug("source is subchannel %04X\n", crw
[0].rsid
);
97 ret
= css_process_crw (crw
[0].rsid
,
98 chain
? crw
[1].rsid
: 0);
102 case CRW_RSC_MONITOR
:
103 pr_debug("source is monitoring facility\n");
106 pr_debug("source is channel path %02X\n", crw
[0].rsid
);
108 * Check for solicited machine checks. These are
109 * created by reset channel path and need not be
110 * reported to the common I/O layer.
112 if (crw
[chain
].slct
) {
113 pr_debug("solicited machine check for "
114 "channel path %02X\n", crw
[0].rsid
);
117 switch (crw
[0].erc
) {
118 case CRW_ERC_IPARM
: /* Path has come. */
119 ret
= chp_process_crw(crw
[0].rsid
, 1);
121 case CRW_ERC_PERRI
: /* Path has gone. */
123 ret
= chp_process_crw(crw
[0].rsid
, 0);
126 pr_debug("Don't know how to handle erc=%x\n",
134 pr_debug("source is configuration-alert facility\n");
137 pr_debug("source is channel subsystem\n");
138 ret
= chsc_process_crw();
143 pr_debug("unknown source\n");
146 /* chain is always 0 or 1 here. */
147 chain
= crw
[chain
].chn
? chain
+ 1 : 0;
150 queue_work(slow_path_wq
, &slow_path_work
);
159 unsigned long long mcck_code
;
162 static DEFINE_PER_CPU(struct mcck_struct
, cpu_mcck
);
165 * Main machine check handler function. Will be called with interrupts enabled
166 * or disabled and machine checks enabled or disabled.
169 s390_handle_mcck(void)
172 struct mcck_struct mcck
;
175 * Disable machine checks and get the current state of accumulated
176 * machine checks. Afterwards delete the old state and enable machine
179 local_irq_save(flags
);
180 local_mcck_disable();
181 mcck
= __get_cpu_var(cpu_mcck
);
182 memset(&__get_cpu_var(cpu_mcck
), 0, sizeof(struct mcck_struct
));
183 clear_thread_flag(TIF_MCCK_PENDING
);
185 local_irq_restore(flags
);
187 if (mcck
.channel_report
)
190 #ifdef CONFIG_MACHCHK_WARNING
192 * The warning may remain for a prolonged period on the bare iron.
193 * (actually till the machine is powered off, or until the problem is gone)
194 * So we just stop listening for the WARNING MCH and prevent continuously
195 * being interrupted. One caveat is however, that we must do this per
196 * processor and cannot use the smp version of ctl_clear_bit().
197 * On VM we only get one interrupt per virtally presented machinecheck.
198 * Though one suffices, we may get one interrupt per (virtual) processor.
200 if (mcck
.warning
) { /* WARNING pending ? */
201 static int mchchk_wng_posted
= 0;
203 * Use single machine clear, as we cannot handle smp right now
205 __ctl_clear_bit(14, 24); /* Disable WARNING MCH */
206 if (xchg(&mchchk_wng_posted
, 1) == 0)
207 kill_cad_pid(SIGPWR
, 1);
211 if (mcck
.kill_task
) {
213 printk(KERN_EMERG
"mcck: Terminating task because of machine "
214 "malfunction (code 0x%016llx).\n", mcck
.mcck_code
);
215 printk(KERN_EMERG
"mcck: task: %s, pid: %d.\n",
216 current
->comm
, current
->pid
);
222 * returns 0 if all registers could be validated
223 * returns 1 otherwise
226 s390_revalidate_registers(struct mci
*mci
)
231 void *fpt_save_area
, *fpt_creg_save_area
;
235 /* General purpose registers */
238 * General purpose registers couldn't be restored and have
239 * unknown contents. Process needs to be terminated.
243 /* Revalidate floating point registers */
246 * Floating point registers can't be restored and
247 * therefore the process needs to be terminated.
257 : : "a" (&S390_lowcore
.floating_pt_save_area
));
260 if (MACHINE_HAS_IEEE
) {
262 fpt_save_area
= &S390_lowcore
.floating_pt_save_area
;
263 fpt_creg_save_area
= &S390_lowcore
.fpt_creg_save_area
;
265 fpt_save_area
= (void *) S390_lowcore
.extended_save_area_addr
;
266 fpt_creg_save_area
= fpt_save_area
+128;
268 /* Floating point control register */
271 * Floating point control register can't be restored.
272 * Task will be terminated.
274 asm volatile("lfpc 0(%0)" : : "a" (&zero
), "m" (zero
));
278 asm volatile("lfpc 0(%0)" : : "a" (fpt_creg_save_area
));
297 : : "a" (fpt_save_area
));
300 /* Revalidate access registers */
303 : : "a" (&S390_lowcore
.access_regs_save_area
));
306 * Access registers have unknown contents.
311 /* Revalidate control registers */
314 * Control registers have unknown contents.
315 * Can't recover and therefore stopping machine.
317 s390_handle_damage("invalid control registers.");
322 : : "a" (&S390_lowcore
.cregs_save_area
));
326 : : "a" (&S390_lowcore
.cregs_save_area
));
330 * We don't even try to revalidate the TOD register, since we simply
331 * can't write something sensible into that register.
336 * See if we can revalidate the TOD programmable register with its
337 * old contents (should be zero) otherwise set it to zero.
348 : : "a" (&S390_lowcore
.tod_progreg_save_area
)
352 /* Revalidate clock comparator register */
356 : "=m" (tmpclock
) : "a" (&(tmpclock
)) : "cc", "memory");
358 /* Check if old PSW is valid */
361 * Can't tell if we come from user or kernel mode
362 * -> stopping machine.
364 s390_handle_damage("old psw invalid.");
366 if (!mci
->ms
|| !mci
->pm
|| !mci
->ia
)
372 #define MAX_IPD_COUNT 29
373 #define MAX_IPD_TIME (5 * 60 * USEC_PER_SEC) /* 5 minutes */
376 * machine check handler.
379 s390_do_machine_check(struct pt_regs
*regs
)
381 static DEFINE_SPINLOCK(ipd_lock
);
382 static unsigned long long last_ipd
;
383 static int ipd_count
;
384 unsigned long long tmp
;
386 struct mcck_struct
*mcck
;
391 mci
= (struct mci
*) &S390_lowcore
.mcck_interruption_code
;
392 mcck
= &__get_cpu_var(cpu_mcck
);
393 umode
= user_mode(regs
);
396 /* System damage -> stopping machine */
397 s390_handle_damage("received system damage machine check.");
401 /* Processing backup -> verify if we can survive this */
402 u64 z_mcic
, o_mcic
, t_mcic
;
404 z_mcic
= (1ULL<<63 | 1ULL<<59 | 1ULL<<29);
405 o_mcic
= (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
406 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
407 1ULL<<30 | 1ULL<<21 | 1ULL<<20 | 1ULL<<17 |
410 z_mcic
= (1ULL<<63 | 1ULL<<59 | 1ULL<<57 | 1ULL<<50 |
412 o_mcic
= (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
413 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
414 1ULL<<30 | 1ULL<<20 | 1ULL<<17 | 1ULL<<16);
416 t_mcic
= *(u64
*)mci
;
418 if (((t_mcic
& z_mcic
) != 0) ||
419 ((t_mcic
& o_mcic
) != o_mcic
)) {
420 s390_handle_damage("processing backup machine "
421 "check with damage.");
425 * Nullifying exigent condition, therefore we might
426 * retry this instruction.
429 spin_lock(&ipd_lock
);
433 if (((tmp
- last_ipd
) >> 12) < MAX_IPD_TIME
)
440 if (ipd_count
== MAX_IPD_COUNT
)
441 s390_handle_damage("too many ipd retries.");
443 spin_unlock(&ipd_lock
);
446 /* Processing damage -> stopping machine */
447 s390_handle_damage("received instruction processing "
448 "damage machine check.");
451 if (s390_revalidate_registers(mci
)) {
454 * Couldn't restore all register contents while in
455 * user mode -> mark task for termination.
458 mcck
->mcck_code
= *(unsigned long long *) mci
;
459 set_thread_flag(TIF_MCCK_PENDING
);
463 * Couldn't restore all register contents while in
464 * kernel mode -> stopping machine.
466 s390_handle_damage("unable to revalidate registers.");
470 /* Timing facility damage */
471 s390_handle_damage("TOD clock damaged");
474 if (mci
->ed
&& mci
->ec
) {
475 /* External damage */
476 if (S390_lowcore
.external_damage_code
& (1U << ED_ETR_SYNC
))
478 if (S390_lowcore
.external_damage_code
& (1U << ED_ETR_SWITCH
))
479 etr_switch_to_local();
483 /* Storage error uncorrected */
484 s390_handle_damage("received storage error uncorrected "
488 /* Storage key-error uncorrected */
489 s390_handle_damage("received storage key-error uncorrected "
492 if (mci
->ds
&& mci
->fa
)
493 /* Storage degradation */
494 s390_handle_damage("received storage degradation machine "
498 /* Channel report word pending */
499 mcck
->channel_report
= 1;
500 set_thread_flag(TIF_MCCK_PENDING
);
504 /* Warning pending */
506 set_thread_flag(TIF_MCCK_PENDING
);
512 * s390_init_machine_check
514 * initialize machine check handling
517 machine_check_init(void)
519 init_MUTEX_LOCKED(&m_sem
);
520 ctl_set_bit(14, 25); /* enable external damage MCH */
521 ctl_set_bit(14, 27); /* enable system recovery MCH */
522 #ifdef CONFIG_MACHCHK_WARNING
523 ctl_set_bit(14, 24); /* enable warning MCH */
529 * Initialize the machine check handler really early to be able to
530 * catch all machine checks that happen during boot
532 arch_initcall(machine_check_init
);
535 * Machine checks for the channel subsystem must be enabled
536 * after the channel subsystem is initialized
539 machine_check_crw_init (void)
541 struct task_struct
*task
;
543 task
= kthread_run(s390_collect_crw_info
, &m_sem
, "kmcheck");
545 return PTR_ERR(task
);
546 ctl_set_bit(14, 28); /* enable channel report MCH */
550 device_initcall (machine_check_crw_init
);