s390x: mvpg test
v4 cover s390x: mvpg test
A simple unit test for the MVPG instruction.
The timeout is set to 10 seconds because the test should complete in a fraction of a second even on busy machines. If the test is run in VSIE and the host of the host is not handling MVPG properly, the test will probably hang.
Testing MVPG behaviour in VSIE is the main motivation for this test.
Anything related to storage keys is not tested.
v3->v4
* add memset after the first successful mvpg to make sure memory is really copied successfully
* add a comment and an additional prefix to the tests skipped when running in TCG
v2->v3
* fix copyright (2020 is over!)
* add the third patch to skip some known issues when running in TCG
v1->v2
* droppped patch 2 which introduced is_pgm();
* patch 1: replace a hardcoded value with the new macro SVC_LEAVE_PSTATE
* patch 2: clear_pgm_int() returns the old value, use that instad of is_pgm()
Claudio Imbrenda (3):
s390x: introduce leave_pstate to leave userspace
s390x: mvpg: simple test
s390x: mvpg: skip some tests when using TCG
s390x/Makefile | 1 + lib/s390x/asm/arch_def.h | 7 + lib/s390x/interrupt.c | 12 +- s390x/mvpg.c | 277 +++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 + 5 files changed, 299 insertions(+), 2 deletions(-) create mode 100644 s390x/mvpg.c
Signature · 1 line
2.26.2
PATCH v4 1/3 s390x: introduce leave_pstate to leave userspace
In most testcases, we enter problem state (userspace) just to test if a privileged instruction causes a fault. In some cases, though, we need to test if an instruction works properly in userspace. This means that we do not expect a fault, and we need an orderly way to leave problem state afterwards.
This patch introduces a simple system based on the SVC instruction.
--- lib/s390x/asm/arch_def.h | 7 +++++++ lib/s390x/interrupt.c | 12 ++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-)
lib/s390x/asm/arch_def.h +7 -0
@@ -173,6 +173,8 @@ struct cpuid { uint64_t reserved : 15; }; +#define SVC_LEAVE_PSTATE 1 +static inline unsigned short stap (void ) {unsigned short cpu_address;
@@ -276,6 +278,11 @@ static inline void enter_pstate(void)load_psw_mask (mask); } +static inline void leave_pstate (void ) +{ + asmvolatile (" svc %0\n" : :"i" (SVC_LEAVE_PSTATE )); +} +static inline int stsi (void *addr,int fc,int sel1,int sel2) { register int r0 asm("0") = (fc << 28) | sel1;
lib/s390x/interrupt.c +10 -2
@@ -188,6 +188,14 @@ int unregister_io_int_func(void (*f)(void))void handle_svc_int (void ) { -report_abort ("Unexpected supervisor call interrupt: on cpu %d at %#lx" , -stap (), lc->svc_old_psw.addr); +uint16_t code = lc->svc_int_code; + +switch (code) { +case SVC_LEAVE_PSTATE : + lc->svc_old_psw.mask &= ~PSW_MASK_PSTATE ; +break ; +default : +report_abort ("Unexpected supervisor call interrupt: code %#x on cpu %d at %#lx" , + code,stap (), lc->svc_old_psw.addr); + } }
Signature · 1 line
2.26.2
PATCH v4 2/3 s390x: mvpg: simple test
In reply to Claudio ImbrendaA simple unit test for the MVPG instruction.
The timeout is set to 10 seconds because the test should complete in a fraction of a second even on busy machines. If the test is run in VSIE and the host of the host is not handling MVPG properly, the test will probably hang.
Testing MVPG behaviour in VSIE is the main motivation for this test.
Anything related to storage keys is not tested.
--- s390x/Makefile | 1 + s390x/mvpg.c | 267 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 + 3 files changed, 272 insertions(+) create mode 100644 s390x/mvpg.c
s390x/Makefile +1 -0
@@ -20,6 +20,7 @@ tests += $(TEST_DIR)/sclp.elf tests += $(TEST_DIR)/css.elf tests += $(TEST_DIR)/uv-guest.elf tests += $(TEST_DIR)/sie.elf +tests += $(TEST_DIR)/mvpg.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) ifneq ($(HOST_KEY_DOCUMENT),)
s390x/mvpg.c new file +267 -0
267 lines not on this page · raw message
s390x/unittests.cfg +4 -0
@@ -99,3 +99,7 @@ file = uv-guest.elf [sie] file = sie.elf + +[mvpg] +file = mvpg.elf +timeout = 10
Signature · 1 line
2.26.2
PATCH v4 3/3 s390x: mvpg: skip some tests when using TCG
In reply to Claudio ImbrendaTCG is known to fail these tests, so add an explicit exception to skip them.
Once TCG has been fixed, it will be enough to revert this patch.
--- s390x/mvpg.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)
s390x/mvpg.c +22 -12
@@ -20,6 +20,7 @@#include <smp.h> #include <alloc_page.h> #include <bitops.h> +#include <vm.h> /* Used to build the appropriate test values for register 0 */ #define KFC (x) ((x) << 10)
@@ -225,20 +226,29 @@ static void test_mmu_prot(void)report (clear_pgm_int () ==PGM_INT_CODE_PROTECTION ,"destination read only" ); fresh +=PAGE_SIZE ; -protect_page (fresh,PAGE_ENTRY_I ); - cc =mvpg (CCO , fresh, source); -report (cc ==1 ,"destination invalid" ); - fresh +=PAGE_SIZE ; +/* Known issue in TCG: CCO flag is not honoured */ +if (vm_is_tcg ()) { +report_prefix_push ("TCG" ); +report_skip ("destination invalid" ); +report_skip ("source invalid" ); +report_skip ("source and destination invalid" ); +report_prefix_pop (); + }else { +protect_page (fresh,PAGE_ENTRY_I ); + cc =mvpg (CCO , fresh, source); +report (cc ==1 ,"destination invalid" ); + fresh +=PAGE_SIZE ; -protect_page (source,PAGE_ENTRY_I ); - cc =mvpg (CCO , fresh, source); -report (cc ==2 ,"source invalid" ); - fresh +=PAGE_SIZE ; +protect_page (source,PAGE_ENTRY_I ); + cc =mvpg (CCO , fresh, source); +report (cc ==2 ,"source invalid" ); + fresh +=PAGE_SIZE ; -protect_page (fresh,PAGE_ENTRY_I ); - cc =mvpg (CCO , fresh, source); -report (cc ==2 ,"source and destination invalid" ); - fresh +=PAGE_SIZE ; +protect_page (fresh,PAGE_ENTRY_I ); + cc =mvpg (CCO , fresh, source); +report (cc ==2 ,"source and destination invalid" ); + fresh +=PAGE_SIZE ; + }unprotect_page (source,PAGE_ENTRY_I );report_prefix_pop ();
Signature · 1 line
2.26.2
Quoted 10 lines · Claudio Imbrenda
A simple unit test for the MVPG instruction.
The timeout is set to 10 seconds because the test should complete in a fraction of a second even on busy machines. If the test is run in VSIE and the host of the host is not handling MVPG properly, the test will probably hang.
Testing MVPG behaviour in VSIE is the main motivation for this test.
Anything related to storage keys is not tested.
Thanks, picked.
Quoted 29 lines
v3->v4
* add memset after the first successful mvpg to make sure memory is really copied successfully
* add a comment and an additional prefix to the tests skipped when running in TCG
v2->v3
* fix copyright (2020 is over!)
* add the third patch to skip some known issues when running in TCG
v1->v2
* droppped patch 2 which introducedis_pgm();
* patch 1: replace a hardcoded value with the new macroSVC_LEAVE_PSTATE
* patch 2:clear_pgm_int()returns the old value, use that instad ofis_pgm()Claudio Imbrenda (3):
s390x: introduceleave_pstateto leave userspace
s390x: mvpg: simple test
s390x: mvpg: skip some tests when using TCGs390x/Makefile | 1 + lib/s390x/asm/arch_def.h | 7 + lib/s390x/interrupt.c | 12 +- s390x/mvpg.c | 277 +++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 + 5 files changed, 299 insertions(+), 2 deletions(-) create mode 100644 s390x/mvpg.c