2 * Machine check handler
4 * Copyright IBM Corp. 2000, 2009
5 * Author(s): Ingo Adlung <adlung@de.ibm.com>,
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>,
7 * Cornelia Huck <cornelia.huck@de.ibm.com>,
8 * Heiko Carstens <heiko.carstens@de.ibm.com>,
11 #include <linux/kernel_stat.h>
12 #include <linux/init.h>
13 #include <linux/errno.h>
14 #include <linux/hardirq.h>
15 #include <linux/time.h>
16 #include <linux/module.h>
17 #include <asm/lowcore.h>
20 #include <asm/cputime.h>
23 #include <asm/switch_to.h>
29 unsigned long long mcck_code
;
32 static DEFINE_PER_CPU(struct mcck_struct
, cpu_mcck
);
34 static void s390_handle_damage(char *msg
)
37 disabled_wait((unsigned long) __builtin_return_address(0));
42 * Main machine check handler function. Will be called with interrupts enabled
43 * or disabled and machine checks enabled or disabled.
45 void s390_handle_mcck(void)
48 struct mcck_struct mcck
;
51 * Disable machine checks and get the current state of accumulated
52 * machine checks. Afterwards delete the old state and enable machine
55 local_irq_save(flags
);
58 * Ummm... Does this make sense at all? Copying the percpu struct
59 * and then zapping it one statement later?
61 memcpy(&mcck
, this_cpu_ptr(&cpu_mcck
), sizeof(mcck
));
62 memset(&mcck
, 0, sizeof(struct mcck_struct
));
63 clear_cpu_flag(CIF_MCCK_PENDING
);
65 local_irq_restore(flags
);
67 if (mcck
.channel_report
)
68 crw_handle_channel_report();
70 * A warning may remain for a prolonged period on the bare iron.
71 * (actually until the machine is powered off, or the problem is gone)
72 * So we just stop listening for the WARNING MCH and avoid continuously
73 * being interrupted. One caveat is however, that we must do this per
74 * processor and cannot use the smp version of ctl_clear_bit().
75 * On VM we only get one interrupt per virtally presented machinecheck.
76 * Though one suffices, we may get one interrupt per (virtual) cpu.
78 if (mcck
.warning
) { /* WARNING pending ? */
79 static int mchchk_wng_posted
= 0;
81 /* Use single cpu clear, as we cannot handle smp here. */
82 __ctl_clear_bit(14, 24); /* Disable WARNING MCH */
83 if (xchg(&mchchk_wng_posted
, 1) == 0)
84 kill_cad_pid(SIGPWR
, 1);
88 printk(KERN_EMERG
"mcck: Terminating task because of machine "
89 "malfunction (code 0x%016llx).\n", mcck
.mcck_code
);
90 printk(KERN_EMERG
"mcck: task: %s, pid: %d.\n",
91 current
->comm
, current
->pid
);
95 EXPORT_SYMBOL_GPL(s390_handle_mcck
);
98 * returns 0 if all registers could be validated
101 static int notrace
s390_revalidate_registers(struct mci
*mci
)
105 void *fpt_save_area
, *fpt_creg_save_area
;
112 * General purpose registers couldn't be restored and have
113 * unknown contents. Process needs to be terminated.
119 * Floating point registers can't be restored and
120 * therefore the process needs to be terminated.
130 : : "a" (&S390_lowcore
.floating_pt_save_area
));
133 if (MACHINE_HAS_IEEE
) {
135 fpt_save_area
= &S390_lowcore
.floating_pt_save_area
;
136 fpt_creg_save_area
= &S390_lowcore
.fpt_creg_save_area
;
138 fpt_save_area
= (void *) S390_lowcore
.extended_save_area_addr
;
139 fpt_creg_save_area
= fpt_save_area
+ 128;
143 * Floating point control register can't be restored.
144 * Task will be terminated.
146 asm volatile("lfpc 0(%0)" : : "a" (&zero
), "m" (zero
));
150 asm volatile("lfpc 0(%0)" : : "a" (fpt_creg_save_area
));
169 : : "a" (fpt_save_area
));
173 /* Revalidate vector registers */
174 if (MACHINE_HAS_VX
&& current
->thread
.vxrs
) {
177 * Vector registers can't be restored and therefore
178 * the process needs to be terminated.
182 restore_vx_regs((__vector128
*)
183 S390_lowcore
.vector_save_area_addr
);
186 /* Revalidate access registers */
189 : : "a" (&S390_lowcore
.access_regs_save_area
));
192 * Access registers have unknown contents.
197 /* Revalidate control registers */
200 * Control registers have unknown contents.
201 * Can't recover and therefore stopping machine.
203 s390_handle_damage("invalid control registers.");
208 : : "a" (&S390_lowcore
.cregs_save_area
));
212 : : "a" (&S390_lowcore
.cregs_save_area
));
216 * We don't even try to revalidate the TOD register, since we simply
217 * can't write something sensible into that register.
221 * See if we can revalidate the TOD programmable register with its
222 * old contents (should be zero) otherwise set it to zero.
233 : : "a" (&S390_lowcore
.tod_progreg_save_area
)
236 /* Revalidate clock comparator register */
237 set_clock_comparator(S390_lowcore
.clock_comparator
);
238 /* Check if old PSW is valid */
241 * Can't tell if we come from user or kernel mode
242 * -> stopping machine.
244 s390_handle_damage("old psw invalid.");
246 if (!mci
->ms
|| !mci
->pm
|| !mci
->ia
)
252 #define MAX_IPD_COUNT 29
253 #define MAX_IPD_TIME (5 * 60 * USEC_PER_SEC) /* 5 minutes */
255 #define ED_STP_ISLAND 6 /* External damage STP island check */
256 #define ED_STP_SYNC 7 /* External damage STP sync check */
257 #define ED_ETR_SYNC 12 /* External damage ETR sync check */
258 #define ED_ETR_SWITCH 13 /* External damage ETR switch to local */
261 * machine check handler.
263 void notrace
s390_do_machine_check(struct pt_regs
*regs
)
265 static int ipd_count
;
266 static DEFINE_SPINLOCK(ipd_lock
);
267 static unsigned long long last_ipd
;
268 struct mcck_struct
*mcck
;
269 unsigned long long tmp
;
274 inc_irq_stat(NMI_NMI
);
275 mci
= (struct mci
*) &S390_lowcore
.mcck_interruption_code
;
276 mcck
= this_cpu_ptr(&cpu_mcck
);
277 umode
= user_mode(regs
);
280 /* System damage -> stopping machine */
281 s390_handle_damage("received system damage machine check.");
285 /* Processing backup -> verify if we can survive this */
286 u64 z_mcic
, o_mcic
, t_mcic
;
288 z_mcic
= (1ULL<<63 | 1ULL<<59 | 1ULL<<29);
289 o_mcic
= (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
290 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
291 1ULL<<30 | 1ULL<<21 | 1ULL<<20 | 1ULL<<17 |
294 z_mcic
= (1ULL<<63 | 1ULL<<59 | 1ULL<<57 | 1ULL<<50 |
296 o_mcic
= (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
297 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
298 1ULL<<30 | 1ULL<<20 | 1ULL<<17 | 1ULL<<16);
300 t_mcic
= *(u64
*)mci
;
302 if (((t_mcic
& z_mcic
) != 0) ||
303 ((t_mcic
& o_mcic
) != o_mcic
)) {
304 s390_handle_damage("processing backup machine "
305 "check with damage.");
309 * Nullifying exigent condition, therefore we might
310 * retry this instruction.
312 spin_lock(&ipd_lock
);
313 tmp
= get_tod_clock();
314 if (((tmp
- last_ipd
) >> 12) < MAX_IPD_TIME
)
319 if (ipd_count
== MAX_IPD_COUNT
)
320 s390_handle_damage("too many ipd retries.");
321 spin_unlock(&ipd_lock
);
323 /* Processing damage -> stopping machine */
324 s390_handle_damage("received instruction processing "
325 "damage machine check.");
328 if (s390_revalidate_registers(mci
)) {
331 * Couldn't restore all register contents while in
332 * user mode -> mark task for termination.
335 mcck
->mcck_code
= *(unsigned long long *) mci
;
336 set_cpu_flag(CIF_MCCK_PENDING
);
339 * Couldn't restore all register contents while in
340 * kernel mode -> stopping machine.
342 s390_handle_damage("unable to revalidate registers.");
346 /* Timing facility damage */
347 s390_handle_damage("TOD clock damaged");
349 if (mci
->ed
&& mci
->ec
) {
350 /* External damage */
351 if (S390_lowcore
.external_damage_code
& (1U << ED_ETR_SYNC
))
353 if (S390_lowcore
.external_damage_code
& (1U << ED_ETR_SWITCH
))
354 etr_switch_to_local();
355 if (S390_lowcore
.external_damage_code
& (1U << ED_STP_SYNC
))
357 if (S390_lowcore
.external_damage_code
& (1U << ED_STP_ISLAND
))
361 /* Storage error uncorrected */
362 s390_handle_damage("received storage error uncorrected "
365 /* Storage key-error uncorrected */
366 s390_handle_damage("received storage key-error uncorrected "
368 if (mci
->ds
&& mci
->fa
)
369 /* Storage degradation */
370 s390_handle_damage("received storage degradation machine "
373 /* Channel report word pending */
374 mcck
->channel_report
= 1;
375 set_cpu_flag(CIF_MCCK_PENDING
);
378 /* Warning pending */
380 set_cpu_flag(CIF_MCCK_PENDING
);
385 static int __init
machine_check_init(void)
387 ctl_set_bit(14, 25); /* enable external damage MCH */
388 ctl_set_bit(14, 27); /* enable system recovery MCH */
389 ctl_set_bit(14, 24); /* enable warning MCH */
392 arch_initcall(machine_check_init
);