s390x: smp, vm lib updates; I/O and smp tests
Hi Paolo,
please merge the following changes:
* refactoring and renaming of lib/s390x/vm.[ch]
* SIGP infrastructure improvements
* fix for floating point register for snippets
* tests for I/O instructions
* more SIGP tests
MERGE:
https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/merge_requests/29
PIPELINE:
https://gitlab.com/imbrenda/kvm-unit-tests/-/pipelines/506807795
PULL:
https://gitlab.com/imbrenda/kvm-unit-tests.git s390x-next-2022-04
Claudio Imbrenda (5):
s390x: remove spurious includes
s390x: skey: remove check for old z/VM version
lib: s390x: rename and refactor vm.[ch]
lib: s390x: functions for machine models
lib: s390x: stidp wrapper and move get_machine_id
Eric Farman (6):
lib: s390x: smp: Retry SIGP SENSE on CC2
s390x: smp: Test SIGP RESTART against stopped CPU
s390x: smp: Fix checks for SIGP STOP STORE STATUS
s390x: smp: Create and use a non-waiting CPU stop
s390x: smp: Create and use a non-waiting CPU restart
lib: s390x: smp: Remove smp_sigp_retry
Janosch Frank (1):
s390x: snippets: c: Load initial cr0
Nico Boehr (15):
s390x: Add more tests for MSCH
s390x: Add test for PFMF low-address protection
s390x: Add sck tests
s390x: Add tests for STCRW
s390x: Add more tests for SSCH
s390x: Add more tests for STSCH
s390x: Add tests for TSCH
s390x: Add EPSW test
s390x: smp: add tests for several invalid SIGP orders
s390x: smp: stop already stopped CPU
s390x: smp: add tests for SET_PREFIX
s390x: smp: add test for EMERGENCY_SIGNAL with invalid CPU address
s390x: smp: add tests for CONDITIONAL EMERGENCY
s390x: add TPROT tests
s390x: stsi: check zero and ignored bits in r0 and r1
s390x/Makefile | 5 +- lib/s390x/asm/arch_def.h | 7 +- lib/s390x/css.h | 17 +++ lib/s390x/hardware.h | 55 +++++++ lib/s390x/smp.h | 3 +- lib/s390x/vm.h | 15 -- lib/s390x/css_lib.c | 60 ++++++++ lib/s390x/hardware.c | 69 +++++++++ lib/s390x/smp.c | 63 +++++++-- lib/s390x/vm.c | 92 ------------ s390x/snippets/c/cstart.S | 6 + s390x/cpumodel.c | 4 +- s390x/css.c | 291 ++++++++++++++++++++++++++++++++++++++ s390x/epsw.c | 113 +++++++++++++++ s390x/mvpg-sie.c | 1 - s390x/mvpg.c | 4 +- s390x/pfmf.c | 29 ++++ s390x/pv-diags.c | 1 - s390x/sck.c | 136 ++++++++++++++++++ s390x/skey.c | 37 +---- s390x/smp.c | 231 +++++++++++++++++++++++++++--- s390x/spec_ex-sie.c | 1 - s390x/stsi.c | 42 ++++-- s390x/tprot.c | 108 ++++++++++++++ s390x/uv-host.c | 4 +- s390x/unittests.cfg | 10 ++ 26 files changed, 1208 insertions(+), 196 deletions(-) create mode 100644 lib/s390x/hardware.h delete mode 100644 lib/s390x/vm.h create mode 100644 lib/s390x/hardware.c delete mode 100644 lib/s390x/vm.c create mode 100644 s390x/epsw.c create mode 100644 s390x/sck.c create mode 100644 s390x/tprot.c
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 04/27] s390x: smp: Create and use a non-waiting CPU stop
From: Eric Farman <[email protected]>
When stopping a CPU, kvm-unit-tests serializes/waits for everything to finish, in order to get a consistent result whenever those functions are used.
But to test the SIGP STOP itself, these additional measures could mask other problems. For example, did the STOP work, or is the CPU still operating?
Let's create a non-waiting SIGP STOP and use it here, to ensure that the CPU is correctly stopped. A smp_cpu_stopped() call will still be used to see that the SIGP STOP has been processed, and the state of the CPU can be used to determine whether the test passes/fails.
--- lib/s390x/smp.h | 1 + lib/s390x/smp.c | 27 +++++++++++++++++++++++++++ s390x/smp.c | 17 +++++++++-------- 3 files changed, 37 insertions(+), 8 deletions(-)
lib/s390x/smp.h +1 -0
@@ -44,6 +44,7 @@ bool smp_sense_running_status(uint16_t idx);int smp_cpu_restart (uint16_t idx);int smp_cpu_start (uint16_t idx,struct psw psw);int smp_cpu_stop (uint16_t idx); +int smp_cpu_stop_nowait (uint16_t idx);int smp_cpu_stop_store_status (uint16_t idx);int smp_cpu_destroy (uint16_t idx);int smp_cpu_setup (uint16_t idx,struct psw psw);
lib/s390x/smp.c +27 -0
@@ -119,6 +119,33 @@ int smp_cpu_stop(uint16_t idx)return rc; } +/* +* Functionally equivalent to smp_cpu_stop(), but without the +* elements that wait/serialize matters itself. +* Used to see if KVM itself is serialized correctly. +*/ +int smp_cpu_stop_nowait (uint16_t idx) +{ +check_idx (idx); + +/* refuse to work on the boot CPU */ +if (idx ==0 ) +return -1 ; + +spin_lock (&lock); + +/* Don't suppress a CC2 with sigp_retry() */ +if (sigp (cpus[idx].addr,SIGP_STOP ,0 ,NULL )) { +spin_unlock (&lock); +return -1 ; + } + + cpus[idx].active = false; +spin_unlock (&lock); + +return 0 ; +} +int smp_cpu_stop_store_status (uint16_t idx) {int rc;
s390x/smp.c +9 -8
@@ -76,14 +76,15 @@ static void test_restart(void)static void test_stop (void ) { -smp_cpu_stop (1 ); -/* -* The smp library waits for the CPU to shut down, but let's -* also do it here, so we don't rely on the library -* implementation -*/ -while (!smp_cpu_stopped (1 )) {} -report_pass ("stop" ); +int rc; + +report_prefix_push ("stop" ); + + rc =smp_cpu_stop_nowait (1 ); +report (!rc,"return code" ); +report (smp_cpu_stopped (1 ),"cpu stopped" ); + +report_prefix_pop (); }static void test_stop_store_status (void )
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 08/27] s390x: Add test for PFMF low-address protection
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
PFMF should respect the low-address protection when clearing pages, hence add some tests for it.
When low-address protection fails, clearing frame 0 is a destructive operation. It messes up interrupts and thus printing test results won't work properly. Hence, we first attempt to clear frame 1 which is not as destructive.
Doing it this way around increases the chances for the user to see a proper failure message instead of QEMU randomly quitting in the middle of the test run.
--- s390x/pfmf.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
s390x/pfmf.c +29 -0
@@ -113,6 +113,34 @@ static void test_1m_clear(void)report_prefix_pop (); } +static void test_low_addr_prot (void ) +{ +union pfmf_r1 r1 = { + .reg.cf =1 , + .reg.fsc =PFMF_FSC_4K + }; + +report_prefix_push ("low-address protection" ); + +report_prefix_push ("0x1000" ); +expect_pgm_int (); +low_prot_enable (); +pfmf (r1.val, (void *)0x1000 ); +low_prot_disable (); +check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +report_prefix_pop (); + +report_prefix_push ("0x0" ); +expect_pgm_int (); +low_prot_enable (); +pfmf (r1.val,0 ); +low_prot_disable (); +check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +report_prefix_pop (); + +report_prefix_pop (); +} +int main (void ) {bool has_edat =test_facility (8 );
@@ -124,6 +152,7 @@ int main(void) }test_priv (); +test_low_addr_prot ();/* Force the buffer pages in */ memset (pagebuf,0 ,PAGE_SIZE *256 );
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 05/27] s390x: smp: Create and use a non-waiting CPU restart
In reply to Claudio ImbrendaFrom: Eric Farman <[email protected]>
The kvm-unit-tests infrastructure for a CPU restart waits for the SIGP RESTART to complete. In order to test the restart itself, create a variation that does not wait, and test the state of the CPU directly.
While here, add some better report prefixes/messages, to clarify which condition is being examined (similar to test_stop_store_status()).
--- lib/s390x/smp.h | 1 + lib/s390x/smp.c | 24 ++++++++++++++++++++++++ s390x/smp.c | 21 ++++++++++++++++++--- 3 files changed, 43 insertions(+), 3 deletions(-)
lib/s390x/smp.h +1 -0
@@ -42,6 +42,7 @@ uint16_t smp_cpu_addr(uint16_t idx);bool smp_cpu_stopped (uint16_t idx);bool smp_sense_running_status (uint16_t idx);int smp_cpu_restart (uint16_t idx); +int smp_cpu_restart_nowait (uint16_t idx);int smp_cpu_start (uint16_t idx,struct psw psw);int smp_cpu_stop (uint16_t idx);int smp_cpu_stop_nowait (uint16_t idx);
lib/s390x/smp.c +24 -0
@@ -194,6 +194,30 @@ int smp_cpu_restart(uint16_t idx)return rc; } +/* +* Functionally equivalent to smp_cpu_restart(), but without the +* elements that wait/serialize matters here in the test. +* Used to see if KVM itself is serialized correctly. +*/ +int smp_cpu_restart_nowait (uint16_t idx) +{ +check_idx (idx); + +spin_lock (&lock); + +/* Don't suppress a CC2 with sigp_retry() */ +if (sigp (cpus[idx].addr,SIGP_RESTART ,0 ,NULL )) { +spin_unlock (&lock); +return -1 ; + } + + cpus[idx].active = true; + +spin_unlock (&lock); + +return 0 ; +} +int smp_cpu_start (uint16_t idx,struct psw psw) {int rc;
s390x/smp.c +18 -3
@@ -54,6 +54,10 @@ static void test_restart(void) {struct cpu *cpu =smp_cpu_from_idx (1 );struct lowcore *lc = cpu->lowcore; +int rc; + +report_prefix_push ("restart" ); +report_prefix_push ("stopped" ); lc->restart_new_psw.mask =extract_psw_mask (); lc->restart_new_psw.addr = (unsigned long )test_func;
@@ -61,17 +65,28 @@ static void test_restart(void)/* Make sure cpu is stopped */ smp_cpu_stop (1 );set_flag (0 ); -smp_cpu_restart (1 ); + rc =smp_cpu_restart_nowait (1 ); +report (!rc,"return code" ); +report (!smp_cpu_stopped (1 ),"cpu started" );wait_for_flag (); +report_pass ("test flag" ); + +report_prefix_pop (); +report_prefix_push ("running" );/* * Wait until cpu 1 has set the flag because it executed the * restart function. */ set_flag (0 ); -smp_cpu_restart (1 ); + rc =smp_cpu_restart_nowait (1 ); +report (!rc,"return code" ); +report (!smp_cpu_stopped (1 ),"cpu started" );wait_for_flag (); -report_pass ("restart while running" ); +report_pass ("test flag" ); + +report_prefix_pop (); +report_prefix_pop (); }static void test_stop (void )
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 01/27] lib: s390x: smp: Retry SIGP SENSE on CC2
In reply to Claudio ImbrendaFrom: Eric Farman <[email protected]>
The routine smp_cpu_stopped() issues a SIGP SENSE, and returns true if it received a CC1 (STATUS STORED) with the STOPPED or CHECK STOP bits enabled. Otherwise, it returns false.
This is misleading, because a CC2 (BUSY) merely indicates that the order code could not be processed, not that the CPU is operating. It could be operating but in the process of being stopped.
Convert the invocation of the SIGP SENSE to retry when a CC2 is received, so we get a more definitive answer.
--- lib/s390x/smp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/s390x/smp.c +1 -1
@@ -78,7 +78,7 @@ bool smp_cpu_stopped(uint16_t idx) {uint32_t status; -if (smp_sigp (idx,SIGP_SENSE ,0 , &status) !=SIGP_CC_STATUS_STORED ) +if (smp_sigp_retry (idx,SIGP_SENSE ,0 , &status) !=SIGP_CC_STATUS_STORED )return false;return !!(status & (SIGP_STATUS_CHECK_STOP |SIGP_STATUS_STOPPED )); }
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 06/27] lib: s390x: smp: Remove smp_sigp_retry
In reply to Claudio ImbrendaFrom: Eric Farman <[email protected]>
The SIGP instruction presents a CC0 when an order is accepted, though the work for the order may be performed asynchronously. While any such work is outstanding, nearly any other SIGP order sent to the same CPU will be returned with a CC2.
Currently, there are two library functions that perform a SIGP, one which retries a SIGP that gets a CC2, and one which doesn't. In practice, the users of this functionality want the CC2 to be handled by the library itself, rather than determine whether it needs to retry the request or not.
To avoid confusion, let's convert the smp_sigp() routine to perform the sigp_retry() logic, and then convert any users of smp_sigp_retry() to smp_sigp(). This of course means that the external _retry() interface can be removed for simplicity.
--- lib/s390x/smp.h | 1 - lib/s390x/smp.c | 14 ++++---------- s390x/smp.c | 4 ++-- 3 files changed, 6 insertions(+), 13 deletions(-)
lib/s390x/smp.h +0 -1
@@ -52,6 +52,5 @@ int smp_cpu_setup(uint16_t idx, struct psw psw);void smp_teardown (void );void smp_setup (void );int smp_sigp (uint16_t idx,uint8_t order,unsigned long parm,uint32_t *status); -int smp_sigp_retry (uint16_t idx,uint8_t order,unsigned long parm,uint32_t *status);#endif
lib/s390x/smp.c +4 -10
@@ -40,12 +40,6 @@ int smp_query_num_cpus(void) }int smp_sigp (uint16_t idx,uint8_t order,unsigned long parm,uint32_t *status) -{ -check_idx (idx); -return sigp (cpus[idx].addr, order, parm, status); -} - -int smp_sigp_retry (uint16_t idx,uint8_t order,unsigned long parm,uint32_t *status) {check_idx (idx);return sigp_retry (cpus[idx].addr, order, parm, status);
@@ -78,7 +72,7 @@ bool smp_cpu_stopped(uint16_t idx) {uint32_t status; -if (smp_sigp_retry (idx,SIGP_SENSE ,0 , &status) !=SIGP_CC_STATUS_STORED ) +if (smp_sigp (idx,SIGP_SENSE ,0 , &status) !=SIGP_CC_STATUS_STORED )return false;return !!(status & (SIGP_STATUS_CHECK_STOP |SIGP_STATUS_STOPPED )); }
@@ -99,7 +93,7 @@ static int smp_cpu_stop_nolock(uint16_t idx, bool store)if (idx ==0 )return -1 ; -if (smp_sigp_retry (idx, order,0 ,NULL )) +if (smp_sigp (idx, order,0 ,NULL ))return -1 ;while (!smp_cpu_stopped (idx))
@@ -251,11 +245,11 @@ static int smp_cpu_setup_nolock(uint16_t idx, struct psw psw)if (cpus[idx].active)return -1 ; -smp_sigp_retry (idx,SIGP_INITIAL_CPU_RESET ,0 ,NULL ); +smp_sigp (idx,SIGP_INITIAL_CPU_RESET ,0 ,NULL ); lc =alloc_pages_flags (1 ,AREA_DMA31 ); cpus[idx].lowcore = lc; -smp_sigp_retry (idx,SIGP_SET_PREFIX , (unsigned long )lc,NULL ); +smp_sigp (idx,SIGP_SET_PREFIX , (unsigned long )lc,NULL );/* Copy all exception psws. */ memcpy (lc, cpus[0 ].lowcore,512 );
s390x/smp.c +2 -2
@@ -266,7 +266,7 @@ static void test_reset_initial(void)smp_cpu_start (1 , psw);wait_for_flag (); -smp_sigp_retry (1 ,SIGP_INITIAL_CPU_RESET ,0 ,NULL ); +smp_sigp (1 ,SIGP_INITIAL_CPU_RESET ,0 ,NULL );smp_sigp (1 ,SIGP_STORE_STATUS_AT_ADDRESS , (uintptr_t )status,NULL );report_prefix_push ("clear" );
@@ -316,7 +316,7 @@ static void test_reset(void)smp_sigp (1 ,SIGP_EXTERNAL_CALL ,0 ,NULL );smp_cpu_start (1 , psw); -smp_sigp_retry (1 ,SIGP_CPU_RESET ,0 ,NULL ); +smp_sigp (1 ,SIGP_CPU_RESET ,0 ,NULL );report (smp_cpu_stopped (1 ),"cpu stopped" );set_flag (0 );
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 03/27] s390x: smp: Fix checks for SIGP STOP STORE STATUS
In reply to Claudio ImbrendaFrom: Eric Farman <[email protected]>
In the routine test_stop_store_status(), the "running" part of the test checks a few of the fields in lowcore (to verify the "STORE STATUS" part of the SIGP order), and then ensures that the CPU has stopped. But this is backwards, according to the Principles of Operation:
The addressed CPU performs the stop function, fol- lowed by the store-status operation (see “Store Sta- tus” on page 4-82).
If the CPU were not yet stopped, the contents of the lowcore fields would be unpredictable. It works today because the library functions wait on the stop function, so the CPU is stopped by the time it comes back. Let's first check that the CPU is stopped first, just to be clear.
While here, add the same check to the second part of the test, even though the CPU is explicitly stopped prior to the SIGP.
--- s390x/smp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
s390x/smp.c +2 -1
@@ -98,9 +98,9 @@ static void test_stop_store_status(void) lc->grs_sa[15 ] =0 ;smp_cpu_stop_store_status (1 );mb (); +report (smp_cpu_stopped (1 ),"cpu stopped" );report (lc->prefix_sa == (uint32_t )(uintptr_t )cpu->lowcore,"prefix" );report (lc->grs_sa[15 ],"stack" ); -report (smp_cpu_stopped (1 ),"cpu stopped" );report_prefix_pop ();report_prefix_push ("stopped" );
@@ -108,6 +108,7 @@ static void test_stop_store_status(void) lc->grs_sa[15 ] =0 ;smp_cpu_stop_store_status (1 );mb (); +report (smp_cpu_stopped (1 ),"cpu stopped" );report (lc->prefix_sa == (uint32_t )(uintptr_t )cpu->lowcore,"prefix" );report (lc->grs_sa[15 ],"stack" );report_prefix_pop ();
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 07/27] s390x: Add more tests for MSCH
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
We already have some coverage for MSCH, but there are more cases to test for:
- invalid SCHIB structure. We cover that by setting reserved bits 0, 1, 6 and 7 in the flags of the PMCW.
Older QEMU versions require this bit to always be zero on msch, which is why this test may fail. A fix is available in QEMU master commit 2df59b73e086 ("s390x/css: fix PMCW invalid mask").
- a pointer to an unaligned SCHIB. We cover misalignment by 1 and 2 bytes. Using pointer to valid memory avoids messing up random memory in case of test failures.
Here's the QEMU PMCW invalid mask fix: https://lists.nongnu.org/archive/html/qemu-s390x/2021-12/msg00100.html
--- s390x/css.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+)
s390x/css.c +58 -0
@@ -27,6 +27,8 @@ static int test_device_sid;static struct senseid *senseid;struct ccw1 *ccw; +char alignment_test_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); +static void test_enumerate (void ) { test_device_sid =css_enumerate ();
@@ -331,6 +333,61 @@ static void test_schm_fmt1(void)free_io_mem (mb1,sizeof (struct measurement_block_format1 )); } +static void test_msch (void ) +{ +int invalid_pmcw_flags[] = {0 ,1 ,6 ,7 }; +struct schib test_schib; +uint16_t old_pmcw_flags; +const int align_to =4 ; +int invalid_flag; +int cc; + +if (!test_device_sid) { +report_skip ("No device" ); +return ; + } + + cc =stsch (test_device_sid, &schib); +if (cc) { +report_fail ("stsch: sch %08x failed with cc=%d" , test_device_sid, cc); +return ; + } + +report_prefix_push ("Unaligned" ); +for (int i =1 ; i < align_to; i *=2 ) { +report_prefix_pushf ("%d" , i); + +expect_pgm_int (); +msch (test_device_sid, (struct schib *)(alignment_test_page + i)); +check_pgm_int_code (PGM_INT_CODE_SPECIFICATION ); + +report_prefix_pop (); + } +report_prefix_pop (); + +report_prefix_push ("Invalid SCHIB" ); + old_pmcw_flags = schib.pmcw.flags; +for (int i =0 ; i <ARRAY_SIZE (invalid_pmcw_flags); i++) { + invalid_flag = invalid_pmcw_flags[i]; + +report_prefix_pushf ("PMCW flag bit %d set" , invalid_flag); + + schib.pmcw.flags = old_pmcw_flags |BIT (15 - invalid_flag); +expect_pgm_int (); +msch (test_device_sid, &schib); +check_pgm_int_code (PGM_INT_CODE_OPERAND ); + + cc =stsch (test_device_sid, &test_schib); +report (!cc,"STSCH succeeded" ); +report (!(test_schib.pmcw.flags &BIT (15 - invalid_flag)),"Clear on STSCH" ); + +report_prefix_pop (); + } +report_prefix_pop (); + + schib.pmcw.flags = old_pmcw_flags; +} + static struct { const char *name; void (*func)(void);
@@ -343,6 +400,7 @@ static struct { { "measurement block (schm)", test_schm }, { "measurement block format0", test_schm_fmt0 }, { "measurement block format1", test_schm_fmt1 }, + { "msch", test_msch }, { NULL, NULL } };
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 02/27] s390x: smp: Test SIGP RESTART against stopped CPU
In reply to Claudio ImbrendaFrom: Eric Farman <[email protected]>
test_restart() makes two smp_cpu_restart() calls against CPU 1. It claims to perform both of them against running (operating) CPUs, but the first invocation tries to achieve this by calling smp_cpu_stop() to CPU 0. This will be rejected by the library.
Let's fix this by making the first restart operate on a stopped CPU, to ensure it gets test coverage instead of relying on other callers.
--- s390x/smp.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
s390x/smp.c +2 -6
@@ -50,10 +50,6 @@ static void test_start(void)report_pass ("start" ); } -/* -* Does only test restart when the target is running. -* The other tests do restarts when stopped multiple times already. -*/ static void test_restart (void ) {struct cpu *cpu =smp_cpu_from_idx (1 );
@@ -62,8 +58,8 @@ static void test_restart(void) lc->restart_new_psw.mask =extract_psw_mask (); lc->restart_new_psw.addr = (unsigned long )test_func; -/* Make sure cpu is running */ -smp_cpu_stop (0 ); +/* Make sure cpu is stopped */ +smp_cpu_stop (1 );set_flag (0 );smp_cpu_restart (1 );wait_for_flag ();
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 09/27] s390x: Add sck tests
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
SCK updates the guest's TOD clock. It needs to be intercepted, hence we should have some tests for it:
- its operand must be 8-byte aligned. We test for 1, 2 and 4 byte misalignment.
- it should actually update the clock value. As guests are unable to stop their clock, we can only check the clock value is at least higher than the value we set.
- it is a privileged call, so expect it to fail when in problem state. We also test the clock value is not changed in this case. We do so by first adjusting it (privileged) to a high value. We then attempt, in nonprivileged mode, to set the clock to a comparatively small value. We can then store the clock value and test its value is strictly higher than the high value we set previously.
SCK is currently broken in QEMU TCG. A fix was posted upstream ("s390x: sck:
load into a temporary not into in1"):
https://lore.kernel.org/qemu-devel/[email protected]/
--- s390x/Makefile | 1 + s390x/sck.c | 136 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 3 + 3 files changed, 140 insertions(+) create mode 100644 s390x/sck.c
s390x/Makefile +1 -0
@@ -17,6 +17,7 @@ tests += $(TEST_DIR)/stsi.elf tests += $(TEST_DIR)/skrf.elf tests += $(TEST_DIR)/smp.elf tests += $(TEST_DIR)/sclp.elf +tests += $(TEST_DIR)/sck.elf tests += $(TEST_DIR)/css.elf tests += $(TEST_DIR)/uv-guest.elf tests += $(TEST_DIR)/sie.elf
s390x/sck.c new file +136 -0
136 lines not on this page · raw message
s390x/unittests.cfg +3 -0
@@ -136,3 +136,6 @@ file = firq.elf timeout = 20 extra_params = -smp 1,maxcpus=3 -cpu qemu -device qemu-s390x-cpu,core-id=2 -device qemu-s390x-cpu,core-id=1 accel = tcg + +[sck] +file = sck.elf
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 10/27] s390x: Add tests for STCRW
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
The test consists of two parts: First a simple check to ensure we enforce an aligned address. We test misalignment by 1 and 2 bytes.
The second part tests the handling of pending Channel Reports (CR). We first assume no CR is initally pending and check STCRW returns accordingly. Then, we generate a CR by resetting a Channel Path using RCHP and make sure this results in exactly one CRW being generated which has a Reporting-Source Code (RSC) corresponding to the Channel Path facility.
--- lib/s390x/css.h | 17 ++++++++++ lib/s390x/css_lib.c | 60 +++++++++++++++++++++++++++++++++ s390x/css.c | 82 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+)
lib/s390x/css.h +17 -0
@@ -266,6 +266,20 @@ static inline int rchp(unsigned long chpid)return cc; } +static inline int stcrw (uint32_t *crw) +{ +int cc; + + asmvolatile ( +" stcrw %[crw]\n" +" ipm %[cc]\n" +" srl %[cc],28" + : [cc]"=d" (cc) + : [crw]"Q" (*crw) + :"cc" ,"memory" ); +return cc; +} +/* Debug functions */ char *dump_pmcw_flags (uint16_t f);char *dump_scsw_flags (uint32_t f);
@@ -294,6 +308,9 @@ int css_residual_count(unsigned int schid);void enable_io_isc (uint8_t isc);int wait_and_check_io_completion (int schid); +int css_find_installed_chpid (int sid,uint8_t *chpid_out); +int css_generate_crw (int sid); +/* * CHSC definitions */
lib/s390x/css_lib.c +60 -0
63 lines not on this page · raw message
s390x/css.c +82 -0
94 lines not on this page · raw message
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 13/27] s390x: Add tests for TSCH
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
TSCH has two special cases which need to be tested:
- unaligned address. We test for misalignment by 1 and 2 bytes.
- channel not operational
- bit 47 in SID not set
--- s390x/css.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
s390x/css.c +36 -0
@@ -581,6 +581,41 @@ static void test_pmcw_bit5(void)report_prefix_pop (); } +static void test_tsch (void ) +{ +const int align_to =4 ; +struct irb irb; +int cc; + +if (!test_device_sid) { +report_skip ("No device" ); +return ; + } + +report_prefix_push ("Unaligned" ); +for (int i =1 ; i < align_to; i *=2 ) { +report_prefix_pushf ("%d" , i); + +expect_pgm_int (); +tsch (test_device_sid, (struct irb *)(alignment_test_page + i)); +check_pgm_int_code (PGM_INT_CODE_SPECIFICATION ); + +report_prefix_pop (); + } +report_prefix_pop (); + +report_prefix_push ("Invalid subchannel number" ); + cc =tsch (0x0001ffff , &irb); +report (cc ==3 ,"Channel not operational" ); +report_prefix_pop (); + +report_prefix_push ("Bit 47 in SID is zero" ); +expect_pgm_int (); +tsch (0x0000ffff , &irb); +check_pgm_int_code (PGM_INT_CODE_OPERAND ); +report_prefix_pop (); +} + static struct { const char *name; void (*func)(void);
@@ -598,6 +633,7 @@ static struct { { "ssch", test_ssch }, { "stsch", test_stsch }, { "pmcw bit 5 ignored", test_pmcw_bit5 }, + { "tsch", test_tsch }, { NULL, NULL } };
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 11/27] s390x: Add more tests for SSCH
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
We already have some coverage of SSCH due to its use in start_ccw1_chain() in css_lib, but two more cases deserve our attention:
- unaligned operand address. We check for misalignment by 1 and 2 bytes.
- an invalid ORB structure.
--- s390x/css.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
s390x/css.c +33 -0
@@ -469,6 +469,38 @@ static void test_stcrw(void)report_prefix_pop (); } +static void test_ssch (void ) +{ +const int align_to =4 ; +struct orb orb; + +if (!test_device_sid) { +report_skip ("No device" ); +return ; + } + +report_prefix_push ("Unaligned" ); +for (int i =1 ; i < align_to; i *=2 ) { +report_prefix_pushf ("%d" , i); + +expect_pgm_int (); +ssch (test_device_sid, (struct orb *)(alignment_test_page + i)); +check_pgm_int_code (PGM_INT_CODE_SPECIFICATION ); + +report_prefix_pop (); + } +report_prefix_pop (); + +report_prefix_push ("Invalid ORB" ); + +memset (&orb,0xff ,sizeof (orb)); +expect_pgm_int (); +ssch (test_device_sid, &orb); +check_pgm_int_code (PGM_INT_CODE_OPERAND ); + +report_prefix_pop (); +} + static struct { const char *name; void (*func)(void);
@@ -483,6 +515,7 @@ static struct { { "measurement block format1", test_schm_fmt1 }, { "msch", test_msch }, { "stcrw", test_stcrw }, + { "ssch", test_ssch }, { NULL, NULL } };
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 12/27] s390x: Add more tests for STSCH
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
css_lib extensively uses STSCH, but two more cases deserve their own tests:
- unaligned address for SCHIB. We check for misalignment by 1 and 2 bytes.
- channel not operational
- bit 47 in SID not set
- bit 5 of PMCW flags.
As per the principles of operation, bit 5 of the PMCW flags shall be ignored by msch and always stored as zero by stsch.
Older QEMU versions require this bit to always be zero on msch, which is why this test may fail. A fix is available in QEMU master commit 2df59b73e086 ("s390x/css: fix PMCW invalid mask").
Here's the QEMU PMCW invalid mask fix: https://lists.nongnu.org/archive/html/qemu-s390x/2021-12/msg00100.html
--- s390x/css.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+)
s390x/css.c +82 -0
@@ -501,6 +501,86 @@ static void test_ssch(void)report_prefix_pop (); } +static void test_stsch (void ) +{ +const int align_to =4 ; +struct schib schib; +int cc; + +if (!test_device_sid) { +report_skip ("No device" ); +return ; + } + +report_prefix_push ("Unaligned" ); +for (int i =1 ; i < align_to; i *=2 ) { +report_prefix_pushf ("%d" , i); + +expect_pgm_int (); +stsch (test_device_sid, (struct schib *)(alignment_test_page + i)); +check_pgm_int_code (PGM_INT_CODE_SPECIFICATION ); + +report_prefix_pop (); + } +report_prefix_pop (); + +report_prefix_push ("Invalid subchannel number" ); + cc =stsch (0x0001ffff , &schib); +report (cc ==3 ,"Channel not operational" ); +report_prefix_pop (); + +/* +* No matter if multiple-subchannel-set facility is installed, bit 47 +* always needs to be 1. +*/ +report_prefix_push ("Bit 47 in SID is zero" ); +expect_pgm_int (); +stsch (0x0000ffff , &schib); +check_pgm_int_code (PGM_INT_CODE_OPERAND ); +report_prefix_pop (); +} + +/* +* According to architecture MSCH does ignore bit 5 of the second word +* but STSCH will store bit 5 as zero. +*/ +static void test_pmcw_bit5 (void ) +{ +int cc; +uint16_t old_pmcw_flags; + + cc =stsch (test_device_sid, &schib); +if (cc) { +report_fail ("stsch: sch %08x failed with cc=%d" , test_device_sid, cc); +return ; + } + old_pmcw_flags = schib.pmcw.flags; + +report_prefix_push ("Bit 5 set" ); + + schib.pmcw.flags = old_pmcw_flags |BIT (15 -5 ); + cc =msch (test_device_sid, &schib); +report (!cc,"MSCH cc == 0" ); + + cc =stsch (test_device_sid, &schib); +report (!cc,"STSCH cc == 0" ); +report (!(schib.pmcw.flags &BIT (15 -5 )),"STSCH PMCW Bit 5 is clear" ); + +report_prefix_pop (); + +report_prefix_push ("Bit 5 clear" ); + + schib.pmcw.flags = old_pmcw_flags & ~BIT (15 -5 ); + cc =msch (test_device_sid, &schib); +report (!cc,"MSCH cc == 0" ); + + cc =stsch (test_device_sid, &schib); +report (!cc,"STSCH cc == 0" ); +report (!(schib.pmcw.flags &BIT (15 -5 )),"STSCH PMCW Bit 5 is clear" ); + +report_prefix_pop (); +} + static struct { const char *name; void (*func)(void);
@@ -516,6 +596,8 @@ static struct { { "msch", test_msch }, { "stcrw", test_stcrw }, { "ssch", test_ssch }, + { "stsch", test_stsch }, + { "pmcw bit 5 ignored", test_pmcw_bit5 }, { NULL, NULL } };
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 16/27] s390x: smp: stop already stopped CPU
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
As per the PoP, the SIGP STOP order is only effective when the CPU is in the operating state. Hence, we should have a test which tries to stop an already stopped CPU.
Even though the SIGP order might be processed asynchronously, we assert the CPU stays stopped.
--- s390x/smp.c | 5 +++++ 1 file changed, 5 insertions(+)
s390x/smp.c +5 -0
@@ -140,6 +140,11 @@ static void test_stop(void)report (!rc,"return code" );report (smp_cpu_stopped (1 ),"cpu stopped" ); +report_prefix_push ("stop stopped CPU" ); +report (!smp_cpu_stop (1 ),"STOP succeeds" ); +report (smp_cpu_stopped (1 ),"CPU is stopped" ); +report_prefix_pop (); +report_prefix_pop (); }
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 15/27] s390x: smp: add tests for several invalid SIGP orders
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
Add tests with for intercepted SIGP orders with invalid values:
- SIGP_STOP with invalid CPU address
- SIGP_START with invalid CPU address
- SIGP_CPU_RESET with invalid CPU address
- SIGP_STOP_AND_STORE_STATUS with invalid CPU address
- SIGP_STORE_STATUS_AT_ADDRESS with invalid CPU address
- invalid order
- invalid order with invalid CPU address
--- s390x/smp.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
s390x/smp.c +48 -0
@@ -19,6 +19,47 @@#include <alloc_page.h> static int testflag =0 ; +#define INVALID_CPU_ADDRESS -4711 +#define INVALID_ORDER_CODE 0xFF +struct sigp_invalid_cases { +int order; +char message[100 ]; +}; +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" }, + {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" }, +}; +static const struct sigp_invalid_cases cases_valid_cpu_addr[] = { + {INVALID_ORDER_CODE ,"invalid order code" }, +}; + +static void test_invalid (void ) +{ +const struct sigp_invalid_cases *c; +uint32_t status; +int cc; +int i; + +report_prefix_push ("invalid parameters" ); + +for (i =0 ; i <ARRAY_SIZE (cases_invalid_cpu_addr); i++) { + c = &cases_invalid_cpu_addr[i]; + cc =sigp (INVALID_CPU_ADDRESS , c->order,0 , &status); +report (cc ==3 , c->message); + } + +for (i =0 ; i <ARRAY_SIZE (cases_valid_cpu_addr); i++) { + c = &cases_valid_cpu_addr[i]; + cc =smp_sigp (1 , c->order,0 , &status); +report (cc ==1 , c->message); + } + +report_prefix_pop (); +}static void wait_for_flag (void ) {
@@ -136,10 +177,16 @@ static void test_store_status(void) {struct cpu_status *status =alloc_pages_flags (1 ,AREA_DMA31 );uint32_t r; +int cc;report_prefix_push ("store status at address" );memset (status,0 ,PAGE_SIZE *2 ); +report_prefix_push ("invalid CPU address" ); + cc =sigp (INVALID_CPU_ADDRESS ,SIGP_STORE_STATUS_AT_ADDRESS , (uintptr_t )status, &r); +report (cc ==3 ,"returned with CC = 3" ); +report_prefix_pop (); +report_prefix_push ("running" );smp_cpu_restart (1 );smp_sigp (1 ,SIGP_STORE_STATUS_AT_ADDRESS , (uintptr_t )status, &r);
@@ -344,6 +391,7 @@ int main(void)smp_cpu_stop (1 );test_start (); +test_invalid ();test_restart ();test_stop ();test_stop_store_status ();
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 14/27] s390x: Add EPSW test
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
EPSW is only intercepted in certain cases. One of these cases is if we have a CRW pending and machine check interrupts are masked. This can be achieved by issuing a RCHP on a valid channel path. This is why we need the CSS lib and an IO device in this test and hence need to skip it when not running under QEMU.
Three special cases deserve our attention:
- upper 32 bits of both operands are never modified,
- second operand is not modified if it is zero.
- when both operands are zero, bits 0-11 and 13-31 of the PSW are stored in r0.
We also verify we get the correct contents when the second operand is zero. To do so, we save the data stored at the first operand in the first case as a reference. As we don't mess with the PSW, the only thing that might change is the Condition Code (CC) due to some instruction in between, so we zero it out using zero_out_cc_from_epsw_op1().
This test must be fenced when running in non-QEMU.
--- s390x/Makefile | 1 + s390x/epsw.c | 113 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 ++ 3 files changed, 118 insertions(+) create mode 100644 s390x/epsw.c
s390x/Makefile +1 -0
@@ -27,6 +27,7 @@ tests += $(TEST_DIR)/edat.elf tests += $(TEST_DIR)/mvpg-sie.elf tests += $(TEST_DIR)/spec_ex-sie.elf tests += $(TEST_DIR)/firq.elf +tests += $(TEST_DIR)/epsw.elf pv-tests += $(TEST_DIR)/pv-diags.elf
s390x/epsw.c new file +113 -0
113 lines not on this page · raw message
s390x/unittests.cfg +4 -0
@@ -139,3 +139,7 @@ accel = tcg [sck] file = sck.elf + +[epsw] +file = epsw.elf +extra_params = -device virtio-net-ccw
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 17/27] s390x: smp: add tests for SET_PREFIX
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
We cover the following cases:
- running CPU
- illegal CPU id
The order should be rejected in both cases.
--- s390x/smp.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)
s390x/smp.c +73 -0
@@ -37,6 +37,8 @@ static const struct sigp_invalid_cases cases_valid_cpu_addr[] = { { INVALID_ORDER_CODE, "invalid order code" }, }; +static uint32_t cpu1_prefix; +static void test_invalid (void ) {const struct sigp_invalid_cases *c;
@@ -213,6 +215,76 @@ static void test_store_status(void)report_prefix_pop (); } +static void loop (void ) +{ +while (1 ) + ; +} + +static void stpx_and_set_flag (void ) +{ + asmvolatile ( +" stpx %[prefix]\n" + : [prefix]"=Q" (cpu1_prefix) + : + : + ); + +set_flag (1 ); +} + +static void test_set_prefix (void ) +{ +struct lowcore *new_lc =alloc_pages_flags (1 ,AREA_DMA31 ); +struct cpu *cpu1 =smp_cpu_from_idx (1 ); +uint32_t status =0 ; +struct psw new_psw; +int cc; + +report_prefix_push ("set prefix" ); + +assert (new_lc); + +memcpy (new_lc, cpu1->lowcore,sizeof (struct lowcore )); + new_lc->restart_new_psw.addr = (unsigned long )loop; + +report_prefix_push ("running" ); +set_flag (0 ); + new_psw.addr = (unsigned long )stpx_and_set_flag; + new_psw.mask =extract_psw_mask (); +smp_cpu_start (1 , new_psw); +wait_for_flag (); + cpu1_prefix =0xFFFFFFFF ; + + cc =smp_sigp (1 ,SIGP_SET_PREFIX , (unsigned long )new_lc, &status); +report (cc ==1 ,"CC = 1" ); +report (status ==SIGP_STATUS_INCORRECT_STATE ,"status = INCORRECT_STATE" ); + +/* +* If the prefix of the other CPU was changed it will enter an endless +* loop. Otherwise, it should eventually set the flag. +*/ +smp_cpu_stop (1 ); +set_flag (0 ); +smp_cpu_restart (1 ); +wait_for_flag (); +report (cpu1_prefix == (uint64_t )cpu1->lowcore,"prefix unchanged" ); + +report_prefix_pop (); + +report_prefix_push ("invalid CPU address" ); + + cc =sigp (INVALID_CPU_ADDRESS ,SIGP_SET_PREFIX , (unsigned long )new_lc, &status); +report (cc ==3 ,"CC = 3" ); + +report_prefix_pop (); + +free_pages (new_lc); + +report_prefix_pop (); + +} +static void ecall (void ) {unsigned long mask;
@@ -401,6 +473,7 @@ int main(void)test_stop ();test_stop_store_status ();test_store_status (); +test_set_prefix ();test_ecall ();test_emcall ();test_sense_running ();
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 20/27] s390x: add TPROT tests
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
Add tests for TEST PROTECTION. We cover the following cases:
- page is read/write
- page is readonly
- lowcore protection
- page is not present
- translation specification exception
We don't cover storage keys and the case where the page can be neither read nor written right now.
This test mainly applies to the TCG case.
--- s390x/Makefile | 1 + s390x/tprot.c | 108 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 3 ++ 3 files changed, 112 insertions(+) create mode 100644 s390x/tprot.c
s390x/Makefile +1 -0
@@ -3,6 +3,7 @@ tests += $(TEST_DIR)/intercept.elf tests += $(TEST_DIR)/emulator.elf tests += $(TEST_DIR)/sieve.elf tests += $(TEST_DIR)/sthyi.elf +tests += $(TEST_DIR)/tprot.elf tests += $(TEST_DIR)/skey.elf tests += $(TEST_DIR)/diag10.elf tests += $(TEST_DIR)/diag308.elf
s390x/tprot.c new file +108 -0
108 lines not on this page · raw message
s390x/unittests.cfg +3 -0
@@ -143,3 +143,6 @@ file = sck.elf [epsw] file = epsw.elf extra_params = -device virtio-net-ccw + +[tprot] +file = tprot.elf
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 18/27] s390x: smp: add test for EMERGENCY_SIGNAL with invalid CPU address
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
In this case, we expect the order to be rejected.
--- s390x/smp.c | 9 +++++++++ 1 file changed, 9 insertions(+)
s390x/smp.c +9 -0
@@ -338,6 +338,7 @@ static void emcall(void)static void test_emcall (void ) {struct psw psw; +int cc; psw.mask =extract_psw_mask (); psw.addr = (unsigned long )emcall;
@@ -350,6 +351,14 @@ static void test_emcall(void)smp_sigp (1 ,SIGP_EMERGENCY_SIGNAL ,0 ,NULL );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 (); }
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 19/27] s390x: smp: add tests for CONDITIONAL EMERGENCY
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
Add a test for the conditional emergency signal.
We cover the following cases:
- invalid CPU address. Should lead to the order being rejected.
- the order is accepted and an emergency signal is delivered. We make sure this is the case by disabling the CPU's PSW for IO interruptions.
Note we intentionally don't cover the case where the signal isn't delivered. As per the PoP, implementations are allowed to make the signal an unconditional one when the condition determination is precluded.
This test is unsupported under PV.
--- s390x/smp.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
s390x/smp.c +43 -0
@@ -16,6 +16,7 @@#include <asm/sigp.h> #include <smp.h> +#include <uv.h> #include <alloc_page.h> static int testflag =0 ;
@@ -362,6 +363,47 @@ static void test_emcall(void)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; + } + +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 ); + +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 ) {report_prefix_push ("sense_running" );
@@ -485,6 +527,7 @@ int main(void)test_set_prefix ();test_ecall ();test_emcall (); +test_cond_emcall ();test_sense_running ();test_reset ();test_reset_initial ();
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 21/27] s390x: stsi: check zero and ignored bits in r0 and r1
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
We previously only checked for two zero bits, one in r0 and one in r1. Let's check all the bits which must be zero and which are ignored to extend the coverage.
--- s390x/stsi.c | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-)
s390x/stsi.c +32 -10
@@ -9,6 +9,7 @@*/ #include <libcflat.h> +#include <bitops.h> #include <asm/page.h> #include <asm/asm-offsets.h> #include <asm/interrupt.h>
@@ -19,19 +20,40 @@ static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE * 2)));static void test_specs (void ) { +int i; +int cc; +report_prefix_push ("specification" ); -report_prefix_push ("inv r0" ); -expect_pgm_int (); -stsi (pagebuf,0 ,1 <<8 ,0 ); -check_pgm_int_code (PGM_INT_CODE_SPECIFICATION ); -report_prefix_pop (); +for (i =36 ; i <=55 ; i++) { +report_prefix_pushf ("set invalid r0 bit %d" , i); +expect_pgm_int (); +stsi (pagebuf,0 ,BIT (63 - i),0 ); +check_pgm_int_code (PGM_INT_CODE_SPECIFICATION ); +report_prefix_pop (); + } -report_prefix_push ("inv r1" ); -expect_pgm_int (); -stsi (pagebuf,1 ,0 ,1 <<16 ); -check_pgm_int_code (PGM_INT_CODE_SPECIFICATION ); -report_prefix_pop (); +for (i =32 ; i <=47 ; i++) { +report_prefix_pushf ("set invalid r1 bit %d" , i); +expect_pgm_int (); +stsi (pagebuf,1 ,0 ,BIT (63 - i)); +check_pgm_int_code (PGM_INT_CODE_SPECIFICATION ); +report_prefix_pop (); + } + +for (i =0 ; i <32 ; i++) { +report_prefix_pushf ("r0 bit %d ignored" , i); + cc =stsi (pagebuf,3 ,2 |BIT (63 - i),2 ); +report (!cc,"CC = 0" ); +report_prefix_pop (); + } + +for (i =0 ; i <32 ; i++) { +report_prefix_pushf ("r1 bit %d ignored" , i); + cc =stsi (pagebuf,3 ,2 ,2 |BIT (63 - i)); +report (!cc,"CC = 0" ); +report_prefix_pop (); + }report_prefix_push ("unaligned" );expect_pgm_int ();
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 22/27] s390x: snippets: c: Load initial cr0
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
As soon as we use C we need to set the AFP bit in cr0 so we can use all fprs.
--- s390x/snippets/c/cstart.S | 6 ++++++ 1 file changed, 6 insertions(+)
s390x/snippets/c/cstart.S +6 -0
@@ -12,6 +12,8 @@ .section .init .globl start start: + larl %r1, initial_cr0 + lctlg %c0, %c0, 0(%r1) /* XOR all registers with themselves to clear them fully. */ .irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 xgr \i,\i
@@ -34,3 +36,7 @@ exit: /* For now let's only use cpu 0 in snippets so this will always work. */ xgr %r0, %r0 sigp %r2, %r0, SIGP_STOP + +initial_cr0: + /* enable AFP-register control, so FP regs (+BFP instr) can be used */ + .quad 0x0000000000040000
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 27/27] lib: s390x: stidp wrapper and move get_machine_id
In reply to Claudio ImbrendaRefactor get_machine_id in arch_def.h into a simple wrapper around stidp, add back get_machine_id in hardware.h using the stidp wrapper.
--- lib/s390x/asm/arch_def.h | 4 +--- lib/s390x/hardware.h | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-)
lib/s390x/asm/arch_def.h +1 -3
@@ -219,13 +219,11 @@ static inline unsigned short stap(void)return cpu_address; } -static inline uint16_t get_machine_id (void ) +static inline uint64_t stidp (void ) {uint64_t cpuid; asmvolatile ("stidp %0" :"=Q" (cpuid)); - cpuid = cpuid >>16 ; - cpuid &=0xffff ;return cpuid; }
lib/s390x/hardware.h +5 -0
@@ -25,6 +25,11 @@ enum s390_host {enum s390_host detect_host (void ); +static inline uint16_t get_machine_id (void ) +{ +return stidp () >>16 ; +} +static inline bool host_is_tcg (void ) {return detect_host () ==HOST_IS_TCG ;
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 26/27] lib: s390x: functions for machine models
In reply to Claudio Imbrenda* move existing macros for machine models to hardware.h
* add machine_is_* functions
--- lib/s390x/asm/arch_def.h | 3 --- lib/s390x/hardware.h | 10 ++++++++++ s390x/uv-host.c | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-)
lib/s390x/asm/arch_def.h +0 -3
@@ -219,9 +219,6 @@ static inline unsigned short stap(void)return cpu_address; } -#define MACHINE_Z15A 0x8561 -#define MACHINE_Z15B 0x8562 -static inline uint16_t get_machine_id (void ) {uint64_t cpuid;
lib/s390x/hardware.h +10 -0
@@ -13,6 +13,9 @@#define _S390X_HARDWARE_H_#include <asm/arch_def.h> +#define MACHINE_Z15 0x8561 +#define MACHINE_Z15T02 0x8562 +enum s390_host {HOST_IS_UNKNOWN ,HOST_IS_LPAR ,
@@ -37,4 +40,11 @@ static inline bool host_is_lpar(void) return detect_host() == HOST_IS_LPAR; } +static inline bool machine_is_z15 (void ) +{ +uint16_t machine =get_machine_id (); + +return machine ==MACHINE_Z15 || machine ==MACHINE_Z15T02 ; +} +#endif /* _S390X_HARDWARE_H_ */
s390x/uv-host.c +2 -2
@@ -9,6 +9,7 @@*/ #include <libcflat.h> +#include <hardware.h> #include <alloc.h> #include <vmalloc.h> #include <sclp.h>
@@ -111,7 +112,6 @@ static void test_config_destroy(void)static void test_cpu_destroy (void ) {int rc; -uint16_t machineid =get_machine_id ();struct uv_cb_nodata uvcb = { .header.len =sizeof (uvcb), .header.cmd =UVC_CMD_DESTROY_SEC_CPU ,
@@ -126,7 +126,7 @@ static void test_cpu_destroy(void) "hdr invalid length"); uvcb.header.len +=8 ; -if (machineid !=MACHINE_Z15A && machineid !=MACHINE_Z15B ) { +if (!machine_is_z15 ()) { uvcb.handle +=1 ; rc =uv_call (0 , (uint64_t )&uvcb);report (rc ==1 && uvcb.header.rc ==UVC_RC_INV_CHANDLE ,"invalid handle" );
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 25/27] lib: s390x: rename and refactor vm.[ch]
In reply to Claudio ImbrendaRefactor and rename vm.[ch] to hardware.[ch]
* Rename vm.[ch] to hardware.[ch]
* Consolidate all detection functions into detect_host, which returns what host system the test is running on
* Rename vm_is_* functions to host_is_*, which are then just wrappers around detect_host
--- s390x/Makefile | 2 +- lib/s390x/hardware.h | 40 +++++++++++++++++++ lib/s390x/vm.h | 15 -------- lib/s390x/hardware.c | 69 +++++++++++++++++++++++++++++++++ lib/s390x/vm.c | 92 -------------------------------------------- s390x/cpumodel.c | 4 +- s390x/epsw.c | 4 +- s390x/mvpg.c | 4 +- 8 files changed, 116 insertions(+), 114 deletions(-) create mode 100644 lib/s390x/hardware.h delete mode 100644 lib/s390x/vm.h create mode 100644 lib/s390x/hardware.c delete mode 100644 lib/s390x/vm.c
s390x/Makefile +1 -1
@@ -81,7 +81,7 @@ cflatobjs += lib/s390x/sclp-console.o cflatobjs += lib/s390x/interrupt.o cflatobjs += lib/s390x/mmu.o cflatobjs += lib/s390x/smp.o -cflatobjs += lib/s390x/vm.o +cflatobjs += lib/s390x/hardware.o cflatobjs += lib/s390x/css_dump.o cflatobjs += lib/s390x/css_lib.o cflatobjs += lib/s390x/malloc_io.o
lib/s390x/hardware.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Functions to retrieve information about the host system. +* +* Copyright (c) 2020 Red Hat Inc +* Copyright 2022 IBM Corp. +* +* Authors: +* Claudio Imbrenda <[email protected]> +*/ + +#ifndef _S390X_HARDWARE_H_ +#define _S390X_HARDWARE_H_ +#include <asm/arch_def.h> + +enum s390_host { +HOST_IS_UNKNOWN , +HOST_IS_LPAR , +HOST_IS_KVM , +HOST_IS_TCG +}; + +enum s390_host detect_host (void ); + +static inline bool host_is_tcg (void ) +{ +return detect_host () ==HOST_IS_TCG ; +} + +static inline bool host_is_kvm (void ) +{ +return detect_host () ==HOST_IS_KVM ; +} + +static inline bool host_is_lpar (void ) +{ +return detect_host () ==HOST_IS_LPAR ; +} + +#endif /* _S390X_HARDWARE_H_ */
lib/s390x/vm.h deleted +0 -15
@@ -1,15 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* -* Functions to retrieve VM-specific information -* -* Copyright (c) 2020 Red Hat Inc -*/ - -#ifndef _S390X_VM_H_ -#define _S390X_VM_H_ - -bool vm_is_tcg (void ); -bool vm_is_kvm (void ); -bool vm_is_lpar (void ); - -#endif /* _S390X_VM_H_ */
lib/s390x/hardware.c new file +69 -0
69 lines not on this page · raw message
lib/s390x/vm.c deleted +0 -92
92 lines not on this page · raw message
s390x/cpumodel.c +2 -2
@@ -10,7 +10,7 @@*/ #include <asm/facility.h> -#include <vm.h> +#include <hardware.h> #include <sclp.h> #include <uv.h> #include <asm/uv.h>
@@ -118,7 +118,7 @@ int main(void)for (i =0 ; i <ARRAY_SIZE (dep); i++) {report_prefix_pushf ("%d implies %d" , dep[i].facility, dep[i].implied);if (test_facility (dep[i].facility)) { -report_xfail (dep[i].expected_tcg_fail &&vm_is_tcg (), +report_xfail (dep[i].expected_tcg_fail &&host_is_tcg (),test_facility (dep[i].implied),"implication not correct" ); }else {
s390x/epsw.c +2 -2
@@ -9,7 +9,7 @@*/ #include <libcflat.h> #include <css.h> -#include <vm.h> +#include <hardware.h> static uint32_t zero_out_cc_from_epsw_op1 (uint32_t epsw_op1) {
@@ -97,7 +97,7 @@ static void test_epsw(void)int main (int argc,char **argv) { -if (!vm_is_kvm () && !vm_is_tcg ()) { +if (!host_is_kvm () && !host_is_tcg ()) {report_skip ("Not running under QEMU" ); goto done; }
s390x/mvpg.c +2 -2
@@ -20,7 +20,7 @@#include <smp.h> #include <alloc_page.h> #include <bitops.h> -#include <vm.h> +#include <hardware.h> /* Used to build the appropriate test values for register 0 */ #define KFC (x) ((x) << 10)
@@ -251,7 +251,7 @@ static void test_mmu_prot(void) fresh +=PAGE_SIZE ;/* Known issue in TCG: CCO flag is not honoured */ -if (vm_is_tcg ()) { +if (host_is_tcg ()) {report_prefix_push ("TCG" );report_skip ("destination invalid" );report_skip ("source invalid" );
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 23/27] s390x: remove spurious includes
In reply to Claudio ImbrendaRemove unused includes of vm.h
--- s390x/mvpg-sie.c | 1 - s390x/pv-diags.c | 1 - s390x/spec_ex-sie.c | 1 - 3 files changed, 3 deletions(-)
s390x/mvpg-sie.c +0 -1
@@ -16,7 +16,6 @@#include <asm/facility.h> #include <asm/mem.h> #include <alloc_page.h> -#include <vm.h> #include <sclp.h> #include <sie.h> #include <snippet.h>
s390x/pv-diags.c +0 -1
@@ -19,7 +19,6 @@#include <asm/sigp.h> #include <smp.h> #include <alloc_page.h> -#include <vm.h> #include <vmalloc.h> #include <sclp.h> #include <snippet.h>
s390x/spec_ex-sie.c +0 -1
@@ -11,7 +11,6 @@#include <asm/page.h> #include <asm/arch_def.h> #include <alloc_page.h> -#include <vm.h> #include <sie.h> #include <snippet.h>
Signature · 1 line
2.34.1
[kvm-unit-tests GIT PULL 24/27] s390x: skey: remove check for old z/VM version
In reply to Claudio ImbrendaRemove the check for z/VM 6.x, since it is not needed anymore.
--- s390x/skey.c | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-)
s390x/skey.c +4 -33
@@ -65,33 +65,9 @@ static void test_set(void) "set key test"); } -/* Returns true if we are running under z/VM 6.x */ -static bool check_for_zvm6 (void ) -{ -int dcbt;/* Descriptor block count */ -int nr; -static const unsigned char zvm6[] = { -/* This is "z/VM 6" in EBCDIC */ -0xa9 ,0x61 ,0xe5 ,0xd4 ,0x40 ,0x40 ,0x40 ,0x40 ,0xf6 - }; - -if (stsi (pagebuf,3 ,2 ,2 )) -return false; - - dcbt = pagebuf[31 ] &0xf ; - -for (nr =0 ; nr < dcbt; nr++) { -if (!memcmp (&pagebuf[32 + nr *64 +24 ], zvm6,sizeof (zvm6))) -return true; - } - -return false; -} -static void test_priv (void ) {union skey skey; -bool is_zvm6 =check_for_zvm6 ();memset (pagebuf,0 ,PAGE_SIZE *2 );report_prefix_push ("privileged" );
@@ -106,15 +82,10 @@ static void test_priv(void)report (skey.str.acc !=3 ,"skey did not change on exception" );report_prefix_push ("iske" ); -if (is_zvm6) { -/* There is a known bug with z/VM 6, so skip the test there */ -report_skip ("not working on z/VM 6" ); - }else { -expect_pgm_int (); -enter_pstate (); -get_storage_key (pagebuf); -check_pgm_int_code (PGM_INT_CODE_PRIVILEGED_OPERATION ); - } +expect_pgm_int (); +enter_pstate (); +get_storage_key (pagebuf); +check_pgm_int_code (PGM_INT_CODE_PRIVILEGED_OPERATION );report_prefix_pop ();report_prefix_pop ();
Signature · 1 line
2.34.1