Skip to contentSkip to conversation

s390x update 2021-10-18

GIT PULL Applied Janosch Frank 2 participants 19 messages Oct 18, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Dear Paolo,

please merge or pull the following changes:
* Skey addressing exception test (David)
* sthyi reg 2 + 1 check (Janosch)
* General cleanup (Thomas, Janosch & Janis)
* Snippet cleanup (Thomas & Janosch)

MERGE:
https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/merge_requests/18

PIPELINE:
https://gitlab.com/frankja/kvm-unit-tests/-/pipelines/390243055

The pipeline fails because the new SKEY checks fail without a QEMU fix which is not yet in the CI's QEMU version. I've already contacted Thomas about this.

PULL:
The following changes since commit b4667f4ca26aea926a2ddecfcb5669e0e4e7cbf4:

arm64: gic-v3: Avoid NULL dereferences (2021-10-12 09:33:49 +0200)

are available in the Git repository at:

https://gitlab.com/frankja/kvm-unit-tests.git s390x-pull-2021-10-18

for you to fetch changes up to a2b44f223e7655155ff926eea60eb40e0b4d14f5:

lib: s390x: Fix copyright message (2021-10-18 09:31:39 +0000)

----------------------------------------------------------------

David Hildenbrand (1):
s390x: skey: Test for ADDRESSING exceptions

Janis Schoetterl-Glausch (1):
lib: s390x: Add access key argument to tprot

Janosch Frank (13):
s390x: uv-host: Explain why we set up the home space and remove the
space change
lib: s390x: Control register constant cleanup
lib: s390x: Print addressing related exception information
s390x: uv: Tolerate 0x100 query return code
s390x: uv-host: Fence a destroy cpu test on z15
lib: s390x: uv: Fix share return value and print
lib: s390x: uv: Add UVC_ERR_DEBUG switch
lib: s390x: Print PGM code as hex
s390x: Add sthyi cc==0 r2+1 verification
s390x: snippets: Set stackptr and stacktop in cstart.S
lib: s390x: Fix PSW constant
lib: s390x: snippet.h: Add a few constants that will make our life
easier
lib: s390x: Fix copyright message

Thomas Huth (2):
s390x: mvpg-sie: Remove unused variable
s390x: snippets: Define all things that are needed to link the libc

 lib/s390x/asm/arch_def.h  | 55 +++++++++++++++++-----------
 lib/s390x/asm/mem.h       | 12 +++++++
 lib/s390x/asm/uv.h        | 21 ++++++-----
 lib/s390x/css.h           |  2 +-
 lib/s390x/fault.c         | 76 +++++++++++++++++++++++++++++++++++++++
 lib/s390x/fault.h         | 44 +++++++++++++++++++++++
 lib/s390x/interrupt.c     | 29 +++++++++++++--
 lib/s390x/sclp.c          |  2 +-
 lib/s390x/sclp.h          |  2 +-
 lib/s390x/smp.c           |  3 +-
 lib/s390x/snippet.h       | 34 ++++++++++++++++++
 s390x/Makefile            |  3 +-
 s390x/mvpg-sie.c          | 16 ++++-----
 s390x/skey.c              | 28 +++++++++++++++
 s390x/skrf.c              |  6 ++--
 s390x/snippets/c/cstart.S | 13 ++++++-
 s390x/snippets/c/flat.lds |  2 ++
 s390x/sthyi.c             | 21 ++++++-----
 s390x/uv-guest.c          |  4 ++-
 s390x/uv-host.c           | 30 ++++++++++------
 20 files changed, 333 insertions(+), 70 deletions(-)
 create mode 100644 lib/s390x/fault.c
 create mode 100644 lib/s390x/fault.h
 create mode 100644 lib/s390x/snippet.h
Signature · 1 line
2.31.1
#1 lore raw

[kvm-unit-tests GIT PULL 01/17] s390x: uv-host: Explain why we set up the home space and remove the space change

UV home addresses don't require us to be in home space but we need to have it set up so hw/fw can use the home asce to translate home virtual addresses.

Hence we add a comment why we're setting up the home asce and remove the address space since it's unneeded.

---
 s390x/uv-host.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
s390x/uv-host.c +8 -3
index 426a67f6..28035707 100644
@@ -444,13 +444,18 @@ static void test_clear(void)
 
 static void setup_vmem(void)
 {
-	uint64_t asce, mask;
+	uint64_t asce;
 
 	setup_mmu(get_max_ram_size(), NULL);
+	/*
+	 * setup_mmu() will enable DAT and set the primary address
+	 * space but we need to have a valid home space since UV calls
+	 * take home space virtual addresses.
+	 *
+	 * Hence we just copy the primary asce into the home space.
+	 */
 	asce = stctg(1);
 	lctlg(13, asce);
-	mask = extract_psw_mask() | 0x0000C00000000000UL;
-	load_psw_mask(mask);
 }
 
 int main(void)
Signature · 1 line
2.31.1
#2 lore raw

[kvm-unit-tests GIT PULL 03/17] lib: s390x: Print addressing related exception information

In reply to Janosch Frank

Right now we only get told the kind of program exception as well as the PSW at the point where it happened.

For addressing exceptions the PSW is not always enough so let's print the TEID which contains the failing address and flags that tell us more about the kind of address exception.

---
 lib/s390x/asm/arch_def.h |  5 +++
 lib/s390x/fault.c        | 76 ++++++++++++++++++++++++++++++++++++++++
 lib/s390x/fault.h        | 44 +++++++++++++++++++++++
 lib/s390x/interrupt.c    | 27 ++++++++++++--
 s390x/Makefile           |  1 +
 5 files changed, 151 insertions(+), 2 deletions(-)
 create mode 100644 lib/s390x/fault.c
 create mode 100644 lib/s390x/fault.h
lib/s390x/asm/arch_def.h +5 -0
index 24892bd8..aa80d840 100644
@@ -41,6 +41,11 @@ struct psw {
 	uint64_t	addr;
 };
 
+#define AS_PRIM				0
+#define AS_ACCR				1
+#define AS_SECN				2
+#define AS_HOME				3
+
 #define PSW_MASK_EXT			0x0100000000000000UL
 #define PSW_MASK_IO			0x0200000000000000UL
 #define PSW_MASK_DAT			0x0400000000000000UL
lib/s390x/fault.c new file +76 -0

76 lines not on this page · raw message

lib/s390x/fault.h new file +44 -0

44 lines not on this page · raw message

lib/s390x/interrupt.c +25 -2
index 01ded49d..126d4c0a 100644
@@ -12,6 +12,8 @@
 #include <sclp.h>
 #include <interrupt.h>
 #include <sie.h>
+#include <fault.h>
+#include <asm/page.h>
 
 static bool pgm_int_expected;
 static bool ext_int_expected;
@@ -76,8 +78,7 @@ static void fixup_pgm_int(struct stack_frame_int *stack)
 		break;
 	case PGM_INT_CODE_PROTECTION:
 		/* Handling for iep.c test case. */
-		if (lc->trans_exc_id & 0x80UL && lc->trans_exc_id & 0x04UL &&
-		    !(lc->trans_exc_id & 0x08UL))
+		if (prot_is_iep(lc->trans_exc_id))
 			/*
 			 * We branched to the instruction that caused
 			 * the exception so we can use the return
@@ -126,6 +127,24 @@ static void fixup_pgm_int(struct stack_frame_int *stack)
 	/* suppressed/terminated/completed point already at the next address */
 }
 
+static void print_storage_exception_information(void)
+{
+	switch (lc->pgm_int_code) {
+	case PGM_INT_CODE_PROTECTION:
+	case PGM_INT_CODE_PAGE_TRANSLATION:
+	case PGM_INT_CODE_SEGMENT_TRANSLATION:
+	case PGM_INT_CODE_ASCE_TYPE:
+	case PGM_INT_CODE_REGION_FIRST_TRANS:
+	case PGM_INT_CODE_REGION_SECOND_TRANS:
+	case PGM_INT_CODE_REGION_THIRD_TRANS:
+	case PGM_INT_CODE_SECURE_STOR_ACCESS:
+	case PGM_INT_CODE_NON_SECURE_STOR_ACCESS:
+	case PGM_INT_CODE_SECURE_STOR_VIOLATION:
+		print_decode_teid(lc->trans_exc_id);
+		break;
+	}
+}
+
 static void print_int_regs(struct stack_frame_int *stack)
 {
 	printf("\n");
@@ -155,6 +174,10 @@ static void print_pgm_info(struct stack_frame_int *stack)
 	       lc->pgm_int_code, stap(), lc->pgm_old_psw.addr, lc->pgm_int_id);
 	print_int_regs(stack);
 	dump_stack();
+
+	/* Dump stack doesn't end with a \n so we add it here instead */
+	printf("\n");
+	print_storage_exception_information();
 	report_summary();
 	abort();
 }
s390x/Makefile +1 -0
index ef8041a6..5d1a33a0 100644
@@ -72,6 +72,7 @@ cflatobjs += lib/s390x/css_lib.o
 cflatobjs += lib/s390x/malloc_io.o
 cflatobjs += lib/s390x/uv.o
 cflatobjs += lib/s390x/sie.o
+cflatobjs += lib/s390x/fault.o
 
 OBJDIRS += lib/s390x
 
Signature · 1 line
2.31.1
#3 lore raw

[kvm-unit-tests GIT PULL 04/17] s390x: skey: Test for ADDRESSING exceptions

In reply to Janosch Frank

From: David Hildenbrand <[email protected]>

... used to be broken in TCG, so let's add a very simple test for SSKE and ISKE. In order to test RRBE as well, introduce a helper to call the machine instruction.

Message-Id: <[email protected]>

---
 lib/s390x/asm/mem.h | 12 ++++++++++++
 s390x/skey.c        | 28 ++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
lib/s390x/asm/mem.h +12 -0
index 40b22b63..845c00cc 100644
@@ -50,6 +50,18 @@ static inline unsigned char get_storage_key(void *addr)
 	return skey;
 }
 
+static inline unsigned char reset_reference_bit(void *addr)
+{
+	int cc;
+
+	asm volatile(
+		"rrbe	0,%1\n"
+		"ipm	%0\n"
+		"srl	%0,28\n"
+		: "=d" (cc) : "a" (addr) : "cc");
+	return cc;
+}
+
 #define PFMF_FSC_4K 0
 #define PFMF_FSC_1M 1
 #define PFMF_FSC_2G 2
s390x/skey.c +28 -0
index 25399443..58a55436 100644
@@ -120,6 +120,33 @@ static void test_priv(void)
 	report_prefix_pop();
 }
 
+static void test_invalid_address(void)
+{
+	void *inv_addr = (void *)-1ull;
+
+	report_prefix_push("invalid address");
+
+	report_prefix_push("sske");
+	expect_pgm_int();
+	set_storage_key(inv_addr, 0, 0);
+	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
+	report_prefix_pop();
+
+	report_prefix_push("iske");
+	expect_pgm_int();
+	get_storage_key(inv_addr);
+	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
+	report_prefix_pop();
+
+	report_prefix_push("rrbe");
+	expect_pgm_int();
+	reset_reference_bit(inv_addr);
+	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
+	report_prefix_pop();
+
+	report_prefix_pop();
+}
+
 int main(void)
 {
 	report_prefix_push("skey");
@@ -128,6 +155,7 @@ int main(void)
 		goto done;
 	}
 	test_priv();
+	test_invalid_address();
 	test_set();
 	test_set_mb();
 	test_chg();
Signature · 1 line
2.31.1
#4 lore raw

[kvm-unit-tests GIT PULL 02/17] lib: s390x: Control register constant cleanup

In reply to Janosch Frank

We had bits and masks defined and don't necessarily need both.

---
 lib/s390x/asm/arch_def.h | 28 ++++++++++++----------------
 lib/s390x/smp.c          |  3 ++-
 s390x/skrf.c             |  3 ++-
 3 files changed, 16 insertions(+), 18 deletions(-)
lib/s390x/asm/arch_def.h +12 -16
index 302ef1ff..24892bd8 100644
@@ -50,10 +50,18 @@ struct psw {
 #define PSW_MASK_BA			0x0000000080000000UL
 #define PSW_MASK_64			PSW_MASK_BA | PSW_MASK_EA;
 
-#define CR0_EXTM_SCLP			0x0000000000000200UL
-#define CR0_EXTM_EXTC			0x0000000000002000UL
-#define CR0_EXTM_EMGC			0x0000000000004000UL
-#define CR0_EXTM_MASK			0x0000000000006200UL
+#define CTL0_LOW_ADDR_PROT		(63 - 35)
+#define CTL0_EDAT			(63 - 40)
+#define CTL0_IEP			(63 - 43)
+#define CTL0_AFP			(63 - 45)
+#define CTL0_VECTOR			(63 - 46)
+#define CTL0_EMERGENCY_SIGNAL		(63 - 49)
+#define CTL0_EXTERNAL_CALL		(63 - 50)
+#define CTL0_CLOCK_COMPARATOR		(63 - 52)
+#define CTL0_SERVICE_SIGNAL		(63 - 54)
+#define CR0_EXTM_MASK			0x0000000000006200UL /* Combined external masks */
+
+#define CTL2_GUARDED_STORAGE		(63 - 59)
 
 struct lowcore {
 	uint8_t		pad_0x0000[0x0080 - 0x0000];	/* 0x0000 */
@@ -235,18 +243,6 @@ static inline uint64_t stctg(int cr)
 	return value;
 }
 
-#define CTL0_LOW_ADDR_PROT	(63 - 35)
-#define CTL0_EDAT		(63 - 40)
-#define CTL0_IEP		(63 - 43)
-#define CTL0_AFP		(63 - 45)
-#define CTL0_VECTOR		(63 - 46)
-#define CTL0_EMERGENCY_SIGNAL	(63 - 49)
-#define CTL0_EXTERNAL_CALL	(63 - 50)
-#define CTL0_CLOCK_COMPARATOR	(63 - 52)
-#define CTL0_SERVICE_SIGNAL	(63 - 54)
-
-#define CTL2_GUARDED_STORAGE	(63 - 59)
-
 static inline void ctl_set_bit(int cr, unsigned int bit)
 {
         uint64_t reg;
lib/s390x/smp.c +2 -1
index 228fe667..da6d32f3 100644
@@ -10,6 +10,7 @@
  *  Janosch Frank <[email protected]>
  */
 #include <libcflat.h>
+#include <bitops.h>
 #include <asm/arch_def.h>
 #include <asm/sigp.h>
 #include <asm/page.h>
@@ -204,7 +205,7 @@ int smp_cpu_setup(uint16_t addr, struct psw psw)
 	cpu->lowcore->sw_int_grs[15] = (uint64_t)cpu->stack + (PAGE_SIZE * 4);
 	lc->restart_new_psw.mask = PSW_MASK_64;
 	lc->restart_new_psw.addr = (uint64_t)smp_cpu_setup_state;
-	lc->sw_int_crs[0] = 0x0000000000040000UL;
+	lc->sw_int_crs[0] = BIT_ULL(CTL0_AFP);
 
 	/* Start processing */
 	smp_cpu_restart_nolock(addr, NULL);
s390x/skrf.c +2 -1
index 9488c32b..8ca7588c 100644
@@ -8,6 +8,7 @@
  *  Janosch Frank <[email protected]>
  */
 #include <libcflat.h>
+#include <bitops.h>
 #include <asm/asm-offsets.h>
 #include <asm-generic/barrier.h>
 #include <asm/interrupt.h>
@@ -125,8 +126,8 @@ static void ecall_cleanup(void)
 {
 	struct lowcore *lc = (void *)0x0;
 
-	lc->sw_int_crs[0] = 0x0000000000040000;
 	lc->ext_new_psw.mask = PSW_MASK_64;
+	lc->sw_int_crs[0] = BIT_ULL(CTL0_AFP);
 
 	/*
 	 * PGM old contains the ext new PSW, we need to clean it up,
Signature · 1 line
2.31.1
#5 lore raw

[kvm-unit-tests GIT PULL 05/17] s390x: mvpg-sie: Remove unused variable

In reply to Janosch Frank

From: Thomas Huth <[email protected]>

The guest_instr variable is not used, which was likely a copy-n-paste issue from the s390x/sie.c test.

Message-Id: <[email protected]>

---
 s390x/mvpg-sie.c | 3 ---
 1 file changed, 3 deletions(-)
s390x/mvpg-sie.c +0 -3
index ccc273b4..5adcec1e 100644
@@ -21,7 +21,6 @@
 #include <sie.h>
 
 static u8 *guest;
-static u8 *guest_instr;
 static struct vm vm;
 
 static uint8_t *src;
@@ -94,8 +93,6 @@ static void setup_guest(void)
 
 	/* Allocate 1MB as guest memory */
 	guest = alloc_pages(8);
-	/* The first two pages are the lowcore */
-	guest_instr = guest + PAGE_SIZE * 2;
 
 	sie_guest_create(&vm, (uint64_t)guest, HPAGE_SIZE);
 
Signature · 1 line
2.31.1
#6 lore raw

[kvm-unit-tests GIT PULL 06/17] s390x: uv: Tolerate 0x100 query return code

In reply to Janosch Frank

RC 0x100 is not an error but a notice that we could have gotten more data from the Ultravisor if we had asked for it. So let's tolerate them in our tests.

---
 s390x/uv-guest.c | 4 +++-
 s390x/uv-host.c  | 8 +++++---
 2 files changed, 8 insertions(+), 4 deletions(-)
s390x/uv-guest.c +3 -1
index f05ae4c3..44ad2154 100644
@@ -71,7 +71,9 @@ static void test_query(void)
 
 	uvcb.header.len = sizeof(uvcb);
 	cc = uv_call(0, (u64)&uvcb);
-	report(cc == 0 && uvcb.header.rc == UVC_RC_EXECUTED, "successful query");
+	report((!cc && uvcb.header.rc == UVC_RC_EXECUTED) ||
+	       (cc == 1 && uvcb.header.rc == 0x100),
+		"successful query");
 
 	/*
 	 * These bits have been introduced with the very first
s390x/uv-host.c +5 -3
index 28035707..4b72c24d 100644
@@ -385,7 +385,7 @@ static void test_init(void)
 
 static void test_query(void)
 {
-	int i = 0;
+	int i = 0, cc;
 
 	uvcb_qui.header.cmd = UVC_CMD_QUI;
 	uvcb_qui.header.len = sizeof(uvcb_qui);
@@ -400,8 +400,10 @@ static void test_query(void)
 	report(uvcb_qui.header.rc == 0x100, "insf length");
 
 	uvcb_qui.header.len = sizeof(uvcb_qui);
-	uv_call(0, (uint64_t)&uvcb_qui);
-	report(uvcb_qui.header.rc == UVC_RC_EXECUTED, "successful query");
+	cc = uv_call(0, (uint64_t)&uvcb_qui);
+	report((!cc && uvcb_qui.header.rc == UVC_RC_EXECUTED) ||
+	       (cc == 1 && uvcb_qui.header.rc == 0x100),
+		"successful query");
 
 	for (i = 0; cmds[i].name; i++)
 		report(uv_query_test_call(cmds[i].call_bit), "%s", cmds[i].name);
Signature · 1 line
2.31.1
#7 lore raw

[kvm-unit-tests GIT PULL 07/17] s390x: uv-host: Fence a destroy cpu test on z15

In reply to Janosch Frank

Firmware will not give us the expected return code on z15 so let's fence it for the z15 machine generation.

---
 lib/s390x/asm/arch_def.h | 14 ++++++++++++++
 s390x/uv-host.c          | 11 +++++++----
 2 files changed, 21 insertions(+), 4 deletions(-)
lib/s390x/asm/arch_def.h +14 -0
index aa80d840..c8d2722a 100644
@@ -219,6 +219,20 @@ 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;
+
+	asm volatile("stidp %0" : "=Q" (cpuid));
+	cpuid = cpuid >> 16;
+	cpuid &= 0xffff;
+
+	return cpuid;
+}
+
 static inline int tprot(unsigned long addr)
 {
 	int cc;
s390x/uv-host.c +7 -4
index 4b72c24d..92a41069 100644
@@ -111,6 +111,7 @@ 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,
@@ -125,10 +126,12 @@ static void test_cpu_destroy(void)
 	       "hdr invalid length");
 	uvcb.header.len += 8;
 
-	uvcb.handle += 1;
-	rc = uv_call(0, (uint64_t)&uvcb);
-	report(rc == 1 && uvcb.header.rc == UVC_RC_INV_CHANDLE, "invalid handle");
-	uvcb.handle -= 1;
+	if (machineid != MACHINE_Z15A && machineid != MACHINE_Z15B) {
+		uvcb.handle += 1;
+		rc = uv_call(0, (uint64_t)&uvcb);
+		report(rc == 1 && uvcb.header.rc == UVC_RC_INV_CHANDLE, "invalid handle");
+		uvcb.handle -= 1;
+	}
 
 	rc = uv_call(0, (uint64_t)&uvcb);
 	report(rc == 0 && uvcb.header.rc == UVC_RC_EXECUTED, "success");
Signature · 1 line
2.31.1
#8 lore raw

[kvm-unit-tests GIT PULL 08/17] lib: s390x: uv: Fix share return value and print

In reply to Janosch Frank

Let's only return 0/1 for success/failure respectively. If needed we can later add rc/rrc pointers so we can check for the reasons of cc==1 cases like we do in the kernel.

As share() might also be used in snippets it's best not to use prints to avoid linking problems so lets remove the report_info().

---
 lib/s390x/asm/uv.h | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
lib/s390x/asm/uv.h +1 -8
index ec10d1c4..2f099553 100644
@@ -219,15 +219,8 @@ static inline int share(unsigned long addr, u16 cmd)
 		.header.len = sizeof(uvcb),
 		.paddr = addr
 	};
-	int cc;
 
-	cc = uv_call(0, (u64)&uvcb);
-	if (!cc && uvcb.header.rc == UVC_RC_EXECUTED)
-		return 0;
-
-	report_info("uv_call: cmd %04x cc %d response code: %04x", cc, cmd,
-		    uvcb.header.rc);
-	return -1;
+	return uv_call(0, (u64)&uvcb);
 }
 
 /*
Signature · 1 line
2.31.1
#9 lore raw

[kvm-unit-tests GIT PULL 09/17] lib: s390x: uv: Add UVC_ERR_DEBUG switch

In reply to Janosch Frank

Every time something goes wrong in a way we don't expect, we need to add debug prints to some UVC to get the unexpected return code.

Let's just put the printing behind a macro so we can enable it if needed via a simple switch.

---
 lib/s390x/asm/uv.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
lib/s390x/asm/uv.h +12 -0
index 2f099553..8baf896f 100644
@@ -12,6 +12,11 @@
 #ifndef _ASMS390X_UV_H_
 #define _ASMS390X_UV_H_
 
+/* Enables printing of command code and return codes for failed UVCs */
+#ifndef UVC_ERR_DEBUG
+#define UVC_ERR_DEBUG	0
+#endif
+
 #define UVC_RC_EXECUTED		0x0001
 #define UVC_RC_INV_CMD		0x0002
 #define UVC_RC_INV_STATE	0x0003
@@ -194,6 +199,13 @@ static inline int uv_call_once(unsigned long r1, unsigned long r2)
 		: [cc] "=d" (cc)
 		: [r1] "a" (r1), [r2] "a" (r2)
 		: "memory", "cc");
+
+	if (UVC_ERR_DEBUG && cc == 1)
+		printf("UV call error: call %x rc %x rrc %x\n",
+		       ((struct uv_cb_header *)r2)->cmd,
+		       ((struct uv_cb_header *)r2)->rc,
+		       ((struct uv_cb_header *)r2)->rrc);
+
 	return cc;
 }
 
Signature · 1 line
2.31.1
#10 lore raw

[kvm-unit-tests GIT PULL 10/17] lib: s390x: Add access key argument to tprot

In reply to Janosch Frank

From: Janis Schoetterl-Glausch <[email protected]>

Currently there is only one callee passing a non zero key, but having the argument will be useful in the future.

---
 lib/s390x/asm/arch_def.h | 6 +++---
 lib/s390x/sclp.c         | 2 +-
 s390x/skrf.c             | 3 +--
 3 files changed, 5 insertions(+), 6 deletions(-)
lib/s390x/asm/arch_def.h +3 -3
index c8d2722a..b34aa792 100644
@@ -233,15 +233,15 @@ static inline uint16_t get_machine_id(void)
 	return cpuid;
 }
 
-static inline int tprot(unsigned long addr)
+static inline int tprot(unsigned long addr, char access_key)
 {
 	int cc;
 
 	asm volatile(
-		"	tprot	0(%1),0\n"
+		"	tprot	0(%1),0(%2)\n"
 		"	ipm	%0\n"
 		"	srl	%0,28\n"
-		: "=d" (cc) : "a" (addr) : "cc");
+		: "=d" (cc) : "a" (addr), "a" (access_key << 4) : "cc");
 	return cc;
 }
 
lib/s390x/sclp.c +1 -1
index 9502d161..02722498 100644
@@ -217,7 +217,7 @@ void sclp_memory_setup(void)
 	/* probe for r/w memory up to max memory size */
 	while (ram_size < max_ram_size) {
 		expect_pgm_int();
-		cc = tprot(ram_size + storage_increment_size - 1);
+		cc = tprot(ram_size + storage_increment_size - 1, 0);
 		/* stop once we receive an exception or have protected memory */
 		if (clear_pgm_int() || cc != 0)
 			break;
s390x/skrf.c +1 -2
index 8ca7588c..ca4efbf1 100644
@@ -103,8 +103,7 @@ static void test_tprot(void)
 {
 	report_prefix_push("tprot");
 	expect_pgm_int();
-	asm volatile("tprot	%[addr],0xf0(0)\n"
-		     : : [addr] "a" (pagebuf) : );
+	tprot((unsigned long)pagebuf, 0xf);
 	check_pgm_int_code(PGM_INT_CODE_SPECIAL_OPERATION);
 	report_prefix_pop();
 }
Signature · 1 line
2.31.1
#11 lore raw

[kvm-unit-tests GIT PULL 11/17] lib: s390x: Print PGM code as hex

In reply to Janosch Frank

We have them defined as hex constants in lib/s390x/asm/arch_def.h so why not print them as hex values?

---
 lib/s390x/interrupt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/s390x/interrupt.c +1 -1
index 126d4c0a..27d3b767 100644
@@ -169,7 +169,7 @@ static void print_pgm_info(struct stack_frame_int *stack)
 		  lc->pgm_old_psw.addr <= (uintptr_t)sie_exit);
 
 	printf("\n");
-	printf("Unexpected program interrupt %s: %d on cpu %d at %#lx, ilen %d\n",
+	printf("Unexpected program interrupt %s: %#x on cpu %d at %#lx, ilen %d\n",
 	       in_sie ? "in SIE" : "",
 	       lc->pgm_int_code, stap(), lc->pgm_old_psw.addr, lc->pgm_int_id);
 	print_int_regs(stack);
Signature · 1 line
2.31.1
#12 lore raw

[kvm-unit-tests GIT PULL 12/17] s390x: Add sthyi cc==0 r2+1 verification

In reply to Janosch Frank

On success r2 + 1 should be 0, let's also check for that.

---
 s390x/sthyi.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
s390x/sthyi.c +12 -9
index db90b56f..11487a0e 100644
@@ -24,16 +24,16 @@ static inline int sthyi(uint64_t vaddr, uint64_t fcode, uint64_t *rc,
 {
 	register uint64_t code asm("0") = fcode;
 	register uint64_t addr asm("2") = vaddr;
-	register uint64_t rc3 asm("3") = 0;
+	register uint64_t rc3 asm("3") = 42;
 	int cc = 0;
 
-	asm volatile(".insn rre,0xB2560000,%[r1],%[r2]\n"
-		     "ipm	 %[cc]\n"
-		     "srl	 %[cc],28\n"
-		     : [cc] "=d" (cc)
-		     : [code] "d" (code), [addr] "a" (addr), [r1] "i" (r1),
-		       [r2] "i" (r2)
-		     : "memory", "cc", "r3");
+	asm volatile(
+		".insn   rre,0xB2560000,%[r1],%[r2]\n"
+		"ipm     %[cc]\n"
+		"srl     %[cc],28\n"
+		: [cc] "=d" (cc), "+d" (rc3)
+		: [code] "d" (code), [addr] "a" (addr), [r1] "i" (r1), [r2] "i" (r2)
+		: "memory", "cc");
 	if (rc)
 		*rc = rc3;
 	return cc;
@@ -139,16 +139,19 @@ static void test_fcode0(void)
 	struct sthyi_hdr_sctn *hdr;
 	struct sthyi_mach_sctn *mach;
 	struct sthyi_par_sctn *par;
+	uint64_t rc = 42;
+	int cc;
 
 	/* Zero destination memory. */
 	memset(pagebuf, 0, PAGE_SIZE);
 
 	report_prefix_push("fcode 0");
-	sthyi((uint64_t)pagebuf, 0, NULL, 0, 2);
+	cc = sthyi((uint64_t)pagebuf, 0, &rc, 0, 2);
 	hdr = (void *)pagebuf;
 	mach = (void *)pagebuf + hdr->INFMOFF;
 	par = (void *)pagebuf + hdr->INFPOFF;
 
+	report(cc == 0 && rc == CODE_SUCCES, "r2 + 1 == 0");
 	test_fcode0_hdr(hdr);
 	test_fcode0_mach(mach);
 	test_fcode0_par(par);
Signature · 1 line
2.31.1
#13 lore raw

[kvm-unit-tests GIT PULL 13/17] s390x: snippets: Set stackptr and stacktop in cstart.S

In reply to Janosch Frank

We have a stack, so why not define it and be a step closer to include the lib into the snippets.

---
 s390x/snippets/c/cstart.S | 2 +-
 s390x/snippets/c/flat.lds | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
s390x/snippets/c/cstart.S +1 -1
index a1754808..031a6b83 100644
@@ -17,7 +17,7 @@ start:
 	xgr \i,\i
 	.endr
 	/* 0x3000 is the stack page for now */
-	lghi	%r15, 0x4000 - 160
+	lghi	%r15, stackptr
 	sam64
 	brasl	%r14, main
 	/* For now let's only use cpu 0 in snippets so this will always work. */
s390x/snippets/c/flat.lds +2 -0
index ce3bfd69..59974b38 100644
@@ -15,6 +15,8 @@ SECTIONS
 		 QUAD(0x0000000000004000)
 	}
 	. = 0x4000;
+	stackptr = . - 160;
+	stacktop = .;
 	.text : {
 		*(.init)
 		*(.text)
Signature · 1 line
2.31.1
#14 lore raw

[kvm-unit-tests GIT PULL 15/17] lib: s390x: Fix PSW constant

In reply to Janosch Frank

Somehow the ";" got into that patch and now complicates compilation. Let's remove it and put the constant in braces.

---
 lib/s390x/asm/arch_def.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/s390x/asm/arch_def.h +1 -1
index b34aa792..40626d72 100644
@@ -53,7 +53,7 @@ struct psw {
 #define PSW_MASK_PSTATE			0x0001000000000000UL
 #define PSW_MASK_EA			0x0000000100000000UL
 #define PSW_MASK_BA			0x0000000080000000UL
-#define PSW_MASK_64			PSW_MASK_BA | PSW_MASK_EA;
+#define PSW_MASK_64			(PSW_MASK_BA | PSW_MASK_EA)
 
 #define CTL0_LOW_ADDR_PROT		(63 - 35)
 #define CTL0_EDAT			(63 - 40)
Signature · 1 line
2.31.1
#15 lore raw

[kvm-unit-tests GIT PULL 16/17] lib: s390x: snippet.h: Add a few constants that will make our life easier

In reply to Janosch Frank

The variable names for the snippet objects are of gigantic length so let's define a few macros to make them easier to read.

Also add a standard PSW which should be used to start the snippet.

---
 lib/s390x/snippet.h | 34 ++++++++++++++++++++++++++++++++++
 s390x/mvpg-sie.c    | 13 ++++++-------
 2 files changed, 40 insertions(+), 7 deletions(-)
 create mode 100644 lib/s390x/snippet.h
lib/s390x/snippet.h new file +34 -0
new file mode 100644
index 00000000..8e4765f8
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Snippet definitions
+ *
+ * Copyright IBM Corp. 2021
+ * Author: Janosch Frank <[email protected]>
+ */
+
+#ifndef _S390X_SNIPPET_H_
+#define _S390X_SNIPPET_H_
+
+/* This macro cuts down the length of the pointers to snippets */
+#define SNIPPET_NAME_START(type, file) \
+	_binary_s390x_snippets_##type##_##file##_gbin_start
+#define SNIPPET_NAME_END(type, file) \
+	_binary_s390x_snippets_##type##_##file##_gbin_end
+
+/* Returns the length of the snippet */
+#define SNIPPET_LEN(type, file) \
+	((uintptr_t)SNIPPET_NAME_END(type, file) - (uintptr_t)SNIPPET_NAME_START(type, file))
+
+/*
+ * C snippet instructions start at 0x4000 due to the prefix and the
+ * stack being before that. ASM snippets don't strictly need a stack
+ * but keeping the starting address the same means less code.
+ */
+#define SNIPPET_ENTRY_ADDR 0x4000
+
+/* Standard entry PSWs for snippets which can simply be copied into the guest PSW */
+static const struct psw snippet_psw = {
+	.mask = PSW_MASK_64,
+	.addr = SNIPPET_ENTRY_ADDR,
+};
+#endif
s390x/mvpg-sie.c +6 -7
index 5adcec1e..d526069d 100644
@@ -19,6 +19,7 @@
 #include <vm.h>
 #include <sclp.h>
 #include <sie.h>
+#include <snippet.h>
 
 static u8 *guest;
 static struct vm vm;
@@ -27,8 +28,8 @@ static uint8_t *src;
 static uint8_t *dst;
 static uint8_t *cmp;
 
-extern const char _binary_s390x_snippets_c_mvpg_snippet_gbin_start[];
-extern const char _binary_s390x_snippets_c_mvpg_snippet_gbin_end[];
+extern const char SNIPPET_NAME_START(c, mvpg_snippet)[];
+extern const char SNIPPET_NAME_END(c, mvpg_snippet)[];
 int binary_size;
 
 static void test_mvpg_pei(void)
@@ -77,10 +78,9 @@ static void test_mvpg_pei(void)
 
 static void test_mvpg(void)
 {
-	int binary_size = ((uintptr_t)_binary_s390x_snippets_c_mvpg_snippet_gbin_end -
-			   (uintptr_t)_binary_s390x_snippets_c_mvpg_snippet_gbin_start);
+	int binary_size = SNIPPET_LEN(c, mvpg_snippet);
 
-	memcpy(guest, _binary_s390x_snippets_c_mvpg_snippet_gbin_start, binary_size);
+	memcpy(guest, SNIPPET_NAME_START(c, mvpg_snippet), binary_size);
 	memset(src, 0x42, PAGE_SIZE);
 	memset(dst, 0x43, PAGE_SIZE);
 	sie(&vm);
@@ -96,8 +96,7 @@ static void setup_guest(void)
 
 	sie_guest_create(&vm, (uint64_t)guest, HPAGE_SIZE);
 
-	vm.sblk->gpsw.addr = PAGE_SIZE * 4;
-	vm.sblk->gpsw.mask = PSW_MASK_64;
+	vm.sblk->gpsw = snippet_psw;
 	vm.sblk->ictl = ICTL_OPEREXC | ICTL_PINT;
 	/* Enable MVPG interpretation as we want to test KVM and not ourselves */
 	vm.sblk->eca = ECA_MVPGI;
Signature · 1 line
2.31.1
#16 lore raw

[kvm-unit-tests GIT PULL 14/17] s390x: snippets: Define all things that are needed to link the libc

In reply to Janosch Frank

From: Thomas Huth <[email protected]>

In the long run, we want to use parts of the libc like memset() etc., too. However, to be able to link it correctly, we have to provide some stub functions like puts() and exit() to avoid that too much other stuff from the lib folder gets pulled into the binaries, which we cannot provide in the snippets (like the sclp support).

Message-Id: <[email protected]>

---
 s390x/Makefile            |  2 +-
 s390x/snippets/c/cstart.S | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
s390x/Makefile +1 -1
index 5d1a33a0..d18b08b0 100644
@@ -81,7 +81,7 @@ asmlib = $(TEST_DIR)/cstart64.o $(TEST_DIR)/cpu.o
 FLATLIBS = $(libcflat)
 
 SNIPPET_DIR = $(TEST_DIR)/snippets
-snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o
+snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o lib/auxinfo.o
 
 # perquisites (=guests) for the snippet hosts.
 # $(TEST_DIR)/<snippet-host>.elf: snippets = $(SNIPPET_DIR)/<c/asm>/<snippet>.gbin
s390x/snippets/c/cstart.S +11 -0
index 031a6b83..aaa5380c 100644
@@ -20,6 +20,17 @@ start:
 	lghi	%r15, stackptr
 	sam64
 	brasl	%r14, main
+	/*
+	 * If main() returns, we stop the CPU with the code below. We also
+	 * route some functions that are required by the libc (but not usable
+	 * from snippets) to the CPU stop code below, so that snippets can
+	 * still be linked against the libc code (to use non-related functions
+	 * like memset() etc.)
+	 */
+.global puts
+.global exit
+puts:
+exit:
 	/* For now let's only use cpu 0 in snippets so this will always work. */
 	xgr	%r0, %r0
 	sigp    %r2, %r0, SIGP_STOP
Signature · 1 line
2.31.1
#17 lore raw

[kvm-unit-tests GIT PULL 17/17] lib: s390x: Fix copyright message

In reply to Janosch Frank

The comma makes no sense, so let's remove it.

---
 lib/s390x/css.h  | 2 +-
 lib/s390x/sclp.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
lib/s390x/css.h +1 -1
index d644971f..0db8a281 100644
@@ -2,7 +2,7 @@
 /*
  * CSS definitions
  *
- * Copyright IBM, Corp. 2020
+ * Copyright IBM Corp. 2020
  * Author: Pierre Morel <[email protected]>
  */
 
lib/s390x/sclp.h +1 -1
index 28e526e2..61e9cf51 100644
@@ -6,7 +6,7 @@
  * Copyright (c) 2013 Alexander Graf <[email protected]>
  *
  * and based on the file include/hw/s390x/sclp.h from QEMU
- * Copyright IBM, Corp. 2012
+ * Copyright IBM Corp. 2012
  * Author: Christian Borntraeger <[email protected]>
  */
 
Signature · 1 line
2.31.1
maintainer Applied
#18 lore raw
In reply to Janosch Frank
Quoted 81 lines · Janosch Frank

Dear Paolo,

please merge or pull the following changes:
* Skey addressing exception test (David)
* sthyi reg 2 + 1 check (Janosch)
* General cleanup (Thomas, Janosch & Janis)
* Snippet cleanup (Thomas & Janosch)

MERGE:
https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/merge_requests/18

PIPELINE:
https://gitlab.com/frankja/kvm-unit-tests/-/pipelines/390243055

The pipeline fails because the new SKEY checks fail without a QEMU fix which is not yet in the CI's QEMU version. I've already contacted Thomas about this.

PULL:
The following changes since commit b4667f4ca26aea926a2ddecfcb5669e0e4e7cbf4:

   arm64: gic-v3: Avoid NULL dereferences (2021-10-12 09:33:49 +0200)

are available in the Git repository at:

   https://gitlab.com/frankja/kvm-unit-tests.git s390x-pull-2021-10-18

for you to fetch changes up to a2b44f223e7655155ff926eea60eb40e0b4d14f5:

   lib: s390x: Fix copyright message (2021-10-18 09:31:39 +0000)

----------------------------------------------------------------

David Hildenbrand (1):
s390x: skey: Test for ADDRESSING exceptions

Janis Schoetterl-Glausch (1):
lib: s390x: Add access key argument to tprot

Janosch Frank (13):
s390x: uv-host: Explain why we set up the home space and remove the
space change
lib: s390x: Control register constant cleanup
lib: s390x: Print addressing related exception information
s390x: uv: Tolerate 0x100 query return code
s390x: uv-host: Fence a destroy cpu test on z15
lib: s390x: uv: Fix share return value and print
lib: s390x: uv: Add UVC_ERR_DEBUG switch
lib: s390x: Print PGM code as hex
s390x: Add sthyi cc==0 r2+1 verification
s390x: snippets: Set stackptr and stacktop in cstart.S
lib: s390x: Fix PSW constant
lib: s390x: snippet.h: Add a few constants that will make our life
easier
lib: s390x: Fix copyright message

Thomas Huth (2):
s390x: mvpg-sie: Remove unused variable
s390x: snippets: Define all things that are needed to link the libc

  lib/s390x/asm/arch_def.h  | 55 +++++++++++++++++-----------
  lib/s390x/asm/mem.h       | 12 +++++++
  lib/s390x/asm/uv.h        | 21 ++++++-----
  lib/s390x/css.h           |  2 +-
  lib/s390x/fault.c         | 76 +++++++++++++++++++++++++++++++++++++++
  lib/s390x/fault.h         | 44 +++++++++++++++++++++++
  lib/s390x/interrupt.c     | 29 +++++++++++++--
  lib/s390x/sclp.c          |  2 +-
  lib/s390x/sclp.h          |  2 +-
  lib/s390x/smp.c           |  3 +-
  lib/s390x/snippet.h       | 34 ++++++++++++++++++
  s390x/Makefile            |  3 +-
  s390x/mvpg-sie.c          | 16 ++++-----
  s390x/skey.c              | 28 +++++++++++++++
  s390x/skrf.c              |  6 ++--
  s390x/snippets/c/cstart.S | 13 ++++++-
  s390x/snippets/c/flat.lds |  2 ++
  s390x/sthyi.c             | 21 ++++++-----
  s390x/uv-guest.c          |  4 ++-
  s390x/uv-host.c           | 30 ++++++++++------
  20 files changed, 333 insertions(+), 70 deletions(-)
Quoted 4 lines

create mode 100644 lib/s390x/fault.c
create mode 100644 lib/s390x/fault.h
create mode 100644 lib/s390x/snippet.h

Merged, thanks.

Paolo