Skip to contentSkip to conversation

s390x update

GIT PULL Janosch Frank 2 participants 18 messages Mar 8, 2021

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

Dear Paolo,

please merge or pull the following changes:
* IO tests PV compatibility (Pierre)
* Backtrace support (Janosch)
* mvpg test (Claudio)
* Fixups (Thomas)

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

PULL:
The following changes since commit 739f7de6b3c8deaf22d2fa5e6016ad2c7bd22ddc:

x86: clean up EFER definitions (2021-02-18 13:31:22 -0500)

are available in the Git repository at:

https://gitlab.com/frankja/kvm-unit-tests.git s390x-pull-2021-08-03

for you to fetch changes up to b7f0f9a2e1fdb9d4235164f0a8d8ea880e1cefd4:

s390x: mvpg: skip some tests when using TCG (2021-03-08 12:03:47 +0100)

----------------------------------------------------------------
Claudio Imbrenda (3):
s390x: introduce leave_pstate to leave userspace
s390x: mvpg: simple test
s390x: mvpg: skip some tests when using TCG

Janosch Frank (8):
s390x: Remove sthyi partition number check
s390x: Fix fpc store address in RESTORE_REGS_STACK
s390x: Fully commit to stack save area for exceptions
s390x: Introduce and use CALL_INT_HANDLER macro
s390x: Provide preliminary backtrace support
s390x: Print more information on program exceptions
s390x: Move diag308_load_reset to stack saving
s390x: Remove SAVE/RESTORE_STACK and lowcore fpc and fprs save areas

Pierre Morel (3):
s390x: pv: implement routine to share/unshare memory
s390x: define UV compatible I/O allocation
s390x: css: pv: css test adaptation for PV

Thomas Huth (2):
lib/s390x/sclp: Clarify that the CPUEntry array could be at a
different spot
Fix the length in the stsi check for the VM name

 lib/s390x/asm-offsets.c   |  17 ++-
 lib/s390x/asm/arch_def.h  |  42 ++++--
 lib/s390x/asm/interrupt.h |   4 +-
 lib/s390x/asm/uv.h        |  39 ++++++
 lib/s390x/css.h           |   3 +-
 lib/s390x/css_lib.c       |  28 ++--
 lib/s390x/interrupt.c     |  61 +++++++--
 lib/s390x/malloc_io.c     |  71 ++++++++++
 lib/s390x/malloc_io.h     |  45 +++++++
 lib/s390x/sclp.h          |   9 +-
 lib/s390x/stack.c         |  20 ++-
 s390x/Makefile            |   3 +
 s390x/cpu.S               |   6 +-
 s390x/css.c               |  43 ++++--
 s390x/cstart64.S          |  25 +---
 s390x/macros.S            |  96 ++++++-------
 s390x/mvpg.c              | 277 ++++++++++++++++++++++++++++++++++++++
 s390x/sthyi.c             |   1 -
 s390x/stsi.c              |   2 +-
 s390x/unittests.cfg       |   4 +
 20 files changed, 657 insertions(+), 139 deletions(-)
 create mode 100644 lib/s390x/malloc_io.c
 create mode 100644 lib/s390x/malloc_io.h
 create mode 100644 s390x/mvpg.c
Signature · 1 line
2.29.2
#1 lore raw

[kvm-unit-tests GIT PULL 14/16] s390x: introduce leave_pstate to leave userspace

From: Claudio Imbrenda <[email protected]>

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 76cb7b33..7e2c5e62 100644
@@ -190,6 +190,8 @@ struct cpuid {
 	uint64_t reserved : 15;
 };
 
+#define SVC_LEAVE_PSTATE 1
+
 static inline unsigned short stap(void)
 {
 	unsigned short cpu_address;
@@ -293,6 +295,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 d9832bc0..ce0003de 100644
@@ -223,6 +223,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.29.2
#2 lore raw

[kvm-unit-tests GIT PULL 01/16] lib/s390x/sclp: Clarify that the CPUEntry array could be at a different spot

In reply to Janosch Frank

From: Thomas Huth <[email protected]>

The "struct CPUEntry entries[0]" in the ReadInfo structure is misleading since the entries could be at a completely different spot. Replace it by a proper comment instead.

Message-Id: <[email protected]>

---
 lib/s390x/sclp.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
lib/s390x/sclp.h +7 -2
index 9f81c0f1..85231333 100644
@@ -131,10 +131,15 @@ typedef struct ReadInfo {
 	uint16_t highest_cpu;
 	uint8_t  _reserved5[124 - 122];     /* 122-123 */
 	uint32_t hmfai;
-	uint8_t reserved7[134 - 128];
+	uint8_t reserved7[134 - 128];       /* 128-133 */
 	uint8_t byte_134_diag318 : 1;
 	uint8_t : 7;
-	struct CPUEntry entries[0];
+	/*
+	 * At the end of the ReadInfo, there are also the CPU entries (see
+	 * struct CPUEntry). When the Extended-Length SCCB (ELS) feature is
+	 * enabled, the start of the CPU entries array begins at an offset
+	 * denoted by the offset_cpu field, otherwise it's at offset 128.
+	 */
 } __attribute__((packed)) ReadInfo;
 
 typedef struct ReadCpuInfo {
Signature · 1 line
2.29.2
#3 lore raw

[kvm-unit-tests GIT PULL 03/16] s390x: define UV compatible I/O allocation

In reply to Janosch Frank

From: Pierre Morel <[email protected]>

To centralize the memory allocation for I/O we define the alloc_io_mem/free_io_mem functions which share the I/O memory with the host in case the guest runs with protected virtualization.

These functions allocate on a page integral granularity to ensure a dedicated sharing of the allocated objects.

Message-Id: <[email protected]>

---
 lib/s390x/malloc_io.c | 71 +++++++++++++++++++++++++++++++++++++++++++
 lib/s390x/malloc_io.h | 45 +++++++++++++++++++++++++++
 s390x/Makefile        |  1 +
 3 files changed, 117 insertions(+)
 create mode 100644 lib/s390x/malloc_io.c
 create mode 100644 lib/s390x/malloc_io.h
lib/s390x/malloc_io.c new file +71 -0
new file mode 100644
index 00000000..1dcf1691
@@ -0,0 +1,71 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * I/O page allocation
+ *
+ * Copyright (c) 2021 IBM Corp
+ *
+ * Authors:
+ *  Pierre Morel <[email protected]>
+ *
+ * Using this interface provide host access to the allocated pages in
+ * case the guest is a protected guest.
+ * This is needed for I/O buffers.
+ *
+ */
+#include <libcflat.h>
+#include <asm/page.h>
+#include <asm/uv.h>
+#include <malloc_io.h>
+#include <alloc_page.h>
+#include <asm/facility.h>
+#include <bitops.h>
+
+static int share_pages(void *p, int count)
+{
+	int i = 0;
+
+	for (i = 0; i < count; i++, p += PAGE_SIZE)
+		if (uv_set_shared((unsigned long)p))
+			break;
+	return i;
+}
+
+static void unshare_pages(void *p, int count)
+{
+	int i;
+
+	for (i = count; i > 0; i--, p += PAGE_SIZE)
+		uv_remove_shared((unsigned long)p);
+}
+
+void *alloc_io_mem(int size, int flags)
+{
+	int order = get_order(size >> PAGE_SHIFT);
+	void *p;
+	int n;
+
+	assert(size);
+
+	p = alloc_pages_flags(order, AREA_DMA31 | flags);
+	if (!p || !test_facility(158))
+		return p;
+
+	n = share_pages(p, 1 << order);
+	if (n == 1 << order)
+		return p;
+
+	unshare_pages(p, n);
+	free_pages(p);
+	return NULL;
+}
+
+void free_io_mem(void *p, int size)
+{
+	int order = get_order(size >> PAGE_SHIFT);
+
+	assert(IS_ALIGNED((uintptr_t)p, PAGE_SIZE));
+
+	if (test_facility(158))
+		unshare_pages(p, 1 << order);
+	free_pages(p);
+}
lib/s390x/malloc_io.h new file +45 -0

45 lines not on this page · raw message

s390x/Makefile +1 -0
index 08d85c9f..f3b0fccf 100644
@@ -64,6 +64,7 @@ cflatobjs += lib/s390x/smp.o
 cflatobjs += lib/s390x/vm.o
 cflatobjs += lib/s390x/css_dump.o
 cflatobjs += lib/s390x/css_lib.o
+cflatobjs += lib/s390x/malloc_io.o
 
 OBJDIRS += lib/s390x
 
Signature · 1 line
2.29.2
#4 lore raw

[kvm-unit-tests GIT PULL 06/16] s390x: Remove sthyi partition number check

In reply to Janosch Frank

Turns out that partition numbers start from 0 and not from 1 so a 0 check doesn't make sense here.

---
 s390x/sthyi.c | 1 -
 1 file changed, 1 deletion(-)
s390x/sthyi.c +0 -1
index d8dfc854..db90b56f 100644
@@ -128,7 +128,6 @@ static void test_fcode0_par(struct sthyi_par_sctn *par)
 		report(sum, "core counts");
 
 	if (par->INFPVAL1 & PART_STSI_SUC) {
-		report(par->INFPPNUM, "number");
 		report(memcmp(par->INFPPNAM, null_buf, sizeof(par->INFPPNAM)),
 		       "name");
 	}
Signature · 1 line
2.29.2
#5 lore raw

[kvm-unit-tests GIT PULL 07/16] s390x: Fix fpc store address in RESTORE_REGS_STACK

In reply to Janosch Frank

The efpc stores in bits 32-63 of a register and we store a full 8 bytes to have the stack 8 byte aligned. This means that the fpc is stored at offset 4 but we load it from offset 0. Lets replace efpc with stfpc and get rid of the stg to store at offset 0.

---
 s390x/macros.S | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
s390x/macros.S +1 -2
index 37a6a63e..e51a557a 100644
@@ -54,8 +54,7 @@
 	.endr
 	/* Save fpc, but keep stack aligned on 64bits */
 	slgfi   %r15, 8
-	efpc	%r0
-	stg	%r0, 0(%r15)
+	stfpc	0(%r15)
 	.endm
 
 /* Restore the register in reverse order */
Signature · 1 line
2.29.2
#6 lore raw

[kvm-unit-tests GIT PULL 08/16] s390x: Fully commit to stack save area for exceptions

In reply to Janosch Frank

Having two sets of macros for saving registers on exceptions makes maintaining harder. Also we have limited space in the lowcore to save stuff and by using the stack as a save area, we can stack exceptions.

So let's use the SAVE/RESTORE_REGS_STACK as the default. When we also move the diag308 macro over we can remove the old SAVE/RESTORE_REGS macros.

---
 lib/s390x/asm-offsets.c   | 15 ++++++++----
 lib/s390x/asm/arch_def.h  | 31 ++++++++++++++++++++-----
 lib/s390x/asm/interrupt.h |  4 ++--
 lib/s390x/interrupt.c     | 20 ++++++++++------
 s390x/cstart64.S          | 18 ++++++++-------
 s390x/macros.S            | 48 +++++++++++++++++++++++----------------
 6 files changed, 90 insertions(+), 46 deletions(-)
lib/s390x/asm-offsets.c +11 -4
index a19f14b9..2658b59a 100644
@@ -70,16 +70,23 @@ int main(void)
 	OFFSET(GEN_LC_ARS_SA, lowcore, ars_sa);
 	OFFSET(GEN_LC_CRS_SA, lowcore, crs_sa);
 	OFFSET(GEN_LC_PGM_INT_TDB, lowcore, pgm_int_tdb);
-	OFFSET(__SF_SIE_CONTROL, stack_frame, empty1[0]);
-	OFFSET(__SF_SIE_SAVEAREA, stack_frame, empty1[1]);
-	OFFSET(__SF_SIE_REASON, stack_frame, empty1[2]);
-	OFFSET(__SF_SIE_FLAGS, stack_frame, empty1[3]);
+	OFFSET(__SF_SIE_CONTROL, stack_frame, argument_area[0]);
+	OFFSET(__SF_SIE_SAVEAREA, stack_frame, argument_area[1]);
+	OFFSET(__SF_SIE_REASON, stack_frame, argument_area[2]);
+	OFFSET(__SF_SIE_FLAGS, stack_frame, argument_area[3]);
 	OFFSET(SIE_SAVEAREA_HOST_GRS, vm_save_area, host.grs[0]);
 	OFFSET(SIE_SAVEAREA_HOST_FPRS, vm_save_area, host.fprs[0]);
 	OFFSET(SIE_SAVEAREA_HOST_FPC, vm_save_area, host.fpc);
 	OFFSET(SIE_SAVEAREA_GUEST_GRS, vm_save_area, guest.grs[0]);
 	OFFSET(SIE_SAVEAREA_GUEST_FPRS, vm_save_area, guest.fprs[0]);
 	OFFSET(SIE_SAVEAREA_GUEST_FPC, vm_save_area, guest.fpc);
+	OFFSET(STACK_FRAME_INT_BACKCHAIN, stack_frame_int, back_chain);
+	OFFSET(STACK_FRAME_INT_FPC, stack_frame_int, fpc);
+	OFFSET(STACK_FRAME_INT_FPRS, stack_frame_int, fprs);
+	OFFSET(STACK_FRAME_INT_CRS, stack_frame_int, crs);
+	OFFSET(STACK_FRAME_INT_GRS0, stack_frame_int, grs0);
+	OFFSET(STACK_FRAME_INT_GRS1, stack_frame_int, grs1);
+	DEFINE(STACK_FRAME_INT_SIZE, sizeof(struct stack_frame_int));
 
 	return 0;
 }
lib/s390x/asm/arch_def.h +25 -6
index 9c4e330a..b8e9fe40 100644
@@ -8,13 +8,32 @@
 #ifndef _ASM_S390X_ARCH_DEF_H_
 #define _ASM_S390X_ARCH_DEF_H_
 
-/*
- * We currently only specify the stack frame members needed for the
- * SIE library code.
- */
 struct stack_frame {
-	unsigned long back_chain;
-	unsigned long empty1[5];
+	struct stack_frame *back_chain;
+	uint64_t reserved;
+	/* GRs 2 - 5 */
+	uint64_t argument_area[4];
+	/* GRs 6 - 15 */
+	uint64_t grs[10];
+	/* FPRs 0, 2, 4, 6 */
+	int64_t  fprs[4];
+};
+
+struct stack_frame_int {
+	struct stack_frame *back_chain;
+	uint64_t reserved;
+	/*
+	 * The GRs are offset compatible with struct stack_frame so we
+	 * can easily fetch GR14 for backtraces.
+	 */
+	/* GRs 2 - 15 */
+	uint64_t grs0[14];
+	/* GRs 0 and 1 */
+	uint64_t grs1[2];
+	uint32_t reserved1;
+	uint32_t fpc;
+	uint64_t fprs[16];
+	uint64_t crs[16];
 };
 
 struct psw {
lib/s390x/asm/interrupt.h +2 -2
index 1a2e2cd8..31e4766d 100644
@@ -14,8 +14,8 @@
 #define EXT_IRQ_SERVICE_SIG	0x2401
 
 void register_pgm_cleanup_func(void (*f)(void));
-void handle_pgm_int(void);
-void handle_ext_int(void);
+void handle_pgm_int(struct stack_frame_int *stack);
+void handle_ext_int(struct stack_frame_int *stack);
 void handle_mcck_int(void);
 void handle_io_int(void);
 void handle_svc_int(void);
lib/s390x/interrupt.c +13 -7
index 1ce36073..46ae0bd7 100644
@@ -56,7 +56,7 @@ void register_pgm_cleanup_func(void (*f)(void))
 	pgm_cleanup_func = f;
 }
 
-static void fixup_pgm_int(void)
+static void fixup_pgm_int(struct stack_frame_int *stack)
 {
 	/* If we have an error on SIE we directly move to sie_exit */
 	if (lc->pgm_old_psw.addr >= (uint64_t)&sie_entry &&
@@ -76,7 +76,13 @@ static void fixup_pgm_int(void)
 		/* Handling for iep.c test case. */
 		if (lc->trans_exc_id & 0x80UL && lc->trans_exc_id & 0x04UL &&
 		    !(lc->trans_exc_id & 0x08UL))
-			lc->pgm_old_psw.addr = lc->sw_int_grs[14];
+			/*
+			 * We branched to the instruction that caused
+			 * the exception so we can use the return
+			 * address in GR14 to jump back and continue
+			 * executing test code.
+			 */
+			lc->pgm_old_psw.addr = stack->grs0[12];
 		break;
 	case PGM_INT_CODE_SEGMENT_TRANSLATION:
 	case PGM_INT_CODE_PAGE_TRANSLATION:
@@ -115,7 +121,7 @@ static void fixup_pgm_int(void)
 	/* suppressed/terminated/completed point already at the next address */
 }
 
-void handle_pgm_int(void)
+void handle_pgm_int(struct stack_frame_int *stack)
 {
 	if (!pgm_int_expected) {
 		/* Force sclp_busy to false, otherwise we will loop forever */
@@ -130,10 +136,10 @@ void handle_pgm_int(void)
 	if (pgm_cleanup_func)
 		(*pgm_cleanup_func)();
 	else
-		fixup_pgm_int();
+		fixup_pgm_int(stack);
 }
 
-void handle_ext_int(void)
+void handle_ext_int(struct stack_frame_int *stack)
 {
 	if (!ext_int_expected &&
 	    lc->ext_int_code != EXT_IRQ_SERVICE_SIG) {
@@ -143,13 +149,13 @@ void handle_ext_int(void)
 	}
 
 	if (lc->ext_int_code == EXT_IRQ_SERVICE_SIG) {
-		lc->sw_int_crs[0] &= ~(1UL << 9);
+		stack->crs[0] &= ~(1UL << 9);
 		sclp_handle_ext();
 	} else {
 		ext_int_expected = false;
 	}
 
-	if (!(lc->sw_int_crs[0] & CR0_EXTM_MASK))
+	if (!(stack->crs[0] & CR0_EXTM_MASK))
 		lc->ext_old_psw.mask &= ~PSW_MASK_EXT;
 }
 
s390x/cstart64.S +10 -8
index ace0c0d9..ad0e2145 100644
@@ -92,21 +92,23 @@ memsetxc:
 
 .section .text
 pgm_int:
-	SAVE_REGS
+	SAVE_REGS_STACK
+	lgr     %r2, %r15
 	brasl	%r14, handle_pgm_int
-	RESTORE_REGS
+	RESTORE_REGS_STACK
 	lpswe	GEN_LC_PGM_OLD_PSW
 
 ext_int:
-	SAVE_REGS
+	SAVE_REGS_STACK
+	lgr     %r2, %r15
 	brasl	%r14, handle_ext_int
-	RESTORE_REGS
+	RESTORE_REGS_STACK
 	lpswe	GEN_LC_EXT_OLD_PSW
 
 mcck_int:
-	SAVE_REGS
+	SAVE_REGS_STACK
 	brasl	%r14, handle_mcck_int
-	RESTORE_REGS
+	RESTORE_REGS_STACK
 	lpswe	GEN_LC_MCCK_OLD_PSW
 
 io_int:
@@ -116,9 +118,9 @@ io_int:
 	lpswe	GEN_LC_IO_OLD_PSW
 
 svc_int:
-	SAVE_REGS
+	SAVE_REGS_STACK
 	brasl	%r14, handle_svc_int
-	RESTORE_REGS
+	RESTORE_REGS_STACK
 	lpswe	GEN_LC_SVC_OLD_PSW
 
 	.align	8
s390x/macros.S +29 -19

74 lines not on this page · raw message

Signature · 1 line
2.29.2
#7 lore raw

[kvm-unit-tests GIT PULL 13/16] s390x: Remove SAVE/RESTORE_STACK and lowcore fpc and fprs save areas

In reply to Janosch Frank

There are no more users. At the same time remove sw_int_fpc and sw_int_frps plus their asm offsets macros since they are also unused now.

---
 lib/s390x/asm-offsets.c  |  2 --
 lib/s390x/asm/arch_def.h |  4 +---
 s390x/macros.S           | 29 -----------------------------
 3 files changed, 1 insertion(+), 34 deletions(-)
lib/s390x/asm-offsets.c +0 -2
index 2658b59a..fbea3278 100644
@@ -54,8 +54,6 @@ int main(void)
 	OFFSET(GEN_LC_MCCK_NEW_PSW, lowcore, mcck_new_psw);
 	OFFSET(GEN_LC_IO_NEW_PSW, lowcore, io_new_psw);
 	OFFSET(GEN_LC_SW_INT_GRS, lowcore, sw_int_grs);
-	OFFSET(GEN_LC_SW_INT_FPRS, lowcore, sw_int_fprs);
-	OFFSET(GEN_LC_SW_INT_FPC, lowcore, sw_int_fpc);
 	OFFSET(GEN_LC_SW_INT_CRS, lowcore, sw_int_crs);
 	OFFSET(GEN_LC_SW_INT_PSW, lowcore, sw_int_psw);
 	OFFSET(GEN_LC_MCCK_EXT_SA_ADDR, lowcore, mcck_ext_sa_addr);
lib/s390x/asm/arch_def.h +1 -3
index b8e9fe40..76cb7b33 100644
@@ -103,9 +103,7 @@ struct lowcore {
 	struct psw	io_new_psw;			/* 0x01f0 */
 	/* sw definition: save area for registers in interrupt handlers */
 	uint64_t	sw_int_grs[16];			/* 0x0200 */
-	uint64_t	sw_int_fprs[16];		/* 0x0280 */
-	uint32_t	sw_int_fpc;			/* 0x0300 */
-	uint8_t		pad_0x0304[0x0308 - 0x0304];	/* 0x0304 */
+	uint8_t		pad_0x0280[0x0308 - 0x0280];	/* 0x0280 */
 	uint64_t	sw_int_crs[16];			/* 0x0308 */
 	struct psw	sw_int_psw;			/* 0x0388 */
 	uint8_t		pad_0x0310[0x11b0 - 0x0398];	/* 0x0398 */
s390x/macros.S +0 -29
index d4f41ec4..13cff299 100644
@@ -33,35 +33,6 @@
 	lpswe	\old_psw
 	.endm
 
-	.macro SAVE_REGS
-	/* save grs 0-15 */
-	stmg	%r0, %r15, GEN_LC_SW_INT_GRS
-	/* save crs 0-15 */
-	stctg	%c0, %c15, GEN_LC_SW_INT_CRS
-	/* load a cr0 that has the AFP control bit which enables all FPRs */
-	larl	%r1, initial_cr0
-	lctlg	%c0, %c0, 0(%r1)
-	/* save fprs 0-15 + fpc */
-	la	%r1, GEN_LC_SW_INT_FPRS
-	.irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
-	std	\i, \i * 8(%r1)
-	.endr
-	stfpc	GEN_LC_SW_INT_FPC
-	.endm
-
-	.macro RESTORE_REGS
-	/* restore fprs 0-15 + fpc */
-	la	%r1, GEN_LC_SW_INT_FPRS
-	.irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
-	ld	\i, \i * 8(%r1)
-	.endr
-	lfpc	GEN_LC_SW_INT_FPC
-	/* restore crs 0-15 */
-	lctlg	%c0, %c15, GEN_LC_SW_INT_CRS
-	/* restore grs 0-15 */
-	lmg	%r0, %r15, GEN_LC_SW_INT_GRS
-	.endm
-
 /* Save registers on the stack (r15), so we can have stacked interrupts. */
 	.macro SAVE_REGS_STACK
 	/* Allocate a full stack frame */
Signature · 1 line
2.29.2
#8 lore raw

[kvm-unit-tests GIT PULL 12/16] s390x: Move diag308_load_reset to stack saving

In reply to Janosch Frank

By moving the last user of SAVE/RESTORE_REGS to the macros that use the stack we can finally remove these macros.

---
 s390x/cpu.S | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
s390x/cpu.S +4 -2
index 5267f029..e2ad56c8 100644
@@ -18,7 +18,7 @@
  */
 .globl diag308_load_reset
 diag308_load_reset:
-	SAVE_REGS
+	SAVE_REGS_STACK
 	/* Backup current PSW mask, as we have to restore it on success */
 	epsw	%r0, %r1
 	st	%r0, GEN_LC_SW_INT_PSW
@@ -31,6 +31,7 @@ diag308_load_reset:
 	ogr	%r0, %r1
 	/* Store it at the reset PSW location (real 0x0) */
 	stg	%r0, 0
+	stg     %r15, GEN_LC_SW_INT_GRS + 15 * 8
 	/* Do the reset */
 	diag    %r0,%r2,0x308
 	/* Failure path */
@@ -40,7 +41,8 @@ diag308_load_reset:
 	/* load a cr0 that has the AFP control bit which enables all FPRs */
 0:	larl	%r1, initial_cr0
 	lctlg	%c0, %c0, 0(%r1)
-	RESTORE_REGS
+	lg      %r15, GEN_LC_SW_INT_GRS + 15 * 8
+	RESTORE_REGS_STACK
 	lhi	%r2, 1
 	larl	%r0, 1f
 	stg	%r0, GEN_LC_SW_INT_PSW + 8
Signature · 1 line
2.29.2
#9 lore raw

[kvm-unit-tests GIT PULL 15/16] s390x: mvpg: simple test

In reply to Janosch Frank

From: Claudio Imbrenda <[email protected]>

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        | 267 ++++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg |   4 +
 3 files changed, 272 insertions(+)
 create mode 100644 s390x/mvpg.c
s390x/Makefile +1 -0
index 20bb5683..b92de9c5 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 +267 -0

267 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.29.2
#10 lore raw

[kvm-unit-tests GIT PULL 16/16] s390x: mvpg: skip some tests when using TCG

In reply to Janosch Frank

From: Claudio Imbrenda <[email protected]>

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 | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)
s390x/mvpg.c +22 -12
index 1776ec6e..5743d5b6 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)
@@ -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.29.2
#11 lore raw

[kvm-unit-tests GIT PULL 05/16] Fix the length in the stsi check for the VM name

In reply to Janosch Frank

From: Thomas Huth <[email protected]>

sizeof(somepointer) results in the size of the pointer, i.e. 8 on a 64-bit system, so the

memcmp(data->ext_names[0], vm_name_ext, sizeof(vm_name_ext))

only compared the first 8 characters of the VM name here. Switch to a proper array to get the sizeof() right.

Message-Id: <[email protected]>

---
 s390x/stsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
s390x/stsi.c +1 -1
index 4109b8d4..87d48047 100644
@@ -106,7 +106,7 @@ static void test_3_2_2(void)
 				 0x00, 0x03 };
 	/* EBCDIC for "KVM/" */
 	const uint8_t cpi_kvm[] = { 0xd2, 0xe5, 0xd4, 0x61 };
-	const char *vm_name_ext = "kvm-unit-test";
+	const char vm_name_ext[] = "kvm-unit-test";
 	struct stsi_322 *data = (void *)pagebuf;
 
 	report_prefix_push("3.2.2");
Signature · 1 line
2.29.2
#12 lore raw

[kvm-unit-tests GIT PULL 10/16] s390x: Provide preliminary backtrace support

In reply to Janosch Frank

After the stack changes we can finally use -mbackchain and have a working backtrace.

---
 lib/s390x/stack.c | 20 ++++++++++++++------
 s390x/Makefile    |  1 +
 s390x/macros.S    |  5 +++++
 3 files changed, 20 insertions(+), 6 deletions(-)
lib/s390x/stack.c +14 -6
index 0fcd1afb..4cf80dae 100644
@@ -3,24 +3,32 @@
  * s390x stack implementation
  *
  * Copyright (c) 2017 Red Hat Inc
+ * Copyright 2021 IBM Corp
  *
  * Authors:
  *  Thomas Huth <[email protected]>
  *  David Hildenbrand <[email protected]>
+ *  Janosch Frank <[email protected]>
  */
 #include <libcflat.h>
 #include <stack.h>
+#include <asm/arch_def.h>
 
 int backtrace_frame(const void *frame, const void **return_addrs, int max_depth)
 {
-	printf("TODO: Implement backtrace_frame(%p, %p, %d) function!\n",
-	       frame, return_addrs, max_depth);
-	return 0;
+	int depth = 0;
+	struct stack_frame *stack = (struct stack_frame *)frame;
+
+	for (depth = 0; stack && depth < max_depth; depth++) {
+		return_addrs[depth] = (void *)stack->grs[8];
+		stack = stack->back_chain;
+	}
+
+	return depth;
 }
 
 int backtrace(const void **return_addrs, int max_depth)
 {
-	printf("TODO: Implement backtrace(%p, %d) function!\n",
-	       return_addrs, max_depth);
-	return 0;
+	return backtrace_frame(__builtin_frame_address(0),
+			       return_addrs, max_depth);
 }
s390x/Makefile +1 -0
index f3b0fccf..20bb5683 100644
@@ -39,6 +39,7 @@ CFLAGS += -ffreestanding
 CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/s390x -I lib
 CFLAGS += -O2
 CFLAGS += -march=zEC12
+CFLAGS += -mbackchain
 CFLAGS += -fno-delete-null-pointer-checks
 LDFLAGS += -nostdlib -Wl,--build-id=none
 
s390x/macros.S +5 -0
index 11f4397a..d4f41ec4 100644
@@ -22,6 +22,11 @@
 	lgr     %r2, %r15
 	/* Allocate stack space for called C function, as specified in s390 ELF ABI */
 	slgfi   %r15, 160
+	/*
+	 * Save the address of the interrupt stack into the back chain
+	 * of the called function.
+	 */
+	stg     %r2, STACK_FRAME_INT_BACKCHAIN(%r15)
 	brasl	%r14, \c_func
 	algfi   %r15, 160
 	RESTORE_REGS_STACK
Signature · 1 line
2.29.2
#13 lore raw

[kvm-unit-tests GIT PULL 04/16] s390x: css: pv: css test adaptation for PV

In reply to Janosch Frank

From: Pierre Morel <[email protected]>

We want the tests to automatically work with or without protected virtualisation.
To do this we need to share the I/O memory with the host.

Let's replace all static allocations with dynamic allocations to clearly separate shared and private memory.

Message-Id: <[email protected]>

---
 lib/s390x/css.h     |  3 +--
 lib/s390x/css_lib.c | 28 ++++++++--------------------
 s390x/css.c         | 43 +++++++++++++++++++++++++++++++------------
 3 files changed, 40 insertions(+), 34 deletions(-)
lib/s390x/css.h +1 -2
index d10d2655..3e574455 100644
@@ -281,8 +281,7 @@ int css_enable(int schid, int isc);
 
 /* Library functions */
 int start_ccw1_chain(unsigned int sid, struct ccw1 *ccw);
-int start_single_ccw(unsigned int sid, int code, void *data, int count,
-		     unsigned char flags);
+struct ccw1 *ccw_alloc(int code, void *data, int count, unsigned char flags);
 void css_irq_io(void);
 int css_residual_count(unsigned int schid);
 
lib/s390x/css_lib.c +8 -20
index 5af6f776..3c244801 100644
@@ -16,6 +16,7 @@
 #include <asm/time.h>
 #include <asm/arch_def.h>
 
+#include <malloc_io.h>
 #include <css.h>
 
 static struct schib schib;
@@ -200,33 +201,20 @@ int start_ccw1_chain(unsigned int sid, struct ccw1 *ccw)
 	return ssch(sid, &orb);
 }
 
-/*
- * In the future, we want to implement support for CCW chains;
- * for that, we will need to work with ccw1 pointers.
- */
-static struct ccw1 unique_ccw;
-
-int start_single_ccw(unsigned int sid, int code, void *data, int count,
-		     unsigned char flags)
+struct ccw1 *ccw_alloc(int code, void *data, int count, unsigned char flags)
 {
-	int cc;
-	struct ccw1 *ccw = &unique_ccw;
+	struct ccw1 *ccw;
+
+	ccw = alloc_io_mem(sizeof(*ccw), 0);
+	if (!ccw)
+		return NULL;
 
-	report_prefix_push("start_subchannel");
-	/* Build the CCW chain with a single CCW */
 	ccw->code = code;
 	ccw->flags = flags;
 	ccw->count = count;
 	ccw->data_address = (int)(unsigned long)data;
 
-	cc = start_ccw1_chain(sid, ccw);
-	if (cc) {
-		report(0, "cc = %d", cc);
-		report_prefix_pop();
-		return cc;
-	}
-	report_prefix_pop();
-	return 0;
+	return ccw;
 }
 
 /* wait_and_check_io_completion:
s390x/css.c +31 -12

89 lines not on this page · raw message

Signature · 1 line
2.29.2
maintainer
#14 lore raw
In reply to Janosch Frank
Quoted 18 lines · Janosch Frank

Dear Paolo,

please merge or pull the following changes:
* IO tests PV compatibility (Pierre)
* Backtrace support (Janosch)
* mvpg test (Claudio)
* Fixups (Thomas)

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

PULL:
The following changes since commit 739f7de6b3c8deaf22d2fa5e6016ad2c7bd22ddc:

   x86: clean up EFER definitions (2021-02-18 13:31:22 -0500)
Quoted 7 lines

are available in the Git repository at:

   https://gitlab.com/frankja/kvm-unit-tests.git s390x-pull-2021-08-03

for you to fetch changes up to b7f0f9a2e1fdb9d4235164f0a8d8ea880e1cefd4:

s390x: mvpg: skip some tests when using TCG (2021-03-08 12:03:47 +0100)

Pulled, thanks.

Paolo

Quoted 51 lines

----------------------------------------------------------------
Claudio Imbrenda (3):

   s390x: introduce leave_pstate to leave userspace
   s390x: mvpg: simple test
   s390x: mvpg: skip some tests when using TCG

Janosch Frank (8):
s390x: Remove sthyi partition number check
s390x: Fix fpc store address in RESTORE_REGS_STACK
s390x: Fully commit to stack save area for exceptions
s390x: Introduce and use CALL_INT_HANDLER macro
s390x: Provide preliminary backtrace support
s390x: Print more information on program exceptions
s390x: Move diag308_load_reset to stack saving
s390x: Remove SAVE/RESTORE_STACK and lowcore fpc and fprs save areas

Pierre Morel (3):
s390x: pv: implement routine to share/unshare memory
s390x: define UV compatible I/O allocation
s390x: css: pv: css test adaptation for PV

Thomas Huth (2):
lib/s390x/sclp: Clarify that the CPUEntry array could be at a
different spot
Fix the length in the stsi check for the VM name

  lib/s390x/asm-offsets.c   |  17 ++-
  lib/s390x/asm/arch_def.h  |  42 ++++--
  lib/s390x/asm/interrupt.h |   4 +-
  lib/s390x/asm/uv.h        |  39 ++++++
  lib/s390x/css.h           |   3 +-
  lib/s390x/css_lib.c       |  28 ++--
  lib/s390x/interrupt.c     |  61 +++++++--
  lib/s390x/malloc_io.c     |  71 ++++++++++
  lib/s390x/malloc_io.h     |  45 +++++++
  lib/s390x/sclp.h          |   9 +-
  lib/s390x/stack.c         |  20 ++-
  s390x/Makefile            |   3 +
  s390x/cpu.S               |   6 +-
  s390x/css.c               |  43 ++++--
  s390x/cstart64.S          |  25 +---
  s390x/macros.S            |  96 ++++++-------
  s390x/mvpg.c              | 277 ++++++++++++++++++++++++++++++++++++++
  s390x/sthyi.c             |   1 -
  s390x/stsi.c              |   2 +-
  s390x/unittests.cfg       |   4 +
  20 files changed, 657 insertions(+), 139 deletions(-)

create mode 100644 lib/s390x/malloc_io.c
create mode 100644 lib/s390x/malloc_io.h
create mode 100644 s390x/mvpg.c

#15 lore raw

[kvm-unit-tests GIT PULL 09/16] s390x: Introduce and use CALL_INT_HANDLER macro

In reply to Janosch Frank

The ELF ABI dictates that we need to allocate 160 bytes of stack space for the C functions we're calling. Since we would need to do that for every interruption handler which, combined with the new stack argument being saved in GR2, makes cstart64.S look a bit messy.

So let's introduce the CALL_INT_HANDLER macro that handles all of that, calls the C interrupt handler and handles cleanup afterwards.

---
 s390x/cstart64.S | 27 +++++----------------------
 s390x/macros.S   | 17 +++++++++++++++++
 2 files changed, 22 insertions(+), 22 deletions(-)
s390x/cstart64.S +5 -22
index ad0e2145..666a9567 100644
@@ -92,36 +92,19 @@ memsetxc:
 
 .section .text
 pgm_int:
-	SAVE_REGS_STACK
-	lgr     %r2, %r15
-	brasl	%r14, handle_pgm_int
-	RESTORE_REGS_STACK
-	lpswe	GEN_LC_PGM_OLD_PSW
+	CALL_INT_HANDLER handle_pgm_int, GEN_LC_PGM_OLD_PSW
 
 ext_int:
-	SAVE_REGS_STACK
-	lgr     %r2, %r15
-	brasl	%r14, handle_ext_int
-	RESTORE_REGS_STACK
-	lpswe	GEN_LC_EXT_OLD_PSW
+	CALL_INT_HANDLER handle_ext_int, GEN_LC_EXT_OLD_PSW
 
 mcck_int:
-	SAVE_REGS_STACK
-	brasl	%r14, handle_mcck_int
-	RESTORE_REGS_STACK
-	lpswe	GEN_LC_MCCK_OLD_PSW
+	CALL_INT_HANDLER handle_mcck_int, GEN_LC_MCCK_OLD_PSW
 
 io_int:
-	SAVE_REGS_STACK
-	brasl	%r14, handle_io_int
-	RESTORE_REGS_STACK
-	lpswe	GEN_LC_IO_OLD_PSW
+	CALL_INT_HANDLER handle_io_int, GEN_LC_IO_OLD_PSW
 
 svc_int:
-	SAVE_REGS_STACK
-	brasl	%r14, handle_svc_int
-	RESTORE_REGS_STACK
-	lpswe	GEN_LC_SVC_OLD_PSW
+	CALL_INT_HANDLER handle_svc_int, GEN_LC_SVC_OLD_PSW
 
 	.align	8
 initial_psw:
s390x/macros.S +17 -0
index a7d62c6f..11f4397a 100644
@@ -11,6 +11,23 @@
  *  David Hildenbrand <[email protected]>
  */
 #include <asm/asm-offsets.h>
+/*
+ * Exception handler macro that saves registers on the stack,
+ * allocates stack space and calls the C handler function. Afterwards
+ * we re-load the registers and load the old PSW.
+ */
+	.macro CALL_INT_HANDLER c_func, old_psw
+	SAVE_REGS_STACK
+	/* Save the stack address in GR2 which is the first function argument */
+	lgr     %r2, %r15
+	/* Allocate stack space for called C function, as specified in s390 ELF ABI */
+	slgfi   %r15, 160
+	brasl	%r14, \c_func
+	algfi   %r15, 160
+	RESTORE_REGS_STACK
+	lpswe	\old_psw
+	.endm
+
 	.macro SAVE_REGS
 	/* save grs 0-15 */
 	stmg	%r0, %r15, GEN_LC_SW_INT_GRS
Signature · 1 line
2.29.2
#16 lore raw

[kvm-unit-tests GIT PULL 11/16] s390x: Print more information on program exceptions

In reply to Janosch Frank

Currently we only get a single line of output if a test runs in a unexpected program exception. Let's also print the general registers to give some more context.

---
 lib/s390x/interrupt.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
lib/s390x/interrupt.c +29 -0
index 46ae0bd7..d9832bc0 100644
@@ -121,11 +121,40 @@ static void fixup_pgm_int(struct stack_frame_int *stack)
 	/* suppressed/terminated/completed point already at the next address */
 }
 
+static void print_int_regs(struct stack_frame_int *stack)
+{
+	printf("\n");
+	printf("GPRS:\n");
+	printf("%016lx %016lx %016lx %016lx\n",
+	       stack->grs1[0], stack->grs1[1], stack->grs0[0], stack->grs0[1]);
+	printf("%016lx %016lx %016lx %016lx\n",
+	       stack->grs0[2], stack->grs0[3], stack->grs0[4], stack->grs0[5]);
+	printf("%016lx %016lx %016lx %016lx\n",
+	       stack->grs0[6], stack->grs0[7], stack->grs0[8], stack->grs0[9]);
+	printf("%016lx %016lx %016lx %016lx\n",
+	       stack->grs0[10], stack->grs0[11], stack->grs0[12], stack->grs0[13]);
+	printf("\n");
+}
+
+static void print_pgm_info(struct stack_frame_int *stack)
+
+{
+	printf("\n");
+	printf("Unexpected program interrupt: %d on cpu %d at %#lx, ilen %d\n",
+	       lc->pgm_int_code, stap(), lc->pgm_old_psw.addr,
+	       lc->pgm_int_id);
+	print_int_regs(stack);
+	dump_stack();
+	report_summary();
+	abort();
+}
+
 void handle_pgm_int(struct stack_frame_int *stack)
 {
 	if (!pgm_int_expected) {
 		/* Force sclp_busy to false, otherwise we will loop forever */
 		sclp_handle_ext();
+		print_pgm_info(stack);
 		report_abort("Unexpected program interrupt: %d on cpu %d at %#lx, ilen %d\n",
 			     lc->pgm_int_code, stap(), lc->pgm_old_psw.addr,
 			     lc->pgm_int_id);
Signature · 1 line
2.29.2
#17 lore raw

[kvm-unit-tests GIT PULL 02/16] s390x: pv: implement routine to share/unshare memory

In reply to Janosch Frank

From: Pierre Morel <[email protected]>

When communicating with the host we need to share part of the memory.

Let's implement the ultravisor calls for this.

Message-Id: <[email protected]>

---
 lib/s390x/asm/uv.h | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
lib/s390x/asm/uv.h +39 -0
index 39d2dc04..9c491844 100644
@@ -79,4 +79,43 @@ static inline int uv_call(unsigned long r1, unsigned long r2)
 	return cc;
 }
 
+static inline int share(unsigned long addr, u16 cmd)
+{
+	struct uv_cb_share uvcb = {
+		.header.cmd = 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;
+}
+
+/*
+ * Guest 2 request to the Ultravisor to make a page shared with the
+ * hypervisor for IO.
+ *
+ * @addr: Real or absolute address of the page to be shared
+ */
+static inline int uv_set_shared(unsigned long addr)
+{
+	return share(addr, UVC_CMD_SET_SHARED_ACCESS);
+}
+
+/*
+ * Guest 2 request to the Ultravisor to make a page unshared.
+ *
+ * @addr: Real or absolute address of the page to be unshared
+ */
+static inline int uv_remove_shared(unsigned long addr)
+{
+	return share(addr, UVC_CMD_REMOVE_SHARED_ACCESS);
+}
+
 #endif
Signature · 1 line
2.29.2