s390x: LPAR boot fix and additional tests
[kvm-unit-tests GIT PULL 02/11] s390x: smp: use an array for sigp calls
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
Tests for the SIGP calls are quite similar, so we have a lot of code duplication right now. Since upcoming changes will add more cases, refactor the code to iterate over an array, similarily as we already do for test_invalid().
The receiving CPU is disabled for IO interrupts. This makes sure the conditional emergency signal is accepted and doesn't hurt the other orders.
Message-Id: <[email protected]>
--- s390x/smp.c | 128 ++++++++++++++++++++-------------------------------- 1 file changed, 50 insertions(+), 78 deletions(-)
s390x/smp.c +50 -78
@@ -43,6 +43,20 @@ static const struct sigp_invalid_cases cases_valid_cpu_addr[] = {static uint32_t cpu1_prefix; +struct sigp_call_cases { +char name[20 ]; +int call; +uint16_t ext_int_expected_type; +unsigned int cr0_bit; +bool supports_pv; +}; +static const struct sigp_call_cases cases_sigp_call[] = { + {"emcall" ,SIGP_EMERGENCY_SIGNAL ,0x1201 ,CTL0_EMERGENCY_SIGNAL , true }, + {"cond emcall" ,SIGP_COND_EMERGENCY_SIGNAL ,0x1201 ,CTL0_EMERGENCY_SIGNAL , false }, + {"ecall" ,SIGP_EXTERNAL_CALL ,0x1202 ,CTL0_EXTERNAL_CALL , true }, +}; +static const struct sigp_call_cases *current_sigp_call_case; +static void test_invalid (void ) {const struct sigp_invalid_cases *c;
@@ -289,97 +303,57 @@ static void test_set_prefix(void) } -static void ecall (void ) +static void call_received (void ) {expect_ext_int (); -ctl_set_bit (0 ,CTL0_EXTERNAL_CALL ); -psw_mask_set_bits (PSW_MASK_EXT ); +ctl_set_bit (0 , current_sigp_call_case->cr0_bit); +/* make sure conditional emergency is accepted by disabling IO interrupts */ +psw_mask_clear_and_set_bits (PSW_MASK_IO ,PSW_MASK_EXT ); + +/* Indicate that we're ready to receive the call */ set_flag (1 ); -while (lowcore.ext_int_code !=0x1202 ) {mb (); } + +while (lowcore.ext_int_code != current_sigp_call_case->ext_int_expected_type) +mb ();report_pass ("received" ); + +ctl_clear_bit (0 , current_sigp_call_case->cr0_bit); + +/* Indicate that we're done */ set_flag (1 ); } -static void test_ecall (void ) +static void test_calls (void ) { +int i;struct psw psw; - psw.mask =extract_psw_mask (); - psw.addr = (unsigned long )ecall; -report_prefix_push ("ecall" ); -set_flag (0 ); +for (i =0 ; i <ARRAY_SIZE (cases_sigp_call); i++) { + current_sigp_call_case = &cases_sigp_call[i]; -smp_cpu_start (1 , psw); -wait_for_flag (); -set_flag (0 ); -smp_sigp (1 ,SIGP_EXTERNAL_CALL ,0 ,NULL ); -wait_for_flag (); -smp_cpu_stop (1 ); -report_prefix_pop (); -} +report_prefix_push (current_sigp_call_case->name); +if (!current_sigp_call_case->supports_pv &&uv_os_is_guest ()) { +report_skip ("Not supported under PV" ); +report_prefix_pop (); +continue ; + } -static void emcall (void ) -{ -expect_ext_int (); -ctl_set_bit (0 ,CTL0_EMERGENCY_SIGNAL ); -psw_mask_set_bits (PSW_MASK_EXT ); -set_flag (1 ); -while (lowcore.ext_int_code !=0x1201 ) {mb (); } -report_pass ("received" ); -set_flag (1 ); -} +set_flag (0 ); + psw.mask =extract_psw_mask (); + psw.addr = (unsigned long )call_received; +smp_cpu_start (1 , psw); -static void test_emcall (void ) -{ -struct psw psw; - psw.mask =extract_psw_mask (); - psw.addr = (unsigned long )emcall; +/* Wait until the receiver has finished setup */ +wait_for_flag (); +set_flag (0 ); -report_prefix_push ("emcall" ); -set_flag (0 ); +smp_sigp (1 , current_sigp_call_case->call,0 ,NULL ); -smp_cpu_start (1 , psw); -wait_for_flag (); -set_flag (0 ); -smp_sigp (1 ,SIGP_EMERGENCY_SIGNAL ,0 ,NULL ); -wait_for_flag (); -smp_cpu_stop (1 ); - -report_prefix_pop (); -} - -static void test_cond_emcall (void ) -{ -uint32_t status =0 ; -struct psw psw; -int cc; - psw.mask =extract_psw_mask () & ~PSW_MASK_IO ; - psw.addr = (unsigned long )emcall; - -report_prefix_push ("conditional emergency call" ); - -if (uv_os_is_guest ()) { -report_skip ("unsupported under PV" ); - goto out; +/* Wait until the receiver has handled the call */ +wait_for_flag (); +smp_cpu_stop (1 ); +report_prefix_pop (); } - -report_prefix_push ("success" ); -set_flag (0 ); - -smp_cpu_start (1 , psw); -wait_for_flag (); -set_flag (0 ); - cc =smp_sigp (1 ,SIGP_COND_EMERGENCY_SIGNAL ,0 , &status); -report (!cc,"CC = 0" ); - -wait_for_flag (); -smp_cpu_stop (1 ); - -report_prefix_pop (); - -out: -report_prefix_pop (); - }static void test_sense_running (void )
@@ -499,9 +473,7 @@ int main(void)test_stop_store_status ();test_store_status ();test_set_prefix (); -test_ecall (); -test_emcall (); -test_cond_emcall (); +test_calls ();test_sense_running ();test_reset ();test_reset_initial ();
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 04/11] lib/s390x: fix SMP setup bug
In reply to Janosch FrankFrom: Claudio Imbrenda <[email protected]>
The lowcore pointer pointing to the current CPU (THIS_CPU) was not initialized for the boot CPU. The pointer is needed for correct interrupt handling, which is needed in the setup process before the struct cpu array is allocated.
The bug went unnoticed because some environments (like qemu/KVM) clear all memory and don't write anything in the lowcore area before starting the payload. The pointer thus pointed to 0, an area of memory also not used. Other environments will write to memory before starting the payload, causing the unit tests to crash at the first interrupt.
Fix by assigning a temporary struct cpu before the rest of the setup process, and assigning the pointer to the correct allocated struct during smp initialization.
Message-Id: <[email protected]>
--- lib/s390x/io.c | 9 +++++++++ lib/s390x/smp.c | 1 + 2 files changed, 10 insertions(+)
lib/s390x/io.c +9 -0
@@ -33,6 +33,15 @@ void puts(const char *s)void setup (void ) { +struct cpu this_cpu_tmp = {0 }; + +/* +* Set a temporary empty struct cpu for the boot CPU, needed for +* correct interrupt handling in the setup process. +* smp_setup will allocate and set the permanent one. +*/ +THIS_CPU = &this_cpu_tmp; +setup_args_progname (ipl_args);setup_facilities ();sclp_read_info ();
lib/s390x/smp.c +1 -0
@@ -353,6 +353,7 @@ void smp_setup(void) cpus[0 ].stack = stackptr; cpus[0 ].lowcore = (void *)0 ; cpus[0 ].active = true; +THIS_CPU = &cpus[0 ]; } }spin_unlock (&lock);
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 05/11] runtime: add support for panic tests
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
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 "panic" group. 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 is resumed 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/
Message-Id: <[email protected]>
--- 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.34.1
[kvm-unit-tests GIT PULL 06/11] lib/s390x: add CPU timer related defines and functions
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
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 constant S390_CLOCK_SHIFT_US for this value. The respective shifts for CPU timer and TOD clock reference it, so the semantic difference between the two defines is kept.
Also add a constant for the CPU timer subclass mask.
Message-Id: <[email protected]>
--- 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.34.1
[kvm-unit-tests GIT PULL 07/11] s390x: add extint loop test
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
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_psw mask has external interrupts enabled and the CPU timer subclass in CR0 is enabled.
QEMU is able to detect this situation and panic the guest, so add a test for it.
Message-Id: <[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.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.34.1
[kvm-unit-tests GIT PULL 09/11] s390x: Add strict mode to specification exception interpretation test
In reply to Janosch FrankFrom: Janis Schoetterl-Glausch <[email protected]>
While specification exception interpretation is not required to occur, it can be useful for automatic regression testing to fail the test if it does not occur.
Add a --strict argument to enable this.--strict takes a list of machine types (as reported by STIDP)
for which to enable strict mode, for example--strict 3931,8562,8561,3907,3906,2965,2964
will enable it for models z16 - z13.
Alternatively, strict mode can be enabled for all but the listed machine types by prefixing the list with a !, for example--strict !1090,1091,2064,2066,2084,2086,2094,2096,2097,2098,2817,2818,2827,2828 will enable it for z/Architecture models except those older than z13. --strict ! will enable it always.
Message-Id: <[email protected]>
--- s390x/spec_ex-sie.c | 53 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-)
s390x/spec_ex-sie.c +51 -2
@@ -7,16 +7,19 @@* specification exception interpretation is off/on. */ #include <libcflat.h> +#include <stdlib.h> #include <sclp.h> #include <asm/page.h> #include <asm/arch_def.h> #include <alloc_page.h> #include <sie.h> #include <snippet.h> +#include <hardware.h> static struct vm vm;extern const char SNIPPET_NAME_START (c ,spec_ex )[];extern const char SNIPPET_NAME_END (c ,spec_ex )[]; +static bool strict;static void setup_guest (void ) {
@@ -37,6 +40,8 @@ static void reset_guest(void)static void test_spec_ex_sie (void ) { +const char *msg; +setup_guest ();report_prefix_push ("SIE spec ex interpretation" );
@@ -60,16 +65,60 @@ static void test_spec_ex_sie(void)report (vm.sblk->icptcode ==ICPT_PROGI && vm.sblk->iprcc ==PGM_INT_CODE_SPECIFICATION ,"Received specification exception intercept" ); -if (vm.sblk->gpsw.addr ==0xdeadbeee ) -report_info ("Interpreted initial exception, intercepted invalid program new PSW exception" ); + msg ="Interpreted initial exception, intercepted invalid program new PSW exception" ; +if (strict) +report (vm.sblk->gpsw.addr ==0xdeadbeee ,"%s" , msg); +else if (vm.sblk->gpsw.addr ==0xdeadbeee ) +report_info ("%s" , msg);else report_info ("Did not interpret initial exception" );report_prefix_pop ();report_prefix_pop (); } +static bool parse_strict (int argc,char **argv) +{ +uint16_t machine_id; +char *list; +bool ret; + +if (argc <1 ) +return false; +if (strcmp ("--strict" , argv[0 ])) +return false; + + machine_id =get_machine_id (); +if (argc <2 ) { +printf ("No argument to --strict, ignoring\n" ); +return false; + } + list = argv[1 ]; +if (list[0 ] =='!' ) { + ret = true; + list++; + }else { + ret = false; + } +while (true) { +long input =0 ; + +if (strlen (list) ==0 ) +return ret; + input =strtol (list, &list,16 ); +if (*list ==',' ) + list++; +else if (*list !='\0' ) +break ; +if (input == machine_id) +return !ret; + } +printf ("Invalid --strict argument \"%s\", ignoring\n" , list); +return ret; +} +int main (int argc,char **argv) { + strict =parse_strict (argc -1 , argv +1 );if (!sclp_facilities.has_sief2) {report_skip ("SIEF2 facility unavailable" ); goto out;
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 10/11] s390x: factor out common args for genprotimg
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
Upcoming changes will add more arguments to genprotimg. To avoid duplicating this logic, move the arguments to genprotimg to a variable.
Message-Id: <[email protected]>
--- s390x/Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
s390x/Makefile +4 -2
@@ -167,11 +167,13 @@ $(SNIPPET_DIR)/c/%.hdr: $(SNIPPET_DIR)/c/%.gbin $(HOST_KEY_DOCUMENT) %.bin: %.elf $(OBJCOPY) -O binary $< $@ +genprotimg_args = --host-key-document $(HOST_KEY_DOCUMENT) --no-verify + %selftest.pv.bin: %selftest.bin $(HOST_KEY_DOCUMENT) $(patsubst %.pv.bin,%.parmfile,$@) - $(GENPROTIMG) --host-key-document $(HOST_KEY_DOCUMENT) --parmfile $(patsubst %.pv.bin,%.parmfile,$@) --no-verify --image $< -o $@ + $(GENPROTIMG) $(genprotimg_args) --parmfile $(patsubst %.pv.bin,%.parmfile,$@) --image $< -o $@ %.pv.bin: %.bin $(HOST_KEY_DOCUMENT) - $(GENPROTIMG) --host-key-document $(HOST_KEY_DOCUMENT) --no-verify --image $< -o $@ + $(GENPROTIMG) $(genprotimg_args) --image $< -o $@ $(snippet_asmlib): $$(patsubst %.o,%.S,$$@) $(asm-offsets) $(CC) $(CFLAGS) -c -nostdlib -o $@ $<
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 08/11] s390x: add pgm spec interrupt loop test
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
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.
Message-Id: <[email protected]>
--- 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.34.1
[kvm-unit-tests GIT PULL 01/11] s390x: smp: move sigp calls with invalid cpu address to array
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
We have the nice array to test SIGP calls with invalid CPU addresses. Move the SIGP cases there to eliminate some of the duplicated code in test_emcall and test_cond_emcall.
Since adding coverage for invalid CPU addresses in the ecall case is now trivial, do that as well.
Message-Id: <[email protected]>
--- s390x/smp.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-)
s390x/smp.c +3 -15
@@ -30,6 +30,9 @@ static const struct sigp_invalid_cases cases_invalid_cpu_addr[] = { { SIGP_STOP, "stop with invalid CPU address" }, { SIGP_START, "start with invalid CPU address" }, { SIGP_CPU_RESET, "reset with invalid CPU address" }, + { SIGP_COND_EMERGENCY_SIGNAL, "conditional emcall with invalid CPU address" }, + { SIGP_EMERGENCY_SIGNAL, "emcall with invalid CPU address" }, + { SIGP_EXTERNAL_CALL, "ecall with invalid CPU address" }, { INVALID_ORDER_CODE, "invalid order code and CPU address" }, { SIGP_SENSE, "sense with invalid CPU address" }, { SIGP_STOP_AND_STORE_STATUS, "stop and store status with invalid CPU address" },
@@ -329,7 +332,6 @@ static void emcall(void)static void test_emcall (void ) {struct psw psw; -int cc; psw.mask =extract_psw_mask (); psw.addr = (unsigned long )emcall;
@@ -343,13 +345,6 @@ static void test_emcall(void)wait_for_flag ();smp_cpu_stop (1 ); -report_prefix_push ("invalid CPU address" ); - - cc =sigp (INVALID_CPU_ADDRESS ,SIGP_EMERGENCY_SIGNAL ,0 ,NULL ); -report (cc ==3 ,"CC = 3" ); - -report_prefix_pop (); -report_prefix_pop (); }
@@ -368,13 +363,6 @@ static void test_cond_emcall(void) goto out; } -report_prefix_push ("invalid CPU address" ); - - cc =sigp (INVALID_CPU_ADDRESS ,SIGP_COND_EMERGENCY_SIGNAL ,0 ,NULL ); -report (cc ==3 ,"CC = 3" ); - -report_prefix_pop (); -report_prefix_push ("success" );set_flag (0 );
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 03/11] s390x: smp: add tests for calls in wait state
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
When the SIGP interpretation facility is in use a SIGP external call to a waiting CPU will result in an exit of the calling cpu. For non-pv guests it's a code 56 (partial execution) exit otherwise its a code 108 (secure instruction notification) exit. Those exits are handled differently from a normal SIGP instruction intercept that happens without interpretation and hence need to be tested.
Message-Id: <[email protected]>
--- s390x/smp.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+)
s390x/smp.c +97 -0
@@ -356,6 +356,102 @@ static void test_calls(void) } } +static void call_in_wait_ext_int_fixup (struct stack_frame_int *stack) +{ +/* Clear wait bit so we don't immediately wait again after the fixup */ + lowcore.ext_old_psw.mask &= ~PSW_MASK_WAIT ; +} + +static void call_in_wait_setup (void ) +{ +expect_ext_int (); +ctl_set_bit (0 , current_sigp_call_case->cr0_bit); +register_ext_cleanup_func (call_in_wait_ext_int_fixup); + +set_flag (1 ); +} + +static void call_in_wait_received (void ) +{ +report (lowcore.ext_int_code == current_sigp_call_case->ext_int_expected_type,"received" ); + +set_flag (1 ); +} + +static void call_in_wait_cleanup (void ) +{ +ctl_clear_bit (0 , current_sigp_call_case->cr0_bit); +register_ext_cleanup_func (NULL ); + +set_flag (1 ); +} + +static void test_calls_in_wait (void ) +{ +int i; +struct psw psw; + +report_prefix_push ("psw wait" ); +for (i =0 ; i <ARRAY_SIZE (cases_sigp_call); i++) { + current_sigp_call_case = &cases_sigp_call[i]; + +report_prefix_push (current_sigp_call_case->name); +if (!current_sigp_call_case->supports_pv &&uv_os_is_guest ()) { +report_skip ("Not supported under PV" ); +report_prefix_pop (); +continue ; + } + +/* Let the secondary CPU setup the external mask and the external interrupt cleanup function */ +set_flag (0 ); + psw.mask =extract_psw_mask (); + psw.addr = (unsigned long )call_in_wait_setup; +smp_cpu_start (1 , psw); + +/* Wait until the receiver has finished setup */ +wait_for_flag (); +set_flag (0 ); + +/* +* To avoid races, we need to know that the secondary CPU has entered wait, +* but the architecture provides no way to check whether the secondary CPU +* is in wait. +* +* But since a waiting CPU is considered operating, simply stop the CPU, set +* up the restart new PSW mask in wait, send the restart interrupt and then +* wait until the CPU becomes operating (done by smp_cpu_start). +*/ +smp_cpu_stop (1 ); + psw.mask =extract_psw_mask () |PSW_MASK_EXT |PSW_MASK_WAIT ; + psw.addr = (unsigned long )call_in_wait_received; +smp_cpu_start (1 , psw); + +smp_sigp (1 , current_sigp_call_case->call,0 ,NULL ); + +/* Wait until the receiver has handled the call */ +wait_for_flag (); +smp_cpu_stop (1 ); +set_flag (0 ); + +/* +* Now clean up the mess we have left behind. If the cleanup +* were part of call_in_wait_received we would not get a chance +* to catch an interrupt that is presented twice since we would +* disable the external call on the first interrupt. +*/ + psw.mask =extract_psw_mask (); + psw.addr = (unsigned long )call_in_wait_cleanup; +smp_cpu_start (1 , psw); + +/* Wait until the cleanup has been completed */ +wait_for_flag (); +smp_cpu_stop (1 ); + +report_prefix_pop (); + } +report_prefix_pop (); +} +static void test_sense_running (void ) {report_prefix_push ("sense_running" );
@@ -474,6 +570,7 @@ int main(void)test_store_status ();test_set_prefix ();test_calls (); +test_calls_in_wait ();test_sense_running ();test_reset ();test_reset_initial ();
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 11/11] s390x: create persistent comm-key
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
To decrypt the dump of a PV guest, the comm-key (CCK) is required. Until now, no comm-key was provided to genprotimg, therefore decrypting the dump of a kvm-unit-test under PV was not possible.
This patch makes sure that we create a random CCK if there's no $(TEST_DIR)/comm.key file.
Also allow dumping of PV tests by passing the appropriate PCF to genprotimg (bit 34). --x-pcf is used to be compatible with older genprotimg versions, which don't support --enable-dump. 0xe0 is the default PCF value and only bit 34 is added.
Unfortunately, recent versions of genprotimg removed the --x-comm-key argument which was used by older versions to specify the CCK. To support these versions, we need to parse the genprotimg help output and decide which argument to use.
Message-Id: <[email protected]>
--- s390x/Makefile | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
s390x/Makefile +22 -4
@@ -164,15 +164,33 @@ $(SNIPPET_DIR)/c/%.hdr: $(SNIPPET_DIR)/c/%.gbin $(HOST_KEY_DOCUMENT) $(RM) $(@:.elf=.aux.o) @chmod a-x $@ +# Secure Execution Customer Communication Key file +# 32 bytes of key material, uses existing one if available +comm-key = $(TEST_DIR)/comm.key +$(comm-key): + dd if=/dev/urandom of=$@ bs=32 count=1 status=none + %.bin: %.elf $(OBJCOPY) -O binary $< $@ -genprotimg_args = --host-key-document $(HOST_KEY_DOCUMENT) --no-verify +# The genprotimg arguments for the cck changed over time so we need to +# figure out which argument to use in order to set the cck +GENPROTIMG_HAS_COMM_KEY = $(shell $(GENPROTIMG) --help | grep -q -- --comm-key && echo yes) +ifeq ($(GENPROTIMG_HAS_COMM_KEY),yes) + GENPROTIMG_COMM_KEY = --comm-key $(comm-key) +else + GENPROTIMG_COMM_KEY = --x-comm-key $(comm-key) +endif -%selftest.pv.bin: %selftest.bin $(HOST_KEY_DOCUMENT) $(patsubst %.pv.bin,%.parmfile,$@) +# use x-pcf to be compatible with old genprotimg versions +# allow dumping + PCKMO +genprotimg_pcf = 0x200000e0 +genprotimg_args = --host-key-document $(HOST_KEY_DOCUMENT) --no-verify $(GENPROTIMG_COMM_KEY) --x-pcf $(genprotimg_pcf) + +%selftest.pv.bin: %selftest.bin $(HOST_KEY_DOCUMENT) $(patsubst %.pv.bin,%.parmfile,$@) $(comm-key) $(GENPROTIMG) $(genprotimg_args) --parmfile $(patsubst %.pv.bin,%.parmfile,$@) --image $< -o $@ -%.pv.bin: %.bin $(HOST_KEY_DOCUMENT) +%.pv.bin: %.bin $(HOST_KEY_DOCUMENT) $(comm-key) $(GENPROTIMG) $(genprotimg_args) --image $< -o $@ $(snippet_asmlib): $$(patsubst %.o,%.S,$$@) $(asm-offsets)
@@ -180,7 +198,7 @@ $(snippet_asmlib): $$(patsubst %.o,%.S,$$@) $(asm-offsets) arch_clean: asm_offsets_clean - $(RM) $(TEST_DIR)/*.{o,elf,bin} $(SNIPPET_DIR)/*/*.{o,elf,*bin,*obj,hdr} $(SNIPPET_DIR)/asm/.*.d $(TEST_DIR)/.*.d lib/s390x/.*.d + $(RM) $(TEST_DIR)/*.{o,elf,bin} $(SNIPPET_DIR)/*/*.{o,elf,*bin,*obj,hdr} $(SNIPPET_DIR)/asm/.*.d $(TEST_DIR)/.*.d lib/s390x/.*.d $(comm-key) generated-files = $(asm-offsets) $(tests:.elf=.o) $(asmlib) $(cflatobjs): $(generated-files)
Signature · 1 line
2.34.1
Dear Paolo,
please merge or pull the following changes:
- SMP setup fix that broke LPAR boot (Claudio)
- Strict mode for specification exception interpretation (Janis)
- Panic test support & tests (Nico)
- SIGP Wait state test (Nico)
- PV dump support (Nico)
MERGE:
https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/merge_requests/35
PULL:
The following changes since commit 7362976db651a2142ec64b5cea2029ab77a5b157:
x86/pmu: Run the "emulation" test iff forced emulation is available (2022-08-10 12:47:18 -0400)
are available in the Git repository at:
https://gitlab.com/frankja/kvm-unit-tests.git s390x-pull-2022-20-09
for you to fetch changes up to 3043685825d906e478ecc3b1bee32b6a7986a6e4:
s390x: create persistent comm-key (2022-09-14 10:27:04 +0000)
----------------------------------------------------------------
Claudio Imbrenda (1):
lib/s390x: fix SMP setup bug
Janis Schoetterl-Glausch (1):
s390x: Add strict mode to specification exception interpretation test
Nico Boehr (9):
s390x: smp: move sigp calls with invalid cpu address to array
s390x: smp: use an array for sigp calls
s390x: smp: add tests for calls in wait state
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
s390x: factor out common args for genprotimg
s390x: create persistent comm-key
lib/s390x/asm/arch_def.h | 1 + lib/s390x/asm/time.h | 17 ++- lib/s390x/io.c | 9 ++ lib/s390x/smp.c | 1 + s390x/Makefile | 32 +++++- s390x/panic-loop-extint.c | 59 ++++++++++ s390x/panic-loop-pgm.c | 38 ++++++ s390x/run | 2 +- s390x/smp.c | 235 +++++++++++++++++++++++--------------- s390x/spec_ex-sie.c | 53 ++++++++- s390x/unittests.cfg | 12 ++ scripts/arch-run.bash | 49 ++++++++ scripts/runtime.bash | 3 + 13 files changed, 413 insertions(+), 98 deletions(-) create mode 100644 s390x/panic-loop-extint.c create mode 100644 s390x/panic-loop-pgm.c
Signature · 1 line
2.34.1