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 <linux/sched/signal.h>
19 #include <linux/export.h>
20 #include <asm/lowcore.h>
23 #include <asm/cputime.h>
26 #include <asm/switch_to.h>
27 #include <asm/ctl_reg.h>
30 unsigned int kill_task
: 1;
31 unsigned int channel_report
: 1;
32 unsigned int warning
: 1;
33 unsigned int stp_queue
: 1;
34 unsigned long mcck_code
;
37 static DEFINE_PER_CPU(struct mcck_struct
, cpu_mcck
);
39 static void s390_handle_damage(void)
42 disabled_wait((unsigned long) __builtin_return_address(0));
47 * Main machine check handler function. Will be called with interrupts enabled
48 * or disabled and machine checks enabled or disabled.
50 void s390_handle_mcck(void)
53 struct mcck_struct mcck
;
56 * Disable machine checks and get the current state of accumulated
57 * machine checks. Afterwards delete the old state and enable machine
60 local_irq_save(flags
);
62 mcck
= *this_cpu_ptr(&cpu_mcck
);
63 memset(this_cpu_ptr(&cpu_mcck
), 0, sizeof(mcck
));
64 clear_cpu_flag(CIF_MCCK_PENDING
);
66 local_irq_restore(flags
);
68 if (mcck
.channel_report
)
69 crw_handle_channel_report();
71 * A warning may remain for a prolonged period on the bare iron.
72 * (actually until the machine is powered off, or the problem is gone)
73 * So we just stop listening for the WARNING MCH and avoid continuously
74 * being interrupted. One caveat is however, that we must do this per
75 * processor and cannot use the smp version of ctl_clear_bit().
76 * On VM we only get one interrupt per virtally presented machinecheck.
77 * Though one suffices, we may get one interrupt per (virtual) cpu.
79 if (mcck
.warning
) { /* WARNING pending ? */
80 static int mchchk_wng_posted
= 0;
82 /* Use single cpu clear, as we cannot handle smp here. */
83 __ctl_clear_bit(14, 24); /* Disable WARNING MCH */
84 if (xchg(&mchchk_wng_posted
, 1) == 0)
85 kill_cad_pid(SIGPWR
, 1);
91 printk(KERN_EMERG
"mcck: Terminating task because of machine "
92 "malfunction (code 0x%016lx).\n", mcck
.mcck_code
);
93 printk(KERN_EMERG
"mcck: task: %s, pid: %d.\n",
94 current
->comm
, current
->pid
);
98 EXPORT_SYMBOL_GPL(s390_handle_mcck
);
101 * returns 0 if all registers could be validated
102 * returns 1 otherwise
104 static int notrace
s390_validate_registers(union mci mci
, int umode
)
115 * General purpose registers couldn't be restored and have
116 * unknown contents. Stop system or terminate process.
119 s390_handle_damage();
122 /* Validate control registers */
125 * Control registers have unknown contents.
126 * Can't recover and therefore stopping machine.
128 s390_handle_damage();
131 " lctlg 0,15,0(%0)\n"
133 : : "a" (&S390_lowcore
.cregs_save_area
) : "memory");
137 * Floating point registers can't be restored. If the
138 * kernel currently uses floating point registers the
139 * system is stopped. If the process has its floating
140 * pointer registers loaded it is terminated.
141 * Otherwise just revalidate the registers.
143 if (S390_lowcore
.fpu_flags
& KERNEL_VXR_V0V7
)
144 s390_handle_damage();
145 if (!test_cpu_flag(CIF_FPU
))
148 fpt_save_area
= &S390_lowcore
.floating_pt_save_area
;
151 * Floating point control register can't be restored.
152 * If the kernel currently uses the floating pointer
153 * registers and needs the FPC register the system is
154 * stopped. If the process has its floating pointer
155 * registers loaded it is terminated. Otherwiese the
156 * FPC is just revalidated.
158 if (S390_lowcore
.fpu_flags
& KERNEL_FPC
)
159 s390_handle_damage();
160 asm volatile("lfpc %0" : : "Q" (zero
));
161 if (!test_cpu_flag(CIF_FPU
))
164 asm volatile("lfpc %0"
165 : : "Q" (S390_lowcore
.fpt_creg_save_area
));
168 if (!MACHINE_HAS_VX
) {
169 /* Validate floating point registers */
187 : : "a" (fpt_save_area
) : "memory");
189 /* Validate vector registers */
194 * Vector registers can't be restored. If the kernel
195 * currently uses vector registers the system is
196 * stopped. If the process has its vector registers
197 * loaded it is terminated. Otherwise just revalidate
200 if (S390_lowcore
.fpu_flags
& KERNEL_VXR
)
201 s390_handle_damage();
202 if (!test_cpu_flag(CIF_FPU
))
205 cr0
.val
= S390_lowcore
.cregs_save_area
[0];
206 cr0
.afp
= cr0
.vx
= 1;
207 __ctl_load(cr0
.val
, 0, 0);
210 " .word 0xe70f,0x1000,0x0036\n" /* vlm 0,15,0(1) */
211 " .word 0xe70f,0x1100,0x0c36\n" /* vlm 16,31,256(1) */
212 : : "Q" (*(struct vx_array
*)
213 &S390_lowcore
.vector_save_area
) : "1");
214 __ctl_load(S390_lowcore
.cregs_save_area
[0], 0, 0);
216 /* Validate access registers */
219 : : "a" (&S390_lowcore
.access_regs_save_area
));
222 * Access registers have unknown contents.
228 * We don't even try to validate the TOD register, since we simply
229 * can't write something sensible into that register.
232 * See if we can validate the TOD programmable register with its
233 * old contents (should be zero) otherwise set it to zero.
244 : : "Q" (S390_lowcore
.tod_progreg_save_area
)
246 /* Validate clock comparator register */
247 set_clock_comparator(S390_lowcore
.clock_comparator
);
248 /* Check if old PSW is valid */
251 * Can't tell if we come from user or kernel mode
252 * -> stopping machine.
254 s390_handle_damage();
256 if (!mci
.ms
|| !mci
.pm
|| !mci
.ia
)
262 #define MAX_IPD_COUNT 29
263 #define MAX_IPD_TIME (5 * 60 * USEC_PER_SEC) /* 5 minutes */
265 #define ED_STP_ISLAND 6 /* External damage STP island check */
266 #define ED_STP_SYNC 7 /* External damage STP sync check */
269 * machine check handler.
271 void notrace
s390_do_machine_check(struct pt_regs
*regs
)
273 static int ipd_count
;
274 static DEFINE_SPINLOCK(ipd_lock
);
275 static unsigned long long last_ipd
;
276 struct mcck_struct
*mcck
;
277 unsigned long long tmp
;
281 inc_irq_stat(NMI_NMI
);
282 mci
.val
= S390_lowcore
.mcck_interruption_code
;
283 mcck
= this_cpu_ptr(&cpu_mcck
);
286 /* System damage -> stopping machine */
287 s390_handle_damage();
291 /* Processing backup -> verify if we can survive this */
292 u64 z_mcic
, o_mcic
, t_mcic
;
293 z_mcic
= (1ULL<<63 | 1ULL<<59 | 1ULL<<29);
294 o_mcic
= (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
295 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
296 1ULL<<30 | 1ULL<<21 | 1ULL<<20 | 1ULL<<17 |
300 if (((t_mcic
& z_mcic
) != 0) ||
301 ((t_mcic
& o_mcic
) != o_mcic
)) {
302 s390_handle_damage();
306 * Nullifying exigent condition, therefore we might
307 * retry this instruction.
309 spin_lock(&ipd_lock
);
310 tmp
= get_tod_clock();
311 if (((tmp
- last_ipd
) >> 12) < MAX_IPD_TIME
)
316 if (ipd_count
== MAX_IPD_COUNT
)
317 s390_handle_damage();
318 spin_unlock(&ipd_lock
);
320 /* Processing damage -> stopping machine */
321 s390_handle_damage();
324 if (s390_validate_registers(mci
, user_mode(regs
))) {
326 * Couldn't restore all register contents for the
327 * user space process -> mark task for termination.
330 mcck
->mcck_code
= mci
.val
;
331 set_cpu_flag(CIF_MCCK_PENDING
);
334 /* Timing facility damage */
335 s390_handle_damage();
337 if (mci
.ed
&& mci
.ec
) {
338 /* External damage */
339 if (S390_lowcore
.external_damage_code
& (1U << ED_STP_SYNC
))
340 mcck
->stp_queue
|= stp_sync_check();
341 if (S390_lowcore
.external_damage_code
& (1U << ED_STP_ISLAND
))
342 mcck
->stp_queue
|= stp_island_check();
344 set_cpu_flag(CIF_MCCK_PENDING
);
347 /* Storage error uncorrected */
348 s390_handle_damage();
350 /* Storage key-error uncorrected */
351 s390_handle_damage();
352 if (mci
.ds
&& mci
.fa
)
353 /* Storage degradation */
354 s390_handle_damage();
356 /* Channel report word pending */
357 mcck
->channel_report
= 1;
358 set_cpu_flag(CIF_MCCK_PENDING
);
361 /* Warning pending */
363 set_cpu_flag(CIF_MCCK_PENDING
);
368 static int __init
machine_check_init(void)
370 ctl_set_bit(14, 25); /* enable external damage MCH */
371 ctl_set_bit(14, 27); /* enable system recovery MCH */
372 ctl_set_bit(14, 24); /* enable warning MCH */
375 early_initcall(machine_check_init
);