s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes
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 handlingNico 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 definesNina 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 testlib/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
[kvm-unit-tests GIT PULL 01/26] s390x: spec_ex: load full register
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.
--- s390x/spec_ex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
s390x/spec_ex.c +1 -1
@@ -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)
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 03/26] lib: s390x: hw: rework do_detect_host so we don't need allocation
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
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.
--- lib/s390x/hardware.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
lib/s390x/hardware.c +5 -6
@@ -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; }
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 02/26] s390x: run PV guests with confidential guest enabled
In reply to Nico BoehrPV 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.
--- s390x/run | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
s390x/run +17 -2
@@ -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"
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 06/26] s390x: spec_ex-sie: refactor to use snippet API
In reply to Nico Boehrspec_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().
--- s390x/spec_ex-sie.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
s390x/spec_ex-sie.c +6 -7
@@ -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 )
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 05/26] lib: s390x: sclp: Add line mode input handling
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
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.
--- lib/s390x/sclp.h | 26 +++++- lib/s390x/sclp-console.c | 181 ++++++++++++++++++++++++++++++++++----- 2 files changed, 186 insertions(+), 21 deletions(-)
lib/s390x/sclp.h +25 -1
@@ -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 0typedef 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 );
lib/s390x/sclp-console.c +161 -20
219 lines not on this page · raw message
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 04/26] lib: s390x: sclp: Add compat handling for HMC ASCII consoles
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
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.
--- lib/s390x/sclp-console.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
lib/s390x/sclp-console.c +24 -1
@@ -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)
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 09/26] s390x: topology: Introduce enums for polarization & cpu type
In reply to Nico BoehrFrom: Nina Schoetterl-Glausch <[email protected]>
Thereby get rid of magic values.
--- lib/s390x/stsi.h | 11 +++++++++++ s390x/topology.c | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-)
lib/s390x/stsi.h +11 -0
@@ -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 0x00ffffffffffff00ULstruct topology_container {uint8_t nl;
s390x/topology.c +4 -2
@@ -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); }
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 11/26] s390x: topology: Use function parameter in stsi_get_sysib
In reply to Nico BoehrFrom: Nina Schoetterl-Glausch <[email protected]>
Actually use the function parameter we're give instead of a hardcoded access to the static variable pagebuf.
--- s390x/topology.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
s390x/topology.c +1 -1
@@ -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" );
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 07/26] s390x: sie: ensure guests are aligned to 2GB
In reply to Nico BoehrUntil 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.
--- 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(-)
lib/s390x/sie.h +2 -0
@@ -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_ */
lib/s390x/snippet.h +3 -6
@@ -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 */
lib/s390x/sie.c +42 -0
54 lines not on this page · raw message
s390x/sie.c +2 -2
@@ -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 ;
Signature · 1 line
2.41.0
Re: [kvm-unit-tests GIT PULL 07/26] s390x: sie: ensure guests are aligned to 2GB
Quoted 31 lines · Nico Boehr
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_pagesallocator 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 <[email protected]>Signed-off-by Nico Boehr <[email protected]>
Quoted 6 lines
--- 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
Re: [kvm-unit-tests GIT PULL 07/26] s390x: sie: ensure guests are aligned to 2GB
Quoted 39 lines · Thomas Huth
Quoted 31 lines · Nico Boehr
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_pagesallocator 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 <[email protected]>Signed-off-by Nico Boehr <[email protected]>Quoted 6 lines
--- 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(-)
Quoted 8 lines
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/[email protected]/
Quoted 5 lines
Thanks,
Thomas
Re: [kvm-unit-tests GIT PULL 07/26] s390x: sie: ensure guests are aligned to 2GB
Quoted 49 lines · Nina Schoetterl-Glausch
Quoted 39 lines · Thomas Huth
Quoted 31 lines · Nico Boehr
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_pagesallocator 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 <[email protected]>Signed-off-by Nico Boehr <[email protected]>Quoted 6 lines
--- 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(-)Quoted 8 lines
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?
Quoted 3 lines
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/[email protected]/
Yes, thanks, I can confirm that this fixes the issue indeed!
Thomas
Re: [kvm-unit-tests GIT PULL 07/26] s390x: sie: ensure guests are aligned to 2GB
In reply to Nina Schoetterl-GlauschQuoting Nina Schoetterl-Glausch (2023-11-23 10:24:12)
Quoted 49 lines · Thomas Huth
Quoted 39 lines · Nico Boehr
Quoted 31 lines
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_pagesallocator 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 <[email protected]>Signed-off-by Nico Boehr <[email protected]>Quoted 6 lines
--- 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(-)Quoted 8 lines
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?
Quoted 3 lines
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/[email protected]/
After discussion with Thomas offline: yes it was a validity and yes the patch mentioned by Nina fixes it.
Thanks.
[kvm-unit-tests GIT PULL 08/26] s390x: mvpg-sie: fix virtual-physical address confusion
In reply to Nico BoehrThe 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.
--- s390x/mvpg-sie.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
s390x/mvpg-sie.c +12 -4
@@ -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 ); }
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 10/26] s390x: topology: Fix report message
In reply to Nico BoehrFrom: Nina Schoetterl-Glausch <[email protected]>
A polarization value of 0 means horizontal polarization.
--- s390x/topology.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
s390x/topology.c +1 -1
@@ -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); }
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 13/26] s390x: topology: Make some report messages unique
In reply to Nico BoehrFrom: Nina Schoetterl-Glausch <[email protected]>
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.
--- s390x/topology.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
s390x/topology.c +6 -6
@@ -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 (); }
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 12/26] s390x: topology: Fix parsing loop
In reply to Nico BoehrFrom: Nina Schoetterl-Glausch <[email protected]>
Without a comparison the loop is infinite.
--- s390x/topology.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
s390x/topology.c +1 -1
@@ -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 ; }
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 14/26] s390x: topology: Refine stsi header test
In reply to Nico BoehrFrom: Nina Schoetterl-Glausch <[email protected]>
Add checks for length field.
Also minor refactor.
--- s390x/topology.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
s390x/topology.c +10 -6
@@ -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 ();
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 15/26] s390x: topology: Rename topology_core to topology_cpu
In reply to Nico BoehrFrom: Nina Schoetterl-Glausch <[email protected]>
This is more in line with the nomenclature in the PoP.
--- lib/s390x/stsi.h | 4 ++-- s390x/topology.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
lib/s390x/stsi.h +2 -2
@@ -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; };
s390x/topology.c +1 -1
@@ -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) {
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 16/26] s390x: topology: Rewrite topology list test
In reply to Nico BoehrFrom: Nina Schoetterl-Glausch <[email protected]>
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.
--- lib/s390x/stsi.h | 36 +++++---- s390x/topology.c | 202 ++++++++++++++++++++++++++++++----------------- 2 files changed, 149 insertions(+), 89 deletions(-)
lib/s390x/stsi.h +21 -15
@@ -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
s390x/topology.c +128 -74
264 lines not on this page · raw message
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 18/26] s390x: topology: Add complex topology test
In reply to Nico BoehrFrom: Nina Schoetterl-Glausch <[email protected]>
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'--- s390x/unittests.cfg | 133 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+)
s390x/unittests.cfg +133 -0
@@ -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 \ +"""
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 17/26] scripts: Implement multiline strings for extra_params
In reply to Nico BoehrFrom: Nina Schoetterl-Glausch <[email protected]>
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 \.
--- scripts/common.bash | 16 ++++++++++++++++ scripts/runtime.bash | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-)
scripts/common.bash +16 -0
@@ -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
scripts/runtime.bash +2 -2
@@ -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)
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 19/26] lib: s390x: introduce bitfield for PSW mask
In reply to Nico BoehrChanging 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.
--- lib/s390x/asm/arch_def.h | 25 ++++++++++++++++++++++++- s390x/selftest.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-)
lib/s390x/asm/arch_def.h +24 -1
@@ -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) })
s390x/selftest.c +34 -0
@@ -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 (); }
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 20/26] s390x: add function to set DAT mode for all interrupts
In reply to Nico BoehrWhen 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.
--- 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(-)
lib/s390x/asm/arch_def.h +6 -4
@@ -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
lib/s390x/asm/interrupt.h +2 -0
@@ -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 ) {
lib/s390x/interrupt.c +35 -0
@@ -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 */
lib/s390x/mmu.c +3 -2
@@ -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 ); }/*
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 21/26] s390x: sie: switch to home space mode before entering SIE
In reply to Nico BoehrThis 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.
--- lib/s390x/asm/arch_def.h | 1 + lib/s390x/sie.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
lib/s390x/asm/arch_def.h +1 -0
@@ -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
lib/s390x/sie.c +26 -0
@@ -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));
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 22/26] s390x: lib: don't forward PSW when handling exception in SIE
In reply to Nico BoehrWhen 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.
--- lib/s390x/interrupt.c | 1 + 1 file changed, 1 insertion(+)
lib/s390x/interrupt.c +1 -0
@@ -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) {
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 23/26] s390x: lib: sie: don't reenter SIE on pgm int
In reply to Nico BoehrAt 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.
--- lib/s390x/asm/interrupt.h | 14 ++++++++++++++ lib/s390x/asm/mem.h | 1 + lib/s390x/sie.c | 7 ++++++- 3 files changed, 21 insertions(+), 1 deletion(-)
lib/s390x/asm/interrupt.h +14 -0
@@ -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
lib/s390x/asm/mem.h +1 -0
@@ -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)))
lib/s390x/sie.c +6 -1
@@ -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); }
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 24/26] s390x: add test source dir to include paths
In reply to Nico BoehrSometimes, 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.
--- s390x/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
s390x/Makefile +1 -1
@@ -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))
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 25/26] s390x: add a test for SIE without MSO/MSL
In reply to Nico BoehrSince we now have the ability to run guests without MSO/MSL, add a test to make sure this doesn't break.
--- 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
s390x/Makefile +2 -0
@@ -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
s390x/snippets/c/sie-dat.h new file +2 -0
@@ -0,0 +1,2 @@ +#define GUEST_TEST_PAGE_COUNT 10 +#define GUEST_TOTAL_PAGE_COUNT 256
s390x/sie-dat.c new file +114 -0
114 lines not on this page · raw message
s390x/snippets/c/sie-dat.c new file +57 -0
57 lines not on this page · raw message
s390x/unittests.cfg +3 -0
@@ -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
Signature · 1 line
2.41.0
[kvm-unit-tests GIT PULL 26/26] lib: s390x: interrupt: remove TEID_ASCE defines
In reply to Nico BoehrThese 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.
--- lib/s390x/asm/interrupt.h | 5 ----- 1 file changed, 5 deletions(-)
lib/s390x/asm/interrupt.h +0 -5
@@ -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 {
Signature · 1 line
2.41.0
Quoted 16 lines · Nico Boehr
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 runningsie()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.
Quoted 4 lines
Thanks
NicoMERGE: https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/merge_requests/48
Thanks, merged now!
Thomas