Skip to contentSkip to conversation

s390x: mvpg test

PATCH Superseded Claudio Imbrenda 3 participants 8 messages Mar 1, 2021 – Mar 2, 2021 KVM

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 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.

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             | 273 +++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg      |   4 +
 5 files changed, 295 insertions(+), 2 deletions(-)
 create mode 100644 s390x/mvpg.c
Signature · 1 line
2.26.2
#1 lore raw

PATCH v3 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
index 9c4e330a..4cf8eb11 100644
@@ -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)
+{
+	asm volatile("	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
index 1ce36073..d0567845 100644
@@ -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
Reviewed-by on v3 1/3
#2 lore raw

Re: [kvm-unit-tests PATCH v3 1/3] s390x: introduce leave_pstate to leave userspace

Quoted 54 lines · Claudio Imbrenda

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
index 9c4e330a..4cf8eb11 100644
@@ -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)
+{
+	asm volatile("	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 +1 -2
index 1ce36073..d0567845 100644
@@ -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;

lib/s390x/interrupt.c int unregister_io_int_func(void (*f)(void)) · line 201

Quoted 10 lines
lib/s390x/interrupt.c +9 -0
+
+	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);
+	}
  }
#3 lore raw

PATCH v3 2/3 s390x: mvpg: simple test

In reply to 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.

---
 s390x/Makefile      |   1 +
 s390x/mvpg.c        | 266 ++++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg |   4 +
 3 files changed, 271 insertions(+)
 create mode 100644 s390x/mvpg.c
s390x/Makefile +1 -0
index 08d85c9f..770eaa0b 100644
@@ -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 +266 -0

266 lines not on this page · raw message

s390x/unittests.cfg +4 -0
index 2298be6c..9f81a608 100644
@@ -99,3 +99,7 @@ file = uv-guest.elf
 
 [sie]
 file = sie.elf
+
+[mvpg]
+file = mvpg.elf
+timeout = 10
Signature · 1 line
2.26.2
Reviewed-by on v3 2/3
#4 lore raw

Re: [kvm-unit-tests PATCH v3 2/3] s390x: mvpg: simple test

Quoted 14 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.

---

[...]

s390x/mvpg.c line 144

Quoted 8 lines
s390x/mvpg.c new file +8 -0
+static void test_success(void)
+{
+	int cc;
+
+	report_prefix_push("success");
+	/* Test successful scenarios, both in supervisor and problem state */
+	cc = mvpg(0, buffer, source);
+	report(page_ok(buffer) && !cc, "Supervisor state MVPG successful");

I'd maybe add a memset(buffer, 0xff, PAGE_SIZE) here to make sure that the buffer really gets re-written before the next page_ok() check.

s390x/mvpg.c line 152

Quoted 7 lines
s390x/mvpg.c new file +7 -0
+	enter_pstate();
+	cc = mvpg(0, buffer, source);
+	leave_pstate();
+	report(page_ok(buffer) && !cc, "Problem state MVPG successful");
+
+	report_prefix_pop();
+}

Anyway:

#5 lore raw

PATCH v3 3/3 s390x: mvpg: skip some tests when using TCG

In reply to Claudio Imbrenda

TCG 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 | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)
s390x/mvpg.c +19 -12
index 792052ad..148095e0 100644
@@ -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)
@@ -224,20 +225,26 @@ 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;
+	if (vm_is_tcg()) {
+		report_skip("destination invalid");
+		report_skip("source invalid");
+		report_skip("source and destination invalid");
+	} 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
Reviewed-by on v3 3/3
#6 lore raw

Re: [kvm-unit-tests PATCH v3 3/3] s390x: mvpg: skip some tests when using TCG

Quoted 23 lines · Claudio Imbrenda

TCG 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 | 31 +++++++++++++++++++------------
  1 file changed, 19 insertions(+), 12 deletions(-)
s390x/mvpg.c +1 -0
index 792052ad..148095e0 100644
@@ -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)
@@ -224,20 +225,26 @@ static void test_mmu_prot(void)
  	report(clear_pgm_int() == PGM_INT_CODE_PROTECTION, "destination read only");

s390x/mvpg.c static void test_mmu_prot(void) · line 231

Quoted 10 lines
s390x/mvpg.c +4 -4
  	fresh += PAGE_SIZE;
 
-	protect_page(fresh, PAGE_ENTRY_I);
-	cc = mvpg(CCO, fresh, source);
-	report(cc == 1, "destination invalid");
-	fresh += PAGE_SIZE;
+	if (vm_is_tcg()) {
+		report_skip("destination invalid");
+		report_skip("source invalid");
+		report_skip("source and destination invalid");

You could also use report_xfail(vm_is_tcg(), ...) instead. That shows that there are still problems without failing CI runs.

Anyway:

#7 lore raw

Re: [kvm-unit-tests PATCH v3 3/3] s390x: mvpg: skip some tests when using TCG

Quoted 26 lines · Thomas Huth
Quoted 25 lines · Claudio Imbrenda

TCG 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 | 31 +++++++++++++++++++------------
  1 file changed, 19 insertions(+), 12 deletions(-)
s390x/mvpg.c +1 -0
index 792052ad..148095e0 100644
@@ -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)
@@ -224,20 +225,26 @@ static void test_mmu_prot(void)
  	report(clear_pgm_int() == PGM_INT_CODE_PROTECTION, "destination read only");
  	fresh += PAGE_SIZE;
 
Quoted 11 lines

s390x/mvpg.c static void test_mmu_prot(void) · line 231

Quoted 8 lines
s390x/mvpg.c +4 -4
-	protect_page(fresh, PAGE_ENTRY_I);
-	cc = mvpg(CCO, fresh, source);
-	report(cc == 1, "destination invalid");
-	fresh += PAGE_SIZE;
+	if (vm_is_tcg()) {
+		report_skip("destination invalid");
+		report_skip("source invalid");
+		report_skip("source and destination invalid");

You could also use report_xfail(vm_is_tcg(), ...) instead. That shows that there are still problems without failing CI runs.

If I remember correctly we fail with a PGM so we would also need to add a expect_pgm_int() call before each test when running under tcg therefore it's not just a 1:1 replacement in this case.

But yes, I'd also like an indication why we're skipping. A comment and a TCG prefix for skips should be enough.

Quoted 4 lines

Anyway: