Skip to contentSkip to conversation

s390x: Remove assert from arch_def.h

PATCH In review Janis Schoetterl-Glausch 5 participants 12 messages Oct 5, 2021 – Oct 6, 2021 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 1/2 s390x: Remove assert from arch_def.h

Do not use asserts in arch_def.h so it can be included by snippets. The caller in stsi.c does not need to be adjusted, returning -1 causes the test to fail.

---
 lib/s390x/asm/arch_def.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
lib/s390x/asm/arch_def.h +3 -2
index 302ef1f..4167e2b 100644
@@ -334,7 +334,7 @@ static inline int stsi(void *addr, int fc, int sel1, int sel2)
 	return cc;
 }
 
-static inline unsigned long stsi_get_fc(void)
+static inline int stsi_get_fc(void)
 {
 	register unsigned long r0 asm("0") = 0;
 	register unsigned long r1 asm("1") = 0;
@@ -346,7 +346,8 @@ static inline unsigned long stsi_get_fc(void)
 		     : "+d" (r0), [cc] "=d" (cc)
 		     : "d" (r1)
 		     : "cc", "memory");
-	assert(!cc);
+	if (cc != 0)
+		return -1;
 	return r0 >> 28;
 }
 
Signature · 1 line
2.31.1
#2 lore raw

Re: [kvm-unit-tests PATCH v2 1/2] [kvm-unit-tests PATCH v2 0/2] Test specification exception

Oops, forgot to Cc the lists on the cover letter, see below.

When specification exception interpretation is enabled, specification exceptions need not result in interceptions.
However, if the exception is due to an invalid program new PSW, interception must occur.
Test this.
Also test that interpretation does occur if interpretation is disabled.

v1 -> v2
Add license and test description
Use lowcore pointer instead of magic value for program new PSW
-> need to get rid of assert in arch_def.h
Do not use odd program new PSW, even if irrelevant Use SIE lib
Reword messages
Fix nits

Janis Schoetterl-Glausch (2):
s390x: Remove assert from arch_def.h
s390x: Add specification exception interception test

 s390x/Makefile             |  2 +
 lib/s390x/asm/arch_def.h   |  5 ++-
 lib/s390x/sie.h            |  1 +
 s390x/snippets/c/spec_ex.c | 20 +++++++++
 s390x/spec_ex-sie.c        | 83 ++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg        |  3 ++
 6 files changed, 112 insertions(+), 2 deletions(-)
 create mode 100644 s390x/snippets/c/spec_ex.c
 create mode 100644 s390x/spec_ex-sie.c

Range-diff against v1:

-:  ------- > 1:  8ad817c s390x: Remove assert from arch_def.h
1:  9e5e161 ! 2:  f8abbae s390x: Add specification exception interception test
    @@ lib/s390x/sie.h: struct kvm_s390_sie_block {
     
      ## s390x/snippets/c/spec_ex.c (new) ##
     @@
    ++// SPDX-License-Identifier: GPL-2.0-only
    ++/*
    ++ * © Copyright IBM Corp. 2021
    ++ *
    ++ * Snippet used by specification exception interception test.
    ++ */
     +#include <stdint.h>
     +#include <asm/arch_def.h>
     +
     +__attribute__((section(".text"))) int main(void)
     +{
    ++	struct lowcore *lowcore = (struct lowcore *) 0;
     +	uint64_t bad_psw = 0;
    -+	struct psw *pgm_new = (struct psw *)464;
     +
    -+	pgm_new->mask = 1UL << (63 - 12); //invalid program new PSW
    -+	pgm_new->addr = 0xdeadbeef;
    ++	/* PSW bit 12 has no name or meaning and must be 0 */
    ++	lowcore->pgm_new_psw.mask = 1UL << (63 - 12);
    ++	lowcore->pgm_new_psw.addr = 0xdeadbeee;
     +	asm volatile ("lpsw %0" :: "Q"(bad_psw));
     +	return 0;
     +}
     
      ## s390x/spec_ex-sie.c (new) ##
     @@
    ++// SPDX-License-Identifier: GPL-2.0-only
    ++/*
    ++ * © Copyright IBM Corp. 2021
    ++ *
    ++ * Specification exception interception test.
    ++ * Checks that specification exception interceptions occur as expected when
    ++ * specification exception interpretation is off/on.
    ++ */
     +#include <libcflat.h>
     +#include <sclp.h>
     +#include <asm/page.h>
    @@ s390x/spec_ex-sie.c (new)
     +			   (uintptr_t)_binary_s390x_snippets_c_spec_ex_gbin_start);
     +
     +	setup_vm();
    -+
    -+	/* Allocate 1MB as guest memory */
     +	guest = alloc_pages(8);
    -+	/* The first two pages are the lowcore */
    -+
    -+	vm.sblk = alloc_page();
    -+
    -+	vm.sblk->cpuflags = CPUSTAT_ZARCH | CPUSTAT_RUNNING;
    -+	vm.sblk->prefix = 0;
    -+	/*
    -+	 * Pageable guest with the same ASCE as the test program, but
    -+	 * the guest memory 0x0 is offset to start at the allocated
    -+	 * guest pages and end after 1MB.
    -+	 *
    -+	 * It's not pretty but faster and easier than managing guest ASCEs.
    -+	 */
    -+	vm.sblk->mso = (u64)guest;
    -+	vm.sblk->msl = (u64)guest;
    -+	vm.sblk->ihcpu = 0xffff;
    -+
    -+	vm.sblk->crycbd = (uint64_t)alloc_page();
    -+
     +	memcpy(guest, _binary_s390x_snippets_c_spec_ex_gbin_start, binary_size);
    ++	sie_guest_create(&vm, (uint64_t) guest, HPAGE_SIZE);
     +}
     +
     +static void reset_guest(void)
     +{
     +	vm.sblk->gpsw.addr = PAGE_SIZE * 4;
    -+	vm.sblk->gpsw.mask = 0x0000000180000000ULL;
    ++	vm.sblk->gpsw.mask = PSW_MASK_64;
    ++	vm.sblk->icptcode = 0;
     +}
     +
     +static void test_spec_ex_sie(void)
     +{
     +	setup_guest();
     +
    -+	report_prefix_push("spec ex interpretation off");
    ++	report_prefix_push("SIE spec ex interpretation");
    ++	report_prefix_push("off");
     +	reset_guest();
    -+	sie64a(vm.sblk, &vm.save_area);
    -+	//interpretation off -> initial exception must cause interception
    ++	sie(&vm);
    ++	/* interpretation off -> initial exception must cause interception */
     +	report(vm.sblk->icptcode == ICPT_PROGI
     +	       && vm.sblk->iprcc == PGM_INT_CODE_SPECIFICATION
    -+	       && vm.sblk->gpsw.addr != 0xdeadbeef,
    -+	       "Received specification exception intercept for non program new PSW");
    ++	       && vm.sblk->gpsw.addr != 0xdeadbeee,
    ++	       "Received specification exception intercept for initial exception");
     +	report_prefix_pop();
     +
    -+	report_prefix_push("spec ex interpretation on");
    ++	report_prefix_push("on");
     +	vm.sblk->ecb |= ECB_SPECI;
     +	reset_guest();
    -+	sie64a(vm.sblk, &vm.save_area);
    -+	// interpretation on -> configuration dependent if initial exception causes
    -+	// interception, but invalid new program PSW must
    ++	sie(&vm);
    ++	/* interpretation on -> configuration dependent if initial exception causes
    ++	 * interception, but invalid new program PSW must
    ++	 */
     +	report(vm.sblk->icptcode == ICPT_PROGI
     +	       && vm.sblk->iprcc == PGM_INT_CODE_SPECIFICATION,
     +	       "Received specification exception intercept");
    -+	if (vm.sblk->gpsw.addr == 0xdeadbeef)
    -+		report_info("Interpreted non program new PSW specification exception");
    ++	if (vm.sblk->gpsw.addr == 0xdeadbeee)
    ++		report_info("Interpreted initial exception, intercepted invalid program new PSW exception");
     +	else
    -+		report_info("Did not interpret non program new PSW specification exception");
    ++		report_info("Did not interpret initial exception");
    ++	report_prefix_pop();
     +	report_prefix_pop();
     +}
     +

base-commit: fe26131eec769cef7ad7e2e1e4e192aa0bdb2bba

Signature · 1 line
2.31.1
Reviewed-by on v2 1/2
#3 lore raw
In reply to Janis Schoetterl-Glausch
Quoted 5 lines · On Tue, 5 Oct 2021 11:11:52 +0200 Janis Schoetterl-Glausch…

Do not use asserts in arch_def.h so it can be included by snippets. The caller in stsi.c does not need to be adjusted, returning -1 causes the test to fail.

Quoted 27 lines
---
 lib/s390x/asm/arch_def.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
lib/s390x/asm/arch_def.h +3 -2
index 302ef1f..4167e2b 100644
@@ -334,7 +334,7 @@ static inline int stsi(void *addr, int fc, int sel1, int sel2)
 	return cc;
 }
 
-static inline unsigned long stsi_get_fc(void)
+static inline int stsi_get_fc(void)
 {
 	register unsigned long r0 asm("0") = 0;
 	register unsigned long r1 asm("1") = 0;
@@ -346,7 +346,8 @@ static inline unsigned long stsi_get_fc(void)
 		     : "+d" (r0), [cc] "=d" (cc)
 		     : "d" (r1)
 		     : "cc", "memory");
-	assert(!cc);
+	if (cc != 0)
+		return -1;
 	return r0 >> 28;
 }
 
#4 lore raw
In reply to Janis Schoetterl-Glausch
Quoted 5 lines · Janis Schoetterl-Glausch

Do not use asserts in arch_def.h so it can be included by snippets. The caller in stsi.c does not need to be adjusted, returning -1 causes the test to fail.

A few days ago I had a minute to investigate what needed to be added to be able to link the libcflat. Fortunately it wasn't a lot and I'll try to post it this week so this patch can hopefully be dropped.

Quoted 28 lines
---
  lib/s390x/asm/arch_def.h | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
lib/s390x/asm/arch_def.h +3 -2
index 302ef1f..4167e2b 100644
@@ -334,7 +334,7 @@ static inline int stsi(void *addr, int fc, int sel1, int sel2)
  	return cc;
  }
 
-static inline unsigned long stsi_get_fc(void)
+static inline int stsi_get_fc(void)
  {
  	register unsigned long r0 asm("0") = 0;
  	register unsigned long r1 asm("1") = 0;
@@ -346,7 +346,8 @@ static inline unsigned long stsi_get_fc(void)
  		     : "+d" (r0), [cc] "=d" (cc)
  		     : "d" (r1)
  		     : "cc", "memory");
-	assert(!cc);
+	if (cc != 0)
+		return -1;
  	return r0 >> 28;
  }
 
#5 lore raw
Quoted 8 lines · Janosch Frank
Quoted 5 lines · Janis Schoetterl-Glausch

Do not use asserts in arch_def.h so it can be included by snippets. The caller in stsi.c does not need to be adjusted, returning -1 causes the test to fail.

A few days ago I had a minute to investigate what needed to be added to be able to link the libcflat. Fortunately it wasn't a lot and I'll try to post it this week so this patch can hopefully be dropped.

One could argue that cc being != 0 is part of the test and so should go through report() and not assert(). Which happens naturally, since the caller will likely compare it to some positive expected value.

Quoted 28 lines
Quoted 27 lines

---
  lib/s390x/asm/arch_def.h | 5 +++--

  1 file changed, 3 insertions(+), 2 deletions(-)
lib/s390x/asm/arch_def.h +3 -1
index 302ef1f..4167e2b 100644
@@ -334,7 +334,7 @@ static inline int stsi(void *addr, int fc, int sel1, int sel2)
       return cc;
   }
   -static inline unsigned long stsi_get_fc(void)
+static inline int stsi_get_fc(void)
   {
       register unsigned long r0 asm("0") = 0;
       register unsigned long r1 asm("1") = 0;
@@ -346,7 +346,8 @@ static inline unsigned long stsi_get_fc(void)
                : "+d" (r0), [cc] "=d" (cc)
                : "d" (r1)
                : "cc", "memory");
-    assert(!cc);
+    if (cc != 0)
+        return -1;
       return r0 >> 28;
   }

#6 lore raw
Quoted 6 lines · Janis Schoetterl-Glausch
Quoted 5 lines · Janosch Frank
Quoted 4 lines · Janis Schoetterl-Glausch

Do not use asserts in arch_def.h so it can be included by snippets. The caller in stsi.c does not need to be adjusted, returning -1 causes the test to fail.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

A few days ago I had a minute to investigate what needed to be added to be able to link the libcflat. Fortunately it wasn't a lot and I'll try to post it this week so this patch can hopefully be dropped.

One could argue that cc being != 0 is part of the test and so should go through report() and not assert(). Which happens naturally, since the caller will likely compare it to some positive expected value.

Yes, I can also live with that if you change the commit message then :)

Quoted 29 lines
Quoted 28 lines
Quoted 27 lines
---
   lib/s390x/asm/arch_def.h | 5 +++--
   1 file changed, 3 insertions(+), 2 deletions(-)
lib/s390x/asm/arch_def.h +3 -1
index 302ef1f..4167e2b 100644
@@ -334,7 +334,7 @@ static inline int stsi(void *addr, int fc, int sel1, int sel2)
       return cc;
   }
   -static inline unsigned long stsi_get_fc(void)
+static inline int stsi_get_fc(void)
   {
       register unsigned long r0 asm("0") = 0;
       register unsigned long r1 asm("1") = 0;
@@ -346,7 +346,8 @@ static inline unsigned long stsi_get_fc(void)
                : "+d" (r0), [cc] "=d" (cc)
                : "d" (r1)
                : "cc", "memory");
-    assert(!cc);
+    if (cc != 0)
+        return -1;
       return r0 >> 28;
   }
 
#7 lore raw

PATCH v2 2/2 s390x: Add specification exception interception test

In reply to a message not in the archive

Check that specification exceptions cause intercepts when specification exception interpretation is off.
Check that specification exceptions caused by program new PSWs cause interceptions.
We cannot assert that non program new PSW specification exceptions are interpreted because whether interpretation occurs or not is configuration dependent.

---
 s390x/Makefile             |  2 +
 lib/s390x/sie.h            |  1 +
 s390x/snippets/c/spec_ex.c | 20 +++++++++
 s390x/spec_ex-sie.c        | 83 ++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg        |  3 ++
 5 files changed, 109 insertions(+)
 create mode 100644 s390x/snippets/c/spec_ex.c
 create mode 100644 s390x/spec_ex-sie.c
s390x/Makefile +2 -0
index ef8041a..7198882 100644
@@ -24,6 +24,7 @@ tests += $(TEST_DIR)/mvpg.elf
 tests += $(TEST_DIR)/uv-host.elf
 tests += $(TEST_DIR)/edat.elf
 tests += $(TEST_DIR)/mvpg-sie.elf
+tests += $(TEST_DIR)/spec_ex-sie.elf
 
 tests_binary = $(patsubst %.elf,%.bin,$(tests))
 ifneq ($(HOST_KEY_DOCUMENT),)
@@ -85,6 +86,7 @@ snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o
 # perquisites (=guests) for the snippet hosts.
 # $(TEST_DIR)/<snippet-host>.elf: snippets = $(SNIPPET_DIR)/<c/asm>/<snippet>.gbin
 $(TEST_DIR)/mvpg-sie.elf: snippets = $(SNIPPET_DIR)/c/mvpg-snippet.gbin
+$(TEST_DIR)/spec_ex-sie.elf: snippets = $(SNIPPET_DIR)/c/spec_ex.gbin
 
 $(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o $(FLATLIBS)
 	$(OBJCOPY) -O binary $(patsubst %.gbin,%.o,$@) $@
lib/s390x/sie.h +1 -0
index ca514ef..7ef7251 100644
@@ -98,6 +98,7 @@ struct kvm_s390_sie_block {
 	uint8_t		fpf;			/* 0x0060 */
 #define ECB_GS		0x40
 #define ECB_TE		0x10
+#define ECB_SPECI	0x08
 #define ECB_SRSI	0x04
 #define ECB_HOSTPROTINT	0x02
 	uint8_t		ecb;			/* 0x0061 */
s390x/snippets/c/spec_ex.c new file +20 -0
new file mode 100644
index 0000000..bdba4f4
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * © Copyright IBM Corp. 2021
+ *
+ * Snippet used by specification exception interception test.
+ */
+#include <stdint.h>
+#include <asm/arch_def.h>
+
+__attribute__((section(".text"))) int main(void)
+{
+	struct lowcore *lowcore = (struct lowcore *) 0;
+	uint64_t bad_psw = 0;
+
+	/* PSW bit 12 has no name or meaning and must be 0 */
+	lowcore->pgm_new_psw.mask = 1UL << (63 - 12);
+	lowcore->pgm_new_psw.addr = 0xdeadbeee;
+	asm volatile ("lpsw %0" :: "Q"(bad_psw));
+	return 0;
+}
s390x/spec_ex-sie.c new file +83 -0

83 lines not on this page · raw message

s390x/unittests.cfg +3 -0
index 9e1802f..3b454b7 100644
@@ -109,3 +109,6 @@ file = edat.elf
 
 [mvpg-sie]
 file = mvpg-sie.elf
+
+[spec_ex-sie]
+file = spec_ex-sie.elf
Signature · 1 line
2.31.1
#8 lore raw

Re: [kvm-unit-tests PATCH v2 2/2] s390x: Add specification exception interception test

Quoted 63 lines · On Tue, 5 Oct 2021 11:11:53 +0200 Janis Schoetterl-Glausch…

Check that specification exceptions cause intercepts when specification exception interpretation is off.
Check that specification exceptions caused by program new PSWs cause interceptions.
We cannot assert that non program new PSW specification exceptions are interpreted because whether interpretation occurs or not is configuration dependent.

---
 s390x/Makefile             |  2 +
 lib/s390x/sie.h            |  1 +
 s390x/snippets/c/spec_ex.c | 20 +++++++++
 s390x/spec_ex-sie.c        | 83 ++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg        |  3 ++
 5 files changed, 109 insertions(+)
 create mode 100644 s390x/snippets/c/spec_ex.c
 create mode 100644 s390x/spec_ex-sie.c
s390x/Makefile +2 -0
index ef8041a..7198882 100644
@@ -24,6 +24,7 @@ tests += $(TEST_DIR)/mvpg.elf
 tests += $(TEST_DIR)/uv-host.elf
 tests += $(TEST_DIR)/edat.elf
 tests += $(TEST_DIR)/mvpg-sie.elf
+tests += $(TEST_DIR)/spec_ex-sie.elf
 
 tests_binary = $(patsubst %.elf,%.bin,$(tests))
 ifneq ($(HOST_KEY_DOCUMENT),)
@@ -85,6 +86,7 @@ snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o
 # perquisites (=guests) for the snippet hosts.
 # $(TEST_DIR)/<snippet-host>.elf: snippets = $(SNIPPET_DIR)/<c/asm>/<snippet>.gbin
 $(TEST_DIR)/mvpg-sie.elf: snippets = $(SNIPPET_DIR)/c/mvpg-snippet.gbin
+$(TEST_DIR)/spec_ex-sie.elf: snippets = $(SNIPPET_DIR)/c/spec_ex.gbin
 
 $(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o $(FLATLIBS)
 	$(OBJCOPY) -O binary $(patsubst %.gbin,%.o,$@) $@
lib/s390x/sie.h +1 -0
index ca514ef..7ef7251 100644
@@ -98,6 +98,7 @@ struct kvm_s390_sie_block {
 	uint8_t		fpf;			/* 0x0060 */
 #define ECB_GS		0x40
 #define ECB_TE		0x10
+#define ECB_SPECI	0x08
 #define ECB_SRSI	0x04
 #define ECB_HOSTPROTINT	0x02
 	uint8_t		ecb;			/* 0x0061 */
s390x/snippets/c/spec_ex.c new file +6 -0
new file mode 100644
index 0000000..bdba4f4
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * © Copyright IBM Corp. 2021
+ *
+ * Snippet used by specification exception interception test.
+ */

s390x/snippets/c/spec_ex.c line 16

Quoted 10 lines
s390x/snippets/c/spec_ex.c new file +10 -0
+#include <stdint.h>
+#include <asm/arch_def.h>
+
+__attribute__((section(".text"))) int main(void)
+{
+	struct lowcore *lowcore = (struct lowcore *) 0;
+	uint64_t bad_psw = 0;
+
+	/* PSW bit 12 has no name or meaning and must be 0 */
+	lowcore->pgm_new_psw.mask = 1UL << (63 - 12);

you can use the BIT or BIT_ULL macro

s390x/snippets/c/spec_ex.c line 17

Quoted 1 line
s390x/snippets/c/spec_ex.c new file +1 -0
+	lowcore->pgm_new_psw.addr = 0xdeadbeee;

if the system is broken, it might actually jump at that address; in that case, will the test fail?

Quoted 103 lines
s390x/snippets/c/spec_ex.c new file +3 -0
+	asm volatile ("lpsw %0" :: "Q"(bad_psw));
+	return 0;
+}
s390x/spec_ex-sie.c new file +83 -0
new file mode 100644
index 0000000..b7e79de
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * © Copyright IBM Corp. 2021
+ *
+ * Specification exception interception test.
+ * Checks that specification exception interceptions occur as expected when
+ * specification exception interpretation is off/on.
+ */
+#include <libcflat.h>
+#include <sclp.h>
+#include <asm/page.h>
+#include <asm/arch_def.h>
+#include <alloc_page.h>
+#include <vm.h>
+#include <sie.h>
+
+static struct vm vm;
+extern const char _binary_s390x_snippets_c_spec_ex_gbin_start[];
+extern const char _binary_s390x_snippets_c_spec_ex_gbin_end[];
+
+static void setup_guest(void)
+{
+	char *guest;
+	int binary_size = ((uintptr_t)_binary_s390x_snippets_c_spec_ex_gbin_end -
+			   (uintptr_t)_binary_s390x_snippets_c_spec_ex_gbin_start);
+
+	setup_vm();
+	guest = alloc_pages(8);
+	memcpy(guest, _binary_s390x_snippets_c_spec_ex_gbin_start, binary_size);
+	sie_guest_create(&vm, (uint64_t) guest, HPAGE_SIZE);
+}
+
+static void reset_guest(void)
+{
+	vm.sblk->gpsw.addr = PAGE_SIZE * 4;
+	vm.sblk->gpsw.mask = PSW_MASK_64;
+	vm.sblk->icptcode = 0;
+}
+
+static void test_spec_ex_sie(void)
+{
+	setup_guest();
+
+	report_prefix_push("SIE spec ex interpretation");
+	report_prefix_push("off");
+	reset_guest();
+	sie(&vm);
+	/* interpretation off -> initial exception must cause interception */
+	report(vm.sblk->icptcode == ICPT_PROGI
+	       && vm.sblk->iprcc == PGM_INT_CODE_SPECIFICATION
+	       && vm.sblk->gpsw.addr != 0xdeadbeee,
+	       "Received specification exception intercept for initial exception");
+	report_prefix_pop();
+
+	report_prefix_push("on");
+	vm.sblk->ecb |= ECB_SPECI;
+	reset_guest();
+	sie(&vm);
+	/* interpretation on -> configuration dependent if initial exception causes
+	 * interception, but invalid new program PSW must
+	 */
+	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");
+	else
+		report_info("Did not interpret initial exception");
+	report_prefix_pop();
+	report_prefix_pop();
+}
+
+int main(int argc, char **argv)
+{
+	if (!sclp_facilities.has_sief2) {
+		report_skip("SIEF2 facility unavailable");
+		goto out;
+	}
+
+	test_spec_ex_sie();
+out:
+	return report_summary();
+}
s390x/unittests.cfg +3 -0
index 9e1802f..3b454b7 100644
@@ -109,3 +109,6 @@ file = edat.elf
 
 [mvpg-sie]
 file = mvpg-sie.elf
+
+[spec_ex-sie]
+file = spec_ex-sie.elf
#9 lore raw

Re: [kvm-unit-tests PATCH v2 2/2] s390x: Add specification exception interception test

Quoted 79 lines · Claudio Imbrenda
Quoted 63 lines · On Tue, 5 Oct 2021 11:11:53 +0200 Janis Schoetterl-Glausch…

Check that specification exceptions cause intercepts when specification exception interpretation is off.
Check that specification exceptions caused by program new PSWs cause interceptions.
We cannot assert that non program new PSW specification exceptions are interpreted because whether interpretation occurs or not is configuration dependent.

---
 s390x/Makefile             |  2 +
 lib/s390x/sie.h            |  1 +
 s390x/snippets/c/spec_ex.c | 20 +++++++++
 s390x/spec_ex-sie.c        | 83 ++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg        |  3 ++
 5 files changed, 109 insertions(+)
 create mode 100644 s390x/snippets/c/spec_ex.c
 create mode 100644 s390x/spec_ex-sie.c
s390x/Makefile +2 -0
index ef8041a..7198882 100644
@@ -24,6 +24,7 @@ tests += $(TEST_DIR)/mvpg.elf
 tests += $(TEST_DIR)/uv-host.elf
 tests += $(TEST_DIR)/edat.elf
 tests += $(TEST_DIR)/mvpg-sie.elf
+tests += $(TEST_DIR)/spec_ex-sie.elf
 
 tests_binary = $(patsubst %.elf,%.bin,$(tests))
 ifneq ($(HOST_KEY_DOCUMENT),)
@@ -85,6 +86,7 @@ snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o
 # perquisites (=guests) for the snippet hosts.
 # $(TEST_DIR)/<snippet-host>.elf: snippets = $(SNIPPET_DIR)/<c/asm>/<snippet>.gbin
 $(TEST_DIR)/mvpg-sie.elf: snippets = $(SNIPPET_DIR)/c/mvpg-snippet.gbin
+$(TEST_DIR)/spec_ex-sie.elf: snippets = $(SNIPPET_DIR)/c/spec_ex.gbin
 
 $(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o $(FLATLIBS)
 	$(OBJCOPY) -O binary $(patsubst %.gbin,%.o,$@) $@
lib/s390x/sie.h +1 -0
index ca514ef..7ef7251 100644
@@ -98,6 +98,7 @@ struct kvm_s390_sie_block {
 	uint8_t		fpf;			/* 0x0060 */
 #define ECB_GS		0x40
 #define ECB_TE		0x10
+#define ECB_SPECI	0x08
 #define ECB_SRSI	0x04
 #define ECB_HOSTPROTINT	0x02
 	uint8_t		ecb;			/* 0x0061 */
s390x/snippets/c/spec_ex.c new file +6 -0
new file mode 100644
index 0000000..bdba4f4
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * © Copyright IBM Corp. 2021
+ *
+ * Snippet used by specification exception interception test.
+ */

s390x/snippets/c/spec_ex.c line 16

Quoted 10 lines
s390x/snippets/c/spec_ex.c new file +10 -0
+#include <stdint.h>
+#include <asm/arch_def.h>
+
+__attribute__((section(".text"))) int main(void)
+{
+	struct lowcore *lowcore = (struct lowcore *) 0;
+	uint64_t bad_psw = 0;
+
+	/* PSW bit 12 has no name or meaning and must be 0 */
+	lowcore->pgm_new_psw.mask = 1UL << (63 - 12);

you can use the BIT or BIT_ULL macro

Quoted 4 lines

s390x/snippets/c/spec_ex.c line 17

Quoted 1 line
s390x/snippets/c/spec_ex.c new file +1 -0
+	lowcore->pgm_new_psw.addr = 0xdeadbeee;

if the system is broken, it might actually jump at that address; in that case, will the test fail?

Broken how? If interpretation is overzealous the test might hang.

[...]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#11 lore raw

Re: [kvm-unit-tests PATCH v2 2/2] s390x: Add specification exception interception test

Quoted 57 lines · Janosch Frank
Quoted 9 lines · Janis Schoetterl-Glausch

Check that specification exceptions cause intercepts when specification exception interpretation is off.
Check that specification exceptions caused by program new PSWs cause interceptions.
We cannot assert that non program new PSW specification exceptions are interpreted because whether interpretation occurs or not is configuration dependent.

Minor nit below.

Quoted 43 lines

---
  s390x/Makefile             |  2 +
  lib/s390x/sie.h            |  1 + s390x/snippets/c/spec_ex.c | 20 +++++++++ s390x/spec_ex-sie.c        | 83 ++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg        |  3 ++

  5 files changed, 109 insertions(+)

  create mode 100644 s390x/snippets/c/spec_ex.c
  create mode 100644 s390x/spec_ex-sie.c

s390x/Makefile +0 -0
index ef8041a..7198882 100644
@@ -24,6 +24,7 @@ tests += $(TEST_DIR)/mvpg.elf

  tests += $(TEST_DIR)/uv-host.elf
  tests += $(TEST_DIR)/edat.elf
  tests += $(TEST_DIR)/mvpg-sie.elf
+tests += $(TEST_DIR)/spec_ex-sie.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) ifneq ($(HOST_KEY_DOCUMENT),)

s390x/Makefile +0 -0
@@ -85,6 +86,7 @@ snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o
   # perquisites (=guests) for the snippet hosts.
   # $(TEST_DIR)/<snippet-host>.elf: snippets = $(SNIPPET_DIR)/<c/asm>/<snippet>.gbin

  $(TEST_DIR)/mvpg-sie.elf: snippets = $(SNIPPET_DIR)/c/mvpg-snippet.gbin +$(TEST_DIR)/spec_ex-sie.elf: snippets = $(SNIPPET_DIR)/c/spec_ex.gbin $(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o $(FLATLIBS) $(OBJCOPY) -O binary $(patsubst %.gbin,%.o,$@) $@

lib/s390x/sie.h +0 -0
index ca514ef..7ef7251 100644
@@ -98,6 +98,7 @@ struct kvm_s390_sie_block {

      uint8_t        fpf;            /* 0x0060 */
  #define ECB_GS        0x40
  #define ECB_TE        0x10
+#define ECB_SPECI    0x08
  #define ECB_SRSI    0x04
  #define ECB_HOSTPROTINT    0x02
      uint8_t        ecb;            /* 0x0061 */

s390x/snippets/c/spec_ex.c new file +0 -0
new file mode 100644
index 0000000..bdba4f4
Quoted 8 lines

s390x/snippets/c/spec_ex.c line 3

Quoted 6 lines
s390x/snippets/c/spec_ex.c new file +3 -0
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ *Copyright IBM Corp. 2021

I'd replace that copyright symbol with the (C) that we have usually.

IBM guidelines say to just drop it if not available. Will do that.

Quoted 1 line

Also, don't you want to add your name/mail in an authors list?

Eh, I don't see the point. Git tracks authorship and having a single source of truth is preferable IMO. Thanks for the reminder, tho.

[...]

Reviewed-by on v2 2/2
#12 lore raw

Re: [kvm-unit-tests PATCH v2 2/2] s390x: Add specification exception interception test

In reply to Janis Schoetterl-Glausch
Quoted 108 lines · Janis Schoetterl-Glausch

Check that specification exceptions cause intercepts when specification exception interpretation is off.
Check that specification exceptions caused by program new PSWs cause interceptions.
We cannot assert that non program new PSW specification exceptions are interpreted because whether interpretation occurs or not is configuration dependent.

---
  s390x/Makefile             |  2 +
  lib/s390x/sie.h            |  1 +
  s390x/snippets/c/spec_ex.c | 20 +++++++++
  s390x/spec_ex-sie.c        | 83 ++++++++++++++++++++++++++++++++++++++
  s390x/unittests.cfg        |  3 ++
  5 files changed, 109 insertions(+)

create mode 100644 s390x/snippets/c/spec_ex.c
create mode 100644 s390x/spec_ex-sie.c

s390x/Makefile +2 -0
index ef8041a..7198882 100644
@@ -24,6 +24,7 @@ tests += $(TEST_DIR)/mvpg.elf
  tests += $(TEST_DIR)/uv-host.elf
  tests += $(TEST_DIR)/edat.elf
  tests += $(TEST_DIR)/mvpg-sie.elf
+tests += $(TEST_DIR)/spec_ex-sie.elf
 
  tests_binary = $(patsubst %.elf,%.bin,$(tests))
  ifneq ($(HOST_KEY_DOCUMENT),)
@@ -85,6 +86,7 @@ snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o
  # perquisites (=guests) for the snippet hosts.
  # $(TEST_DIR)/<snippet-host>.elf: snippets = $(SNIPPET_DIR)/<c/asm>/<snippet>.gbin
  $(TEST_DIR)/mvpg-sie.elf: snippets = $(SNIPPET_DIR)/c/mvpg-snippet.gbin
+$(TEST_DIR)/spec_ex-sie.elf: snippets = $(SNIPPET_DIR)/c/spec_ex.gbin
 
  $(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o $(FLATLIBS)
  	$(OBJCOPY) -O binary $(patsubst %.gbin,%.o,$@) $@
lib/s390x/sie.h +1 -0
index ca514ef..7ef7251 100644
@@ -98,6 +98,7 @@ struct kvm_s390_sie_block {
  	uint8_t		fpf;			/* 0x0060 */
  #define ECB_GS		0x40
  #define ECB_TE		0x10
+#define ECB_SPECI	0x08
  #define ECB_SRSI	0x04
  #define ECB_HOSTPROTINT	0x02
  	uint8_t		ecb;			/* 0x0061 */
s390x/snippets/c/spec_ex.c new file +20 -0
new file mode 100644
index 0000000..bdba4f4
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * © Copyright IBM Corp. 2021
+ *
+ * Snippet used by specification exception interception test.
+ */
+#include <stdint.h>
+#include <asm/arch_def.h>
+
+__attribute__((section(".text"))) int main(void)
+{
+	struct lowcore *lowcore = (struct lowcore *) 0;
+	uint64_t bad_psw = 0;
+
+	/* PSW bit 12 has no name or meaning and must be 0 */
+	lowcore->pgm_new_psw.mask = 1UL << (63 - 12);
+	lowcore->pgm_new_psw.addr = 0xdeadbeee;
+	asm volatile ("lpsw %0" :: "Q"(bad_psw));
+	return 0;
+}
s390x/spec_ex-sie.c new file +25 -0
new file mode 100644
index 0000000..b7e79de
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * © Copyright IBM Corp. 2021
+ *
+ * Specification exception interception test.
+ * Checks that specification exception interceptions occur as expected when
+ * specification exception interpretation is off/on.
+ */
+#include <libcflat.h>
+#include <sclp.h>
+#include <asm/page.h>
+#include <asm/arch_def.h>
+#include <alloc_page.h>
+#include <vm.h>
+#include <sie.h>
+
+static struct vm vm;
+extern const char _binary_s390x_snippets_c_spec_ex_gbin_start[];
+extern const char _binary_s390x_snippets_c_spec_ex_gbin_end[];
+
+static void setup_guest(void)
+{
+	char *guest;
+	int binary_size = ((uintptr_t)_binary_s390x_snippets_c_spec_ex_gbin_end -
+			   (uintptr_t)_binary_s390x_snippets_c_spec_ex_gbin_start);

s390x/spec_ex-sie.c line 35

Quoted 10 lines
s390x/spec_ex-sie.c new file +10 -0
+
+	setup_vm();
+	guest = alloc_pages(8);
+	memcpy(guest, _binary_s390x_snippets_c_spec_ex_gbin_start, binary_size);
+	sie_guest_create(&vm, (uint64_t) guest, HPAGE_SIZE);
+}
+
+static void reset_guest(void)
+{
+	vm.sblk->gpsw.addr = PAGE_SIZE * 4;

Could we please get a #define for this magic PAGE_SIZE * 4 value, with a comment mentioning that the value comes from s390x/snippets/c/flat.lds ? I know it's already like this in the mvpg-sie.c test, so this could also be done in a follow-up patch instead, to fix mvpg-sie.c, too.

By the way, Janosch, do you remember why it s PAGE_SIZE * 4 and not PAGE_SIZE * 2 ? Space for additional SMP lowcores?

Quoted 54 lines
s390x/spec_ex-sie.c new file +48 -0
+	vm.sblk->gpsw.mask = PSW_MASK_64;
+	vm.sblk->icptcode = 0;
+}
+
+static void test_spec_ex_sie(void)
+{
+	setup_guest();
+
+	report_prefix_push("SIE spec ex interpretation");
+	report_prefix_push("off");
+	reset_guest();
+	sie(&vm);
+	/* interpretation off -> initial exception must cause interception */
+	report(vm.sblk->icptcode == ICPT_PROGI
+	       && vm.sblk->iprcc == PGM_INT_CODE_SPECIFICATION
+	       && vm.sblk->gpsw.addr != 0xdeadbeee,
+	       "Received specification exception intercept for initial exception");
+	report_prefix_pop();
+
+	report_prefix_push("on");
+	vm.sblk->ecb |= ECB_SPECI;
+	reset_guest();
+	sie(&vm);
+	/* interpretation on -> configuration dependent if initial exception causes
+	 * interception, but invalid new program PSW must
+	 */
+	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");
+	else
+		report_info("Did not interpret initial exception");
+	report_prefix_pop();
+	report_prefix_pop();
+}
+
+int main(int argc, char **argv)
+{
+	if (!sclp_facilities.has_sief2) {
+		report_skip("SIEF2 facility unavailable");
+		goto out;
+	}
+
+	test_spec_ex_sie();
+out:
+	return report_summary();
+}
s390x/unittests.cfg +0 -0
index 9e1802f..3b454b7 100644

s390x/unittests.cfg file = edat.elf · line 114

Quoted 6 lines
s390x/unittests.cfg +3 -0
@@ -109,3 +109,6 @@ file = edat.elf
 
  [mvpg-sie]
  file = mvpg-sie.elf
+
+[spec_ex-sie]
+file = spec_ex-sie.elf
#13 lore raw

Re: [kvm-unit-tests PATCH v2 2/2] s390x: Add specification exception interception test

Quoted 125 lines · Thomas Huth
Quoted 108 lines · Janis Schoetterl-Glausch

Check that specification exceptions cause intercepts when specification exception interpretation is off.
Check that specification exceptions caused by program new PSWs cause interceptions.
We cannot assert that non program new PSW specification exceptions are interpreted because whether interpretation occurs or not is configuration dependent.

---
   s390x/Makefile             |  2 +
   lib/s390x/sie.h            |  1 +
   s390x/snippets/c/spec_ex.c | 20 +++++++++
   s390x/spec_ex-sie.c        | 83 ++++++++++++++++++++++++++++++++++++++
   s390x/unittests.cfg        |  3 ++
   5 files changed, 109 insertions(+)

create mode 100644 s390x/snippets/c/spec_ex.c
create mode 100644 s390x/spec_ex-sie.c

s390x/Makefile +2 -0
index ef8041a..7198882 100644
@@ -24,6 +24,7 @@ tests += $(TEST_DIR)/mvpg.elf
   tests += $(TEST_DIR)/uv-host.elf
   tests += $(TEST_DIR)/edat.elf
   tests += $(TEST_DIR)/mvpg-sie.elf
+tests += $(TEST_DIR)/spec_ex-sie.elf
 
   tests_binary = $(patsubst %.elf,%.bin,$(tests))
   ifneq ($(HOST_KEY_DOCUMENT),)
@@ -85,6 +86,7 @@ snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o
   # perquisites (=guests) for the snippet hosts.
   # $(TEST_DIR)/<snippet-host>.elf: snippets = $(SNIPPET_DIR)/<c/asm>/<snippet>.gbin
   $(TEST_DIR)/mvpg-sie.elf: snippets = $(SNIPPET_DIR)/c/mvpg-snippet.gbin
+$(TEST_DIR)/spec_ex-sie.elf: snippets = $(SNIPPET_DIR)/c/spec_ex.gbin
 
   $(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o $(FLATLIBS)
   	$(OBJCOPY) -O binary $(patsubst %.gbin,%.o,$@) $@
lib/s390x/sie.h +1 -0
index ca514ef..7ef7251 100644
@@ -98,6 +98,7 @@ struct kvm_s390_sie_block {
   	uint8_t		fpf;			/* 0x0060 */
   #define ECB_GS		0x40
   #define ECB_TE		0x10
+#define ECB_SPECI	0x08
   #define ECB_SRSI	0x04
   #define ECB_HOSTPROTINT	0x02
   	uint8_t		ecb;			/* 0x0061 */
s390x/snippets/c/spec_ex.c new file +19 -0
new file mode 100644
index 0000000..bdba4f4
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
 
+ *
+ * Snippet used by specification exception interception test.
+ */
+#include <stdint.h>
+#include <asm/arch_def.h>
+
+__attribute__((section(".text"))) int main(void)
+{
+	struct lowcore *lowcore = (struct lowcore *) 0;
+	uint64_t bad_psw = 0;
+
+	/* PSW bit 12 has no name or meaning and must be 0 */
+	lowcore->pgm_new_psw.mask = 1UL << (63 - 12);
+	lowcore->pgm_new_psw.addr = 0xdeadbeee;
+	asm volatile ("lpsw %0" :: "Q"(bad_psw));
+	return 0;
+}
s390x/spec_ex-sie.c new file +24 -0
new file mode 100644
index 0000000..b7e79de
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
 
+ *
+ * Specification exception interception test.
+ * Checks that specification exception interceptions occur as expected when
+ * specification exception interpretation is off/on.
+ */
+#include <libcflat.h>
+#include <sclp.h>
+#include <asm/page.h>
+#include <asm/arch_def.h>
+#include <alloc_page.h>
+#include <vm.h>
+#include <sie.h>
+
+static struct vm vm;
+extern const char _binary_s390x_snippets_c_spec_ex_gbin_start[];
+extern const char _binary_s390x_snippets_c_spec_ex_gbin_end[];
+
+static void setup_guest(void)
+{
+	char *guest;
+	int binary_size = ((uintptr_t)_binary_s390x_snippets_c_spec_ex_gbin_end -
+			   (uintptr_t)_binary_s390x_snippets_c_spec_ex_gbin_start);

s390x/spec_ex-sie.c line 35

Quoted 10 lines
s390x/spec_ex-sie.c new file +10 -0
+
+	setup_vm();
+	guest = alloc_pages(8);
+	memcpy(guest, _binary_s390x_snippets_c_spec_ex_gbin_start, binary_size);
+	sie_guest_create(&vm, (uint64_t) guest, HPAGE_SIZE);
+}
+
+static void reset_guest(void)
+{
+	vm.sblk->gpsw.addr = PAGE_SIZE * 4;

Could we please get a #define for this magic PAGE_SIZE * 4 value, with a comment mentioning that the value comes from s390x/snippets/c/flat.lds ? I know it's already like this in the mvpg-sie.c test, so this could also be done in a follow-up patch instead, to fix mvpg-sie.c, too.

Quoted 2 lines

By the way, Janosch, do you remember why it s PAGE_SIZE * 4 and not PAGE_SIZE * 2 ? Space for additional SMP lowcores?

I've put the stack on Page 4 because I can't guarantee what people do on higher pages so I hope we don't need more than a page or two for the stack. It's very much a hack :)

Quoted 64 lines
Quoted 55 lines
s390x/spec_ex-sie.c new file +48 -0
+	vm.sblk->gpsw.mask = PSW_MASK_64;
+	vm.sblk->icptcode = 0;
+}
+
+static void test_spec_ex_sie(void)
+{
+	setup_guest();
+
+	report_prefix_push("SIE spec ex interpretation");
+	report_prefix_push("off");
+	reset_guest();
+	sie(&vm);
+	/* interpretation off -> initial exception must cause interception */
+	report(vm.sblk->icptcode == ICPT_PROGI
+	       && vm.sblk->iprcc == PGM_INT_CODE_SPECIFICATION
+	       && vm.sblk->gpsw.addr != 0xdeadbeee,
+	       "Received specification exception intercept for initial exception");
+	report_prefix_pop();
+
+	report_prefix_push("on");
+	vm.sblk->ecb |= ECB_SPECI;
+	reset_guest();
+	sie(&vm);
+	/* interpretation on -> configuration dependent if initial exception causes
+	 * interception, but invalid new program PSW must
+	 */
+	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");
+	else
+		report_info("Did not interpret initial exception");
+	report_prefix_pop();
+	report_prefix_pop();
+}
+
+int main(int argc, char **argv)
+{
+	if (!sclp_facilities.has_sief2) {
+		report_skip("SIEF2 facility unavailable");
+		goto out;
+	}
+
+	test_spec_ex_sie();
+out:
+	return report_summary();
+}
s390x/unittests.cfg +0 -0
index 9e1802f..3b454b7 100644

s390x/unittests.cfg file = edat.elf · line 114

Quoted 6 lines
s390x/unittests.cfg +3 -0
@@ -109,3 +109,6 @@ file = edat.elf
 
   [mvpg-sie]
   file = mvpg-sie.elf
+
+[spec_ex-sie]
+file = spec_ex-sie.elf