xref: /linux/arch/s390/kernel/nmi.c (revision 916cda1aa1b412d7cf2991c3af7479544942d121)
1f5daba1dSHeiko Carstens /*
2f5daba1dSHeiko Carstens  *   Machine check handler
3f5daba1dSHeiko Carstens  *
4f5daba1dSHeiko Carstens  *    Copyright IBM Corp. 2000, 2009
5f5daba1dSHeiko Carstens  *    Author(s): Ingo Adlung <adlung@de.ibm.com>,
6f5daba1dSHeiko Carstens  *		 Martin Schwidefsky <schwidefsky@de.ibm.com>,
7f5daba1dSHeiko Carstens  *		 Cornelia Huck <cornelia.huck@de.ibm.com>,
8f5daba1dSHeiko Carstens  *		 Heiko Carstens <heiko.carstens@de.ibm.com>,
9f5daba1dSHeiko Carstens  */
10f5daba1dSHeiko Carstens 
11052ff461SHeiko Carstens #include <linux/kernel_stat.h>
12f5daba1dSHeiko Carstens #include <linux/init.h>
13f5daba1dSHeiko Carstens #include <linux/errno.h>
1481f64b87SHeiko Carstens #include <linux/hardirq.h>
15f5daba1dSHeiko Carstens #include <linux/time.h>
163f07c014SIngo Molnar #include <linux/module.h>
173f07c014SIngo Molnar #include <linux/sched/signal.h>
183f07c014SIngo Molnar 
193994a52bSPaul Gortmaker #include <linux/export.h>
20f5daba1dSHeiko Carstens #include <asm/lowcore.h>
21f5daba1dSHeiko Carstens #include <asm/smp.h>
22fd5ada04SMartin Schwidefsky #include <asm/stp.h>
2376d4e00aSMartin Schwidefsky #include <asm/cputime.h>
24f5daba1dSHeiko Carstens #include <asm/nmi.h>
25f5daba1dSHeiko Carstens #include <asm/crw.h>
2680703617SMartin Schwidefsky #include <asm/switch_to.h>
27cad49cfcSHeiko Carstens #include <asm/ctl_reg.h>
28f5daba1dSHeiko Carstens 
29f5daba1dSHeiko Carstens struct mcck_struct {
3036324963SHeiko Carstens 	unsigned int kill_task : 1;
3136324963SHeiko Carstens 	unsigned int channel_report : 1;
3236324963SHeiko Carstens 	unsigned int warning : 1;
3329b0a825SHeiko Carstens 	unsigned int stp_queue : 1;
34dc6e1555SHeiko Carstens 	unsigned long mcck_code;
35f5daba1dSHeiko Carstens };
36f5daba1dSHeiko Carstens 
37f5daba1dSHeiko Carstens static DEFINE_PER_CPU(struct mcck_struct, cpu_mcck);
38f5daba1dSHeiko Carstens 
393d68286aSHeiko Carstens static void s390_handle_damage(void)
40f5daba1dSHeiko Carstens {
41f5daba1dSHeiko Carstens 	smp_send_stop();
42f5daba1dSHeiko Carstens 	disabled_wait((unsigned long) __builtin_return_address(0));
43f5daba1dSHeiko Carstens 	while (1);
44f5daba1dSHeiko Carstens }
45f5daba1dSHeiko Carstens 
46f5daba1dSHeiko Carstens /*
47f5daba1dSHeiko Carstens  * Main machine check handler function. Will be called with interrupts enabled
48f5daba1dSHeiko Carstens  * or disabled and machine checks enabled or disabled.
49f5daba1dSHeiko Carstens  */
50f5daba1dSHeiko Carstens void s390_handle_mcck(void)
51f5daba1dSHeiko Carstens {
52f5daba1dSHeiko Carstens 	unsigned long flags;
53f5daba1dSHeiko Carstens 	struct mcck_struct mcck;
54f5daba1dSHeiko Carstens 
55f5daba1dSHeiko Carstens 	/*
56f5daba1dSHeiko Carstens 	 * Disable machine checks and get the current state of accumulated
57f5daba1dSHeiko Carstens 	 * machine checks. Afterwards delete the old state and enable machine
58f5daba1dSHeiko Carstens 	 * checks again.
59f5daba1dSHeiko Carstens 	 */
60f5daba1dSHeiko Carstens 	local_irq_save(flags);
61f5daba1dSHeiko Carstens 	local_mcck_disable();
622cb4a182SSebastian Ott 	mcck = *this_cpu_ptr(&cpu_mcck);
632cb4a182SSebastian Ott 	memset(this_cpu_ptr(&cpu_mcck), 0, sizeof(mcck));
64d3a73acbSMartin Schwidefsky 	clear_cpu_flag(CIF_MCCK_PENDING);
65f5daba1dSHeiko Carstens 	local_mcck_enable();
66f5daba1dSHeiko Carstens 	local_irq_restore(flags);
67f5daba1dSHeiko Carstens 
68f5daba1dSHeiko Carstens 	if (mcck.channel_report)
69f5daba1dSHeiko Carstens 		crw_handle_channel_report();
70f5daba1dSHeiko Carstens 	/*
717b886416SHeiko Carstens 	 * A warning may remain for a prolonged period on the bare iron.
727b886416SHeiko Carstens 	 * (actually until the machine is powered off, or the problem is gone)
737b886416SHeiko Carstens 	 * So we just stop listening for the WARNING MCH and avoid continuously
74f5daba1dSHeiko Carstens 	 * being interrupted.  One caveat is however, that we must do this per
75f5daba1dSHeiko Carstens 	 * processor and cannot use the smp version of ctl_clear_bit().
76f5daba1dSHeiko Carstens 	 * On VM we only get one interrupt per virtally presented machinecheck.
777b886416SHeiko Carstens 	 * Though one suffices, we may get one interrupt per (virtual) cpu.
78f5daba1dSHeiko Carstens 	 */
79f5daba1dSHeiko Carstens 	if (mcck.warning) {	/* WARNING pending ? */
80f5daba1dSHeiko Carstens 		static int mchchk_wng_posted = 0;
817b886416SHeiko Carstens 
827b886416SHeiko Carstens 		/* Use single cpu clear, as we cannot handle smp here. */
83f5daba1dSHeiko Carstens 		__ctl_clear_bit(14, 24);	/* Disable WARNING MCH */
84f5daba1dSHeiko Carstens 		if (xchg(&mchchk_wng_posted, 1) == 0)
85f5daba1dSHeiko Carstens 			kill_cad_pid(SIGPWR, 1);
86f5daba1dSHeiko Carstens 	}
8729b0a825SHeiko Carstens 	if (mcck.stp_queue)
8829b0a825SHeiko Carstens 		stp_queue_work();
89f5daba1dSHeiko Carstens 	if (mcck.kill_task) {
90f5daba1dSHeiko Carstens 		local_irq_enable();
91f5daba1dSHeiko Carstens 		printk(KERN_EMERG "mcck: Terminating task because of machine "
92dc6e1555SHeiko Carstens 		       "malfunction (code 0x%016lx).\n", mcck.mcck_code);
93f5daba1dSHeiko Carstens 		printk(KERN_EMERG "mcck: task: %s, pid: %d.\n",
94f5daba1dSHeiko Carstens 		       current->comm, current->pid);
95f5daba1dSHeiko Carstens 		do_exit(SIGSEGV);
96f5daba1dSHeiko Carstens 	}
97f5daba1dSHeiko Carstens }
98f5daba1dSHeiko Carstens EXPORT_SYMBOL_GPL(s390_handle_mcck);
99f5daba1dSHeiko Carstens 
100f5daba1dSHeiko Carstens /*
101f5daba1dSHeiko Carstens  * returns 0 if all registers could be validated
102f5daba1dSHeiko Carstens  * returns 1 otherwise
103f5daba1dSHeiko Carstens  */
1048f149ea6SMartin Schwidefsky static int notrace s390_validate_registers(union mci mci, int umode)
105f5daba1dSHeiko Carstens {
106f5daba1dSHeiko Carstens 	int kill_task;
107f5daba1dSHeiko Carstens 	u64 zero;
10886fa7087SHeiko Carstens 	void *fpt_save_area;
109*916cda1aSMartin Schwidefsky 	struct mcesa *mcesa;
110f5daba1dSHeiko Carstens 
111f5daba1dSHeiko Carstens 	kill_task = 0;
112f5daba1dSHeiko Carstens 	zero = 0;
113f5daba1dSHeiko Carstens 
114dc6e1555SHeiko Carstens 	if (!mci.gr) {
115f5daba1dSHeiko Carstens 		/*
116f5daba1dSHeiko Carstens 		 * General purpose registers couldn't be restored and have
1178f149ea6SMartin Schwidefsky 		 * unknown contents. Stop system or terminate process.
118f5daba1dSHeiko Carstens 		 */
1198f149ea6SMartin Schwidefsky 		if (!umode)
1208f149ea6SMartin Schwidefsky 			s390_handle_damage();
121f5daba1dSHeiko Carstens 		kill_task = 1;
122f5daba1dSHeiko Carstens 	}
12370e28aa0SHeiko Carstens 	/* Validate control registers */
12470e28aa0SHeiko Carstens 	if (!mci.cr) {
12570e28aa0SHeiko Carstens 		/*
12670e28aa0SHeiko Carstens 		 * Control registers have unknown contents.
12770e28aa0SHeiko Carstens 		 * Can't recover and therefore stopping machine.
12870e28aa0SHeiko Carstens 		 */
12970e28aa0SHeiko Carstens 		s390_handle_damage();
13070e28aa0SHeiko Carstens 	} else {
13170e28aa0SHeiko Carstens 		asm volatile(
1325791d90dSHeiko Carstens 			"	lctlg	0,15,0(%0)\n"
1335791d90dSHeiko Carstens 			"	ptlb\n"
13470e28aa0SHeiko Carstens 			: : "a" (&S390_lowcore.cregs_save_area) : "memory");
13570e28aa0SHeiko Carstens 	}
136dc6e1555SHeiko Carstens 	if (!mci.fp) {
137f5daba1dSHeiko Carstens 		/*
1388f149ea6SMartin Schwidefsky 		 * Floating point registers can't be restored. If the
1398f149ea6SMartin Schwidefsky 		 * kernel currently uses floating point registers the
1408f149ea6SMartin Schwidefsky 		 * system is stopped. If the process has its floating
1418f149ea6SMartin Schwidefsky 		 * pointer registers loaded it is terminated.
1428f149ea6SMartin Schwidefsky 		 * Otherwise just revalidate the registers.
143f5daba1dSHeiko Carstens 		 */
1448f149ea6SMartin Schwidefsky 		if (S390_lowcore.fpu_flags & KERNEL_VXR_V0V7)
1458f149ea6SMartin Schwidefsky 			s390_handle_damage();
1468f149ea6SMartin Schwidefsky 		if (!test_cpu_flag(CIF_FPU))
147f5daba1dSHeiko Carstens 			kill_task = 1;
148f5daba1dSHeiko Carstens 	}
149f5daba1dSHeiko Carstens 	fpt_save_area = &S390_lowcore.floating_pt_save_area;
150dc6e1555SHeiko Carstens 	if (!mci.fc) {
151f5daba1dSHeiko Carstens 		/*
152f5daba1dSHeiko Carstens 		 * Floating point control register can't be restored.
1538f149ea6SMartin Schwidefsky 		 * If the kernel currently uses the floating pointer
1548f149ea6SMartin Schwidefsky 		 * registers and needs the FPC register the system is
1558f149ea6SMartin Schwidefsky 		 * stopped. If the process has its floating pointer
1568f149ea6SMartin Schwidefsky 		 * registers loaded it is terminated. Otherwiese the
1578f149ea6SMartin Schwidefsky 		 * FPC is just revalidated.
158f5daba1dSHeiko Carstens 		 */
1598f149ea6SMartin Schwidefsky 		if (S390_lowcore.fpu_flags & KERNEL_FPC)
1608f149ea6SMartin Schwidefsky 			s390_handle_damage();
16186fa7087SHeiko Carstens 		asm volatile("lfpc %0" : : "Q" (zero));
1628f149ea6SMartin Schwidefsky 		if (!test_cpu_flag(CIF_FPU))
163f5daba1dSHeiko Carstens 			kill_task = 1;
16486fa7087SHeiko Carstens 	} else {
16586fa7087SHeiko Carstens 		asm volatile("lfpc %0"
16686fa7087SHeiko Carstens 			     : : "Q" (S390_lowcore.fpt_creg_save_area));
16786fa7087SHeiko Carstens 	}
168f5daba1dSHeiko Carstens 
169*916cda1aSMartin Schwidefsky 	mcesa = (struct mcesa *)(S390_lowcore.mcesad & MCESA_ORIGIN_MASK);
170cad49cfcSHeiko Carstens 	if (!MACHINE_HAS_VX) {
171975be635SHeiko Carstens 		/* Validate floating point registers */
172f5daba1dSHeiko Carstens 		asm volatile(
173f5daba1dSHeiko Carstens 			"	ld	0,0(%0)\n"
174f5daba1dSHeiko Carstens 			"	ld	1,8(%0)\n"
175f5daba1dSHeiko Carstens 			"	ld	2,16(%0)\n"
176f5daba1dSHeiko Carstens 			"	ld	3,24(%0)\n"
177f5daba1dSHeiko Carstens 			"	ld	4,32(%0)\n"
178f5daba1dSHeiko Carstens 			"	ld	5,40(%0)\n"
179f5daba1dSHeiko Carstens 			"	ld	6,48(%0)\n"
180f5daba1dSHeiko Carstens 			"	ld	7,56(%0)\n"
181f5daba1dSHeiko Carstens 			"	ld	8,64(%0)\n"
182f5daba1dSHeiko Carstens 			"	ld	9,72(%0)\n"
183f5daba1dSHeiko Carstens 			"	ld	10,80(%0)\n"
184f5daba1dSHeiko Carstens 			"	ld	11,88(%0)\n"
185f5daba1dSHeiko Carstens 			"	ld	12,96(%0)\n"
186f5daba1dSHeiko Carstens 			"	ld	13,104(%0)\n"
187f5daba1dSHeiko Carstens 			"	ld	14,112(%0)\n"
188f5daba1dSHeiko Carstens 			"	ld	15,120(%0)\n"
18986fa7087SHeiko Carstens 			: : "a" (fpt_save_area) : "memory");
190cad49cfcSHeiko Carstens 	} else {
191975be635SHeiko Carstens 		/* Validate vector registers */
192cad49cfcSHeiko Carstens 		union ctlreg0 cr0;
193cad49cfcSHeiko Carstens 
194dc6e1555SHeiko Carstens 		if (!mci.vr) {
19580703617SMartin Schwidefsky 			/*
1968f149ea6SMartin Schwidefsky 			 * Vector registers can't be restored. If the kernel
1978f149ea6SMartin Schwidefsky 			 * currently uses vector registers the system is
1988f149ea6SMartin Schwidefsky 			 * stopped. If the process has its vector registers
1998f149ea6SMartin Schwidefsky 			 * loaded it is terminated. Otherwise just revalidate
2008f149ea6SMartin Schwidefsky 			 * the registers.
20180703617SMartin Schwidefsky 			 */
2028f149ea6SMartin Schwidefsky 			if (S390_lowcore.fpu_flags & KERNEL_VXR)
2038f149ea6SMartin Schwidefsky 				s390_handle_damage();
2048f149ea6SMartin Schwidefsky 			if (!test_cpu_flag(CIF_FPU))
20580703617SMartin Schwidefsky 				kill_task = 1;
20680703617SMartin Schwidefsky 		}
207cad49cfcSHeiko Carstens 		cr0.val = S390_lowcore.cregs_save_area[0];
208cad49cfcSHeiko Carstens 		cr0.afp = cr0.vx = 1;
209cad49cfcSHeiko Carstens 		__ctl_load(cr0.val, 0, 0);
2109977e886SHendrik Brueckner 		asm volatile(
2119977e886SHendrik Brueckner 			"	la	1,%0\n"
2129977e886SHendrik Brueckner 			"	.word	0xe70f,0x1000,0x0036\n"	/* vlm 0,15,0(1) */
2139977e886SHendrik Brueckner 			"	.word	0xe70f,0x1100,0x0c36\n"	/* vlm 16,31,256(1) */
214*916cda1aSMartin Schwidefsky 			: : "Q" (*(struct vx_array *) mcesa->vector_save_area)
215*916cda1aSMartin Schwidefsky 			: "1");
216cad49cfcSHeiko Carstens 		__ctl_load(S390_lowcore.cregs_save_area[0], 0, 0);
21780703617SMartin Schwidefsky 	}
218975be635SHeiko Carstens 	/* Validate access registers */
219f5daba1dSHeiko Carstens 	asm volatile(
220f5daba1dSHeiko Carstens 		"	lam	0,15,0(%0)"
221f5daba1dSHeiko Carstens 		: : "a" (&S390_lowcore.access_regs_save_area));
222dc6e1555SHeiko Carstens 	if (!mci.ar) {
223f5daba1dSHeiko Carstens 		/*
224f5daba1dSHeiko Carstens 		 * Access registers have unknown contents.
225f5daba1dSHeiko Carstens 		 * Terminating task.
226f5daba1dSHeiko Carstens 		 */
227f5daba1dSHeiko Carstens 		kill_task = 1;
228f5daba1dSHeiko Carstens 	}
229*916cda1aSMartin Schwidefsky 	/* Validate guarded storage registers */
230*916cda1aSMartin Schwidefsky 	if (MACHINE_HAS_GS && (S390_lowcore.cregs_save_area[2] & (1UL << 4))) {
231*916cda1aSMartin Schwidefsky 		if (!mci.gs)
232*916cda1aSMartin Schwidefsky 			/*
233*916cda1aSMartin Schwidefsky 			 * Guarded storage register can't be restored and
234*916cda1aSMartin Schwidefsky 			 * the current processes uses guarded storage.
235*916cda1aSMartin Schwidefsky 			 * It has to be terminated.
236*916cda1aSMartin Schwidefsky 			 */
237*916cda1aSMartin Schwidefsky 			kill_task = 1;
238*916cda1aSMartin Schwidefsky 		else
239*916cda1aSMartin Schwidefsky 			load_gs_cb((struct gs_cb *)
240*916cda1aSMartin Schwidefsky 				   mcesa->guarded_storage_save_area);
241*916cda1aSMartin Schwidefsky 	}
242f5daba1dSHeiko Carstens 	/*
243975be635SHeiko Carstens 	 * We don't even try to validate the TOD register, since we simply
244f5daba1dSHeiko Carstens 	 * can't write something sensible into that register.
245f5daba1dSHeiko Carstens 	 */
246f5daba1dSHeiko Carstens 	/*
247975be635SHeiko Carstens 	 * See if we can validate the TOD programmable register with its
248f5daba1dSHeiko Carstens 	 * old contents (should be zero) otherwise set it to zero.
249f5daba1dSHeiko Carstens 	 */
250dc6e1555SHeiko Carstens 	if (!mci.pr)
251f5daba1dSHeiko Carstens 		asm volatile(
252f5daba1dSHeiko Carstens 			"	sr	0,0\n"
253f5daba1dSHeiko Carstens 			"	sckpf"
254f5daba1dSHeiko Carstens 			: : : "0", "cc");
255f5daba1dSHeiko Carstens 	else
256f5daba1dSHeiko Carstens 		asm volatile(
25786fa7087SHeiko Carstens 			"	l	0,%0\n"
258f5daba1dSHeiko Carstens 			"	sckpf"
25986fa7087SHeiko Carstens 			: : "Q" (S390_lowcore.tod_progreg_save_area)
260f5daba1dSHeiko Carstens 			: "0", "cc");
261975be635SHeiko Carstens 	/* Validate clock comparator register */
262e8129c64SHeiko Carstens 	set_clock_comparator(S390_lowcore.clock_comparator);
263f5daba1dSHeiko Carstens 	/* Check if old PSW is valid */
264dc6e1555SHeiko Carstens 	if (!mci.wp)
265f5daba1dSHeiko Carstens 		/*
266f5daba1dSHeiko Carstens 		 * Can't tell if we come from user or kernel mode
267f5daba1dSHeiko Carstens 		 * -> stopping machine.
268f5daba1dSHeiko Carstens 		 */
2693d68286aSHeiko Carstens 		s390_handle_damage();
270f5daba1dSHeiko Carstens 
271dc6e1555SHeiko Carstens 	if (!mci.ms || !mci.pm || !mci.ia)
272f5daba1dSHeiko Carstens 		kill_task = 1;
273f5daba1dSHeiko Carstens 
274f5daba1dSHeiko Carstens 	return kill_task;
275f5daba1dSHeiko Carstens }
276f5daba1dSHeiko Carstens 
277f5daba1dSHeiko Carstens #define MAX_IPD_COUNT	29
278f5daba1dSHeiko Carstens #define MAX_IPD_TIME	(5 * 60 * USEC_PER_SEC) /* 5 minutes */
279f5daba1dSHeiko Carstens 
280f5daba1dSHeiko Carstens #define ED_STP_ISLAND	6	/* External damage STP island check */
281f5daba1dSHeiko Carstens #define ED_STP_SYNC	7	/* External damage STP sync check */
282f5daba1dSHeiko Carstens 
283f5daba1dSHeiko Carstens /*
284f5daba1dSHeiko Carstens  * machine check handler.
285f5daba1dSHeiko Carstens  */
286f5daba1dSHeiko Carstens void notrace s390_do_machine_check(struct pt_regs *regs)
287f5daba1dSHeiko Carstens {
288f5daba1dSHeiko Carstens 	static int ipd_count;
289f5daba1dSHeiko Carstens 	static DEFINE_SPINLOCK(ipd_lock);
290f5daba1dSHeiko Carstens 	static unsigned long long last_ipd;
291f5daba1dSHeiko Carstens 	struct mcck_struct *mcck;
292f5daba1dSHeiko Carstens 	unsigned long long tmp;
293dc6e1555SHeiko Carstens 	union mci mci;
294f5daba1dSHeiko Carstens 
29581f64b87SHeiko Carstens 	nmi_enter();
296420f42ecSHeiko Carstens 	inc_irq_stat(NMI_NMI);
297dc6e1555SHeiko Carstens 	mci.val = S390_lowcore.mcck_interruption_code;
298eb7e7d76SChristoph Lameter 	mcck = this_cpu_ptr(&cpu_mcck);
299f5daba1dSHeiko Carstens 
300dc6e1555SHeiko Carstens 	if (mci.sd) {
301f5daba1dSHeiko Carstens 		/* System damage -> stopping machine */
3023d68286aSHeiko Carstens 		s390_handle_damage();
303f5daba1dSHeiko Carstens 	}
304dc6e1555SHeiko Carstens 	if (mci.pd) {
305dc6e1555SHeiko Carstens 		if (mci.b) {
306f5daba1dSHeiko Carstens 			/* Processing backup -> verify if we can survive this */
307f5daba1dSHeiko Carstens 			u64 z_mcic, o_mcic, t_mcic;
308f5daba1dSHeiko Carstens 			z_mcic = (1ULL<<63 | 1ULL<<59 | 1ULL<<29);
309f5daba1dSHeiko Carstens 			o_mcic = (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 |
310f5daba1dSHeiko Carstens 				  1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 |
311f5daba1dSHeiko Carstens 				  1ULL<<30 | 1ULL<<21 | 1ULL<<20 | 1ULL<<17 |
312f5daba1dSHeiko Carstens 				  1ULL<<16);
313dc6e1555SHeiko Carstens 			t_mcic = mci.val;
314f5daba1dSHeiko Carstens 
315f5daba1dSHeiko Carstens 			if (((t_mcic & z_mcic) != 0) ||
316f5daba1dSHeiko Carstens 			    ((t_mcic & o_mcic) != o_mcic)) {
3173d68286aSHeiko Carstens 				s390_handle_damage();
318f5daba1dSHeiko Carstens 			}
319f5daba1dSHeiko Carstens 
320f5daba1dSHeiko Carstens 			/*
321f5daba1dSHeiko Carstens 			 * Nullifying exigent condition, therefore we might
322f5daba1dSHeiko Carstens 			 * retry this instruction.
323f5daba1dSHeiko Carstens 			 */
324f5daba1dSHeiko Carstens 			spin_lock(&ipd_lock);
3251aae0560SHeiko Carstens 			tmp = get_tod_clock();
326f5daba1dSHeiko Carstens 			if (((tmp - last_ipd) >> 12) < MAX_IPD_TIME)
327f5daba1dSHeiko Carstens 				ipd_count++;
328f5daba1dSHeiko Carstens 			else
329f5daba1dSHeiko Carstens 				ipd_count = 1;
330f5daba1dSHeiko Carstens 			last_ipd = tmp;
331f5daba1dSHeiko Carstens 			if (ipd_count == MAX_IPD_COUNT)
3323d68286aSHeiko Carstens 				s390_handle_damage();
333f5daba1dSHeiko Carstens 			spin_unlock(&ipd_lock);
334f5daba1dSHeiko Carstens 		} else {
335f5daba1dSHeiko Carstens 			/* Processing damage -> stopping machine */
3363d68286aSHeiko Carstens 			s390_handle_damage();
337f5daba1dSHeiko Carstens 		}
338f5daba1dSHeiko Carstens 	}
3398f149ea6SMartin Schwidefsky 	if (s390_validate_registers(mci, user_mode(regs))) {
340f5daba1dSHeiko Carstens 		/*
3418f149ea6SMartin Schwidefsky 		 * Couldn't restore all register contents for the
3428f149ea6SMartin Schwidefsky 		 * user space process -> mark task for termination.
343f5daba1dSHeiko Carstens 		 */
344f5daba1dSHeiko Carstens 		mcck->kill_task = 1;
345dc6e1555SHeiko Carstens 		mcck->mcck_code = mci.val;
346d3a73acbSMartin Schwidefsky 		set_cpu_flag(CIF_MCCK_PENDING);
347f5daba1dSHeiko Carstens 	}
348dc6e1555SHeiko Carstens 	if (mci.cd) {
349f5daba1dSHeiko Carstens 		/* Timing facility damage */
3503d68286aSHeiko Carstens 		s390_handle_damage();
351f5daba1dSHeiko Carstens 	}
352dc6e1555SHeiko Carstens 	if (mci.ed && mci.ec) {
353f5daba1dSHeiko Carstens 		/* External damage */
354f5daba1dSHeiko Carstens 		if (S390_lowcore.external_damage_code & (1U << ED_STP_SYNC))
35529b0a825SHeiko Carstens 			mcck->stp_queue |= stp_sync_check();
356f5daba1dSHeiko Carstens 		if (S390_lowcore.external_damage_code & (1U << ED_STP_ISLAND))
35729b0a825SHeiko Carstens 			mcck->stp_queue |= stp_island_check();
358fd5ada04SMartin Schwidefsky 		if (mcck->stp_queue)
35929b0a825SHeiko Carstens 			set_cpu_flag(CIF_MCCK_PENDING);
360f5daba1dSHeiko Carstens 	}
361dc6e1555SHeiko Carstens 	if (mci.se)
362f5daba1dSHeiko Carstens 		/* Storage error uncorrected */
3633d68286aSHeiko Carstens 		s390_handle_damage();
364dc6e1555SHeiko Carstens 	if (mci.ke)
365f5daba1dSHeiko Carstens 		/* Storage key-error uncorrected */
3663d68286aSHeiko Carstens 		s390_handle_damage();
367dc6e1555SHeiko Carstens 	if (mci.ds && mci.fa)
368f5daba1dSHeiko Carstens 		/* Storage degradation */
3693d68286aSHeiko Carstens 		s390_handle_damage();
370dc6e1555SHeiko Carstens 	if (mci.cp) {
371f5daba1dSHeiko Carstens 		/* Channel report word pending */
372f5daba1dSHeiko Carstens 		mcck->channel_report = 1;
373d3a73acbSMartin Schwidefsky 		set_cpu_flag(CIF_MCCK_PENDING);
374f5daba1dSHeiko Carstens 	}
375dc6e1555SHeiko Carstens 	if (mci.w) {
376f5daba1dSHeiko Carstens 		/* Warning pending */
377f5daba1dSHeiko Carstens 		mcck->warning = 1;
378d3a73acbSMartin Schwidefsky 		set_cpu_flag(CIF_MCCK_PENDING);
379f5daba1dSHeiko Carstens 	}
38081f64b87SHeiko Carstens 	nmi_exit();
381f5daba1dSHeiko Carstens }
382f5daba1dSHeiko Carstens 
383f5daba1dSHeiko Carstens static int __init machine_check_init(void)
384f5daba1dSHeiko Carstens {
385f5daba1dSHeiko Carstens 	ctl_set_bit(14, 25);	/* enable external damage MCH */
386f5daba1dSHeiko Carstens 	ctl_set_bit(14, 27);	/* enable system recovery MCH */
387f5daba1dSHeiko Carstens 	ctl_set_bit(14, 24);	/* enable warning MCH */
388f5daba1dSHeiko Carstens 	return 0;
389f5daba1dSHeiko Carstens }
39024d05ff8SHeiko Carstens early_initcall(machine_check_init);
391