Add panic test support
v5 cover Add panic test support
v4->v5:
---
* use psw_mask_set_bits instead of load_psw_mask/extract_psw_mask (thanks Claudio)
* add missing space in pgm int (thanks Janosch)
* set bit 12 to cause a pgm int (thanks Janosch)
v3->v4:
---
* avoid backslash at line end in scripts wherever possible (thanks Claudio)
* remove selfmade interrupt handlers and use kvm-unit-test default handers. This simplifies the code quite a bit.
* fix cpu timer and clock comparator confusion
v2->v3:
---
* rename TIMING_S390_SHIFT_US->S390_CLOCK_SHIFT_US (thanks Claudio)
* rename cpu_timer_set -> cpu_timer_set_ms (thanks Claudio)
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 related defines and functions
s390x: add extint loop test
s390x: add pgm spec interrupt loop test
lib/s390x/asm/arch_def.h | 1 + lib/s390x/asm/time.h | 17 ++++++++++- s390x/Makefile | 2 ++ s390x/panic-loop-extint.c | 59 +++++++++++++++++++++++++++++++++++++++ s390x/panic-loop-pgm.c | 38 +++++++++++++++++++++++++ s390x/run | 2 +- s390x/unittests.cfg | 12 ++++++++ scripts/arch-run.bash | 49 ++++++++++++++++++++++++++++++++ scripts/runtime.bash | 3 ++ 9 files changed, 181 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 v5 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
Re: [kvm-unit-tests PATCH v5 1/4] runtime: add support for panic tests
Quoted 2 lines · Nico Boehr
QEMU supports a guest state "guest-panicked" which indicates something in the guest went wrong, for example on s390x, when an external
s/,/./
Quoted 8 lines
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
Either:
"panic" group
or
group called "panic"
Quoted 8 lines
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
s/continued/is resumed when/
Quoted 8 lines
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/
Signed-off-by Nico Boehr <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Claudio Imbrenda <[email protected]>
Quoted 107 lines
--- 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@@ -104,6 +104,14 @@ qmp () echo '{ "execute": "qmp_capabilities" }{ "execute":' "$2" '}' | ncat -U $1 } +qmp_events () +{ + while ! test -S "$1"; do sleep 0.1; done + echo '{ "execute": "qmp_capabilities" }{ "execute": "cont" }' | + ncat --no-shutdown -U $1 | + jq -c 'select(has("event"))' +} + run_migration () { if ! command -v ncat >/dev/null 2>&1; then@@ -164,6 +172,40 @@ run_migration () return $ret } +run_panic () +{ + if ! command -v ncat >/dev/null 2>&1; then + echo "${FUNCNAME[0]} needs ncat (netcat)" >&2 + return 77 + fi + + if ! command -v jq >/dev/null 2>&1; then + echo "${FUNCNAME[0]} needs jq" >&2 + return 77 + fi + + qmp=$(mktemp -u -t panic-qmp.XXXXXXXXXX) + + trap 'kill 0; exit 2' INT TERM + trap 'rm -f ${qmp}' RETURN EXIT + + # start VM stopped so we don't miss any events + eval "$@" -chardev socket,id=mon1,path=${qmp},server=on,wait=off \ + -mon chardev=mon1,mode=control -S & + + panic_event_count=$(qmp_events ${qmp} | jq -c 'select(.event == "GUEST_PANICKED")' | wc -l) + if [ "$panic_event_count" -lt 1 ]; then + echo "FAIL: guest did not panic" + ret=3 + else + # some QEMU versions report multiple panic events + echo "PASS: guest panicked" + ret=1 + fi + + return $ret +} + migration_cmd () { if [ "$MIGRATION" = "yes" ]; then@@ -171,6 +213,13 @@ migration_cmd () fi } +panic_cmd () +{ + if [ "$PANIC" = "yes" ]; then + echo "run_panic" + fi +} + search_qemu_binary () { local save_path=$PATHscripts/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
PATCH v5 2/4 lib/s390x: add CPU timer related defines and functions
In reply to Nico BoehrUpcoming changes will make use of the CPU timer, so add some defines and functions to work with the CPU timer.
Since shifts for both CPU timer and TOD clock are the same, introduce a new define S390_CLOCK_SHIFT_US. The respective shifts for CPU timer and TOD clock reference it, so the semantic difference between the two defines is kept.
Also add a define for the CPU timer subclass mask.
--- lib/s390x/asm/arch_def.h | 1 + lib/s390x/asm/time.h | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-)
lib/s390x/asm/arch_def.h +1 -0
@@ -78,6 +78,7 @@ struct cpu {#define CTL0_EMERGENCY_SIGNAL (63 - 49)#define CTL0_EXTERNAL_CALL (63 - 50)#define CTL0_CLOCK_COMPARATOR (63 - 52) +#define CTL0_CPU_TIMER (63 - 53)#define CTL0_SERVICE_SIGNAL (63 - 54)#define CR0_EXTM_MASK 0x0000000000006200UL/* Combined external masks */
lib/s390x/asm/time.h +16 -1
@@ -11,9 +11,13 @@#ifndef _ASMS390X_TIME_H_#define _ASMS390X_TIME_H_ -#define STCK_SHIFT_US (63 - 51) +#define S390_CLOCK_SHIFT_US (63 - 51) + +#define STCK_SHIFT_US S390_CLOCK_SHIFT_US#define STCK_MAX ((1UL << 52) - 1) +#define CPU_TIMER_SHIFT_US S390_CLOCK_SHIFT_US +static inline uint64_t get_clock_us (void ) {uint64_t clk;
@@ -45,4 +49,15 @@ static inline void mdelay(unsigned long ms) udelay(ms * 1000); } +static inline void cpu_timer_set_ms (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 v5 2/4] lib/s390x: add CPU timer related defines and functions
Quoted 5 lines · Nico Boehr
Upcoming changes will make use of the CPU timer, so add some defines and functions to work with the CPU timer.
Since shifts for both CPU timer and TOD clock are the same, introduce a new define
S390_CLOCK_SHIFT_US. The respective shifts for CPU timer and
introduce the new constant "S390_CLOCK_SHIFT_US" for that value
Quoted 4 lines
TOD clock reference it, so the semantic difference between the two defines is kept.
Also add a define for the CPU timer subclass mask.
Constant
Quoted 2 lines
Signed-off-by Nico Boehr <[email protected]>
Quoted 52 lines
--- lib/s390x/asm/arch_def.h | 1 + lib/s390x/asm/time.h | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-)lib/s390x/asm/arch_def.h +1
-0@@ -78,6 +78,7 @@ struct cpu {#define CTL0_EMERGENCY_SIGNAL (63 - 49)#define CTL0_EXTERNAL_CALL (63 - 50)#define CTL0_CLOCK_COMPARATOR (63 - 52) +#define CTL0_CPU_TIMER (63 - 53)#define CTL0_SERVICE_SIGNAL (63 - 54)#define CR0_EXTM_MASK 0x0000000000006200UL/* Combined external masks */ lib/s390x/asm/time.h +16
-1@@ -11,9 +11,13 @@#ifndef _ASMS390X_TIME_H_#define _ASMS390X_TIME_H_ -#define STCK_SHIFT_US (63 - 51) +#define S390_CLOCK_SHIFT_US (63 - 51) + +#define STCK_SHIFT_US S390_CLOCK_SHIFT_US#define STCK_MAX ((1UL << 52) - 1) +#define CPU_TIMER_SHIFT_US S390_CLOCK_SHIFT_US +static inline uint64_t get_clock_us (void ) {uint64_t clk;@@ -45,4 +49,15 @@ static inline void mdelay(unsigned long ms) udelay(ms * 1000); } +static inline void cpu_timer_set_ms (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
PATCH v5 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 | 59 +++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 6 ++++ 3 files changed, 66 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 +59 -0
59 lines not on this page · raw message
s390x/unittests.cfg +6 -0
@@ -185,3 +185,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
Re: [kvm-unit-tests PATCH v5 3/4] s390x: add extint loop test
Quoted 3 lines · Nico Boehr
The CPU timer interrupt stays pending as long as the CPU timer value is negative. This can lead to interruption loops when the
ext_new_pswmask has external interrupts enabled.
and the CPU timer subclass in CR0 is enabled
Otherwise:
Quoted 104 lines
QEMU is able to detect this situation and panic the guest, so add a test for it.
Signed-off-by Nico Boehr <[email protected]>Reviewed-by Thomas Huth <[email protected]>--- s390x/Makefile | 1 + s390x/panic-loop-extint.c | 59 +++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 6 ++++ 3 files changed, 66 insertions(+)create mode 100644
s390x/panic-loop-extint.cs390x/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.elfs390x/panic-loop-extint.c new file +59
-0@@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* External interrupt loop test +* +* Copyright IBM Corp. 2022 +* +* Authors: +* Nico Boehr <[email protected]> +*/ +#include <libcflat.h> +#include <asm/interrupt.h> +#include <asm/barrier.h> +#include <asm/time.h> +#include <hardware.h> +#include <bitops.h> + +static void ext_int_cleanup (struct stack_frame_int *stack) +{ +/* +* Since we form a loop of ext interrupts, this code should never be +* executed. In case it is executed, something went wrong and we want to +* print a failure. +* +* Because the CPU timer subclass mask is still enabled, the CPU timer +* interrupt will fire every time we enable external interrupts, +* preventing us from printing the failure on the console. To avoid +* this, clear the CPU timer subclass mask here. +*/ + stack->crs[0 ] &= ~BIT (CTL0_CPU_TIMER ); +} + +int main (void ) +{ +report_prefix_push ("panic-loop-extint" ); + +if (!host_is_qemu () ||host_is_tcg ()) { +report_skip ("QEMU-KVM-only test" ); + goto out; + } + +expect_ext_int (); + lowcore.ext_new_psw.mask |=PSW_MASK_EXT ; + +psw_mask_set_bits (PSW_MASK_EXT ); + +register_ext_cleanup_func (ext_int_cleanup); + +cpu_timer_set_ms (10 ); +ctl_set_bit (0 ,CTL0_CPU_TIMER ); +mdelay (2000 ); + +register_ext_cleanup_func (NULL ); + +report_fail ("survived extint loop" ); + +out: +report_prefix_pop (); +return report_summary (); +}s390x/unittests.cfg +6
-0@@ -185,3 +185,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
PATCH v5 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 | 38 ++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 6 ++++++ 3 files changed, 45 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 +38 -0
@@ -0,0 +1,38 @@ +/* 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> + +int main (void ) +{ +report_prefix_push ("panic-loop-pgm" ); + +if (!host_is_qemu () ||host_is_tcg ()) { +report_skip ("QEMU-KVM-only test" ); + goto out; + } + +expect_pgm_int (); +/* bit 12 set is invalid */ + lowcore.pgm_new_psw.mask =extract_psw_mask () |BIT (63 -12 ); +mb (); + +/* cause a pgm int */ +psw_mask_set_bits (BIT (63 -12 )); + +report_fail ("survived pgm int loop" ); + +out: +report_prefix_pop (); +return report_summary (); +}
s390x/unittests.cfg +6 -0
@@ -191,3 +191,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 v5 4/4] s390x: add pgm spec interrupt loop test
Quoted 8 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]>Reviewed-by Claudio Imbrenda <[email protected]>
Quoted 77 lines
--- s390x/Makefile | 1 + s390x/panic-loop-pgm.c | 38 ++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 6 ++++++ 3 files changed, 45 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 +38
-0@@ -0,0 +1,38 @@ +/* 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> + +int main (void ) +{ +report_prefix_push ("panic-loop-pgm" ); + +if (!host_is_qemu () ||host_is_tcg ()) { +report_skip ("QEMU-KVM-only test" ); + goto out; + } + +expect_pgm_int (); +/* bit 12 set is invalid */ + lowcore.pgm_new_psw.mask =extract_psw_mask () |BIT (63 -12 ); +mb (); + +/* cause a pgm int */ +psw_mask_set_bits (BIT (63 -12 )); + +report_fail ("survived pgm int loop" ); + +out: +report_prefix_pop (); +return report_summary (); +}s390x/unittests.cfg +6
-0@@ -191,3 +191,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