public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes
@ 2023-11-10 13:52 Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 01/26] s390x: spec_ex: load full register Nico Boehr
                   ` (26 more replies)
  0 siblings, 27 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones; +Cc: kvm, frankja, imbrenda

Hi Paolo and/or Thomas,

lots of code for s390x has accumulated, so it's time for another PR :)

Please note that this PR includes a common code change from Nina (see below).

Changes in this pull request:

* Nina contributed multiline support for unittests.cfg in common code,
* Janosch contributed enhancements for the sclp console,
* Nina fixed some issues in the topology tests and improved coverage,
* I've added support for running sie() tests without MSO/MSL,
* kvm-unit-tests is now compatible with environments which require 2GB alignment
  of guests in SIE,
* several smaller improvements and bug fixes.

Thanks
Nico

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

PIPELINE: https://gitlab.com/Nico-Boehr/kvm-unit-tests/-/pipelines/1067877258

PULL: https://gitlab.com/Nico-Boehr/kvm-unit-tests.git pr-2023-11-09
----
The following changes since commit bfe5d7d0e14c8199d134df84d6ae8487a9772c48:

  migration: Fix test harness hang if source does not reach migration point (2023-10-19 10:06:54 +0200)

are available in the Git repository at:

  https://gitlab.com/Nico-Boehr/kvm-unit-tests.git pr-2023-11-09

for you to fetch changes up to bb88caeff9dd2ee57511bc9efbb742a8d6197903:

  lib: s390x: interrupt: remove TEID_ASCE defines (2023-11-10 09:50:33 +0100)

----------------------------------------------------------------
Janosch Frank (3):
      lib: s390x: hw: rework do_detect_host so we don't need allocation
      lib: s390x: sclp: Add compat handling for HMC ASCII consoles
      lib: s390x: sclp: Add line mode input handling

Nico Boehr (13):
      s390x: spec_ex: load full register
      s390x: run PV guests with confidential guest enabled
      s390x: spec_ex-sie: refactor to use snippet API
      s390x: sie: ensure guests are aligned to 2GB
      s390x: mvpg-sie: fix virtual-physical address confusion
      lib: s390x: introduce bitfield for PSW mask
      s390x: add function to set DAT mode for all interrupts
      s390x: sie: switch to home space mode before entering SIE
      s390x: lib: don't forward PSW when handling exception in SIE
      s390x: lib: sie: don't reenter SIE on pgm int
      s390x: add test source dir to include paths
      s390x: add a test for SIE without MSO/MSL
      lib: s390x: interrupt: remove TEID_ASCE defines

Nina Schoetterl-Glausch (10):
      s390x: topology: Introduce enums for polarization & cpu type
      s390x: topology: Fix report message
      s390x: topology: Use function parameter in stsi_get_sysib
      s390x: topology: Fix parsing loop
      s390x: topology: Make some report messages unique
      s390x: topology: Refine stsi header test
      s390x: topology: Rename topology_core to topology_cpu
      s390x: topology: Rewrite topology list test
      scripts: Implement multiline strings for extra_params
      s390x: topology: Add complex topology test

 lib/s390x/asm/arch_def.h   |  36 ++++++-
 lib/s390x/asm/interrupt.h  |  21 ++++-
 lib/s390x/asm/mem.h        |   1 +
 lib/s390x/hardware.c       |  11 +--
 lib/s390x/interrupt.c      |  36 +++++++
 lib/s390x/mmu.c            |   5 +-
 lib/s390x/sclp-console.c   | 206 +++++++++++++++++++++++++++++++++++-----
 lib/s390x/sclp.h           |  26 ++++-
 lib/s390x/sie.c            |  75 ++++++++++++++-
 lib/s390x/sie.h            |   2 +
 lib/s390x/snippet.h        |   9 +-
 lib/s390x/stsi.h           |  47 ++++++---
 s390x/Makefile             |   4 +-
 s390x/mvpg-sie.c           |  16 +++-
 s390x/run                  |  19 +++-
 s390x/selftest.c           |  34 +++++++
 s390x/sie-dat.c            | 114 ++++++++++++++++++++++
 s390x/sie.c                |   4 +-
 s390x/snippets/c/sie-dat.c |  57 +++++++++++
 s390x/snippets/c/sie-dat.h |   2 +
 s390x/spec_ex-sie.c        |  13 ++-
 s390x/spec_ex.c            |   2 +-
 s390x/topology.c           | 230 ++++++++++++++++++++++++++++-----------------
 s390x/unittests.cfg        | 136 +++++++++++++++++++++++++++
 scripts/common.bash        |  16 ++++
 scripts/runtime.bash       |   4 +-
 26 files changed, 960 insertions(+), 166 deletions(-)
 create mode 100644 s390x/sie-dat.c
 create mode 100644 s390x/snippets/c/sie-dat.c
 create mode 100644 s390x/snippets/c/sie-dat.h

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 01/26] s390x: spec_ex: load full register
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 02/26] s390x: run PV guests with confidential guest enabled Nico Boehr
                   ` (25 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones; +Cc: kvm, frankja, imbrenda

There may be contents left in the upper 32 bits of executed_addr; hence
we should use a 64-bit load to make sure they are overwritten.

Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Link: https://lore.kernel.org/r/20230811112949.888903-1-nrb@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 s390x/spec_ex.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/s390x/spec_ex.c b/s390x/spec_ex.c
index e3dd85d..72b9425 100644
--- a/s390x/spec_ex.c
+++ b/s390x/spec_ex.c
@@ -142,7 +142,7 @@ static int psw_odd_address(void)
 		"	larl	%%r1,0f\n"
 		"	stg	%%r1,%[fixup_addr]\n"
 		"	lpswe	%[odd_psw]\n"
-		"0:	lr	%[executed_addr],%%r0\n"
+		"0:	lgr	%[executed_addr],%%r0\n"
 	: [fixup_addr] "=&T" (fixup_psw.addr),
 	  [executed_addr] "=d" (executed_addr)
 	: [odd_psw] "Q" (odd)
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 02/26] s390x: run PV guests with confidential guest enabled
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 01/26] s390x: spec_ex: load full register Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 03/26] lib: s390x: hw: rework do_detect_host so we don't need allocation Nico Boehr
                   ` (24 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones
  Cc: kvm, frankja, imbrenda, Nina Schoetterl-Glausch

PV can only handle one page of SCLP read info, hence it can only support
a maximum of 247 CPUs.

To make sure we respect these limitations under PV, add a confidential
guest device to QEMU when launching a PV guest.

This fixes the topology-2 test failing under PV.

Also refactor the run script a bit to reduce code duplication by moving
the check whether we're running a PV guest to a function.

Suggested-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Reviewed-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Link: https://lore.kernel.org/r/20230925135259.1685540-1-nrb@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 s390x/run | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/s390x/run b/s390x/run
index dcbf3f0..e58fa4a 100755
--- a/s390x/run
+++ b/s390x/run
@@ -14,19 +14,34 @@ set_qemu_accelerator || exit $?
 qemu=$(search_qemu_binary) ||
 	exit $?
 
-if [ "${1: -7}" = ".pv.bin" ] || [ "${TESTNAME: -3}" = "_PV" ] && [ "$ACCEL" = "tcg" ]; then
+is_pv() {
+	if [ "${1: -7}" = ".pv.bin" ] || [ "${TESTNAME: -3}" = "_PV" ]; then
+		return 0
+	fi
+	return 1
+}
+
+if is_pv && [ "$ACCEL" = "tcg" ]; then
 	echo "Protected Virtualization isn't supported under TCG"
 	exit 2
 fi
 
-if [ "${1: -7}" = ".pv.bin" ] || [ "${TESTNAME: -3}" = "_PV" ] && [ "$MIGRATION" = "yes" ]; then
+if is_pv && [ "$MIGRATION" = "yes" ]; then
 	echo "Migration isn't supported under Protected Virtualization"
 	exit 2
 fi
 
 M='-machine s390-ccw-virtio'
 M+=",accel=$ACCEL$ACCEL_PROPS"
+
+if is_pv; then
+	M+=",confidential-guest-support=pv0"
+fi
+
 command="$qemu -nodefaults -nographic $M"
+if is_pv; then
+	command+=" -object s390-pv-guest,id=pv0"
+fi
 command+=" -chardev stdio,id=con0 -device sclpconsole,chardev=con0"
 command+=" -kernel"
 command="$(panic_cmd) $(migration_cmd) $(timeout_cmd) $command"
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 03/26] lib: s390x: hw: rework do_detect_host so we don't need allocation
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 01/26] s390x: spec_ex: load full register Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 02/26] s390x: run PV guests with confidential guest enabled Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 04/26] lib: s390x: sclp: Add compat handling for HMC ASCII consoles Nico Boehr
                   ` (23 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones; +Cc: kvm, frankja, imbrenda

From: Janosch Frank <frankja@linux.ibm.com>

The current implementation needs to allocate a page for stsi 1.1.1 and
3.2.2. As such it's not usable before the allocator is set
up.

Unfortunately we might end up with detect_host calls before the
allocator setup is done. For example in the SCLP console setup code.

Let's allocate the stsi storage on the stack to solve that problem.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Link: https://lore.kernel.org/r/20231031095519.73311-2-frankja@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 lib/s390x/hardware.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/lib/s390x/hardware.c b/lib/s390x/hardware.c
index 2bcf9c4..2175256 100644
--- a/lib/s390x/hardware.c
+++ b/lib/s390x/hardware.c
@@ -13,6 +13,7 @@
 #include <libcflat.h>
 #include <alloc_page.h>
 #include <asm/arch_def.h>
+#include <asm/page.h>
 #include "hardware.h"
 #include "stsi.h"
 
@@ -21,9 +22,10 @@ static const uint8_t qemu_ebcdic[] = { 0xd8, 0xc5, 0xd4, 0xe4 };
 /* The string "KVM/" in EBCDIC */
 static const uint8_t kvm_ebcdic[] = { 0xd2, 0xe5, 0xd4, 0x61 };
 
-static enum s390_host do_detect_host(void *buf)
+static enum s390_host do_detect_host(void)
 {
-	struct sysinfo_3_2_2 *stsi_322 = buf;
+	uint8_t buf[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
+	struct sysinfo_3_2_2 *stsi_322 = (struct sysinfo_3_2_2 *)buf;
 
 	if (stsi_get_fc() == 2)
 		return HOST_IS_LPAR;
@@ -56,14 +58,11 @@ enum s390_host detect_host(void)
 {
 	static enum s390_host host = HOST_IS_UNKNOWN;
 	static bool initialized = false;
-	void *buf;
 
 	if (initialized)
 		return host;
 
-	buf = alloc_page();
-	host = do_detect_host(buf);
-	free_page(buf);
+	host = do_detect_host();
 	initialized = true;
 	return host;
 }
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 04/26] lib: s390x: sclp: Add compat handling for HMC ASCII consoles
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (2 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 03/26] lib: s390x: hw: rework do_detect_host so we don't need allocation Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 05/26] lib: s390x: sclp: Add line mode input handling Nico Boehr
                   ` (22 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones; +Cc: kvm, frankja, imbrenda

From: Janosch Frank <frankja@linux.ibm.com>

Without the \r the output of the HMC ASCII console takes a lot of
additional effort to read in comparison to the line mode console.

Additionally we add a console clear for the HMC ASCII console so that
old messages from a previously running operating system are not
polluting the console.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Link: https://lore.kernel.org/r/20231031095519.73311-3-frankja@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 lib/s390x/sclp-console.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/lib/s390x/sclp-console.c b/lib/s390x/sclp-console.c
index 19c74e4..6c965b6 100644
--- a/lib/s390x/sclp-console.c
+++ b/lib/s390x/sclp-console.c
@@ -11,6 +11,7 @@
 #include <asm/arch_def.h>
 #include <asm/io.h>
 #include <asm/spinlock.h>
+#include "hardware.h"
 #include "sclp.h"
 
 /*
@@ -85,6 +86,8 @@ static uint8_t _ascebc[256] = {
      0x90, 0x3F, 0x3F, 0x3F, 0x3F, 0xEA, 0x3F, 0xFF
 };
 
+static bool lpar_ascii_compat;
+
 static char lm_buff[120];
 static unsigned char lm_buff_off;
 static struct spinlock lm_buff_lock;
@@ -97,14 +100,29 @@ static void sclp_print_ascii(const char *str)
 {
 	int len = strlen(str);
 	WriteEventData *sccb = (void *)_sccb;
+	char *str_dest = (char *)&sccb->msg;
+	int src_ind, dst_ind;
 
 	sclp_mark_busy();
 	memset(sccb, 0, sizeof(*sccb));
+
+	for (src_ind = 0, dst_ind = 0;
+	     src_ind < len && dst_ind < (PAGE_SIZE / 2);
+	     src_ind++, dst_ind++) {
+		str_dest[dst_ind] = str[src_ind];
+		/* Add a \r to the \n for HMC ASCII console */
+		if (str[src_ind] == '\n' && lpar_ascii_compat) {
+			dst_ind++;
+			str_dest[dst_ind] = '\r';
+		}
+	}
+
+	/* Len might have changed because of the compat behavior */
+	len = dst_ind;
 	sccb->h.length = offsetof(WriteEventData, msg) + len;
 	sccb->h.function_code = SCLP_FC_NORMAL_WRITE;
 	sccb->ebh.length = sizeof(EventBufferHeader) + len;
 	sccb->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA;
-	memcpy(&sccb->msg, str, len);
 
 	sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb);
 }
@@ -218,8 +236,13 @@ static void sclp_console_disable_read(void)
 
 void sclp_console_setup(void)
 {
+	lpar_ascii_compat = detect_host() == HOST_IS_LPAR;
+
 	/* We send ASCII and line mode. */
 	sclp_write_event_mask(0, SCLP_EVENT_MASK_MSG_ASCII | SCLP_EVENT_MASK_MSG);
+	/* Hard terminal reset to clear screen for HMC ASCII console */
+	if (lpar_ascii_compat)
+		sclp_print_ascii("\ec");
 }
 
 void sclp_print(const char *str)
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 05/26] lib: s390x: sclp: Add line mode input handling
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (3 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 04/26] lib: s390x: sclp: Add compat handling for HMC ASCII consoles Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 06/26] s390x: spec_ex-sie: refactor to use snippet API Nico Boehr
                   ` (21 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones; +Cc: kvm, frankja, imbrenda

From: Janosch Frank <frankja@linux.ibm.com>

Time to add line-mode input so we can use input handling under LPAR if
there's no access to a ASCII console.

Line-mode IO is pretty wild and the documentation could be improved a
lot. Hence I've copied the input parsing functions from Linux.

For some reason output is a type 2 event but input is a type 1
event. This also means that the input and output structures are
different from each other.

The input can consist of multiple structures which don't contain text
data before the input text data is reached. Hence we need a bunch of
search functions to retrieve a pointer to the text data.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Link: https://lore.kernel.org/r/20231031095519.73311-4-frankja@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 lib/s390x/sclp.h         |  26 +++++-
 lib/s390x/sclp-console.c | 181 ++++++++++++++++++++++++++++++++++-----
 2 files changed, 186 insertions(+), 21 deletions(-)

diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h
index 6a611bc..22f120d 100644
--- a/lib/s390x/sclp.h
+++ b/lib/s390x/sclp.h
@@ -226,6 +226,7 @@ typedef struct SCCB {
 } __attribute__((packed)) SCCB;
 
 /* SCLP event types */
+#define SCLP_EVENT_OP_CMD			0x01
 #define SCLP_EVENT_ASCII_CONSOLE_DATA           0x1a
 #define SCLP_EVENT_SIGNAL_QUIESCE               0x1d
 
@@ -233,6 +234,7 @@ typedef struct SCCB {
 #define SCLP_EVENT_MASK_SIGNAL_QUIESCE          0x00000008
 #define SCLP_EVENT_MASK_MSG_ASCII               0x00000040
 #define SCLP_EVENT_MASK_MSG          		0x40000000
+#define SCLP_EVENT_MASK_OPCMD			0x80000000
 
 #define SCLP_UNCONDITIONAL_READ                 0x00
 #define SCLP_SELECTIVE_READ                     0x01
@@ -296,6 +298,23 @@ struct mdb {
 	struct mto mto;
 } __attribute__((packed));
 
+/* vector keys and ids */
+#define GDS_ID_MDSMU		0x1310
+#define GDS_ID_CPMSU		0x1212
+#define GDS_ID_TEXTCMD		0x1320
+#define GDS_KEY_SELFDEFTEXTMSG	0x31
+#define EBC_MDB                 0xd4c4c240
+
+struct gds_vector {
+	uint16_t     length;
+	uint16_t     gds_id;
+} __attribute__((packed));
+
+struct gds_subvector {
+	uint8_t      length;
+	uint8_t      key;
+} __attribute__((packed));
+
 typedef struct EventBufferHeader {
 	uint16_t length;
 	uint8_t  type;
@@ -320,12 +339,17 @@ typedef struct ReadEventData {
 
 #define SCLP_EVENT_ASCII_TYPE_DATA_STREAM_FOLLOWS 0
 typedef struct ReadEventDataAsciiConsole {
-	SCCBHeader h;
 	EventBufferHeader ebh;
 	uint8_t type;
 	char data[];
 } __attribute__((packed)) ReadEventDataAsciiConsole;
 
+struct ReadEventDataLMConsole {
+	SCCBHeader h;
+	EventBufferHeader ebh;
+	struct gds_vector v[];
+};
+
 extern char _sccb[];
 void sclp_setup_int(void);
 void sclp_handle_ext(void);
diff --git a/lib/s390x/sclp-console.c b/lib/s390x/sclp-console.c
index 6c965b6..5de3325 100644
--- a/lib/s390x/sclp-console.c
+++ b/lib/s390x/sclp-console.c
@@ -1,8 +1,13 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
 /*
- * SCLP ASCII access driver
+ * SCLP line mode and ASCII console driver
+ * Some parts taken from the Linux kernel.
  *
  * Copyright (c) 2013 Alexander Graf <agraf@suse.de>
+ *
+ * Copyright IBM Corp. 1999
+ * Author(s): Martin Peschke <mpeschke@de.ibm.com>
+ *	      Martin Schwidefsky <schwidefsky@de.ibm.com>
  */
 
 #include <libcflat.h>
@@ -86,6 +91,41 @@ static uint8_t _ascebc[256] = {
      0x90, 0x3F, 0x3F, 0x3F, 0x3F, 0xEA, 0x3F, 0xFF
 };
 
+static const uint8_t _ebcasc[] = {
+	0x00, 0x01, 0x02, 0x03, 0x07, 0x09, 0x07, 0x7F,
+	0x07, 0x07, 0x07, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+	0x10, 0x11, 0x12, 0x13, 0x07, 0x0A, 0x08, 0x07,
+	0x18, 0x19, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
+	0x07, 0x07, 0x1C, 0x07, 0x07, 0x0A, 0x17, 0x1B,
+	0x07, 0x07, 0x07, 0x07, 0x07, 0x05, 0x06, 0x07,
+	0x07, 0x07, 0x16, 0x07, 0x07, 0x07, 0x07, 0x04,
+	0x07, 0x07, 0x07, 0x07, 0x14, 0x15, 0x07, 0x1A,
+	0x20, 0xFF, 0x83, 0x84, 0x85, 0xA0, 0x07, 0x86,
+	0x87, 0xA4, 0x5B, 0x2E, 0x3C, 0x28, 0x2B, 0x21,
+	0x26, 0x82, 0x88, 0x89, 0x8A, 0xA1, 0x8C, 0x07,
+	0x8D, 0xE1, 0x5D, 0x24, 0x2A, 0x29, 0x3B, 0x5E,
+	0x2D, 0x2F, 0x07, 0x8E, 0x07, 0x07, 0x07, 0x8F,
+	0x80, 0xA5, 0x07, 0x2C, 0x25, 0x5F, 0x3E, 0x3F,
+	0x07, 0x90, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
+	0x70, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22,
+	0x07, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+	0x68, 0x69, 0xAE, 0xAF, 0x07, 0x07, 0x07, 0xF1,
+	0xF8, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70,
+	0x71, 0x72, 0xA6, 0xA7, 0x91, 0x07, 0x92, 0x07,
+	0xE6, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
+	0x79, 0x7A, 0xAD, 0xAB, 0x07, 0x07, 0x07, 0x07,
+	0x9B, 0x9C, 0x9D, 0xFA, 0x07, 0x07, 0x07, 0xAC,
+	0xAB, 0x07, 0xAA, 0x7C, 0x07, 0x07, 0x07, 0x07,
+	0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+	0x48, 0x49, 0x07, 0x93, 0x94, 0x95, 0xA2, 0x07,
+	0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
+	0x51, 0x52, 0x07, 0x96, 0x81, 0x97, 0xA3, 0x98,
+	0x5C, 0xF6, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
+	0x59, 0x5A, 0xFD, 0x07, 0x99, 0x07, 0x07, 0x07,
+	0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+	0x38, 0x39, 0x07, 0x07, 0x9A, 0x07, 0x07, 0x07,
+};
+
 static bool lpar_ascii_compat;
 
 static char lm_buff[120];
@@ -226,7 +266,8 @@ static void sclp_write_event_mask(int receive_mask, int send_mask)
 
 static void sclp_console_enable_read(void)
 {
-	sclp_write_event_mask(SCLP_EVENT_MASK_MSG_ASCII, SCLP_EVENT_MASK_MSG_ASCII | SCLP_EVENT_MASK_MSG);
+	sclp_write_event_mask(SCLP_EVENT_MASK_MSG_ASCII | SCLP_EVENT_MASK_OPCMD,
+			      SCLP_EVENT_MASK_MSG_ASCII | SCLP_EVENT_MASK_MSG);
 }
 
 static void sclp_console_disable_read(void)
@@ -264,37 +305,137 @@ void sclp_print(const char *str)
 	sclp_print_lm(str);
 }
 
-static int console_refill_read_buffer(void)
+static char *console_read_ascii(struct EventBufferHeader *ebh, int *len)
 {
+	struct ReadEventDataAsciiConsole *evdata = (void *)ebh;
 	const int max_event_buffer_len = SCCB_SIZE - offsetof(ReadEventDataAsciiConsole, ebh);
-	ReadEventDataAsciiConsole *sccb = (void *)_sccb;
-	const int event_buffer_ascii_recv_header_len = sizeof(sccb->ebh) + sizeof(sccb->type);
-	int ret = -1;
+	const int event_buffer_ascii_recv_header_len = offsetof(ReadEventDataAsciiConsole, data);
+
+	assert(ebh->length <= max_event_buffer_len);
+	assert(ebh->length > event_buffer_ascii_recv_header_len);
+
+	*len = ebh->length - event_buffer_ascii_recv_header_len;
+	return evdata->data;
+}
+
+
+static struct gds_vector *sclp_find_gds_vector(void *start, void *end, uint16_t id)
+{
+	struct gds_vector *v;
+
+	for (v = start; (void *)v < end; v = (void *)v + v->length)
+		if (v->gds_id == id)
+			return v;
+	return NULL;
+}
+
+static struct gds_subvector *sclp_eval_selfdeftextmsg(struct gds_subvector *sv)
+{
+	void *end;
+
+	end = (void *)sv + sv->length;
+	for (sv = sv + 1; (void *)sv < end; sv = (void *)sv + sv->length)
+		if (sv->key == 0x30)
+			return sv;
+	return NULL;
+}
+
+static struct gds_subvector *sclp_eval_textcmd(struct gds_vector *v)
+{
+	struct gds_subvector *sv;
+	void *end;
+
+	end = (void *)v + v->length;
+	for (sv = (struct gds_subvector *)(v + 1); (void *)sv < end;
+	     sv = (void *)sv + sv->length)
+		if (sv->key == GDS_KEY_SELFDEFTEXTMSG)
+			return sclp_eval_selfdeftextmsg(sv);
+	return NULL;
+}
+
+static struct gds_subvector *sclp_eval_cpmsu(struct gds_vector *v)
+{
+	void *end;
+
+	end = (void *)v + v->length;
+	for (v = v + 1; (void *)v < end; v = (void *)v + v->length)
+		if (v->gds_id == GDS_ID_TEXTCMD)
+			return sclp_eval_textcmd(v);
+	return NULL;
+}
+
+static struct gds_subvector *sclp_eval_mdsmu(struct gds_vector *v)
+{
+	v = sclp_find_gds_vector(v + 1, (void *)v + v->length, GDS_ID_CPMSU);
+	if (v)
+		return sclp_eval_cpmsu(v);
+	return NULL;
+}
+
+static char *console_read_lm(struct EventBufferHeader *ebh, int *len)
+{
+	struct gds_vector *v = (void *)ebh + sizeof(*ebh);
+	struct gds_subvector *sv;
+
+	v = sclp_find_gds_vector(v, (void *)ebh + ebh->length,
+				 GDS_ID_MDSMU);
+	if (!v)
+		return NULL;
+
+	sv = sclp_eval_mdsmu(v);
+	if (!sv)
+		return NULL;
+
+	*len = sv->length - (sizeof(*sv));
+	return (char *)(sv + 1);
+}
+
+static void ebc_to_asc(char *data, int len)
+{
+	int i;
+
+	for (i = 0; i < len; i++)
+		data[i] = _ebcasc[(uint8_t)data[i]];
+}
+
+static int console_refill_read_buffer(void)
+{
+	struct SCCBHeader *sccb = (struct SCCBHeader *)_sccb;
+	struct EventBufferHeader *ebh = (void *)_sccb + sizeof(struct SCCBHeader);
+	char *data;
+	int ret = -1, len;
 
 	sclp_console_enable_read();
 
 	sclp_mark_busy();
-	memset(sccb, 0, SCCB_SIZE);
-	sccb->h.length = PAGE_SIZE;
-	sccb->h.function_code = SCLP_UNCONDITIONAL_READ;
-	sccb->h.control_mask[2] = SCLP_CM2_VARIABLE_LENGTH_RESPONSE;
+	memset(_sccb, 0, SCCB_SIZE);
+	sccb->length = PAGE_SIZE;
+	sccb->function_code = SCLP_UNCONDITIONAL_READ;
+	sccb->control_mask[2] = SCLP_CM2_VARIABLE_LENGTH_RESPONSE;
 
 	sclp_service_call(SCLP_CMD_READ_EVENT_DATA, sccb);
 
-	if (sccb->h.response_code == SCLP_RC_NO_EVENT_BUFFERS_STORED ||
-	    sccb->ebh.type != SCLP_EVENT_ASCII_CONSOLE_DATA ||
-	    sccb->type != SCLP_EVENT_ASCII_TYPE_DATA_STREAM_FOLLOWS) {
-		ret = -1;
+	if (sccb->response_code == SCLP_RC_NO_EVENT_BUFFERS_STORED)
 		goto out;
-	}
 
-	assert(sccb->ebh.length <= max_event_buffer_len);
-	assert(sccb->ebh.length > event_buffer_ascii_recv_header_len);
+	switch (ebh->type) {
+	case SCLP_EVENT_OP_CMD:
+		data = console_read_lm(ebh, &len);
+		if (data)
+			ebc_to_asc(data, len);
+		break;
+	case SCLP_EVENT_ASCII_CONSOLE_DATA:
+		data = console_read_ascii(ebh, &len);
+		break;
+	default:
+		goto out;
+	}
 
-	read_buf_length = sccb->ebh.length - event_buffer_ascii_recv_header_len;
+	if (!data)
+		goto out;
 
-	assert(read_buf_length <= sizeof(read_buf));
-	memcpy(read_buf, sccb->data, read_buf_length);
+	assert(len <= sizeof(read_buf));
+	memcpy(read_buf, data, len);
 
 	read_index = 0;
 	ret = 0;
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 06/26] s390x: spec_ex-sie: refactor to use snippet API
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (4 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 05/26] lib: s390x: sclp: Add line mode input handling Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 07/26] s390x: sie: ensure guests are aligned to 2GB Nico Boehr
                   ` (20 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones; +Cc: kvm, frankja, imbrenda

spec_ex-sie uses a snippet, but allocated the memory on its own without
obvious reason to do so.

Refactor the test to use snippet_init().

Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Link: https://lore.kernel.org/r/20231106170849.1184162-2-nrb@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 s390x/spec_ex-sie.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/s390x/spec_ex-sie.c b/s390x/spec_ex-sie.c
index 5fa135b..fe2f23e 100644
--- a/s390x/spec_ex-sie.c
+++ b/s390x/spec_ex-sie.c
@@ -17,19 +17,18 @@
 #include <hardware.h>
 
 static struct vm vm;
-extern const char SNIPPET_NAME_START(c, spec_ex)[];
-extern const char SNIPPET_NAME_END(c, spec_ex)[];
 static bool strict;
 
 static void setup_guest(void)
 {
-	char *guest;
-	int binary_size = SNIPPET_LEN(c, spec_ex);
+	extern const char SNIPPET_NAME_START(c, spec_ex)[];
+	extern const char SNIPPET_NAME_END(c, spec_ex)[];
 
 	setup_vm();
-	guest = alloc_pages(8);
-	memcpy(guest, SNIPPET_NAME_START(c, spec_ex), binary_size);
-	sie_guest_create(&vm, (uint64_t) guest, HPAGE_SIZE);
+
+	snippet_setup_guest(&vm, false);
+	snippet_init(&vm, SNIPPET_NAME_START(c, spec_ex),
+		     SNIPPET_LEN(c, spec_ex), SNIPPET_UNPACK_OFF);
 }
 
 static void reset_guest(void)
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 07/26] s390x: sie: ensure guests are aligned to 2GB
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (5 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 06/26] s390x: spec_ex-sie: refactor to use snippet API Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-22 11:06   ` Thomas Huth
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 08/26] s390x: mvpg-sie: fix virtual-physical address confusion Nico Boehr
                   ` (19 subsequent siblings)
  26 siblings, 1 reply; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones; +Cc: kvm, frankja, imbrenda

Until now, kvm-unit-tests has aligned guests to 1 MB in the host virtual
address space. Unfortunately, some s390x environments require guests to
be 2GB aligned in the host virtual address space, preventing
kvm-unit-tests which act as a hypervisor from running there.

We can't easily put guests at address 0, since we want to be able to run
with MSO/MSL without having to maintain separate page tables for the
guest physical memory. 2GB is also not a good choice, since the
alloc_pages allocator will place its metadata there when the host has
more than 2GB of memory. In addition, we also want a bit of space after
the end of the host physical memory to be able to catch accesses beyond
the end of physical memory.

The vmalloc allocator unfortunately allocates memory starting at the
highest virtual address which is not suitable for guest memory either
due to additional constraints of some environments.

The physical page allocator in memalign_pages() is also not a optimal
choice, since every test running SIE would then require at least 4GB+1MB
of physical memory.

This results in a few quite complex allocation requirements, hence add a
new function sie_guest_alloc() which allocates memory for a guest and
then establishes a properly aligned virtual space mapping.

Rework snippet test and sie tests to use the new sie_guest_alloc()
function.

Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Link: https://lore.kernel.org/r/20231106170849.1184162-3-nrb@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 lib/s390x/sie.h     |  2 ++
 lib/s390x/snippet.h |  9 +++------
 lib/s390x/sie.c     | 42 ++++++++++++++++++++++++++++++++++++++++++
 s390x/sie.c         |  4 ++--
 4 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/lib/s390x/sie.h b/lib/s390x/sie.h
index 147cb0f..c1724cf 100644
--- a/lib/s390x/sie.h
+++ b/lib/s390x/sie.h
@@ -285,4 +285,6 @@ void sie_guest_sca_create(struct vm *vm);
 void sie_guest_create(struct vm *vm, uint64_t guest_mem, uint64_t guest_mem_len);
 void sie_guest_destroy(struct vm *vm);
 
+uint8_t *sie_guest_alloc(uint64_t guest_size);
+
 #endif /* _S390X_SIE_H_ */
diff --git a/lib/s390x/snippet.h b/lib/s390x/snippet.h
index 11ec54c..910849a 100644
--- a/lib/s390x/snippet.h
+++ b/lib/s390x/snippet.h
@@ -125,14 +125,11 @@ static inline void snippet_pv_init(struct vm *vm, const char *gbin,
 /* Allocates and sets up a snippet based guest */
 static inline void snippet_setup_guest(struct vm *vm, bool is_pv)
 {
-	u8 *guest;
-
-	/* Allocate 1MB as guest memory */
-	guest = alloc_pages(8);
-	memset(guest, 0, HPAGE_SIZE);
+	const unsigned long guest_size = SZ_1M;
+	uint8_t *guest_start = sie_guest_alloc(guest_size);
 
 	/* Initialize the vm struct and allocate control blocks */
-	sie_guest_create(vm, (uint64_t)guest, HPAGE_SIZE);
+	sie_guest_create(vm, (uint64_t)guest_start, guest_size);
 
 	if (is_pv) {
 		/* FMT4 needs a ESCA */
diff --git a/lib/s390x/sie.c b/lib/s390x/sie.c
index b44febd..97a093b 100644
--- a/lib/s390x/sie.c
+++ b/lib/s390x/sie.c
@@ -15,6 +15,8 @@
 #include <asm/page.h>
 #include <libcflat.h>
 #include <alloc_page.h>
+#include <vmalloc.h>
+#include <sclp.h>
 
 void sie_expect_validity(struct vm *vm)
 {
@@ -111,6 +113,46 @@ void sie_guest_create(struct vm *vm, uint64_t guest_mem, uint64_t guest_mem_len)
 	vm->sblk->crycbd = (uint32_t)(uintptr_t)vm->crycb;
 }
 
+/**
+ * sie_guest_alloc() - Allocate memory for a guest and map it in virtual address
+ * space such that it is properly aligned.
+ * @guest_size: the desired size of the guest in bytes.
+ */
+uint8_t *sie_guest_alloc(uint64_t guest_size)
+{
+	static unsigned long guest_counter = 1;
+	u8 *guest_phys, *guest_virt;
+	unsigned long i;
+	pgd_t *root;
+
+	setup_vm();
+	root = (pgd_t *)(stctg(1) & PAGE_MASK);
+
+	/*
+	 * Start of guest memory in host virtual space needs to be aligned to
+	 * 2GB for some environments. It also can't be at 2GB since the memory
+	 * allocator stores its page_states metadata there.
+	 * Thus we use the next multiple of 4GB after the end of physical
+	 * mapping. This also leaves space after end of physical memory so the
+	 * page immediately after physical memory is guaranteed not to be
+	 * present.
+	 */
+	guest_virt = (uint8_t *)ALIGN(get_ram_size() + guest_counter * 4UL * SZ_1G, SZ_2G);
+	guest_counter++;
+
+	guest_phys = alloc_pages(get_order(guest_size) - 12);
+	/*
+	 * Establish a new mapping of the guest memory so it can be 2GB aligned
+	 * without actually requiring 2GB physical memory.
+	 */
+	for (i = 0; i < guest_size; i += PAGE_SIZE) {
+		install_page(root, __pa(guest_phys + i), guest_virt + i);
+	}
+	memset(guest_virt, 0, guest_size);
+
+	return guest_virt;
+}
+
 /* Frees the memory that was gathered on initialization */
 void sie_guest_destroy(struct vm *vm)
 {
diff --git a/s390x/sie.c b/s390x/sie.c
index cd3cea1..ce5b606 100644
--- a/s390x/sie.c
+++ b/s390x/sie.c
@@ -89,8 +89,8 @@ static void setup_guest(void)
 {
 	setup_vm();
 
-	/* Allocate 1MB as guest memory */
-	guest = alloc_pages(8);
+	guest = sie_guest_alloc(SZ_1M);
+
 	/* The first two pages are the lowcore */
 	guest_instr = guest + PAGE_SIZE * 2;
 
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 08/26] s390x: mvpg-sie: fix virtual-physical address confusion
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (6 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 07/26] s390x: sie: ensure guests are aligned to 2GB Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 09/26] s390x: topology: Introduce enums for polarization & cpu type Nico Boehr
                   ` (18 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones; +Cc: kvm, frankja, imbrenda

The addresses reported for the partial execution of mvpg instruction are
physical addresses. Now that MSO is a virtual address, we can't simply
compare the PEI fields in the sie block with MSO, but need to do an
additional translation step.

Add the necessary virtual-physical translations.

Link: https://lore.kernel.org/r/20231106170849.1184162-4-nrb@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 s390x/mvpg-sie.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/s390x/mvpg-sie.c b/s390x/mvpg-sie.c
index 99f4859..d182b49 100644
--- a/s390x/mvpg-sie.c
+++ b/s390x/mvpg-sie.c
@@ -12,6 +12,7 @@
 #include <asm-generic/barrier.h>
 #include <asm/pgtable.h>
 #include <mmu.h>
+#include <vmalloc.h>
 #include <asm/page.h>
 #include <asm/facility.h>
 #include <asm/mem.h>
@@ -23,7 +24,9 @@
 static struct vm vm;
 
 static uint8_t *src;
+static phys_addr_t src_phys;
 static uint8_t *dst;
+static phys_addr_t dst_phys;
 static uint8_t *cmp;
 
 static void test_mvpg_pei(void)
@@ -38,8 +41,8 @@ static void test_mvpg_pei(void)
 	protect_page(src, PAGE_ENTRY_I);
 	sie(&vm);
 	report(vm.sblk->icptcode == ICPT_PARTEXEC, "Partial execution");
-	report((uintptr_t)**pei_src == (uintptr_t)src + PAGE_ENTRY_I, "PEI_SRC correct");
-	report((uintptr_t)**pei_dst == (uintptr_t)dst, "PEI_DST correct");
+	report((uintptr_t)**pei_src == (uintptr_t)src_phys + PAGE_ENTRY_I, "PEI_SRC correct");
+	report((uintptr_t)**pei_dst == (uintptr_t)dst_phys, "PEI_DST correct");
 	unprotect_page(src, PAGE_ENTRY_I);
 	report(!memcmp(cmp, dst, PAGE_SIZE), "Destination intact");
 	/*
@@ -60,8 +63,8 @@ static void test_mvpg_pei(void)
 	protect_page(dst, PAGE_ENTRY_I);
 	sie(&vm);
 	report(vm.sblk->icptcode == ICPT_PARTEXEC, "Partial execution");
-	report((uintptr_t)**pei_src == (uintptr_t)src, "PEI_SRC correct");
-	report((uintptr_t)**pei_dst == (uintptr_t)dst + PAGE_ENTRY_I, "PEI_DST correct");
+	report((uintptr_t)**pei_src == (uintptr_t)src_phys, "PEI_SRC correct");
+	report((uintptr_t)**pei_dst == (uintptr_t)dst_phys + PAGE_ENTRY_I, "PEI_DST correct");
 	/* Needed for the memcmp and general cleanup */
 	unprotect_page(dst, PAGE_ENTRY_I);
 	report(!memcmp(cmp, dst, PAGE_SIZE), "Destination intact");
@@ -82,8 +85,10 @@ static void setup_guest(void)
 {
 	extern const char SNIPPET_NAME_START(c, mvpg_snippet)[];
 	extern const char SNIPPET_NAME_END(c, mvpg_snippet)[];
+	pgd_t *root;
 
 	setup_vm();
+	root = (pgd_t *)(stctg(1) & PAGE_MASK);
 
 	snippet_setup_guest(&vm, false);
 	snippet_init(&vm, SNIPPET_NAME_START(c, mvpg_snippet),
@@ -94,6 +99,9 @@ static void setup_guest(void)
 
 	src = (uint8_t *) vm.sblk->mso + PAGE_SIZE * 6;
 	dst = (uint8_t *) vm.sblk->mso + PAGE_SIZE * 5;
+	src_phys = virt_to_pte_phys(root, src);
+	dst_phys = virt_to_pte_phys(root, dst);
+
 	cmp = alloc_page();
 	memset(cmp, 0, PAGE_SIZE);
 }
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 09/26] s390x: topology: Introduce enums for polarization & cpu type
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (7 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 08/26] s390x: mvpg-sie: fix virtual-physical address confusion Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 10/26] s390x: topology: Fix report message Nico Boehr
                   ` (17 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones
  Cc: kvm, frankja, imbrenda, Nina Schoetterl-Glausch

From: Nina Schoetterl-Glausch <nsg@linux.ibm.com>

Thereby get rid of magic values.

Reviewed-by: Nico Boehr <nrb@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Link: https://lore.kernel.org/r/20231030160349.458764-2-nsg@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 lib/s390x/stsi.h | 11 +++++++++++
 s390x/topology.c |  6 ++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/lib/s390x/stsi.h b/lib/s390x/stsi.h
index 1351a6f..2f6182c 100644
--- a/lib/s390x/stsi.h
+++ b/lib/s390x/stsi.h
@@ -41,6 +41,17 @@ struct topology_core {
 	uint64_t mask;
 };
 
+enum topology_polarization {
+	POLARIZATION_HORIZONTAL = 0,
+	POLARIZATION_VERTICAL_LOW = 1,
+	POLARIZATION_VERTICAL_MEDIUM = 2,
+	POLARIZATION_VERTICAL_HIGH = 3,
+};
+
+enum cpu_type {
+	CPU_TYPE_IFL = 3,
+};
+
 #define CONTAINER_TLE_RES_BITS 0x00ffffffffffff00UL
 struct topology_container {
 	uint8_t nl;
diff --git a/s390x/topology.c b/s390x/topology.c
index 6955823..6ab8c8d 100644
--- a/s390x/topology.c
+++ b/s390x/topology.c
@@ -261,7 +261,7 @@ static uint8_t *check_tle(void *tc)
 	report(!(*(uint64_t *)tc & CPUS_TLE_RES_BITS), "reserved bits %016lx",
 	       *(uint64_t *)tc & CPUS_TLE_RES_BITS);
 
-	report(cpus->type == 0x03, "type IFL");
+	report(cpus->type == CPU_TYPE_IFL, "type IFL");
 
 	report_info("origin: %d", cpus->origin);
 	report_info("mask: %016lx", cpus->mask);
@@ -275,7 +275,9 @@ static uint8_t *check_tle(void *tc)
 	if (!cpus->d)
 		report_skip("Not dedicated");
 	else
-		report(cpus->pp == 3 || cpus->pp == 0, "Dedicated CPUs are either vertically polarized or have high entitlement");
+		report(cpus->pp == POLARIZATION_VERTICAL_HIGH ||
+		       cpus->pp == POLARIZATION_HORIZONTAL,
+		       "Dedicated CPUs are either vertically polarized or have high entitlement");
 
 	return tc + sizeof(*cpus);
 }
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 10/26] s390x: topology: Fix report message
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (8 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 09/26] s390x: topology: Introduce enums for polarization & cpu type Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 11/26] s390x: topology: Use function parameter in stsi_get_sysib Nico Boehr
                   ` (16 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones
  Cc: kvm, frankja, imbrenda, Nina Schoetterl-Glausch

From: Nina Schoetterl-Glausch <nsg@linux.ibm.com>

A polarization value of 0 means horizontal polarization.

Reviewed-by: Nico Boehr <nrb@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Link: https://lore.kernel.org/r/20231030160349.458764-3-nsg@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 s390x/topology.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/s390x/topology.c b/s390x/topology.c
index 6ab8c8d..1c4a86f 100644
--- a/s390x/topology.c
+++ b/s390x/topology.c
@@ -277,7 +277,7 @@ static uint8_t *check_tle(void *tc)
 	else
 		report(cpus->pp == POLARIZATION_VERTICAL_HIGH ||
 		       cpus->pp == POLARIZATION_HORIZONTAL,
-		       "Dedicated CPUs are either vertically polarized or have high entitlement");
+		       "Dedicated CPUs are either horizontally polarized or have high entitlement");
 
 	return tc + sizeof(*cpus);
 }
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 11/26] s390x: topology: Use function parameter in stsi_get_sysib
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (9 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 10/26] s390x: topology: Fix report message Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 12/26] s390x: topology: Fix parsing loop Nico Boehr
                   ` (15 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones
  Cc: kvm, frankja, imbrenda, Nina Schoetterl-Glausch

From: Nina Schoetterl-Glausch <nsg@linux.ibm.com>

Actually use the function parameter we're give instead of a hardcoded
access to the static variable pagebuf.

Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Nico Boehr <nrb@linux.ibm.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Link: https://lore.kernel.org/r/20231030160349.458764-4-nsg@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 s390x/topology.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/s390x/topology.c b/s390x/topology.c
index 1c4a86f..032e80d 100644
--- a/s390x/topology.c
+++ b/s390x/topology.c
@@ -324,7 +324,7 @@ static int stsi_get_sysib(struct sysinfo_15_1_x *info, int sel2)
 
 	report_prefix_pushf("SYSIB");
 
-	ret = stsi(pagebuf, 15, 1, sel2);
+	ret = stsi(info, 15, 1, sel2);
 
 	if (max_nested_lvl >= sel2) {
 		report(!ret, "Valid instruction");
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 12/26] s390x: topology: Fix parsing loop
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (10 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 11/26] s390x: topology: Use function parameter in stsi_get_sysib Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 13/26] s390x: topology: Make some report messages unique Nico Boehr
                   ` (14 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones
  Cc: kvm, frankja, imbrenda, Nina Schoetterl-Glausch

From: Nina Schoetterl-Glausch <nsg@linux.ibm.com>

Without a comparison the loop is infinite.

Reviewed-by: Nico Boehr <nrb@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Link: https://lore.kernel.org/r/20231030160349.458764-5-nsg@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 s390x/topology.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/s390x/topology.c b/s390x/topology.c
index 032e80d..c8ad4bc 100644
--- a/s390x/topology.c
+++ b/s390x/topology.c
@@ -468,7 +468,7 @@ static void parse_topology_args(int argc, char **argv)
 		if (flag[0] != '-')
 			report_abort("Argument is expected to begin with '-'");
 		flag++;
-		for (level = 0; ARRAY_SIZE(levels); level++) {
+		for (level = 0; level < ARRAY_SIZE(levels); level++) {
 			if (!strcmp(levels[level], flag))
 				break;
 		}
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 13/26] s390x: topology: Make some report messages unique
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (11 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 12/26] s390x: topology: Fix parsing loop Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 14/26] s390x: topology: Refine stsi header test Nico Boehr
                   ` (13 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones
  Cc: kvm, frankja, imbrenda, Nina Schoetterl-Glausch

From: Nina Schoetterl-Glausch <nsg@linux.ibm.com>

When we test something, i.e. do a report() we want unique messages,
otherwise, from the test output, it will appear as if the same test was
run multiple times, possible with different PASS/FAIL values.

Convert some reports that don't actually test anything topology specific
into asserts.
Refine the report message for others.

Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Nico Boehr <nrb@linux.ibm.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Link: https://lore.kernel.org/r/20231030160349.458764-6-nsg@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 s390x/topology.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/s390x/topology.c b/s390x/topology.c
index c8ad4bc..03bc3d3 100644
--- a/s390x/topology.c
+++ b/s390x/topology.c
@@ -114,7 +114,7 @@ static void check_polarization_change(void)
 	report_prefix_push("Polarization change");
 
 	/* We expect a clean state through reset */
-	report(diag308_load_reset(1), "load normal reset done");
+	assert(diag308_load_reset(1));
 
 	/*
 	 * Set vertical polarization to verify that RESET sets
@@ -123,7 +123,7 @@ static void check_polarization_change(void)
 	cc = ptf(PTF_REQ_VERTICAL, &rc);
 	report(cc == 0, "Set vertical polarization.");
 
-	report(diag308_load_reset(1), "load normal reset done");
+	assert(diag308_load_reset(1));
 
 	cc = ptf(PTF_CHECK, &rc);
 	report(cc == 0, "Reset should clear topology report");
@@ -137,25 +137,25 @@ static void check_polarization_change(void)
 	report(cc == 0, "Change to vertical");
 
 	cc = ptf(PTF_CHECK, &rc);
-	report(cc == 1, "Should report");
+	report(cc == 1, "Should report change after horizontal -> vertical");
 
 	cc = ptf(PTF_REQ_VERTICAL, &rc);
 	report(cc == 2 && rc == PTF_ERR_ALRDY_POLARIZED, "Double change to vertical");
 
 	cc = ptf(PTF_CHECK, &rc);
-	report(cc == 0, "Should not report");
+	report(cc == 0, "Should not report change after vertical -> vertical");
 
 	cc = ptf(PTF_REQ_HORIZONTAL, &rc);
 	report(cc == 0, "Change to horizontal");
 
 	cc = ptf(PTF_CHECK, &rc);
-	report(cc == 1, "Should Report");
+	report(cc == 1, "Should report change after vertical -> horizontal");
 
 	cc = ptf(PTF_REQ_HORIZONTAL, &rc);
 	report(cc == 2 && rc == PTF_ERR_ALRDY_POLARIZED, "Double change to horizontal");
 
 	cc = ptf(PTF_CHECK, &rc);
-	report(cc == 0, "Should not report");
+	report(cc == 0, "Should not report change after horizontal -> horizontal");
 
 	report_prefix_pop();
 }
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 14/26] s390x: topology: Refine stsi header test
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (12 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 13/26] s390x: topology: Make some report messages unique Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 15/26] s390x: topology: Rename topology_core to topology_cpu Nico Boehr
                   ` (12 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones
  Cc: kvm, frankja, imbrenda, Nina Schoetterl-Glausch

From: Nina Schoetterl-Glausch <nsg@linux.ibm.com>

Add checks for length field.
Also minor refactor.

Reviewed-by: Nico Boehr <nrb@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Link: https://lore.kernel.org/r/20231030160349.458764-7-nsg@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 s390x/topology.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/s390x/topology.c b/s390x/topology.c
index 03bc3d3..6a5f100 100644
--- a/s390x/topology.c
+++ b/s390x/topology.c
@@ -187,18 +187,23 @@ static void stsi_check_maxcpus(struct sysinfo_15_1_x *info)
 }
 
 /*
- * stsi_check_mag
+ * stsi_check_header
  * @info: Pointer to the stsi information
+ * @sel2: stsi selector 2 value
  *
  * MAG field should match the architecture defined containers
  * when MNEST as returned by SCLP matches MNEST of the SYSIB.
  */
-static void stsi_check_mag(struct sysinfo_15_1_x *info)
+static void stsi_check_header(struct sysinfo_15_1_x *info, int sel2)
 {
 	int i;
 
-	report_prefix_push("MAG");
+	report_prefix_push("Header");
 
+	/* Header is 16 bytes, each TLE 8 or 16, therefore alignment must be 8 at least */
+	report(IS_ALIGNED(info->length, 8), "Length %d multiple of 8", info->length);
+	report(info->length < PAGE_SIZE, "Length %d in bounds", info->length);
+	report(sel2 == info->mnest, "Valid mnest");
 	stsi_check_maxcpus(info);
 
 	/*
@@ -328,7 +333,6 @@ static int stsi_get_sysib(struct sysinfo_15_1_x *info, int sel2)
 
 	if (max_nested_lvl >= sel2) {
 		report(!ret, "Valid instruction");
-		report(sel2 == info->mnest, "Valid mnest");
 	} else {
 		report(ret, "Invalid instruction");
 	}
@@ -367,7 +371,7 @@ static void check_sysinfo_15_1_x(struct sysinfo_15_1_x *info, int sel2)
 		goto vertical;
 	}
 
-	stsi_check_mag(info);
+	stsi_check_header(info, sel2);
 	stsi_check_tle_coherency(info);
 
 vertical:
@@ -380,7 +384,7 @@ vertical:
 		goto end;
 	}
 
-	stsi_check_mag(info);
+	stsi_check_header(info, sel2);
 	stsi_check_tle_coherency(info);
 	report_prefix_pop();
 
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 15/26] s390x: topology: Rename topology_core to topology_cpu
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (13 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 14/26] s390x: topology: Refine stsi header test Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 16/26] s390x: topology: Rewrite topology list test Nico Boehr
                   ` (11 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones
  Cc: kvm, frankja, imbrenda, Nina Schoetterl-Glausch

From: Nina Schoetterl-Glausch <nsg@linux.ibm.com>

This is more in line with the nomenclature in the PoP.

Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Nico Boehr <nrb@linux.ibm.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Link: https://lore.kernel.org/r/20231030160349.458764-8-nsg@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 lib/s390x/stsi.h | 4 ++--
 s390x/topology.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/s390x/stsi.h b/lib/s390x/stsi.h
index 2f6182c..1e9d095 100644
--- a/lib/s390x/stsi.h
+++ b/lib/s390x/stsi.h
@@ -30,7 +30,7 @@ struct sysinfo_3_2_2 {
 };
 
 #define CPUS_TLE_RES_BITS 0x00fffffff8000000UL
-struct topology_core {
+struct topology_cpu {
 	uint8_t nl;
 	uint8_t reserved1[3];
 	uint8_t reserved4:5;
@@ -61,7 +61,7 @@ struct topology_container {
 
 union topology_entry {
 	uint8_t nl;
-	struct topology_core cpu;
+	struct topology_cpu cpu;
 	struct topology_container container;
 };
 
diff --git a/s390x/topology.c b/s390x/topology.c
index 6a5f100..df158ae 100644
--- a/s390x/topology.c
+++ b/s390x/topology.c
@@ -247,7 +247,7 @@ done:
 static uint8_t *check_tle(void *tc)
 {
 	struct topology_container *container = tc;
-	struct topology_core *cpus;
+	struct topology_cpu *cpus;
 	int n;
 
 	if (container->nl) {
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 16/26] s390x: topology: Rewrite topology list test
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (14 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 15/26] s390x: topology: Rename topology_core to topology_cpu Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 17/26] scripts: Implement multiline strings for extra_params Nico Boehr
                   ` (10 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones
  Cc: kvm, frankja, imbrenda, Nina Schoetterl-Glausch

From: Nina Schoetterl-Glausch <nsg@linux.ibm.com>

Rewrite recursion with separate functions for checking containers,
containers containing CPUs and CPUs.
This improves comprehension and allows for more tests.
We now also test for ordering of CPU TLEs and number of child entries.

Acked-by: Janosch Frank <frankja@linux.ibm.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Link: https://lore.kernel.org/r/20231030160349.458764-9-nsg@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 lib/s390x/stsi.h |  36 +++++----
 s390x/topology.c | 202 ++++++++++++++++++++++++++++++-----------------
 2 files changed, 149 insertions(+), 89 deletions(-)

diff --git a/lib/s390x/stsi.h b/lib/s390x/stsi.h
index 1e9d095..f2290ca 100644
--- a/lib/s390x/stsi.h
+++ b/lib/s390x/stsi.h
@@ -30,15 +30,18 @@ struct sysinfo_3_2_2 {
 };
 
 #define CPUS_TLE_RES_BITS 0x00fffffff8000000UL
-struct topology_cpu {
-	uint8_t nl;
-	uint8_t reserved1[3];
-	uint8_t reserved4:5;
-	uint8_t d:1;
-	uint8_t pp:2;
-	uint8_t type;
-	uint16_t origin;
-	uint64_t mask;
+union topology_cpu {
+	uint64_t raw[2];
+	struct {
+		uint8_t nl;
+		uint8_t reserved1[3];
+		uint8_t reserved4:5;
+		uint8_t d:1;
+		uint8_t pp:2;
+		uint8_t type;
+		uint16_t origin;
+		uint64_t mask;
+	};
 };
 
 enum topology_polarization {
@@ -53,16 +56,19 @@ enum cpu_type {
 };
 
 #define CONTAINER_TLE_RES_BITS 0x00ffffffffffff00UL
-struct topology_container {
-	uint8_t nl;
-	uint8_t reserved[6];
-	uint8_t id;
+union topology_container {
+	uint64_t raw;
+	struct {
+		uint8_t nl;
+		uint8_t reserved[6];
+		uint8_t id;
+	};
 };
 
 union topology_entry {
 	uint8_t nl;
-	struct topology_cpu cpu;
-	struct topology_container container;
+	union topology_cpu cpu;
+	union topology_container container;
 };
 
 #define CPU_TOPOLOGY_MAX_LEVEL 6
diff --git a/s390x/topology.c b/s390x/topology.c
index df158ae..01021eb 100644
--- a/s390x/topology.c
+++ b/s390x/topology.c
@@ -2,7 +2,7 @@
 /*
  * CPU Topology
  *
- * Copyright IBM Corp. 2022
+ * Copyright IBM Corp. 2022, 2023
  *
  * Authors:
  *  Pierre Morel <pmorel@linux.ibm.com>
@@ -23,7 +23,6 @@ static uint8_t pagebuf[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
 
 static int max_nested_lvl;
 static int number_of_cpus;
-static int cpus_in_masks;
 static int max_cpus;
 
 /*
@@ -238,108 +237,163 @@ done:
 }
 
 /**
- * check_tle:
- * @tc: pointer to first TLE
+ * stsi_get_sysib:
+ * @info: pointer to the STSI info structure
+ * @sel2: the selector giving the topology level to check
  *
- * Recursively check the containers TLEs until we
- * find a CPU TLE.
+ * Fill the sysinfo_15_1_x info structure and check the
+ * SYSIB header.
+ *
+ * Returns instruction validity.
  */
-static uint8_t *check_tle(void *tc)
+static int stsi_get_sysib(struct sysinfo_15_1_x *info, int sel2)
 {
-	struct topology_container *container = tc;
-	struct topology_cpu *cpus;
-	int n;
+	int ret;
 
-	if (container->nl) {
-		report_info("NL: %d id: %d", container->nl, container->id);
+	report_prefix_pushf("SYSIB");
 
-		report(!(*(uint64_t *)tc & CONTAINER_TLE_RES_BITS),
-		       "reserved bits %016lx",
-		       *(uint64_t *)tc & CONTAINER_TLE_RES_BITS);
+	ret = stsi(info, 15, 1, sel2);
 
-		return check_tle(tc + sizeof(*container));
+	if (max_nested_lvl >= sel2) {
+		report(!ret, "Valid instruction");
+	} else {
+		report(ret, "Invalid instruction");
 	}
 
-	report_info("NL: %d", container->nl);
-	cpus = tc;
+	report_prefix_pop();
 
-	report(!(*(uint64_t *)tc & CPUS_TLE_RES_BITS), "reserved bits %016lx",
-	       *(uint64_t *)tc & CPUS_TLE_RES_BITS);
+	return ret;
+}
 
-	report(cpus->type == CPU_TYPE_IFL, "type IFL");
+static int check_cpu(union topology_cpu *cpu,
+		     union topology_container *parent)
+{
+	report_prefix_pushf("%d:%d:%d:%d", cpu->d, cpu->pp, cpu->type, cpu->origin);
 
-	report_info("origin: %d", cpus->origin);
-	report_info("mask: %016lx", cpus->mask);
-	report_info("dedicated: %d entitlement: %d", cpus->d, cpus->pp);
+	report(!(cpu->raw[0] & CPUS_TLE_RES_BITS), "reserved bits %016lx",
+	       cpu->raw[0] & CPUS_TLE_RES_BITS);
 
-	n = __builtin_popcountl(cpus->mask);
-	report(n <= expected_topo_lvl[0], "CPUs per mask: %d out of max %d",
-	       n, expected_topo_lvl[0]);
-	cpus_in_masks += n;
+	report(cpu->type == CPU_TYPE_IFL, "type IFL");
 
-	if (!cpus->d)
-		report_skip("Not dedicated");
-	else
-		report(cpus->pp == POLARIZATION_VERTICAL_HIGH ||
-		       cpus->pp == POLARIZATION_HORIZONTAL,
+	if (cpu->d)
+		report(cpu->pp == POLARIZATION_VERTICAL_HIGH ||
+		       cpu->pp == POLARIZATION_HORIZONTAL,
 		       "Dedicated CPUs are either horizontally polarized or have high entitlement");
+	else
+		report_skip("Not dedicated");
+
+	report_prefix_pop();
 
-	return tc + sizeof(*cpus);
+	return __builtin_popcountl(cpu->mask);
 }
 
-/**
- * stsi_check_tle_coherency:
- * @info: Pointer to the stsi information
- *
- * We verify that we get the expected number of Topology List Entry
- * containers for a specific level.
- */
-static void stsi_check_tle_coherency(struct sysinfo_15_1_x *info)
+static union topology_container *check_child_cpus(struct sysinfo_15_1_x *info,
+						  union topology_container *cont,
+						  union topology_cpu *child,
+						  unsigned int *cpus_in_masks)
 {
-	void *tc, *end;
+	void *last = ((void *)info) + info->length;
+	union topology_cpu *prev_cpu = NULL;
+	bool correct_ordering = true;
+	unsigned int cpus = 0;
+	int i;
 
-	report_prefix_push("TLE");
-	cpus_in_masks = 0;
+	for (i = 0; (void *)&child[i] < last && child[i].nl == 0; prev_cpu = &child[i++]) {
+		cpus += check_cpu(&child[i], cont);
+		if (prev_cpu) {
+			if (prev_cpu->type > child[i].type) {
+				report_info("Incorrect ordering wrt type for child %d", i);
+				correct_ordering = false;
+			}
+			if (prev_cpu->type < child[i].type)
+				continue;
+			if (prev_cpu->pp < child[i].pp) {
+				report_info("Incorrect ordering wrt polarization for child %d", i);
+				correct_ordering = false;
+			}
+			if (prev_cpu->pp > child[i].pp)
+				continue;
+			if (!prev_cpu->d && child[i].d) {
+				report_info("Incorrect ordering wrt dedication for child %d", i);
+				correct_ordering = false;
+			}
+			if (prev_cpu->d && !child[i].d)
+				continue;
+			if (prev_cpu->origin > child[i].origin) {
+				report_info("Incorrect ordering wrt origin for child %d", i);
+				correct_ordering = false;
+			}
+		}
+	}
+	report(correct_ordering, "children correctly ordered");
+	report(cpus <= expected_topo_lvl[0], "%d children <= max of %d",
+	       cpus, expected_topo_lvl[0]);
+	*cpus_in_masks += cpus;
 
-	tc = info->tle;
-	end = (void *)info + info->length;
+	return (union topology_container *)&child[i];
+}
 
-	while (tc < end)
-		tc = check_tle(tc);
+static union topology_container *check_container(struct sysinfo_15_1_x *info,
+						 union topology_container *cont,
+						 union topology_entry *child,
+						 unsigned int *cpus_in_masks);
 
-	report(cpus_in_masks == number_of_cpus, "CPUs in mask %d",
-	       cpus_in_masks);
+static union topology_container *check_child_containers(struct sysinfo_15_1_x *info,
+							union topology_container *cont,
+							union topology_container *child,
+							unsigned int *cpus_in_masks)
+{
+	void *last = ((void *)info) + info->length;
+	union topology_container *entry;
+	int i;
 
-	report_prefix_pop();
+	for (i = 0, entry = child; (void *)entry < last && entry->nl == cont->nl - 1; i++) {
+		entry = check_container(info, entry, (union topology_entry *)(entry + 1),
+					cpus_in_masks);
+	}
+	if (max_nested_lvl == info->mnest)
+		report(i <= expected_topo_lvl[cont->nl - 1], "%d children <= max of %d",
+		       i, expected_topo_lvl[cont->nl - 1]);
+
+	return entry;
 }
 
-/**
- * stsi_get_sysib:
- * @info: pointer to the STSI info structure
- * @sel2: the selector giving the topology level to check
- *
- * Fill the sysinfo_15_1_x info structure and check the
- * SYSIB header.
- *
- * Returns instruction validity.
- */
-static int stsi_get_sysib(struct sysinfo_15_1_x *info, int sel2)
+static union topology_container *check_container(struct sysinfo_15_1_x *info,
+						 union topology_container *cont,
+						 union topology_entry *child,
+						 unsigned int *cpus_in_masks)
 {
-	int ret;
+	union topology_container *entry;
 
-	report_prefix_pushf("SYSIB");
+	report_prefix_pushf("%d", cont->id);
 
-	ret = stsi(info, 15, 1, sel2);
+	report(cont->nl - 1 == child->nl, "Level %d one above child level %d",
+	       cont->nl, child->nl);
+	report(!(cont->raw & CONTAINER_TLE_RES_BITS), "reserved bits %016lx",
+	       cont->raw & CONTAINER_TLE_RES_BITS);
 
-	if (max_nested_lvl >= sel2) {
-		report(!ret, "Valid instruction");
-	} else {
-		report(ret, "Invalid instruction");
-	}
+	if (cont->nl > 1)
+		entry = check_child_containers(info, cont, &child->container, cpus_in_masks);
+	else
+		entry = check_child_cpus(info, cont, &child->cpu, cpus_in_masks);
 
 	report_prefix_pop();
+	return entry;
+}
 
-	return ret;
+static void check_topology_list(struct sysinfo_15_1_x *info, int sel2)
+{
+	union topology_container dummy = { .nl = sel2, .id = 0 };
+	unsigned int cpus_in_masks = 0;
+
+	report_prefix_push("TLE");
+
+	check_container(info, &dummy, info->tle, &cpus_in_masks);
+	report(cpus_in_masks == number_of_cpus,
+	       "Number of CPUs %d equals  %d CPUs in masks",
+	       number_of_cpus, cpus_in_masks);
+
+	report_prefix_pop();
 }
 
 /**
@@ -372,7 +426,7 @@ static void check_sysinfo_15_1_x(struct sysinfo_15_1_x *info, int sel2)
 	}
 
 	stsi_check_header(info, sel2);
-	stsi_check_tle_coherency(info);
+	check_topology_list(info, sel2);
 
 vertical:
 	report_prefix_pop();
@@ -385,7 +439,7 @@ vertical:
 	}
 
 	stsi_check_header(info, sel2);
-	stsi_check_tle_coherency(info);
+	check_topology_list(info, sel2);
 	report_prefix_pop();
 
 end:
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 17/26] scripts: Implement multiline strings for extra_params
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (15 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 16/26] s390x: topology: Rewrite topology list test Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 18/26] s390x: topology: Add complex topology test Nico Boehr
                   ` (9 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones
  Cc: kvm, frankja, imbrenda, Nina Schoetterl-Glausch

From: Nina Schoetterl-Glausch <nsg@linux.ibm.com>

Implement a rudimentary form only.
extra_params can get long when passing a lot of arguments to qemu.
Multiline strings help with readability of the .cfg file.
Multiline strings begin and end with """, which must occur on separate
lines.

For example:
extra_params = """-cpu max,ctop=on -smp cpus=1,cores=16,maxcpus=128 \
-append '-drawers 2 -books 2 -sockets 2 -cores 16' \
-device max-s390x-cpu,core-id=31,drawer-id=0,book-id=0,socket-id=0"""

The command string built with extra_params is eval'ed by the runtime
script, so the newlines need to be escaped with \.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Link: https://lore.kernel.org/r/20231030160349.458764-10-nsg@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 scripts/common.bash  | 16 ++++++++++++++++
 scripts/runtime.bash |  4 ++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/scripts/common.bash b/scripts/common.bash
index 7b983f7..b9413d6 100644
--- a/scripts/common.bash
+++ b/scripts/common.bash
@@ -36,6 +36,22 @@ function for_each_unittest()
 			kernel=$TEST_DIR/${BASH_REMATCH[1]}
 		elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
 			smp=${BASH_REMATCH[1]}
+		elif [[ $line =~ ^extra_params\ *=\ *'"""'(.*)$ ]]; then
+			opts=${BASH_REMATCH[1]}$'\n'
+			while read -r -u $fd; do
+				#escape backslash newline, but not double backslash
+				if [[ $opts =~ [^\\]*(\\*)$'\n'$ ]]; then
+					if (( ${#BASH_REMATCH[1]} % 2 == 1 )); then
+						opts=${opts%\\$'\n'}
+					fi
+				fi
+				if [[ "$REPLY" =~ ^(.*)'"""'[:blank:]*$ ]]; then
+					opts+=${BASH_REMATCH[1]}
+					break
+				else
+					opts+=$REPLY$'\n'
+				fi
+			done
 		elif [[ $line =~ ^extra_params\ *=\ *(.*)$ ]]; then
 			opts=${BASH_REMATCH[1]}
 		elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
diff --git a/scripts/runtime.bash b/scripts/runtime.bash
index ada8ffd..fc156f2 100644
--- a/scripts/runtime.bash
+++ b/scripts/runtime.bash
@@ -15,7 +15,7 @@ extract_summary()
 # We assume that QEMU is going to work if it tried to load the kernel
 premature_failure()
 {
-    local log="$(eval $(get_cmdline _NO_FILE_4Uhere_) 2>&1)"
+    local log="$(eval "$(get_cmdline _NO_FILE_4Uhere_)" 2>&1)"
 
     echo "$log" | grep "_NO_FILE_4Uhere_" |
         grep -q -e "could not \(load\|open\) kernel" -e "error loading" &&
@@ -168,7 +168,7 @@ function run()
     # extra_params in the config file may contain backticks that need to be
     # expanded, so use eval to start qemu.  Use "> >(foo)" instead of a pipe to
     # preserve the exit status.
-    summary=$(eval $cmdline 2> >(RUNTIME_log_stderr $testname) \
+    summary=$(eval "$cmdline" 2> >(RUNTIME_log_stderr $testname) \
                              > >(tee >(RUNTIME_log_stdout $testname $kernel) | extract_summary))
     ret=$?
     [ "$KUT_STANDALONE" != "yes" ] && echo > >(RUNTIME_log_stdout $testname $kernel)
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 18/26] s390x: topology: Add complex topology test
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (16 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 17/26] scripts: Implement multiline strings for extra_params Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 19/26] lib: s390x: introduce bitfield for PSW mask Nico Boehr
                   ` (8 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones
  Cc: kvm, frankja, imbrenda, Nina Schoetterl-Glausch

From: Nina Schoetterl-Glausch <nsg@linux.ibm.com>

Run the topology test case with a complex topology configuration.
Randomly generated with:
python -c 'import random
ds=bs=ss=2
cs=16
cids=list(range(1,ds*bs*ss*cs))
random.shuffle(cids)
i = 0
for d in range(ds):
    for b in range(bs):
        for s in range(ss):
            for c in range(cs):
                if (d,b,s,c) != (0,0,0,0):
                    ded=["false","true"][random.randrange(0,2)]
                    ent="high" if ded == "true" else ["low", "medium", "high"][random.randrange(0,3)]
                    print(f"-device max-s390x-cpu,core-id={cids[i]},drawer-id={d},book-id={b},socket-id={s},entitlement={ent},dedicated={ded}")
                    i+=1'

Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Link: https://lore.kernel.org/r/20231030160349.458764-11-nsg@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 s390x/unittests.cfg | 133 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 133 insertions(+)

diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
index 68e119e..b08b0fb 100644
--- a/s390x/unittests.cfg
+++ b/s390x/unittests.cfg
@@ -247,3 +247,136 @@ file = topology.elf
 [topology-2]
 file = topology.elf
 extra_params = -cpu max,ctop=on -smp sockets=31,cores=8,maxcpus=248  -append '-sockets 31 -cores 8'
+
+[topology-3]
+file = topology.elf
+extra_params = """-cpu max,ctop=on -smp cpus=1,drawers=2,books=2,sockets=2,cores=16,maxcpus=128 \
+-append '-drawers 2 -books 2 -sockets 2 -cores 16' \
+-device max-s390x-cpu,core-id=31,drawer-id=0,book-id=0,socket-id=0,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=11,drawer-id=0,book-id=0,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=95,drawer-id=0,book-id=0,socket-id=0,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=73,drawer-id=0,book-id=0,socket-id=0,entitlement=high,dedicated=false \
+-device max-s390x-cpu,core-id=78,drawer-id=0,book-id=0,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=13,drawer-id=0,book-id=0,socket-id=0,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=40,drawer-id=0,book-id=0,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=101,drawer-id=0,book-id=0,socket-id=0,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=29,drawer-id=0,book-id=0,socket-id=0,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=56,drawer-id=0,book-id=0,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=92,drawer-id=0,book-id=0,socket-id=0,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=30,drawer-id=0,book-id=0,socket-id=0,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=118,drawer-id=0,book-id=0,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=71,drawer-id=0,book-id=0,socket-id=0,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=93,drawer-id=0,book-id=0,socket-id=0,entitlement=high,dedicated=false \
+-device max-s390x-cpu,core-id=16,drawer-id=0,book-id=0,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=5,drawer-id=0,book-id=0,socket-id=1,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=42,drawer-id=0,book-id=0,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=98,drawer-id=0,book-id=0,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=44,drawer-id=0,book-id=0,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=23,drawer-id=0,book-id=0,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=65,drawer-id=0,book-id=0,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=102,drawer-id=0,book-id=0,socket-id=1,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=57,drawer-id=0,book-id=0,socket-id=1,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=125,drawer-id=0,book-id=0,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=127,drawer-id=0,book-id=0,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=82,drawer-id=0,book-id=0,socket-id=1,entitlement=high,dedicated=false \
+-device max-s390x-cpu,core-id=14,drawer-id=0,book-id=0,socket-id=1,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=91,drawer-id=0,book-id=0,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=12,drawer-id=0,book-id=0,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=8,drawer-id=0,book-id=0,socket-id=1,entitlement=high,dedicated=false \
+-device max-s390x-cpu,core-id=112,drawer-id=0,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=109,drawer-id=0,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=19,drawer-id=0,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=96,drawer-id=0,book-id=1,socket-id=0,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=67,drawer-id=0,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=80,drawer-id=0,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=108,drawer-id=0,book-id=1,socket-id=0,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=34,drawer-id=0,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=18,drawer-id=0,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=39,drawer-id=0,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=53,drawer-id=0,book-id=1,socket-id=0,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=46,drawer-id=0,book-id=1,socket-id=0,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=3,drawer-id=0,book-id=1,socket-id=0,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=76,drawer-id=0,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=15,drawer-id=0,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=7,drawer-id=0,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=81,drawer-id=0,book-id=1,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=1,drawer-id=0,book-id=1,socket-id=1,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=113,drawer-id=0,book-id=1,socket-id=1,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=38,drawer-id=0,book-id=1,socket-id=1,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=90,drawer-id=0,book-id=1,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=117,drawer-id=0,book-id=1,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=62,drawer-id=0,book-id=1,socket-id=1,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=85,drawer-id=0,book-id=1,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=49,drawer-id=0,book-id=1,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=24,drawer-id=0,book-id=1,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=107,drawer-id=0,book-id=1,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=103,drawer-id=0,book-id=1,socket-id=1,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=33,drawer-id=0,book-id=1,socket-id=1,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=51,drawer-id=0,book-id=1,socket-id=1,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=21,drawer-id=0,book-id=1,socket-id=1,entitlement=high,dedicated=false \
+-device max-s390x-cpu,core-id=72,drawer-id=0,book-id=1,socket-id=1,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=63,drawer-id=1,book-id=0,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=105,drawer-id=1,book-id=0,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=74,drawer-id=1,book-id=0,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=50,drawer-id=1,book-id=0,socket-id=0,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=60,drawer-id=1,book-id=0,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=22,drawer-id=1,book-id=0,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=43,drawer-id=1,book-id=0,socket-id=0,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=48,drawer-id=1,book-id=0,socket-id=0,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=35,drawer-id=1,book-id=0,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=58,drawer-id=1,book-id=0,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=106,drawer-id=1,book-id=0,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=123,drawer-id=1,book-id=0,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=122,drawer-id=1,book-id=0,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=9,drawer-id=1,book-id=0,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=10,drawer-id=1,book-id=0,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=25,drawer-id=1,book-id=0,socket-id=0,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=116,drawer-id=1,book-id=0,socket-id=1,entitlement=high,dedicated=false \
+-device max-s390x-cpu,core-id=26,drawer-id=1,book-id=0,socket-id=1,entitlement=high,dedicated=false \
+-device max-s390x-cpu,core-id=17,drawer-id=1,book-id=0,socket-id=1,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=20,drawer-id=1,book-id=0,socket-id=1,entitlement=high,dedicated=false \
+-device max-s390x-cpu,core-id=59,drawer-id=1,book-id=0,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=54,drawer-id=1,book-id=0,socket-id=1,entitlement=high,dedicated=false \
+-device max-s390x-cpu,core-id=70,drawer-id=1,book-id=0,socket-id=1,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=88,drawer-id=1,book-id=0,socket-id=1,entitlement=high,dedicated=false \
+-device max-s390x-cpu,core-id=6,drawer-id=1,book-id=0,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=52,drawer-id=1,book-id=0,socket-id=1,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=55,drawer-id=1,book-id=0,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=124,drawer-id=1,book-id=0,socket-id=1,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=61,drawer-id=1,book-id=0,socket-id=1,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=84,drawer-id=1,book-id=0,socket-id=1,entitlement=high,dedicated=false \
+-device max-s390x-cpu,core-id=68,drawer-id=1,book-id=0,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=86,drawer-id=1,book-id=0,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=4,drawer-id=1,book-id=1,socket-id=0,entitlement=high,dedicated=false \
+-device max-s390x-cpu,core-id=75,drawer-id=1,book-id=1,socket-id=0,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=115,drawer-id=1,book-id=1,socket-id=0,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=28,drawer-id=1,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=120,drawer-id=1,book-id=1,socket-id=0,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=41,drawer-id=1,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=87,drawer-id=1,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=119,drawer-id=1,book-id=1,socket-id=0,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=114,drawer-id=1,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=104,drawer-id=1,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=27,drawer-id=1,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=121,drawer-id=1,book-id=1,socket-id=0,entitlement=high,dedicated=false \
+-device max-s390x-cpu,core-id=126,drawer-id=1,book-id=1,socket-id=0,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=37,drawer-id=1,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=32,drawer-id=1,book-id=1,socket-id=0,entitlement=high,dedicated=false \
+-device max-s390x-cpu,core-id=94,drawer-id=1,book-id=1,socket-id=0,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=110,drawer-id=1,book-id=1,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=77,drawer-id=1,book-id=1,socket-id=1,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=36,drawer-id=1,book-id=1,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=66,drawer-id=1,book-id=1,socket-id=1,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=83,drawer-id=1,book-id=1,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=47,drawer-id=1,book-id=1,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=99,drawer-id=1,book-id=1,socket-id=1,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=79,drawer-id=1,book-id=1,socket-id=1,entitlement=low,dedicated=false \
+-device max-s390x-cpu,core-id=100,drawer-id=1,book-id=1,socket-id=1,entitlement=medium,dedicated=false \
+-device max-s390x-cpu,core-id=89,drawer-id=1,book-id=1,socket-id=1,entitlement=high,dedicated=false \
+-device max-s390x-cpu,core-id=2,drawer-id=1,book-id=1,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=45,drawer-id=1,book-id=1,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=69,drawer-id=1,book-id=1,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=64,drawer-id=1,book-id=1,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=97,drawer-id=1,book-id=1,socket-id=1,entitlement=high,dedicated=true \
+-device max-s390x-cpu,core-id=111,drawer-id=1,book-id=1,socket-id=1,entitlement=medium,dedicated=false \
+"""
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 19/26] lib: s390x: introduce bitfield for PSW mask
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (17 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 18/26] s390x: topology: Add complex topology test Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 20/26] s390x: add function to set DAT mode for all interrupts Nico Boehr
                   ` (7 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones; +Cc: kvm, frankja, imbrenda

Changing the PSW mask is currently little clumsy, since there is only the
PSW_MASK_* defines. This makes it hard to change e.g. only the address
space in the current PSW without a lot of bit fiddling.

Introduce a bitfield for the PSW mask. This makes this kind of
modifications much simpler and easier to read.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Link: https://lore.kernel.org/r/20231106163738.1116942-2-nrb@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 lib/s390x/asm/arch_def.h | 25 ++++++++++++++++++++++++-
 s390x/selftest.c         | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h
index bb26e00..f629b6d 100644
--- a/lib/s390x/asm/arch_def.h
+++ b/lib/s390x/asm/arch_def.h
@@ -37,9 +37,32 @@ struct stack_frame_int {
 };
 
 struct psw {
-	uint64_t	mask;
+	union {
+		uint64_t	mask;
+		struct {
+			uint64_t reserved00:1;
+			uint64_t per:1;
+			uint64_t reserved02:3;
+			uint64_t dat:1;
+			uint64_t io:1;
+			uint64_t ext:1;
+			uint64_t key:4;
+			uint64_t reserved12:1;
+			uint64_t mchk:1;
+			uint64_t wait:1;
+			uint64_t pstate:1;
+			uint64_t as:2;
+			uint64_t cc:2;
+			uint64_t prg_mask:4;
+			uint64_t reserved24:7;
+			uint64_t ea:1;
+			uint64_t ba:1;
+			uint64_t reserved33:31;
+		};
+	};
 	uint64_t	addr;
 };
+_Static_assert(sizeof(struct psw) == 16, "PSW size");
 
 #define PSW(m, a) ((struct psw){ .mask = (m), .addr = (uint64_t)(a) })
 
diff --git a/s390x/selftest.c b/s390x/selftest.c
index 13fd36b..92ed4e5 100644
--- a/s390x/selftest.c
+++ b/s390x/selftest.c
@@ -74,6 +74,39 @@ static void test_malloc(void)
 	report_prefix_pop();
 }
 
+static void test_psw_mask(void)
+{
+	uint64_t expected_key = 0xf;
+	struct psw test_psw = PSW(0, 0);
+
+	report_prefix_push("PSW mask");
+	test_psw.mask = PSW_MASK_DAT;
+	report(test_psw.dat, "DAT matches expected=0x%016lx actual=0x%016lx", PSW_MASK_DAT, test_psw.mask);
+
+	test_psw.mask = PSW_MASK_IO;
+	report(test_psw.io, "IO matches expected=0x%016lx actual=0x%016lx", PSW_MASK_IO, test_psw.mask);
+
+	test_psw.mask = PSW_MASK_EXT;
+	report(test_psw.ext, "EXT matches expected=0x%016lx actual=0x%016lx", PSW_MASK_EXT, test_psw.mask);
+
+	test_psw.mask = expected_key << (63 - 11);
+	report(test_psw.key == expected_key, "PSW Key matches expected=0x%lx actual=0x%x", expected_key, test_psw.key);
+
+	test_psw.mask = 1UL << (63 - 13);
+	report(test_psw.mchk, "MCHK matches");
+
+	test_psw.mask = PSW_MASK_WAIT;
+	report(test_psw.wait, "Wait matches expected=0x%016lx actual=0x%016lx", PSW_MASK_WAIT, test_psw.mask);
+
+	test_psw.mask = PSW_MASK_PSTATE;
+	report(test_psw.pstate, "Pstate matches expected=0x%016lx actual=0x%016lx", PSW_MASK_PSTATE, test_psw.mask);
+
+	test_psw.mask = PSW_MASK_64;
+	report(test_psw.ea && test_psw.ba, "BA/EA matches expected=0x%016lx actual=0x%016lx", PSW_MASK_64, test_psw.mask);
+
+	report_prefix_pop();
+}
+
 int main(int argc, char**argv)
 {
 	report_prefix_push("selftest");
@@ -89,6 +122,7 @@ int main(int argc, char**argv)
 	test_fp();
 	test_pgm_int();
 	test_malloc();
+	test_psw_mask();
 
 	return report_summary();
 }
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 20/26] s390x: add function to set DAT mode for all interrupts
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (18 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 19/26] lib: s390x: introduce bitfield for PSW mask Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 21/26] s390x: sie: switch to home space mode before entering SIE Nico Boehr
                   ` (6 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones; +Cc: kvm, frankja, imbrenda

When toggling DAT or switch address space modes, it is likely that
interrupts should be handled in the same DAT or address space mode.

Add a function which toggles DAT and address space mode for all
interruptions, except restart interrupts.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Link: https://lore.kernel.org/r/20231106163738.1116942-3-nrb@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 lib/s390x/asm/arch_def.h  | 10 ++++++----
 lib/s390x/asm/interrupt.h |  2 ++
 lib/s390x/interrupt.c     | 35 +++++++++++++++++++++++++++++++++++
 lib/s390x/mmu.c           |  5 +++--
 4 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h
index f629b6d..5beaf15 100644
--- a/lib/s390x/asm/arch_def.h
+++ b/lib/s390x/asm/arch_def.h
@@ -84,10 +84,12 @@ struct cpu {
 	bool in_interrupt_handler;
 };
 
-#define AS_PRIM				0
-#define AS_ACCR				1
-#define AS_SECN				2
-#define AS_HOME				3
+enum address_space {
+	AS_PRIM = 0,
+	AS_ACCR = 1,
+	AS_SECN = 2,
+	AS_HOME = 3
+};
 
 #define PSW_MASK_DAT			0x0400000000000000UL
 #define PSW_MASK_IO			0x0200000000000000UL
diff --git a/lib/s390x/asm/interrupt.h b/lib/s390x/asm/interrupt.h
index 35c1145..d01f8a8 100644
--- a/lib/s390x/asm/interrupt.h
+++ b/lib/s390x/asm/interrupt.h
@@ -83,6 +83,8 @@ void expect_ext_int(void);
 uint16_t clear_pgm_int(void);
 void check_pgm_int_code(uint16_t code);
 
+void irq_set_dat_mode(bool use_dat, enum address_space as);
+
 /* Activate low-address protection */
 static inline void low_prot_enable(void)
 {
diff --git a/lib/s390x/interrupt.c b/lib/s390x/interrupt.c
index 3f993a3..e990c18 100644
--- a/lib/s390x/interrupt.c
+++ b/lib/s390x/interrupt.c
@@ -9,6 +9,7 @@
  */
 #include <libcflat.h>
 #include <asm/barrier.h>
+#include <asm/mem.h>
 #include <asm/asm-offsets.h>
 #include <sclp.h>
 #include <interrupt.h>
@@ -104,6 +105,40 @@ void register_ext_cleanup_func(void (*f)(struct stack_frame_int *))
 	THIS_CPU->ext_cleanup_func = f;
 }
 
+/**
+ * irq_set_dat_mode - Set the DAT mode of all interrupt handlers, except for
+ * restart.
+ * @use_dat: specifies whether to use DAT or not
+ * @as: specifies the address space mode to use. Not set if use_dat is false.
+ *
+ * This will update the DAT mode and address space mode of all interrupt new
+ * PSWs.
+ *
+ * Since enabling DAT needs initialized CRs and the restart new PSW is often used
+ * to initialize CRs, the restart new PSW is never touched to avoid the chicken
+ * and egg situation.
+ */
+void irq_set_dat_mode(bool use_dat, enum address_space as)
+{
+	struct psw* irq_psws[] = {
+		OPAQUE_PTR(GEN_LC_EXT_NEW_PSW),
+		OPAQUE_PTR(GEN_LC_SVC_NEW_PSW),
+		OPAQUE_PTR(GEN_LC_PGM_NEW_PSW),
+		OPAQUE_PTR(GEN_LC_MCCK_NEW_PSW),
+		OPAQUE_PTR(GEN_LC_IO_NEW_PSW),
+	};
+	struct psw *psw;
+
+	assert(as == AS_PRIM || as == AS_ACCR || as == AS_SECN || as == AS_HOME);
+
+	for (size_t i = 0; i < ARRAY_SIZE(irq_psws); i++) {
+		psw = irq_psws[i];
+		psw->dat = use_dat;
+		if (use_dat)
+			psw->as = as;
+	}
+}
+
 static void fixup_pgm_int(struct stack_frame_int *stack)
 {
 	/* If we have an error on SIE we directly move to sie_exit */
diff --git a/lib/s390x/mmu.c b/lib/s390x/mmu.c
index b474d70..9a179d6 100644
--- a/lib/s390x/mmu.c
+++ b/lib/s390x/mmu.c
@@ -12,6 +12,7 @@
 #include <asm/pgtable.h>
 #include <asm/arch_def.h>
 #include <asm/barrier.h>
+#include <asm/interrupt.h>
 #include <vmalloc.h>
 #include "mmu.h"
 
@@ -41,8 +42,8 @@ static void mmu_enable(pgd_t *pgtable)
 	/* enable dat (primary == 0 set as default) */
 	enable_dat();
 
-	/* we can now also use DAT unconditionally in our PGM handler */
-	lowcore.pgm_new_psw.mask |= PSW_MASK_DAT;
+	/* we can now also use DAT in all interrupt handlers */
+	irq_set_dat_mode(true, AS_PRIM);
 }
 
 /*
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 21/26] s390x: sie: switch to home space mode before entering SIE
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (19 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 20/26] s390x: add function to set DAT mode for all interrupts Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 22/26] s390x: lib: don't forward PSW when handling exception in SIE Nico Boehr
                   ` (5 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones; +Cc: kvm, frankja, imbrenda

This is to prepare for running guests without MSO/MSL, which is
currently not possible.

We already have code in sie64a to setup a guest primary ASCE before
entering SIE, so we can in theory switch to the page tables which
translate gpa to hpa.

But the host is running in primary space mode already, so changing the
primary ASCE before entering SIE will also affect the host's code and
data.

To make this switch useful, the host should run in a different address
space mode. Hence, set up and change to home address space mode before
installing the guest ASCE.

The home space ASCE is just copied over from the primary space ASCE, so
no functional change is intended, also for tests that want to use
MSO/MSL. If a test intends to use a different primary space ASCE, it can
now just set the guest.asce in the save_area.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Link: https://lore.kernel.org/r/20231106163738.1116942-4-nrb@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 lib/s390x/asm/arch_def.h |  1 +
 lib/s390x/sie.c          | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h
index 5beaf15..745a338 100644
--- a/lib/s390x/asm/arch_def.h
+++ b/lib/s390x/asm/arch_def.h
@@ -92,6 +92,7 @@ enum address_space {
 };
 
 #define PSW_MASK_DAT			0x0400000000000000UL
+#define PSW_MASK_HOME			0x0000C00000000000UL
 #define PSW_MASK_IO			0x0200000000000000UL
 #define PSW_MASK_EXT			0x0100000000000000UL
 #define PSW_MASK_KEY			0x00F0000000000000UL
diff --git a/lib/s390x/sie.c b/lib/s390x/sie.c
index 97a093b..b8ee43e 100644
--- a/lib/s390x/sie.c
+++ b/lib/s390x/sie.c
@@ -54,6 +54,8 @@ void sie_handle_validity(struct vm *vm)
 
 void sie(struct vm *vm)
 {
+	uint64_t old_cr13;
+
 	if (vm->sblk->sdf == 2)
 		memcpy(vm->sblk->pv_grregs, vm->save_area.guest.grs,
 		       sizeof(vm->save_area.guest.grs));
@@ -61,6 +63,24 @@ void sie(struct vm *vm)
 	/* Reset icptcode so we don't trip over it below */
 	vm->sblk->icptcode = 0;
 
+	/*
+	 * Set up home address space to match primary space. Instead of running
+	 * in home space all the time, we switch every time in sie() because:
+	 * - tests that depend on running in primary space mode don't need to be
+	 *   touched
+	 * - it avoids regressions in tests
+	 * - switching every time makes it easier to extend this in the future,
+	 *   for example to allow tests to run in whatever space they want
+	 */
+	old_cr13 = stctg(13);
+	lctlg(13, stctg(1));
+
+	/* switch to home space so guest tables can be different from host */
+	psw_mask_set_bits(PSW_MASK_HOME);
+
+	/* also handle all interruptions in home space while in SIE */
+	irq_set_dat_mode(true, AS_HOME);
+
 	while (vm->sblk->icptcode == 0) {
 		sie64a(vm->sblk, &vm->save_area);
 		sie_handle_validity(vm);
@@ -68,6 +88,12 @@ void sie(struct vm *vm)
 	vm->save_area.guest.grs[14] = vm->sblk->gg14;
 	vm->save_area.guest.grs[15] = vm->sblk->gg15;
 
+	irq_set_dat_mode(true, AS_PRIM);
+	psw_mask_clear_bits(PSW_MASK_HOME);
+
+	/* restore the old CR 13 */
+	lctlg(13, old_cr13);
+
 	if (vm->sblk->sdf == 2)
 		memcpy(vm->save_area.guest.grs, vm->sblk->pv_grregs,
 		       sizeof(vm->save_area.guest.grs));
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 22/26] s390x: lib: don't forward PSW when handling exception in SIE
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (20 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 21/26] s390x: sie: switch to home space mode before entering SIE Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 23/26] s390x: lib: sie: don't reenter SIE on pgm int Nico Boehr
                   ` (4 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones; +Cc: kvm, frankja, imbrenda

When we're handling a pgm int in SIE, we want to return to the SIE
cleanup after handling the exception. That's why we set pgm_old_psw to
the sie_exit label in fixup_pgm_int.

On nullifing pgm ints, fixup_pgm_int will also forward the old PSW such
that we don't cause an pgm int again.

However, when we want to return to the sie_exit label, this is not
needed (since we've manually set pgm_old_psw). Instead, forwarding the
PSW might cause us to skip an instruction or end up in the middle of an
instruction.

So, let's just skip the rest of the fixup in case we're inside SIE.

Note that we're intentionally not fixing up the PSW in the guest; that's
best left to the test at hand by registering their own psw fixup.

Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Link: https://lore.kernel.org/r/20231106163738.1116942-5-nrb@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 lib/s390x/interrupt.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/s390x/interrupt.c b/lib/s390x/interrupt.c
index e990c18..f7843a8 100644
--- a/lib/s390x/interrupt.c
+++ b/lib/s390x/interrupt.c
@@ -145,6 +145,7 @@ static void fixup_pgm_int(struct stack_frame_int *stack)
 	if (lowcore.pgm_old_psw.addr >= (uint64_t)&sie_entry &&
 	    lowcore.pgm_old_psw.addr <= (uint64_t)&sie_exit) {
 		lowcore.pgm_old_psw.addr = (uint64_t)&sie_exit;
+		return;
 	}
 
 	switch (lowcore.pgm_int_code) {
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 23/26] s390x: lib: sie: don't reenter SIE on pgm int
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (21 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 22/26] s390x: lib: don't forward PSW when handling exception in SIE Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 24/26] s390x: add test source dir to include paths Nico Boehr
                   ` (3 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones; +Cc: kvm, frankja, imbrenda

At the moment, when a PGM int occurs while in SIE, we will just reenter
SIE after the interrupt handler was called.

This is because sie() has a loop which checks icptcode and re-enters SIE
if it is zero.

However, this behaviour is quite undesirable for SIE tests, since it
doesn't give the host the chance to assert on the PGM int. Instead, we
will just re-enter SIE, on nullifing conditions even causing the
exception again.

In sie(), check whether a pgm int code is set in lowcore. If it has,
exit the loop so the test can react to the interrupt. Add a new function
read_pgm_int_code() to obtain the interrupt code.

Note that this introduces a slight oddity with sie and pgm int in
certain cases: If a PGM int occurs between a expect_pgm_int() and sie(),
we will now never enter SIE until the pgm_int_code is cleared by e.g.
clear_pgm_int().

Also add missing include of facility.h to mem.h.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Link: https://lore.kernel.org/r/20231106163738.1116942-6-nrb@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 lib/s390x/asm/interrupt.h | 14 ++++++++++++++
 lib/s390x/asm/mem.h       |  1 +
 lib/s390x/sie.c           |  7 ++++++-
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/lib/s390x/asm/interrupt.h b/lib/s390x/asm/interrupt.h
index d01f8a8..39b43b6 100644
--- a/lib/s390x/asm/interrupt.h
+++ b/lib/s390x/asm/interrupt.h
@@ -97,4 +97,18 @@ static inline void low_prot_disable(void)
 	ctl_clear_bit(0, CTL0_LOW_ADDR_PROT);
 }
 
+/**
+ * read_pgm_int_code - Get the program interruption code of the last pgm int
+ * on the current CPU.
+ *
+ * This is similar to clear_pgm_int(), except that it doesn't clear the
+ * interruption information from lowcore.
+ *
+ * Return: 0 when none occurred.
+ */
+static inline uint16_t read_pgm_int_code(void)
+{
+	return lowcore.pgm_int_code;
+}
+
 #endif
diff --git a/lib/s390x/asm/mem.h b/lib/s390x/asm/mem.h
index 64ef59b..94d58c3 100644
--- a/lib/s390x/asm/mem.h
+++ b/lib/s390x/asm/mem.h
@@ -8,6 +8,7 @@
 #ifndef _ASMS390X_MEM_H_
 #define _ASMS390X_MEM_H_
 #include <asm/arch_def.h>
+#include <asm/facility.h>
 
 /* create pointer while avoiding compiler warnings */
 #define OPAQUE_PTR(x) ((void *)(((uint64_t)&lowcore) + (x)))
diff --git a/lib/s390x/sie.c b/lib/s390x/sie.c
index b8ee43e..28fbf14 100644
--- a/lib/s390x/sie.c
+++ b/lib/s390x/sie.c
@@ -13,6 +13,7 @@
 #include <libcflat.h>
 #include <sie.h>
 #include <asm/page.h>
+#include <asm/interrupt.h>
 #include <libcflat.h>
 #include <alloc_page.h>
 #include <vmalloc.h>
@@ -56,6 +57,9 @@ void sie(struct vm *vm)
 {
 	uint64_t old_cr13;
 
+	/* When a pgm int code is set, we'll never enter SIE below. */
+	assert(!read_pgm_int_code());
+
 	if (vm->sblk->sdf == 2)
 		memcpy(vm->sblk->pv_grregs, vm->save_area.guest.grs,
 		       sizeof(vm->save_area.guest.grs));
@@ -81,7 +85,8 @@ void sie(struct vm *vm)
 	/* also handle all interruptions in home space while in SIE */
 	irq_set_dat_mode(true, AS_HOME);
 
-	while (vm->sblk->icptcode == 0) {
+	/* leave SIE when we have an intercept or an interrupt so the test can react to it */
+	while (vm->sblk->icptcode == 0 && !read_pgm_int_code()) {
 		sie64a(vm->sblk, &vm->save_area);
 		sie_handle_validity(vm);
 	}
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 24/26] s390x: add test source dir to include paths
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (22 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 23/26] s390x: lib: sie: don't reenter SIE on pgm int Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 25/26] s390x: add a test for SIE without MSO/MSL Nico Boehr
                   ` (2 subsequent siblings)
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones; +Cc: kvm, frankja, imbrenda

Sometimes, it is useful to share some defines between a snippet and a
test. By adding the source directory to include paths, header files can
be placed in the snippet directory and included from the test (or vice
versa).

This is a prerequisite for future tests.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Link: https://lore.kernel.org/r/20231106163738.1116942-7-nrb@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 s390x/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/s390x/Makefile b/s390x/Makefile
index 6e96719..947a434 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -67,7 +67,7 @@ test_cases: $(tests)
 test_cases_binary: $(tests_binary)
 test_cases_pv: $(tests_pv_binary)
 
-INCLUDE_PATHS = $(SRCDIR)/lib $(SRCDIR)/lib/s390x
+INCLUDE_PATHS = $(SRCDIR)/lib $(SRCDIR)/lib/s390x $(SRCDIR)/s390x
 # Include generated header files (e.g. in case of out-of-source builds)
 INCLUDE_PATHS += lib
 CPPFLAGS = $(addprefix -I,$(INCLUDE_PATHS))
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 25/26] s390x: add a test for SIE without MSO/MSL
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (23 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 24/26] s390x: add test source dir to include paths Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 26/26] lib: s390x: interrupt: remove TEID_ASCE defines Nico Boehr
  2023-11-10 15:25 ` [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Thomas Huth
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones; +Cc: kvm, frankja, imbrenda

Since we now have the ability to run guests without MSO/MSL, add a test
to make sure this doesn't break.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Link: https://lore.kernel.org/r/20231106163738.1116942-8-nrb@linux.ibm.com
[ nrb: __pa -> virt_to_pte_phys to fix incompatiblity with 2g align ]
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 s390x/Makefile             |   2 +
 s390x/snippets/c/sie-dat.h |   2 +
 s390x/sie-dat.c            | 114 +++++++++++++++++++++++++++++++++++++
 s390x/snippets/c/sie-dat.c |  57 +++++++++++++++++++
 s390x/unittests.cfg        |   3 +
 5 files changed, 178 insertions(+)
 create mode 100644 s390x/snippets/c/sie-dat.h
 create mode 100644 s390x/sie-dat.c
 create mode 100644 s390x/snippets/c/sie-dat.c

diff --git a/s390x/Makefile b/s390x/Makefile
index 947a434..f79fd00 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -41,6 +41,7 @@ tests += $(TEST_DIR)/migration-sck.elf
 tests += $(TEST_DIR)/exittime.elf
 tests += $(TEST_DIR)/ex.elf
 tests += $(TEST_DIR)/topology.elf
+tests += $(TEST_DIR)/sie-dat.elf
 
 pv-tests += $(TEST_DIR)/pv-diags.elf
 pv-tests += $(TEST_DIR)/pv-icptcode.elf
@@ -123,6 +124,7 @@ snippet_lib = $(snippet_asmlib) lib/auxinfo.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)/sie-dat.elf: snippets = $(SNIPPET_DIR)/c/sie-dat.gbin
 $(TEST_DIR)/spec_ex-sie.elf: snippets = $(SNIPPET_DIR)/c/spec_ex.gbin
 
 $(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-yield.gbin
diff --git a/s390x/snippets/c/sie-dat.h b/s390x/snippets/c/sie-dat.h
new file mode 100644
index 0000000..ed3f99f
--- /dev/null
+++ b/s390x/snippets/c/sie-dat.h
@@ -0,0 +1,2 @@
+#define GUEST_TEST_PAGE_COUNT 10
+#define GUEST_TOTAL_PAGE_COUNT 256
diff --git a/s390x/sie-dat.c b/s390x/sie-dat.c
new file mode 100644
index 0000000..f025777
--- /dev/null
+++ b/s390x/sie-dat.c
@@ -0,0 +1,114 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Tests SIE with paging.
+ *
+ * Copyright 2023 IBM Corp.
+ *
+ * Authors:
+ *    Nico Boehr <nrb@linux.ibm.com>
+ */
+#include <libcflat.h>
+#include <vmalloc.h>
+#include <asm/pgtable.h>
+#include <mmu.h>
+#include <asm/page.h>
+#include <asm/interrupt.h>
+#include <alloc_page.h>
+#include <sclp.h>
+#include <sie.h>
+#include <snippet.h>
+#include "snippets/c/sie-dat.h"
+
+static struct vm vm;
+static pgd_t *guest_root;
+
+static void test_sie_dat(void)
+{
+	uint64_t test_page_gpa, test_page_hpa;
+	uint8_t *test_page_hva, expected_val;
+	bool contents_match;
+	uint8_t r1;
+
+	/* guest will tell us the guest physical address of the test buffer */
+	sie(&vm);
+	assert(vm.sblk->icptcode == ICPT_INST &&
+	       (vm.sblk->ipa & 0xff00) == 0x8300 && vm.sblk->ipb == 0x9c0000);
+
+	r1 = (vm.sblk->ipa & 0xf0) >> 4;
+	test_page_gpa = vm.save_area.guest.grs[r1];
+	test_page_hpa = virt_to_pte_phys(guest_root, (void*)test_page_gpa);
+	test_page_hva = __va(test_page_hpa);
+	report_info("test buffer gpa=0x%lx hva=%p", test_page_gpa, test_page_hva);
+
+	/* guest will now write to the test buffer and we verify the contents */
+	sie(&vm);
+	assert(vm.sblk->icptcode == ICPT_INST &&
+	       vm.sblk->ipa == 0x8300 && vm.sblk->ipb == 0x440000);
+
+	contents_match = true;
+	for (unsigned int i = 0; i < GUEST_TEST_PAGE_COUNT; i++) {
+		expected_val = 42 + i;
+		if (test_page_hva[i * PAGE_SIZE] != expected_val) {
+			report_fail("page %u mismatch actual_val=%x expected_val=%x",
+				    i, test_page_hva[i], expected_val);
+			contents_match = false;
+		}
+	}
+	report(contents_match, "test buffer contents match");
+
+	/* the guest will now write to an unmapped address and we check that this causes a segment translation exception */
+	report_prefix_push("guest write to unmapped");
+	expect_pgm_int();
+	sie(&vm);
+	check_pgm_int_code(PGM_INT_CODE_SEGMENT_TRANSLATION);
+	report((lowcore.trans_exc_id & PAGE_MASK) == (GUEST_TOTAL_PAGE_COUNT * PAGE_SIZE), "TEID address match");
+	report_prefix_pop();
+}
+
+static void setup_guest(void)
+{
+	extern const char SNIPPET_NAME_START(c, sie_dat)[];
+	extern const char SNIPPET_NAME_END(c, sie_dat)[];
+	uint64_t guest_max_addr;
+	pgd_t *root;
+
+	setup_vm();
+	root = (pgd_t *)(stctg(1) & PAGE_MASK);
+
+	snippet_setup_guest(&vm, false);
+
+	/* allocate a region-1 table */
+	guest_root = pgd_alloc_one();
+
+	/* map guest memory 1:1 */
+	guest_max_addr = GUEST_TOTAL_PAGE_COUNT * PAGE_SIZE;
+	for (uint64_t i = 0; i < guest_max_addr; i += PAGE_SIZE)
+		install_page(guest_root, virt_to_pte_phys(root, vm.guest_mem + i), (void *)i);
+
+	/* set up storage limit supression - leave mso and msl intact they are ignored anyways */
+	vm.sblk->cpuflags |= CPUSTAT_SM;
+
+	/* set up the guest asce */
+	vm.save_area.guest.asce = __pa(guest_root) | ASCE_DT_REGION1 | REGION_TABLE_LENGTH;
+
+	snippet_init(&vm, SNIPPET_NAME_START(c, sie_dat),
+		     SNIPPET_LEN(c, sie_dat), SNIPPET_UNPACK_OFF);
+}
+
+int main(void)
+{
+	report_prefix_push("sie-dat");
+	if (!sclp_facilities.has_sief2) {
+		report_skip("SIEF2 facility unavailable");
+		goto done;
+	}
+
+	setup_guest();
+	test_sie_dat();
+	sie_guest_destroy(&vm);
+
+done:
+	report_prefix_pop();
+	return report_summary();
+
+}
diff --git a/s390x/snippets/c/sie-dat.c b/s390x/snippets/c/sie-dat.c
new file mode 100644
index 0000000..ecfcb60
--- /dev/null
+++ b/s390x/snippets/c/sie-dat.c
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Snippet used by the sie-dat.c test to verify paging without MSO/MSL
+ *
+ * Copyright (c) 2023 IBM Corp
+ *
+ * Authors:
+ *  Nico Boehr <nrb@linux.ibm.com>
+ */
+#include <libcflat.h>
+#include <asm-generic/page.h>
+#include "sie-dat.h"
+
+static uint8_t test_pages[GUEST_TEST_PAGE_COUNT * PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
+
+static inline void force_exit(void)
+{
+	asm volatile("diag	0,0,0x44\n"
+		     :
+		     :
+		     : "memory"
+	);
+}
+
+static inline void force_exit_value(uint64_t val)
+{
+	asm volatile("diag	%[val],0,0x9c\n"
+		     :
+		     : [val] "d"(val)
+		     : "memory"
+	);
+}
+
+int main(void)
+{
+	uint8_t *invalid_ptr;
+
+	memset(test_pages, 0, sizeof(test_pages));
+	/* tell the host the page's physical address (we're running DAT off) */
+	force_exit_value((uint64_t)test_pages);
+
+	/* write some value to the page so the host can verify it */
+	for (size_t i = 0; i < GUEST_TEST_PAGE_COUNT; i++)
+		test_pages[i * PAGE_SIZE] = 42 + i;
+
+	/* indicate we've written all pages */
+	force_exit();
+
+	/* the first unmapped address */
+	invalid_ptr = (uint8_t *)(GUEST_TOTAL_PAGE_COUNT * PAGE_SIZE);
+	*invalid_ptr = 42;
+
+	/* indicate we've written the non-allowed page (should never get here) */
+	force_exit();
+
+	return 0;
+}
diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
index b08b0fb..f5024b6 100644
--- a/s390x/unittests.cfg
+++ b/s390x/unittests.cfg
@@ -380,3 +380,6 @@ extra_params = """-cpu max,ctop=on -smp cpus=1,drawers=2,books=2,sockets=2,cores
 -device max-s390x-cpu,core-id=97,drawer-id=1,book-id=1,socket-id=1,entitlement=high,dedicated=true \
 -device max-s390x-cpu,core-id=111,drawer-id=1,book-id=1,socket-id=1,entitlement=medium,dedicated=false \
 """
+
+[sie-dat]
+file = sie-dat.elf
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [kvm-unit-tests GIT PULL 26/26] lib: s390x: interrupt: remove TEID_ASCE defines
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (24 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 25/26] s390x: add a test for SIE without MSO/MSL Nico Boehr
@ 2023-11-10 13:52 ` Nico Boehr
  2023-11-10 15:25 ` [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Thomas Huth
  26 siblings, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-10 13:52 UTC (permalink / raw)
  To: thuth, pbonzini, andrew.jones; +Cc: kvm, frankja, imbrenda

These defines were - I can only guess - meant for the asce_id field.
Since print_decode_teid() used AS_PRIM and friends instead, I see little
benefit in keeping these around.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Link: https://lore.kernel.org/r/20231106163738.1116942-9-nrb@linux.ibm.com
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 lib/s390x/asm/interrupt.h | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/lib/s390x/asm/interrupt.h b/lib/s390x/asm/interrupt.h
index 39b43b6..61d156d 100644
--- a/lib/s390x/asm/interrupt.h
+++ b/lib/s390x/asm/interrupt.h
@@ -13,11 +13,6 @@
 #define EXT_IRQ_EXTERNAL_CALL	0x1202
 #define EXT_IRQ_SERVICE_SIG	0x2401
 
-#define TEID_ASCE_PRIMARY	0
-#define TEID_ASCE_AR		1
-#define TEID_ASCE_SECONDARY	2
-#define TEID_ASCE_HOME		3
-
 union teid {
 	unsigned long val;
 	union {
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* Re: [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes
  2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
                   ` (25 preceding siblings ...)
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 26/26] lib: s390x: interrupt: remove TEID_ASCE defines Nico Boehr
@ 2023-11-10 15:25 ` Thomas Huth
  26 siblings, 0 replies; 32+ messages in thread
From: Thomas Huth @ 2023-11-10 15:25 UTC (permalink / raw)
  To: Nico Boehr, pbonzini, andrew.jones; +Cc: kvm, frankja, imbrenda

On 10/11/2023 14.52, Nico Boehr wrote:
> Hi Paolo and/or Thomas,
> 
> lots of code for s390x has accumulated, so it's time for another PR :)
> 
> Please note that this PR includes a common code change from Nina (see below).
> 
> Changes in this pull request:
> 
> * Nina contributed multiline support for unittests.cfg in common code,
> * Janosch contributed enhancements for the sclp console,
> * Nina fixed some issues in the topology tests and improved coverage,
> * I've added support for running sie() tests without MSO/MSL,
> * kvm-unit-tests is now compatible with environments which require 2GB alignment
>    of guests in SIE,
> * several smaller improvements and bug fixes.
> 
> Thanks
> Nico
> 
> MERGE: https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/merge_requests/48

Thanks, merged now!

  Thomas



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [kvm-unit-tests GIT PULL 07/26] s390x: sie: ensure guests are aligned to 2GB
  2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 07/26] s390x: sie: ensure guests are aligned to 2GB Nico Boehr
@ 2023-11-22 11:06   ` Thomas Huth
  2023-11-23  9:24     ` Nina Schoetterl-Glausch
  0 siblings, 1 reply; 32+ messages in thread
From: Thomas Huth @ 2023-11-22 11:06 UTC (permalink / raw)
  To: Nico Boehr; +Cc: kvm, frankja, imbrenda, Jan Richter

On 10/11/2023 14.52, Nico Boehr wrote:
> Until now, kvm-unit-tests has aligned guests to 1 MB in the host virtual
> address space. Unfortunately, some s390x environments require guests to
> be 2GB aligned in the host virtual address space, preventing
> kvm-unit-tests which act as a hypervisor from running there.
> 
> We can't easily put guests at address 0, since we want to be able to run
> with MSO/MSL without having to maintain separate page tables for the
> guest physical memory. 2GB is also not a good choice, since the
> alloc_pages allocator will place its metadata there when the host has
> more than 2GB of memory. In addition, we also want a bit of space after
> the end of the host physical memory to be able to catch accesses beyond
> the end of physical memory.
> 
> The vmalloc allocator unfortunately allocates memory starting at the
> highest virtual address which is not suitable for guest memory either
> due to additional constraints of some environments.
> 
> The physical page allocator in memalign_pages() is also not a optimal
> choice, since every test running SIE would then require at least 4GB+1MB
> of physical memory.
> 
> This results in a few quite complex allocation requirements, hence add a
> new function sie_guest_alloc() which allocates memory for a guest and
> then establishes a properly aligned virtual space mapping.
> 
> Rework snippet test and sie tests to use the new sie_guest_alloc()
> function.
> 
> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> Link: https://lore.kernel.org/r/20231106170849.1184162-3-nrb@linux.ibm.com
> Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
> ---
>   lib/s390x/sie.h     |  2 ++
>   lib/s390x/snippet.h |  9 +++------
>   lib/s390x/sie.c     | 42 ++++++++++++++++++++++++++++++++++++++++++
>   s390x/sie.c         |  4 ++--
>   4 files changed, 49 insertions(+), 8 deletions(-)

  Hi Nico!

a colleague of mine (Jan) told me today that the current SIE-related tests 
of the kvm-unit-tests are failing when being run from a KVM guest (i.e. when 
we're testing a double-nested scenario). I've bisected the problem and ended 
up with this patch here.
Could you please check whether "./run_tests.sh sie mvpg-sie spec_ex-sie" 
still works for you from within a KVM guest?

  Thanks,
   Thomas


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [kvm-unit-tests GIT PULL 07/26] s390x: sie: ensure guests are aligned to 2GB
  2023-11-22 11:06   ` Thomas Huth
@ 2023-11-23  9:24     ` Nina Schoetterl-Glausch
  2023-11-23 13:03       ` Thomas Huth
  2023-11-23 14:16       ` Nico Boehr
  0 siblings, 2 replies; 32+ messages in thread
From: Nina Schoetterl-Glausch @ 2023-11-23  9:24 UTC (permalink / raw)
  To: Thomas Huth, Nico Boehr; +Cc: kvm, frankja, imbrenda, Jan Richter

On Wed, 2023-11-22 at 12:06 +0100, Thomas Huth wrote:
> On 10/11/2023 14.52, Nico Boehr wrote:
> > Until now, kvm-unit-tests has aligned guests to 1 MB in the host virtual
> > address space. Unfortunately, some s390x environments require guests to
> > be 2GB aligned in the host virtual address space, preventing
> > kvm-unit-tests which act as a hypervisor from running there.
> > 
> > We can't easily put guests at address 0, since we want to be able to run
> > with MSO/MSL without having to maintain separate page tables for the
> > guest physical memory. 2GB is also not a good choice, since the
> > alloc_pages allocator will place its metadata there when the host has
> > more than 2GB of memory. In addition, we also want a bit of space after
> > the end of the host physical memory to be able to catch accesses beyond
> > the end of physical memory.
> > 
> > The vmalloc allocator unfortunately allocates memory starting at the
> > highest virtual address which is not suitable for guest memory either
> > due to additional constraints of some environments.
> > 
> > The physical page allocator in memalign_pages() is also not a optimal
> > choice, since every test running SIE would then require at least 4GB+1MB
> > of physical memory.
> > 
> > This results in a few quite complex allocation requirements, hence add a
> > new function sie_guest_alloc() which allocates memory for a guest and
> > then establishes a properly aligned virtual space mapping.
> > 
> > Rework snippet test and sie tests to use the new sie_guest_alloc()
> > function.
> > 
> > Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> > Link: https://lore.kernel.org/r/20231106170849.1184162-3-nrb@linux.ibm.com
> > Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
> > ---
> >   lib/s390x/sie.h     |  2 ++
> >   lib/s390x/snippet.h |  9 +++------
> >   lib/s390x/sie.c     | 42 ++++++++++++++++++++++++++++++++++++++++++
> >   s390x/sie.c         |  4 ++--
> >   4 files changed, 49 insertions(+), 8 deletions(-)
> 
>   Hi Nico!
> 
> a colleague of mine (Jan) told me today that the current SIE-related tests 
> of the kvm-unit-tests are failing when being run from a KVM guest (i.e. when 
> we're testing a double-nested scenario). I've bisected the problem and ended 
> up with this patch here.
> Could you please check whether "./run_tests.sh sie mvpg-sie spec_ex-sie" 
> still works for you from within a KVM guest?

If you're getting a validity intercept, this should be fixed by
KVM: s390: vsie: fix wrong VIR 37 when MSO is used
https://lore.kernel.org/kvm/20231102153549.53984-1-imbrenda@linux.ibm.com/
> 
>   Thanks,
>    Thomas
> 
> 


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [kvm-unit-tests GIT PULL 07/26] s390x: sie: ensure guests are aligned to 2GB
  2023-11-23  9:24     ` Nina Schoetterl-Glausch
@ 2023-11-23 13:03       ` Thomas Huth
  2023-11-23 14:16       ` Nico Boehr
  1 sibling, 0 replies; 32+ messages in thread
From: Thomas Huth @ 2023-11-23 13:03 UTC (permalink / raw)
  To: Nina Schoetterl-Glausch, Nico Boehr; +Cc: kvm, frankja, imbrenda, Jan Richter

On 23/11/2023 10.24, Nina Schoetterl-Glausch wrote:
> On Wed, 2023-11-22 at 12:06 +0100, Thomas Huth wrote:
>> On 10/11/2023 14.52, Nico Boehr wrote:
>>> Until now, kvm-unit-tests has aligned guests to 1 MB in the host virtual
>>> address space. Unfortunately, some s390x environments require guests to
>>> be 2GB aligned in the host virtual address space, preventing
>>> kvm-unit-tests which act as a hypervisor from running there.
>>>
>>> We can't easily put guests at address 0, since we want to be able to run
>>> with MSO/MSL without having to maintain separate page tables for the
>>> guest physical memory. 2GB is also not a good choice, since the
>>> alloc_pages allocator will place its metadata there when the host has
>>> more than 2GB of memory. In addition, we also want a bit of space after
>>> the end of the host physical memory to be able to catch accesses beyond
>>> the end of physical memory.
>>>
>>> The vmalloc allocator unfortunately allocates memory starting at the
>>> highest virtual address which is not suitable for guest memory either
>>> due to additional constraints of some environments.
>>>
>>> The physical page allocator in memalign_pages() is also not a optimal
>>> choice, since every test running SIE would then require at least 4GB+1MB
>>> of physical memory.
>>>
>>> This results in a few quite complex allocation requirements, hence add a
>>> new function sie_guest_alloc() which allocates memory for a guest and
>>> then establishes a properly aligned virtual space mapping.
>>>
>>> Rework snippet test and sie tests to use the new sie_guest_alloc()
>>> function.
>>>
>>> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
>>> Link: https://lore.kernel.org/r/20231106170849.1184162-3-nrb@linux.ibm.com
>>> Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
>>> ---
>>>    lib/s390x/sie.h     |  2 ++
>>>    lib/s390x/snippet.h |  9 +++------
>>>    lib/s390x/sie.c     | 42 ++++++++++++++++++++++++++++++++++++++++++
>>>    s390x/sie.c         |  4 ++--
>>>    4 files changed, 49 insertions(+), 8 deletions(-)
>>
>>    Hi Nico!
>>
>> a colleague of mine (Jan) told me today that the current SIE-related tests
>> of the kvm-unit-tests are failing when being run from a KVM guest (i.e. when
>> we're testing a double-nested scenario). I've bisected the problem and ended
>> up with this patch here.
>> Could you please check whether "./run_tests.sh sie mvpg-sie spec_ex-sie"
>> still works for you from within a KVM guest?
> 
> If you're getting a validity intercept, this should be fixed by
> KVM: s390: vsie: fix wrong VIR 37 when MSO is used
> https://lore.kernel.org/kvm/20231102153549.53984-1-imbrenda@linux.ibm.com/

Yes, thanks, I can confirm that this fixes the issue indeed!

  Thomas



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [kvm-unit-tests GIT PULL 07/26] s390x: sie: ensure guests are aligned to 2GB
  2023-11-23  9:24     ` Nina Schoetterl-Glausch
  2023-11-23 13:03       ` Thomas Huth
@ 2023-11-23 14:16       ` Nico Boehr
  1 sibling, 0 replies; 32+ messages in thread
From: Nico Boehr @ 2023-11-23 14:16 UTC (permalink / raw)
  To: Nina Schoetterl-Glausch, Thomas Huth; +Cc: kvm, frankja, imbrenda, Jan Richter

Quoting Nina Schoetterl-Glausch (2023-11-23 10:24:12)
> On Wed, 2023-11-22 at 12:06 +0100, Thomas Huth wrote:
> > On 10/11/2023 14.52, Nico Boehr wrote:
> > > Until now, kvm-unit-tests has aligned guests to 1 MB in the host virtual
> > > address space. Unfortunately, some s390x environments require guests to
> > > be 2GB aligned in the host virtual address space, preventing
> > > kvm-unit-tests which act as a hypervisor from running there.
> > > 
> > > We can't easily put guests at address 0, since we want to be able to run
> > > with MSO/MSL without having to maintain separate page tables for the
> > > guest physical memory. 2GB is also not a good choice, since the
> > > alloc_pages allocator will place its metadata there when the host has
> > > more than 2GB of memory. In addition, we also want a bit of space after
> > > the end of the host physical memory to be able to catch accesses beyond
> > > the end of physical memory.
> > > 
> > > The vmalloc allocator unfortunately allocates memory starting at the
> > > highest virtual address which is not suitable for guest memory either
> > > due to additional constraints of some environments.
> > > 
> > > The physical page allocator in memalign_pages() is also not a optimal
> > > choice, since every test running SIE would then require at least 4GB+1MB
> > > of physical memory.
> > > 
> > > This results in a few quite complex allocation requirements, hence add a
> > > new function sie_guest_alloc() which allocates memory for a guest and
> > > then establishes a properly aligned virtual space mapping.
> > > 
> > > Rework snippet test and sie tests to use the new sie_guest_alloc()
> > > function.
> > > 
> > > Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> > > Link: https://lore.kernel.org/r/20231106170849.1184162-3-nrb@linux.ibm.com
> > > Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
> > > ---
> > >   lib/s390x/sie.h     |  2 ++
> > >   lib/s390x/snippet.h |  9 +++------
> > >   lib/s390x/sie.c     | 42 ++++++++++++++++++++++++++++++++++++++++++
> > >   s390x/sie.c         |  4 ++--
> > >   4 files changed, 49 insertions(+), 8 deletions(-)
> > 
> >   Hi Nico!
> > 
> > a colleague of mine (Jan) told me today that the current SIE-related tests 
> > of the kvm-unit-tests are failing when being run from a KVM guest (i.e. when 
> > we're testing a double-nested scenario). I've bisected the problem and ended 
> > up with this patch here.
> > Could you please check whether "./run_tests.sh sie mvpg-sie spec_ex-sie" 
> > still works for you from within a KVM guest?
> 
> If you're getting a validity intercept, this should be fixed by
> KVM: s390: vsie: fix wrong VIR 37 when MSO is used
> https://lore.kernel.org/kvm/20231102153549.53984-1-imbrenda@linux.ibm.com/

After discussion with Thomas offline: yes it was a validity and yes the
patch mentioned by Nina fixes it.

Thanks.

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2023-11-23 14:16 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 01/26] s390x: spec_ex: load full register Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 02/26] s390x: run PV guests with confidential guest enabled Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 03/26] lib: s390x: hw: rework do_detect_host so we don't need allocation Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 04/26] lib: s390x: sclp: Add compat handling for HMC ASCII consoles Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 05/26] lib: s390x: sclp: Add line mode input handling Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 06/26] s390x: spec_ex-sie: refactor to use snippet API Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 07/26] s390x: sie: ensure guests are aligned to 2GB Nico Boehr
2023-11-22 11:06   ` Thomas Huth
2023-11-23  9:24     ` Nina Schoetterl-Glausch
2023-11-23 13:03       ` Thomas Huth
2023-11-23 14:16       ` Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 08/26] s390x: mvpg-sie: fix virtual-physical address confusion Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 09/26] s390x: topology: Introduce enums for polarization & cpu type Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 10/26] s390x: topology: Fix report message Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 11/26] s390x: topology: Use function parameter in stsi_get_sysib Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 12/26] s390x: topology: Fix parsing loop Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 13/26] s390x: topology: Make some report messages unique Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 14/26] s390x: topology: Refine stsi header test Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 15/26] s390x: topology: Rename topology_core to topology_cpu Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 16/26] s390x: topology: Rewrite topology list test Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 17/26] scripts: Implement multiline strings for extra_params Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 18/26] s390x: topology: Add complex topology test Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 19/26] lib: s390x: introduce bitfield for PSW mask Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 20/26] s390x: add function to set DAT mode for all interrupts Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 21/26] s390x: sie: switch to home space mode before entering SIE Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 22/26] s390x: lib: don't forward PSW when handling exception in SIE Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 23/26] s390x: lib: sie: don't reenter SIE on pgm int Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 24/26] s390x: add test source dir to include paths Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 25/26] s390x: add a test for SIE without MSO/MSL Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 26/26] lib: s390x: interrupt: remove TEID_ASCE defines Nico Boehr
2023-11-10 15:25 ` [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Thomas Huth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox