Add panic test support
v2 cover Add panic test support
v1->v2:
---
* fix spelling mistakes/long lines (thanks Thomas)
* quoting improvments (thanks Thomas)
* smaller timeout for tests (thanks Thomas and Janis)
* move function and defines for cpu timer to time.h (thanks Janosch)
* fence tests for non-QEMU/KVM (thanks Janosch)
QEMU suports a guest state "guest-panicked" which indicates something in the guest went wrong, for example on s390x, when an external interrupt loop was triggered.
Since the guest does not continue to run when it is in the guest-panicked state, it is currently impossible to write panicking tests in kvm-unit-tests. Support from the runtime is needed to check that the guest enters the guest-panicked state.
This series adds the required support to the runtime together with two tests for s390x which cause guest panics.
Nico Boehr (4):
runtime: add support for panic tests
lib: s390x: add CPU timer functions to time.h
s390x: add extint loop test
s390x: add pgm spec interrupt loop test
lib/s390x/asm/time.h | 16 ++++++++++- s390x/Makefile | 2 ++ s390x/panic-loop-extint.c | 60 +++++++++++++++++++++++++++++++++++++++ s390x/panic-loop-pgm.c | 53 ++++++++++++++++++++++++++++++++++ s390x/run | 2 +- s390x/unittests.cfg | 12 ++++++++ scripts/arch-run.bash | 49 ++++++++++++++++++++++++++++++++ scripts/runtime.bash | 3 ++ 8 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 s390x/panic-loop-extint.c create mode 100644 s390x/panic-loop-pgm.c
Signature · 1 line
2.36.1
PATCH v2 1/4 runtime: add support for panic tests
QEMU supports a guest state "guest-panicked" which indicates something in the guest went wrong, for example on s390x, when an external interrupt loop was triggered.
Since the guest does not continue to run when it is in the guest-panicked state, it is currently impossible to write panicking tests in kvm-unit-tests. Support from the runtime is needed to check that the guest enters the guest-panicked state.
Similar to migration tests, add a new group panic. Tests in this group must enter the guest-panicked state to succeed.
The runtime will spawn a QEMU instance, connect to the QMP and listen for events. To parse the QMP protocol, jq[1] is used. Same as with netcat in the migration tests, panic tests won't run if jq is not installed.
The guest is created in the stopped state and only continued when connection to the QMP was successful. This ensures no events are missed between QEMU start and the connect to the QMP.
[1] https://stedolan.github.io/jq/
--- s390x/run | 2 +- scripts/arch-run.bash | 49 +++++++++++++++++++++++++++++++++++++++++++ scripts/runtime.bash | 3 +++ 3 files changed, 53 insertions(+), 1 deletion(-)
s390x/run +1 -1
@@ -30,7 +30,7 @@ M+=",accel=$ACCEL" command="$qemu -nodefaults -nographic $M" command+=" -chardev stdio,id=con0 -device sclpconsole,chardev=con0" command+=" -kernel" -command="$(migration_cmd) $(timeout_cmd) $command" +command="$(panic_cmd) $(migration_cmd) $(timeout_cmd) $command" # We return the exit code via stdout, not via the QEMU return code run_qemu_status $command "$@"
scripts/arch-run.bash +49 -0
67 lines not on this page · raw message
scripts/runtime.bash +3 -0
@@ -145,6 +145,9 @@ function run() if find_word "migration" "$groups"; then cmdline="MIGRATION=yes $cmdline" fi + if find_word "panic" "$groups"; then + cmdline="PANIC=yes $cmdline" + fi if [ "$verbose" = "yes" ]; then echo $cmdline fi
Signature · 1 line
2.36.1
PATCH v2 2/4 lib: s390x: add CPU timer functions to time.h
In reply to Nico BoehrUpcoming changes will make use of the CPU timer, so add a convenience function to set the CPU timer.
Since shifts for both CPU timer and TOD clock are the same, introduce a new define TIMING_S390_SHIFT_US. The respective shifts for CPU timer and TOD clock reference it, so the semantic difference between the two defines is kept.
--- lib/s390x/asm/time.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
lib/s390x/asm/time.h +15 -1
@@ -11,9 +11,13 @@#ifndef _ASMS390X_TIME_H_#define _ASMS390X_TIME_H_ -#define STCK_SHIFT_US (63 - 51) +#define TIMING_S390_SHIFT_US (63 - 51) + +#define STCK_SHIFT_US TIMING_S390_SHIFT_US#define STCK_MAX ((1UL << 52) - 1) +#define CPU_TIMER_SHIFT_US TIMING_S390_SHIFT_US +static inline uint64_t get_clock_us (void ) {uint64_t clk;
@@ -45,4 +49,14 @@ static inline void mdelay(unsigned long ms) udelay(ms * 1000); } +static inline void cpu_timer_set (int64_t timeout_ms) +{ +int64_t timer_value = (timeout_ms *1000 ) <<CPU_TIMER_SHIFT_US ; + asmvolatile ( +"spt %[timer_value]\n" + : + : [timer_value]"Q" (timer_value) + ); +} +#endif
Signature · 1 line
2.36.1
Re: [kvm-unit-tests PATCH v2 2/4] lib: s390x: add CPU timer functions to time.h
Quoted 18 lines · On Mon, 4 Jul 2022 14:13:26 +0200 Nico Boehr <[email protected]> wrote:
Upcoming changes will make use of the CPU timer, so add a convenience function to set the CPU timer.
Since shifts for both CPU timer and TOD clock are the same, introduce a new define
TIMING_S390_SHIFT_US. The respective shifts for CPU timer and TOD clock reference it, so the semantic difference between the two defines is kept.Signed-off-by Nico Boehr <[email protected]>--- lib/s390x/asm/time.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)lib/s390x/asm/time.h +0
-0
lib/s390x/asm/time.h line 14
Quoted 5 lines
lib/s390x/asm/time.h +1
-1@@ -11,9 +11,13 @@#ifndef _ASMS390X_TIME_H_#define _ASMS390X_TIME_H_ -#define STCK_SHIFT_US (63 - 51) +#define TIMING_S390_SHIFT_US (63 - 51)
I would call it S390_CLOCK_SHIFT_US
Quoted 10 lines
lib/s390x/asm/time.h +4
-0+ +#define STCK_SHIFT_US TIMING_S390_SHIFT_US#define STCK_MAX ((1UL << 52) - 1) +#define CPU_TIMER_SHIFT_US TIMING_S390_SHIFT_US +static inline uint64_t get_clock_us (void ) {uint64_t clk;
lib/s390x/asm/time.h static inline void mdelay(unsigned long ms) · line 52
Quoted 4 lines
lib/s390x/asm/time.h +1
-0@@ -45,4 +49,14 @@ static inline void mdelay(unsigned long ms)udelay (ms *1000 ); } +static inline void cpu_timer_set (int64_t timeout_ms)
I would call the function cpu_timer_set_ms
so that it's clear what unit goes in, and it makes things easier if in the future someone needs a _us version
Quoted 10 lines
lib/s390x/asm/time.h +9
-0+{ +int64_t timer_value = (timeout_ms *1000 ) <<CPU_TIMER_SHIFT_US ; + asmvolatile ( +"spt %[timer_value]\n" + : + : [timer_value]"Q" (timer_value) + ); +} +#endif
Re: [kvm-unit-tests PATCH v2 2/4] lib: s390x: add CPU timer functions to time.h
Quoting Claudio Imbrenda (2022-07-05 10:20:11)
Sorry Claudio, missed your mail as well...
Quoted 5 lines
Quoted 5 lines
lib/s390x/asm/time.h +0
-0@@ -11,9 +11,13 @@
[...]
Quoted 3 lines
Quoted 1 line
+#define
TIMING_S390_SHIFT_US(63 - 51)I would call it
S390_CLOCK_SHIFT_US
Will do.
[...]
Quoted 6 lines
Quoted 1 line
+static inline void
cpu_timer_set(int64_t timeout_ms)I would call the function
cpu_timer_set_msso that it's clear what unit goes in, and it makes things easier if in the future someone needs a
_usversion
Makes sense, that's also how the other functions are, so it is more consistent.
PATCH v2 3/4 s390x: add extint loop test
In reply to Nico BoehrThe CPU timer interrupt stays pending as long as the CPU timer value is negative. This can lead to interruption loops when the ext_new_psw mask has external interrupts enabled.
QEMU is able to detect this situation and panic the guest, so add a test for it.
--- s390x/Makefile | 1 + s390x/panic-loop-extint.c | 60 +++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 6 ++++ 3 files changed, 67 insertions(+) create mode 100644 s390x/panic-loop-extint.c
s390x/Makefile +1 -0
@@ -34,6 +34,7 @@ tests += $(TEST_DIR)/migration.elf tests += $(TEST_DIR)/pv-attest.elf tests += $(TEST_DIR)/migration-cmm.elf tests += $(TEST_DIR)/migration-skey.elf +tests += $(TEST_DIR)/panic-loop-extint.elf pv-tests += $(TEST_DIR)/pv-diags.elf
s390x/panic-loop-extint.c new file +60 -0
60 lines not on this page · raw message
s390x/unittests.cfg +6 -0
@@ -184,3 +184,9 @@ groups = migration [migration-skey] file = migration-skey.elf groups = migration + +[panic-loop-extint] +file = panic-loop-extint.elf +groups = panic +accel = kvm +timeout = 5
Signature · 1 line
2.36.1
PATCH v2 4/4 s390x: add pgm spec interrupt loop test
In reply to Nico BoehrAn invalid PSW causes a program interrupt. When an invalid PSW is introduced in the pgm_new_psw, an interrupt loop occurs as soon as a program interrupt is caused.
QEMU should detect that and panic the guest, hence add a test for it.
--- s390x/Makefile | 1 + s390x/panic-loop-pgm.c | 53 ++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 6 +++++ 3 files changed, 60 insertions(+) create mode 100644 s390x/panic-loop-pgm.c
s390x/Makefile +1 -0
@@ -35,6 +35,7 @@ tests += $(TEST_DIR)/pv-attest.elf tests += $(TEST_DIR)/migration-cmm.elf tests += $(TEST_DIR)/migration-skey.elf tests += $(TEST_DIR)/panic-loop-extint.elf +tests += $(TEST_DIR)/panic-loop-pgm.elf pv-tests += $(TEST_DIR)/pv-diags.elf
s390x/panic-loop-pgm.c new file +53 -0
53 lines not on this page · raw message
s390x/unittests.cfg +6 -0
@@ -190,3 +190,9 @@ file = panic-loop-extint.elf groups = panic accel = kvm timeout = 5 + +[panic-loop-pgm] +file = panic-loop-pgm.elf +groups = panic +accel = kvm +timeout = 5
Signature · 1 line
2.36.1
Re: [kvm-unit-tests PATCH v2 4/4] s390x: add pgm spec interrupt loop test
Quoted 56 lines · Nico Boehr
An invalid PSW causes a program interrupt. When an invalid PSW is introduced in the
pgm_new_psw, an interrupt loop occurs as soon as a program interrupt is caused.QEMU should detect that and panic the guest, hence add a test for it.
Signed-off-by Nico Boehr <[email protected]>--- s390x/Makefile | 1 + s390x/panic-loop-pgm.c | 53 ++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 6 +++++ 3 files changed, 60 insertions(+)create mode 100644
s390x/panic-loop-pgm.cs390x/Makefile +1
-0@@ -35,6 +35,7 @@ tests += $(TEST_DIR)/pv-attest.elf tests += $(TEST_DIR)/migration-cmm.elf tests += $(TEST_DIR)/migration-skey.elf tests += $(TEST_DIR)/panic-loop-extint.elf +tests += $(TEST_DIR)/panic-loop-pgm.elf pv-tests += $(TEST_DIR)/pv-diags.elfs390x/panic-loop-pgm.c new file +24
-0@@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Program interrupt loop test +* +* Copyright IBM Corp. 2022 +* +* Authors: +* Nico Boehr <[email protected]> +*/ +#include <libcflat.h> +#include <bitops.h> +#include <asm/interrupt.h> +#include <asm/barrier.h> +#include <hardware.h> + +static void pgm_int_handler (void ) +{ +/* +* return to pgm_old_psw. This gives us the chance to print the return_fail +* in case something goes wrong. +*/ + asmvolatile ( +"lpswe %[pgm_old_psw]\n" + :
s390x/panic-loop-pgm.c line 34
Quoted 10 lines
s390x/panic-loop-pgm.c new file +10
-0+ : [pgm_old_psw] "Q"(lowcore.pgm_old_psw) + : "memory" + ); +} + +int main (void ) +{ +report_prefix_push ("panic-loop-pgm" ); + +if (!host_is_qemu () ||host_is_tcg ()) {
Is TCG not able to detect the loop? ... if so, we should maybe fix QEMU?
Quoted 9 lines
s390x/panic-loop-pgm.c new file +9
-0+report_skip ("QEMU-KVM-only test" ); + goto out; + } + + lowcore.pgm_new_psw.addr = (uint64_t ) pgm_int_handler; +/* bit 12 set is invalid */ + lowcore.pgm_new_psw.mask =extract_psw_mask () |BIT (63 -12 ); +mb (); +
s390x/panic-loop-pgm.c line 53
Quoted 10 lines
s390x/panic-loop-pgm.c new file +10
-0+/* cause a pgm int */ + *((int *)-4 ) =0x42 ; +mb (); + +report_fail ("survived pgmint loop" ); + +out: +report_prefix_pop (); +return report_summary (); +}
Re: [kvm-unit-tests PATCH v2 4/4] s390x: add pgm spec interrupt loop test
Quoting Thomas Huth (2022-07-11 14:54:57)
[...]
Quoted 5 lines
Quoted 5 lines
s390x/panic-loop-pgm.c new file +0
-0
[...]
Quoted 7 lines
s390x/panic-loop-pgm.c line 34
Quoted 5 lines
s390x/panic-loop-pgm.c new file +5
-0+int main (void ) +{ +report_prefix_push ("panic-loop-pgm" ); + +if (!host_is_qemu () ||host_is_tcg ()) {Is TCG not able to detect the loop? ... if so, we should maybe fix QEMU?
Sorry, Thomas, I seem to have missed your mail.
Yes, TCG is not able to detect the PGM loop. Should I just go ahead and remove the check so we at least know that there is something left to fix?