xref: /kvm-unit-tests/s390x/panic-loop-extint.c (revision 8a078df4dde8f4a0113b9d45bb02140ea9c24ba5)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * External interrupt loop test
4  *
5  * Copyright IBM Corp. 2022
6  *
7  * Authors:
8  *  Nico Boehr <nrb@linux.ibm.com>
9  */
10 #include <libcflat.h>
11 #include <asm/interrupt.h>
12 #include <asm/barrier.h>
13 #include <asm/time.h>
14 #include <hardware.h>
15 #include <bitops.h>
16 
ext_int_cleanup(struct stack_frame_int * stack)17 static void ext_int_cleanup(struct stack_frame_int *stack)
18 {
19 	/*
20 	 * Since we form a loop of ext interrupts, this code should never be
21 	 * executed. In case it is executed, something went wrong and we want to
22 	 * print a failure.
23 	 *
24 	 * Because the CPU timer subclass mask is still enabled, the CPU timer
25 	 * interrupt will fire every time we enable external interrupts,
26 	 * preventing us from printing the failure on the console. To avoid
27 	 * this, clear the CPU timer subclass mask here.
28 	 */
29 	stack->crs[0] &= ~BIT(CTL0_CPU_TIMER);
30 }
31 
main(void)32 int main(void)
33 {
34 	report_prefix_push("panic-loop-extint");
35 
36 	if (!host_is_qemu() || host_is_tcg()) {
37 		report_skip("QEMU-KVM-only test");
38 		goto out;
39 	}
40 
41 	expect_ext_int();
42 	lowcore.ext_new_psw.mask |= PSW_MASK_EXT;
43 
44 	psw_mask_set_bits(PSW_MASK_EXT);
45 
46 	register_ext_cleanup_func(ext_int_cleanup);
47 
48 	cpu_timer_set_ms(10);
49 	ctl_set_bit(0, CTL0_CPU_TIMER);
50 	mdelay(2000);
51 
52 	register_ext_cleanup_func(NULL);
53 
54 	report_fail("survived extint loop");
55 
56 out:
57 	report_prefix_pop();
58 	return report_summary();
59 }
60