New s390x kvm-unit-tests
Hi Paolo, hi Radim,
the following changes since commit 5eb7ccf658f29642ca6c197fd086f4da0d8d8a73:
x86: VMX: INVEPT after modifying PA mapping in ept_untwiddle (2019-09-11 17:45:28 +0200)
are available in the Git repository at:
https://gitlab.com/huth/kvm-unit-tests.git tags/s390x-2019-09-18
for you to fetch changes up to 47df95c747e1c46e7bfb524e734d98a7d9757cb1:
s390x: Add storage key removal facility (2019-09-18 13:48:09 +0200)
----------------------------------------------------------------
New s390x kvm-unit-tests from Janosch Frank
----------------------------------------------------------------
Janosch Frank (9):
s390x: Support PSW restart boot
s390x: Diag288 test
s390x: Move stsi to library
s390x: STSI tests
s390x: Add diag308 subcode 0 testing
s390x: Move pfmf to lib and make address void
s390x: Storage key library functions now take void ptr addresses
s390x: Bump march to zEC12
s390x: Add storage key removal facilitylib/s390x/asm/arch_def.h | 17 +++++++ lib/s390x/asm/mem.h | 40 ++++++++++++--- s390x/Makefile | 5 +- s390x/cstart64.S | 27 ++++++++++ s390x/diag288.c | 114 +++++++++++++++++++++++++++++++++++++++++ s390x/diag308.c | 31 ++++-------- s390x/flat.lds | 14 ++++-- s390x/pfmf.c | 71 +++++++++----------------- s390x/skey.c | 47 ++++++----------- s390x/skrf.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++ s390x/stsi.c | 84 +++++++++++++++++++++++++++++++ s390x/unittests.cfg | 7 +++ 12 files changed, 475 insertions(+), 110 deletions(-) create mode 100644 s390x/diag288.c create mode 100644 s390x/skrf.c create mode 100644 s390x/stsi.c
[kvm-unit-tests PULL 1/9] s390x: Support PSW restart boot
From: Janosch Frank <[email protected]>
Add a boot PSW to PSW restart new, so we can also boot via a PSW restart.
Message-Id: <[email protected]>
--- s390x/flat.lds | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
s390x/flat.lds +9 -5
@@ -1,14 +1,18 @@ SECTIONS { - /* - * Initial short psw for disk boot, with 31 bit addressing for - * non z/Arch environment compatibility and the instruction - * address 0x10000 (cstart64.S .init). - */ .lowcore : { + /* + * Initial short psw for disk boot, with 31 bit addressing for + * non z/Arch environment compatibility and the instruction + * address 0x10000 (cstart64.S .init). + */ . = 0; LONG(0x00080000) LONG(0x80010000) + /* Restart new PSW for booting via PSW restart. */ + . = 0x1a0; + QUAD(0x0000000180000000) + QUAD(0x0000000000010000) } . = 0x10000; .text : {
Signature · 1 line
2.18.1
[kvm-unit-tests PULL 2/9] s390x: Diag288 test
In reply to Thomas HuthFrom: Janosch Frank <[email protected]>
A small test for the watchdog via diag288.
Minimum timer value is 15 (seconds) and the only supported action with QEMU is restart.
Message-Id: <[email protected]>
--- lib/s390x/asm/arch_def.h | 1 + s390x/Makefile | 1 + s390x/diag288.c | 114 +++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 ++ 4 files changed, 120 insertions(+) create mode 100644 s390x/diag288.c
lib/s390x/asm/arch_def.h +1 -0
@@ -15,6 +15,7 @@ struct psw {uint64_t addr; }; +#define PSW_MASK_EXT 0x0100000000000000UL#define PSW_MASK_DAT 0x0400000000000000UL#define PSW_MASK_PSTATE 0x0001000000000000UL
s390x/Makefile +1 -0
@@ -12,6 +12,7 @@ tests += $(TEST_DIR)/vector.elf tests += $(TEST_DIR)/gs.elf tests += $(TEST_DIR)/iep.elf tests += $(TEST_DIR)/cpumodel.elf +tests += $(TEST_DIR)/diag288.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binary
s390x/diag288.c new file +114 -0
114 lines not on this page · raw message
s390x/unittests.cfg +4 -0
@@ -64,3 +64,7 @@ file = iep.elf [cpumodel] file = cpumodel.elf + +[diag288] +file = diag288.elf +extra_params=-device diag288,id=watchdog0 --watchdog-action inject-nmi
Signature · 1 line
2.18.1
[kvm-unit-tests PULL 3/9] s390x: Move stsi to library
In reply to Thomas HuthFrom: Janosch Frank <[email protected]>
It's needed in multiple tests now.
Return value changes from 0/-1 to the cc.
Message-Id: <[email protected]>
--- lib/s390x/asm/arch_def.h | 16 ++++++++++++++++ s390x/skey.c | 18 ------------------ 2 files changed, 16 insertions(+), 18 deletions(-)
lib/s390x/asm/arch_def.h +16 -0
@@ -240,4 +240,20 @@ static inline void enter_pstate(void)load_psw_mask (mask); } +static inline int stsi (void *addr,int fc,int sel1,int sel2) +{ + register int r0 asm("0") = (fc << 28) | sel1; + register int r1 asm("1") = sel2; +int cc; + + asmvolatile ( +"stsi 0(%3)\n" +"ipm %[cc]\n" +"srl %[cc],28\n" + :"+d" (r0), [cc]"=d" (cc) + :"d" (r1),"a" (addr) + :"cc" ,"memory" ); + return cc; +} +#endif
s390x/skey.c +0 -18
@@ -70,24 +70,6 @@ static void test_set(void) skey.str.acc == ret.str.acc && skey.str.fp == ret.str.fp); } -static inline int stsi (void *addr,int fc,int sel1,int sel2) -{ - register int r0 asm("0") = (fc << 28) | sel1; - register int r1 asm("1") = sel2; -int rc =0 ; - - asmvolatile ( -" stsi 0(%3)\n" -" jz 0f\n" -" lhi %1,-1\n" -"0:\n" - :"+d" (r0),"+d" (rc) - :"d" (r1),"a" (addr) - :"cc" ,"memory" ); - -return rc; -} -/* Returns true if we are running under z/VM 6.x */ static bool check_for_zvm6 (void ) {
Signature · 1 line
2.18.1
[kvm-unit-tests PULL 4/9] s390x: STSI tests
In reply to Thomas HuthFrom: Janosch Frank <[email protected]>
For now let's concentrate on the error conditions.
Message-Id: <[email protected]>
--- s390x/Makefile | 1 + s390x/stsi.c | 84 +++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 3 ++ 3 files changed, 88 insertions(+) create mode 100644 s390x/stsi.c
s390x/Makefile +1 -0
@@ -13,6 +13,7 @@ tests += $(TEST_DIR)/gs.elf tests += $(TEST_DIR)/iep.elf tests += $(TEST_DIR)/cpumodel.elf tests += $(TEST_DIR)/diag288.elf +tests += $(TEST_DIR)/stsi.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binary
s390x/stsi.c new file +84 -0
84 lines not on this page · raw message
s390x/unittests.cfg +3 -0
@@ -68,3 +68,6 @@ file = cpumodel.elf [diag288] file = diag288.elf extra_params=-device diag288,id=watchdog0 --watchdog-action inject-nmi + +[stsi] +file = stsi.elf
Signature · 1 line
2.18.1
[kvm-unit-tests PULL 5/9] s390x: Add diag308 subcode 0 testing
In reply to Thomas HuthFrom: Janosch Frank <[email protected]>
By adding a load reset routine to cstart.S we can also test the clear reset done by subcode 0, as we now can restore our registers again.
Message-Id: <[email protected]>
--- s390x/cstart64.S | 27 +++++++++++++++++++++++++++ s390x/diag308.c | 31 ++++++++++--------------------- 2 files changed, 37 insertions(+), 21 deletions(-)
s390x/cstart64.S +27 -0
@@ -145,6 +145,33 @@ memsetxc: .endm .section .text +/* + * load_reset calling convention: + * %r2 subcode (0 or 1) + */ +.globl diag308_load_reset +diag308_load_reset: + SAVE_REGS + /* Save the first PSW word to the IPL PSW */ + epsw %r0, %r1 + st %r0, 0 + /* Store the address and the bit for 31 bit addressing */ + larl %r0, 0f + oilh %r0, 0x8000 + st %r0, 0x4 + /* Do the reset */ + diag %r0,%r2,0x308 + /* Failure path */ + xgr %r2, %r2 + br %r14 + /* Success path */ + /* We lost cr0 due to the reset */ +0: larl %r1, initial_cr0 + lctlg %c0, %c0, 0(%r1) + RESTORE_REGS + lhi %r2, 1 + br %r14 + pgm_int: SAVE_REGS brasl %r14, handle_pgm_int
s390x/diag308.c +10 -21
@@ -21,32 +21,20 @@ static void test_priv(void)check_pgm_int_code (PGM_INT_CODE_PRIVILEGED_OPERATION ); } +/* -* Check that diag308 with subcode 1 loads the PSW at address 0, i.e. +* Check that diag308 with subcode 0 and 1 loads the PSW at address 0, i.e. * that we can put a pointer into address 4 which then gets executed. */ +extern int diag308_load_reset (u64 ); +static void test_subcode0 (void ) +{ +report ("load modified clear done" ,diag308_load_reset (0 )); +} +static void test_subcode1 (void ) { -uint64_t saved_psw = *(uint64_t *)0 ; -long subcode =1 ; -long ret, tmp; - - asmvolatile ( -" epsw %0,%1\n" -" st %0,0\n" -" larl %0,0f\n" -" oilh %0,0x8000\n" -" st %0,4\n" -" diag 0,%2,0x308\n" -" lghi %0,0\n" -" j 1f\n" -"0: lghi %0,1\n" -"1:" - :"=&d" (ret),"=&d" (tmp) :"d" (subcode) :"memory" ); - - *(uint64_t *)0 = saved_psw; - -report ("load normal reset done" , ret ==1 ); +report ("load normal reset done" ,diag308_load_reset (1 )); }/* Expect a specification exception when using an uneven register */
@@ -107,6 +95,7 @@ static struct {void (*func)(void ); } tests[] = { { "privileged", test_priv }, + { "subcode 0", test_subcode0 }, { "subcode 1", test_subcode1 }, { "subcode 5", test_subcode5 }, { "subcode 6", test_subcode6 },
Signature · 1 line
2.18.1
[kvm-unit-tests PULL 6/9] s390x: Move pfmf to lib and make address void
In reply to Thomas HuthFrom: Janosch Frank <[email protected]>
It's needed by other tests soon.
Message-Id: <[email protected]>
--- lib/s390x/asm/mem.h | 31 ++++++++++++++++++++++++ s390x/pfmf.c | 57 +++++++++++---------------------------------- 2 files changed, 44 insertions(+), 44 deletions(-)
lib/s390x/asm/mem.h +31 -0
@@ -54,4 +54,35 @@ static inline unsigned char get_storage_key(unsigned long addr) asmvolatile ("iske %0,%1" :"=d" (skey) :"a" (addr));return skey; } + +#define PFMF_FSC_4K 0 +#define PFMF_FSC_1M 1 +#define PFMF_FSC_2G 2 + +union pfmf_r1 { +struct { +unsigned long pad0 :32 ; +unsigned long pad1 :12 ; +unsigned long pad_fmfi :2 ; +unsigned long sk :1 ;/* set key*/ +unsigned long cf :1 ;/* clear frame */ +unsigned long ui :1 ;/* usage indication */ +unsigned long fsc :3 ; +unsigned long pad2 :1 ; +unsigned long mr :1 ; +unsigned long mc :1 ; +unsigned long pad3 :1 ; +unsigned long key :8 ;/* storage keys */ + } reg; +unsigned long val; +}; + +static inline void *pfmf (unsigned long r1,void *paddr) +{ + register void * addr asm("1") = paddr; + + asmvolatile (".insn rre,0xb9af0000,%[r1],%[addr]" + : [addr]"+a" (addr) : [r1]"d" (r1) :"memory" ); +return addr; +}#endif
s390x/pfmf.c +13 -44
119 lines not on this page · raw message
Signature · 1 line
2.18.1
[kvm-unit-tests PULL 7/9] s390x: Storage key library functions now take void ptr addresses
In reply to Thomas HuthFrom: Janosch Frank <[email protected]>
Now all mem.h functions are consistent in how they take a memory address. Also we have less casting in the future.
Message-Id: <[email protected]>
--- lib/s390x/asm/mem.h | 9 +++------ s390x/pfmf.c | 4 ++-- s390x/skey.c | 24 +++++++++++------------- 3 files changed, 16 insertions(+), 21 deletions(-)
lib/s390x/asm/mem.h +3 -6
@@ -26,9 +26,7 @@ union skey {uint8_t val; }; -static inline void set_storage_key (unsigned long addr, -unsigned char skey, -int nq) +static inline void set_storage_key (void *addr,unsigned char skey,int nq) {if (nq) asm volatile(".insn rrf,0xb22b0000,%0,%1,8,0"
@@ -37,8 +35,7 @@ static inline void set_storage_key(unsigned long addr, asmvolatile ("sske %0,%1" : :"d" (skey),"a" (addr)); } -static inline unsigned long set_storage_key_mb (unsigned long addr, -unsigned char skey) +static inline void *set_storage_key_mb (void *addr,unsigned char skey) {assert (test_facility (8 ));
@@ -47,7 +44,7 @@ static inline unsigned long set_storage_key_mb(unsigned long addr,return addr; } -static inline unsigned char get_storage_key (unsigned long addr) +static inline unsigned char get_storage_key (void *addr) {unsigned char skey;
s390x/pfmf.c +2 -2
@@ -39,7 +39,7 @@ static void test_4k_key(void) r1.reg.fsc =PFMF_FSC_4K ; r1.reg.key =0x30 ;pfmf (r1.val, pagebuf); - skey.val =get_storage_key ((unsigned long ) pagebuf); + skey.val =get_storage_key (pagebuf); skey.val &=SKEY_ACC |SKEY_FP ;report ("set storage keys" , skey.val ==0x30 );report_prefix_pop ();
@@ -59,7 +59,7 @@ static void test_1m_key(void) r1.reg.key =0x30 ;pfmf (r1.val, pagebuf);for (i =0 ; i <256 ; i++) { - skey.val =get_storage_key ((unsigned long ) pagebuf + i *PAGE_SIZE ); + skey.val =get_storage_key (pagebuf + i *PAGE_SIZE ); skey.val &=SKEY_ACC |SKEY_FP ;if (skey.val !=0x30 ) { rp = false;
s390x/skey.c +11 -13
@@ -18,14 +18,12 @@ static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE * 2))); -const unsigned long page0 = (unsigned long )pagebuf; -const unsigned long page1 = (unsigned long )(pagebuf +PAGE_SIZE );static void test_set_mb (void ) {union skey skey, ret1, ret2; -unsigned long addr =0x10000 -2 *PAGE_SIZE ; -unsigned long end =0x10000 ; +void *addr = (void *)0x10000 -2 *PAGE_SIZE ; +void *end = (void *)0x10000 ;/* Multi block support came with EDAT 1 */ if (!test_facility (8 ))
@@ -46,10 +44,10 @@ static void test_chg(void)union skey skey1, skey2; skey1.val =0x30 ; -set_storage_key (page0, skey1.val,0 ); - skey1.val =get_storage_key (page0); +set_storage_key (pagebuf, skey1.val,0 ); + skey1.val =get_storage_key (pagebuf); pagebuf[0 ] =3 ; - skey2.val =get_storage_key (page0); + skey2.val =get_storage_key (pagebuf);report ("chg bit test" , !skey1.str.ch && skey2.str.ch); }
@@ -58,9 +56,9 @@ static void test_set(void)union skey skey, ret; skey.val =0x30 ; - ret.val =get_storage_key (page0); -set_storage_key (page0, skey.val,0 ); - ret.val =get_storage_key (page0); + ret.val =get_storage_key (pagebuf); +set_storage_key (pagebuf, skey.val,0 ); + ret.val =get_storage_key (pagebuf);/* * For all set tests we only test the ACC and FP bits. RF and * CH are set by the machine for memory references and changes
@@ -103,11 +101,11 @@ static void test_priv(void)report_prefix_push ("sske" );expect_pgm_int ();enter_pstate (); -set_storage_key (page0,0x30 ,0 ); +set_storage_key (pagebuf,0x30 ,0 );check_pgm_int_code (PGM_INT_CODE_PRIVILEGED_OPERATION );report_prefix_pop (); - skey.val =get_storage_key (page0); + skey.val =get_storage_key (pagebuf);report ("skey did not change on exception" , skey.str.acc !=3 );report_prefix_push ("iske" );
@@ -117,7 +115,7 @@ static void test_priv(void) }else {expect_pgm_int ();enter_pstate (); -get_storage_key (page0); +get_storage_key (pagebuf);check_pgm_int_code (PGM_INT_CODE_PRIVILEGED_OPERATION ); }report_prefix_pop ();
Signature · 1 line
2.18.1
[kvm-unit-tests PULL 8/9] s390x: Bump march to zEC12
In reply to Thomas HuthFrom: Janosch Frank <[email protected]>
TCG has majored a lot and can now support many newer instructions, so there's no need to compile with the ancient march z900.
Message-Id: <[email protected]>
--- s390x/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
s390x/Makefile +1 -1
@@ -25,7 +25,7 @@ CFLAGS += -std=gnu99 CFLAGS += -ffreestanding CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/s390x -I lib CFLAGS += -O2 -CFLAGS += -march=z900 +CFLAGS += -march=zEC12 CFLAGS += -fno-delete-null-pointer-checks LDFLAGS += -nostdlib -Wl,--build-id=none
Signature · 1 line
2.18.1
[kvm-unit-tests PULL 9/9] s390x: Add storage key removal facility
In reply to Thomas HuthFrom: Janosch Frank <[email protected]>
The storage key removal facility (stfle bit 169) makes all key related instructions result in a special operation exception if they handle a key.
Let's make sure that the skey and pfmf tests only run non key code (pfmf) or not at all (skey).
Also let's test this new facility. As lots of instructions are affected by this, only some of them are tested for now.
Message-Id: <[email protected]>
--- s390x/Makefile | 1 + s390x/pfmf.c | 10 ++++ s390x/skey.c | 5 ++ s390x/skrf.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 s390x/skrf.c
s390x/Makefile +1 -0
@@ -14,6 +14,7 @@ tests += $(TEST_DIR)/iep.elf tests += $(TEST_DIR)/cpumodel.elf tests += $(TEST_DIR)/diag288.elf tests += $(TEST_DIR)/stsi.elf +tests += $(TEST_DIR)/skrf.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binary
s390x/pfmf.c +10 -0
@@ -34,6 +34,10 @@ static void test_4k_key(void)union skey skey;report_prefix_push ("4K" ); +if (test_facility (169 )) { +report_skip ("storage key removal facility is active" ); + goto out; + } r1.val =0 ; r1.reg.sk =1 ; r1.reg.fsc =PFMF_FSC_4K ;
@@ -42,6 +46,7 @@ static void test_4k_key(void) skey.val =get_storage_key (pagebuf); skey.val &=SKEY_ACC |SKEY_FP ;report ("set storage keys" , skey.val ==0x30 ); +out:report_prefix_pop (); }
@@ -53,6 +58,10 @@ static void test_1m_key(void)union skey skey;report_prefix_push ("1M" ); +if (test_facility (169 )) { +report_skip ("storage key removal facility is active" ); + goto out; + } r1.val =0 ; r1.reg.sk =1 ; r1.reg.fsc =PFMF_FSC_1M ;
@@ -67,6 +76,7 @@ static void test_1m_key(void) } }report ("set storage keys" , rp); +out:report_prefix_pop (); }
s390x/skey.c +5 -0
@@ -126,10 +126,15 @@ static void test_priv(void)int main (void ) {report_prefix_push ("skey" ); +if (test_facility (169 )) { +report_skip ("storage key removal facility is active" ); + goto done; + }test_priv ();test_set ();test_set_mb ();test_chg (); +done:report_prefix_pop ();return report_summary (); }
s390x/skrf.c new file +128 -0
128 lines not on this page · raw message
Signature · 1 line
2.18.1