s390x: tests and fixes for PV, timing
Hi Paolo,
please merge the following changes:
* library fixes to allow multi-cpu PV guests
* additional tests and fixes for uv-host
* timing tests and library improvements
* misc fixes
MERGE: https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/merge_requests/36
PIPELINE: https://gitlab.com/imbrenda/kvm-unit-tests/-/pipelines/676271045
PULL: https://gitlab.com/imbrenda/kvm-unit-tests.git s390x-next-2022-10
Claudio Imbrenda (2):
lib: s390x: terminate if PGM interrupt in interrupt handler
s390x: uv-host: fix allocation of UV memory
Janis Schoetterl-Glausch (2):
s390x: Add specification exception test
s390x: Test specification exceptions during transaction
Janosch Frank (14):
s390x: uv-host: Add access checks for donated memory
s390x: uv-host: Add uninitialized UV tests
s390x: uv-host: Test uv immediate parameter
s390x: uv-host: Add access exception test
s390x: uv-host: Add a set secure config parameters test function
s390x: uv-host: Remove duplicated +
s390x: uv-host: Fence against being run as a PV guest
s390x: uv-host: Fix init storage origin and length check
s390x: snippets: asm: Add a macro to write an exception PSW
s390x: MAKEFILE: Use $< instead of pathsubst
lib: s390x: sie: Improve validity handling and make it vm specific
lib: s390x: Use a new asce for each PV guest
lib: s390x: Enable reusability of VMs that were in PV mode
lib: s390x: sie: Properly populate SCA
Nico Boehr (4):
lib/s390x: move TOD clock related functions to library
s390x: add migration TOD clock test
s390x: add exittime tests
s390x: do not enable PV dump support by default
configure | 11 + s390x/Makefile | 31 +- lib/s390x/asm/arch_def.h | 17 + lib/s390x/asm/time.h | 50 ++- lib/s390x/sie.h | 43 ++- lib/s390x/uv.h | 5 +- lib/s390x/asm-offsets.c | 2 + lib/s390x/interrupt.c | 20 +- lib/s390x/sie.c | 35 +- lib/s390x/uv.c | 35 +- s390x/cpu.S | 6 + s390x/snippets/asm/macros.S | 28 ++ s390x/snippets/asm/snippet-pv-diag-288.S | 4 +- s390x/snippets/asm/snippet-pv-diag-500.S | 6 +- s390x/exittime.c | 296 +++++++++++++++++ s390x/migration-sck.c | 54 ++++ s390x/sck.c | 32 -- s390x/spec_ex.c | 392 +++++++++++++++++++++++ s390x/uv-host.c | 266 ++++++++++++++- s390x/unittests.cfg | 11 + 20 files changed, 1260 insertions(+), 84 deletions(-) create mode 100644 s390x/snippets/asm/macros.S create mode 100644 s390x/exittime.c create mode 100644 s390x/migration-sck.c create mode 100644 s390x/spec_ex.c
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 02/22] s390x: Test specification exceptions during transaction
From: Janis Schoetterl-Glausch <[email protected]>
Program interruptions during transactional execution cause other interruption codes.
Check that we see the expected code for (some) specification exceptions.
Message-Id: <[email protected]>
--- lib/s390x/asm/arch_def.h | 1 + s390x/spec_ex.c | 199 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 195 insertions(+), 5 deletions(-)
lib/s390x/asm/arch_def.h +1 -0
@@ -73,6 +73,7 @@ struct cpu {#define PSW_MASK_BA 0x0000000080000000UL#define PSW_MASK_64 (PSW_MASK_BA | PSW_MASK_EA) +#define CTL0_TRANSACT_EX_CTL (63 - 8)#define CTL0_LOW_ADDR_PROT (63 - 35)#define CTL0_EDAT (63 - 40)#define CTL0_FETCH_PROTECTION_OVERRIDE (63 - 38)
s390x/spec_ex.c +194 -5
242 lines not on this page · raw message
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 03/22] lib/s390x: move TOD clock related functions to library
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
The TOD-clock related functions can be useful for other tests beside the sck test, hence move them to the library.
While at it, add a wrapper for stckf, express get_clock_us() with stck() and remove an unneeded memory clobber.
Message-Id: <[email protected]>
--- lib/s390x/asm/time.h | 50 +++++++++++++++++++++++++++++++++++++++++++- s390x/sck.c | 32 ---------------------------- 2 files changed, 49 insertions(+), 33 deletions(-)
lib/s390x/asm/time.h +49 -1
@@ -18,11 +18,59 @@#define CPU_TIMER_SHIFT_US S390_CLOCK_SHIFT_US +static inline int sck (uint64_t *time) +{ +int cc; + + asmvolatile ( +" sck %[time]\n" +" ipm %[cc]\n" +" srl %[cc],28\n" + : [cc]"=d" (cc) + : [time]"Q" (*time) + :"cc" + ); + +return cc; +} + +static inline int stck (uint64_t *time) +{ +int cc; + + asmvolatile ( +" stck %[time]\n" +" ipm %[cc]\n" +" srl %[cc],28\n" + : [cc]"=d" (cc), [time]"=Q" (*time) + : + :"cc" + ); + +return cc; +} + +static inline int stckf (uint64_t *time) +{ +int cc; + + asmvolatile ( +" stckf %[time]\n" +" ipm %[cc]\n" +" srl %[cc],28\n" + : [cc]"=d" (cc), [time]"=Q" (*time) + : + :"cc" + ); + +return cc; +} +static inline uint64_t get_clock_us (void ) {uint64_t clk; - asmvolatile (" stck %0 " : :"Q" (clk) :"memory" ); +stck (&clk);return clk >>STCK_SHIFT_US ; }
s390x/sck.c +0 -32
@@ -12,38 +12,6 @@#include <asm/interrupt.h> #include <asm/time.h> -static inline int sck (uint64_t *time) -{ -int cc; - - asmvolatile ( -" sck %[time]\n" -" ipm %[cc]\n" -" srl %[cc],28\n" - : [cc]"=d" (cc) - : [time]"Q" (*time) - :"cc" - ); - -return cc; -} - -static inline int stck (uint64_t *time) -{ -int cc; - - asmvolatile ( -" stck %[time]\n" -" ipm %[cc]\n" -" srl %[cc],28\n" - : [cc]"=d" (cc), [time]"=Q" (*time) - : - :"cc" ,"memory" - ); - -return cc; -} -static void test_priv (void ) { uint64_t time_to_set_privileged = 0xfacef00dcafe0000,
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 01/22] s390x: Add specification exception test
In reply to Claudio ImbrendaFrom: Janis Schoetterl-Glausch <[email protected]>
Generate specification exceptions and check that they occur.
Message-Id: <[email protected]>
--- s390x/Makefile | 1 + lib/s390x/asm/arch_def.h | 5 + s390x/spec_ex.c | 203 +++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 3 + 4 files changed, 212 insertions(+) create mode 100644 s390x/spec_ex.c
s390x/Makefile +1 -0
@@ -27,6 +27,7 @@ tests += $(TEST_DIR)/uv-host.elf tests += $(TEST_DIR)/edat.elf tests += $(TEST_DIR)/mvpg-sie.elf tests += $(TEST_DIR)/spec_ex-sie.elf +tests += $(TEST_DIR)/spec_ex.elf tests += $(TEST_DIR)/firq.elf tests += $(TEST_DIR)/epsw.elf tests += $(TEST_DIR)/adtl-status.elf
lib/s390x/asm/arch_def.h +5 -0
@@ -41,6 +41,11 @@ struct psw {uint64_t addr; }; +struct short_psw { +uint32_t mask; +uint32_t addr; +}; +struct cpu {struct lowcore *lowcore;uint64_t *stack;
s390x/spec_ex.c new file +203 -0
203 lines not on this page · raw message
s390x/unittests.cfg +3 -0
@@ -114,6 +114,9 @@ file = mvpg-sie.elf [spec_ex-sie] file = spec_ex-sie.elf +[spec_ex] +file = spec_ex.elf + [firq-linear-cpu-ids-kvm] file = firq.elf timeout = 20
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 04/22] s390x: add migration TOD clock test
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
On migration, we expect the guest clock value to be preserved. Add a test to verify this:
- advance the guest TOD by much more than we need to migrate
- migrate the guest
- get the guest TOD
After migration, assert the guest TOD value is at least the value we set before migration. This is the minimal check for architectural compliance; implementations may decide to do something more sophisticated.
Message-Id: <[email protected]>
--- s390x/Makefile | 1 + s390x/migration-sck.c | 54 +++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 ++++ 3 files changed, 59 insertions(+) create mode 100644 s390x/migration-sck.c
s390x/Makefile +1 -0
@@ -37,6 +37,7 @@ tests += $(TEST_DIR)/migration-cmm.elf tests += $(TEST_DIR)/migration-skey.elf tests += $(TEST_DIR)/panic-loop-extint.elf tests += $(TEST_DIR)/panic-loop-pgm.elf +tests += $(TEST_DIR)/migration-sck.elf pv-tests += $(TEST_DIR)/pv-diags.elf
s390x/migration-sck.c new file +54 -0
54 lines not on this page · raw message
s390x/unittests.cfg +4 -0
@@ -200,3 +200,7 @@ file = panic-loop-pgm.elf groups = panic accel = kvm timeout = 5 + +[migration-sck] +file = migration-sck.elf +groups = migration
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 07/22] s390x: uv-host: Add access checks for donated memory
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
Let's check if the UV really protected all the memory we donated.
Reviewed-by; Steffen Eiden <[email protected]>
Message-Id: <[email protected]>
--- s390x/uv-host.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
s390x/uv-host.c +37 -0
@@ -43,6 +43,32 @@ static void cpu_loop(void)for (;;) {} } +/* +* Checks if a memory area is protected as secure memory. +* Will return true if all pages are protected, false otherwise. +*/ +static bool access_check_3d (uint8_t *access_ptr,uint64_t len) +{ +assert (!(len & ~PAGE_MASK )); +assert (!((uint64_t )access_ptr & ~PAGE_MASK )); + +while (len) { +expect_pgm_int (); +READ_ONCE (*access_ptr); +if (clear_pgm_int () !=PGM_INT_CODE_SECURE_STOR_ACCESS ) +return false; +expect_pgm_int (); +WRITE_ONCE (*access_ptr,42 ); +if (clear_pgm_int () !=PGM_INT_CODE_SECURE_STOR_ACCESS ) +return false; + + access_ptr +=PAGE_SIZE ; + len -=PAGE_SIZE ; + } + +return true; +} +static struct cmd_list cmds[] = { {"init" ,UVC_CMD_INIT_UV ,sizeof (struct uv_cb_init ),BIT_UVC_CMD_INIT_UV }, {"create conf" ,UVC_CMD_CREATE_SEC_CONF ,sizeof (struct uv_cb_cgc ),BIT_UVC_CMD_CREATE_SEC_CONF },
@@ -194,6 +220,10 @@ static void test_cpu_create(void)report (rc ==0 && uvcb_csc.header.rc ==UVC_RC_EXECUTED && uvcb_csc.cpu_handle,"success" ); + rc =access_check_3d ((uint8_t *)uvcb_csc.stor_origin, + uvcb_qui.cpu_stor_len); +report (rc,"Storage protection" ); + tmp = uvcb_csc.stor_origin; uvcb_csc.stor_origin = (unsigned long )memalign (PAGE_SIZE , uvcb_qui.cpu_stor_len); rc =uv_call (0 , (uint64_t )&uvcb_csc);
@@ -292,6 +322,13 @@ static void test_config_create(void) rc =uv_call (0 , (uint64_t )&uvcb_cgc);report (rc ==0 && uvcb_cgc.header.rc ==UVC_RC_EXECUTED ,"successful" ); + rc =access_check_3d ((uint8_t *)uvcb_cgc.conf_base_stor_origin, + uvcb_qui.conf_base_phys_stor_len); +report (rc,"Base storage protection" ); + + rc =access_check_3d ((uint8_t *)uvcb_cgc.conf_var_stor_origin, vsize); +report (rc,"Variable storage protection" ); + uvcb_cgc.header.rc =0 ; uvcb_cgc.header.rrc =0 ; tmp = uvcb_cgc.guest_handle;
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 08/22] s390x: uv-host: Add uninitialized UV tests
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
Let's also test for rc 0x3
Message-Id: <[email protected]>
--- s390x/uv-host.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 2 deletions(-)
s390x/uv-host.c +77 -2
@@ -109,6 +109,25 @@ static void test_priv(void)report_prefix_pop (); } +static void test_uv_uninitialized (void ) +{ +struct uv_cb_header uvcb = {}; +int i; + +report_prefix_push ("uninitialized" ); + +for (i =0 ; cmds[i].name; i++) { +if (cmds[i].cmd ==UVC_CMD_INIT_UV ) +continue ; +expect_pgm_int (); + uvcb.cmd = cmds[i].cmd; + uvcb.len = cmds[i].len; +uv_call_once (0 , (uint64_t )&uvcb); +report (uvcb.rc ==UVC_RC_INV_STATE ,"%s" , cmds[i].name); + } +report_prefix_pop (); +} +static void test_config_destroy (void ) {int rc;
@@ -476,13 +495,68 @@ static void test_invalid(void)report_prefix_pop (); } +static void setup_test_clear (void ) +{ +unsigned long vsize; +int rc; + + uvcb_cgc.header.cmd =UVC_CMD_CREATE_SEC_CONF ; + uvcb_cgc.header.len =sizeof (uvcb_cgc); + + uvcb_cgc.guest_stor_origin =0 ; + uvcb_cgc.guest_stor_len =42 * (1UL <<20 ); + vsize = uvcb_qui.conf_base_virt_stor_len + + ((uvcb_cgc.guest_stor_len / (1UL <<20 )) * uvcb_qui.conf_virt_var_stor_len); + + uvcb_cgc.conf_base_stor_origin = (uint64_t )memalign (PAGE_SIZE *4 , uvcb_qui.conf_base_phys_stor_len); + uvcb_cgc.conf_var_stor_origin = (uint64_t )memalign (PAGE_SIZE , vsize); + uvcb_cgc.guest_asce = (uint64_t )memalign (PAGE_SIZE ,4 *PAGE_SIZE ) |ASCE_DT_SEGMENT |REGION_TABLE_LENGTH |ASCE_P ; + uvcb_cgc.guest_sca = (uint64_t )memalign (PAGE_SIZE *4 ,PAGE_SIZE *4 ); + + rc =uv_call (0 , (uint64_t )&uvcb_cgc); +assert (rc ==0 ); + + uvcb_csc.header.len =sizeof (uvcb_csc); + uvcb_csc.header.cmd =UVC_CMD_CREATE_SEC_CPU ; + uvcb_csc.guest_handle = uvcb_cgc.guest_handle; + uvcb_csc.stor_origin = (unsigned long )memalign (PAGE_SIZE , uvcb_qui.cpu_stor_len); + uvcb_csc.state_origin = (unsigned long )memalign (PAGE_SIZE ,PAGE_SIZE ); + + rc =uv_call (0 , (uint64_t )&uvcb_csc); +assert (rc ==0 ); +} +static void test_clear (void ) { -uint64_t *tmp = (void *)uvcb_init.stor_origin; +uint64_t *tmp; + +report_prefix_push ("load normal reset" ); + +/* +* Setup a config and a cpu so we can check if a diag308 reset +* clears the donated memory and makes the pages unsecure. +*/ +setup_test_clear ();diag308_load_reset (1 );sclp_console_setup (); -report (!*tmp,"memory cleared after reset 1" ); + + tmp = (void *)uvcb_init.stor_origin; +report (!*tmp,"uv init donated memory cleared" ); + + tmp = (void *)uvcb_cgc.conf_base_stor_origin; +report (!*tmp,"config base donated memory cleared" ); + + tmp = (void *)uvcb_cgc.conf_base_stor_origin; +report (!*tmp,"config variable donated memory cleared" ); + + tmp = (void *)uvcb_csc.stor_origin; +report (!*tmp,"cpu donated memory cleared after reset 1" ); + +/* Check if uninitialized after reset */ +test_uv_uninitialized (); + +report_prefix_pop (); }static void setup_vmem (void )
@@ -513,6 +587,7 @@ int main(void)test_priv ();test_invalid (); +test_uv_uninitialized ();test_query ();test_init ();
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 06/22] s390x: do not enable PV dump support by default
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
Currently, dump support is always enabled by setting the respective plaintext control flag (PCF). Unfortunately, older machines without support for PV dump will not start the guest when this PCF is set. This will result in an error message like this:
qemu-system-s390x: KVM PV command 2 (KVM_PV_SET_SEC_PARMS) failed: header rc 106 rrc 0 IOCTL rc: -22
Hence, by default, disable dump support to preserve compatibility with older machines. Users can enable dumping support by passing --enable-dump to the configure script.
Message-Id: <[email protected]>
--- configure | 11 +++++++++++ s390x/Makefile | 26 +++++++++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-)
configure +11 -0
@@ -28,6 +28,7 @@ errata_force=0 erratatxt="$srcdir/errata.txt" host_key_document= gen_se_header= +enable_dump=no page_size= earlycon= efi=
@@ -67,6 +68,9 @@ usage() { --gen-se-header=GEN_SE_HEADER Provide an executable to generate a PV header requires --host-key-document. (s390x-snippets only) + --[enable|disable]-dump + Allow PV guests to be dumped. Requires at least z16. + (s390x only) --page-size=PAGE_SIZE Specify the page size (translation granule) (4k, 16k or 64k, default is 64k, arm64 only)
@@ -146,6 +150,12 @@ while [[ "$1" = -* ]]; do --gen-se-header) gen_se_header="$arg" ;; + --enable-dump) + enable_dump=yes + ;; + --disable-dump) + enable_dump=no + ;; --page-size) page_size="$arg" ;;
@@ -387,6 +397,7 @@ U32_LONG_FMT=$u32_long WA_DIVIDE=$wa_divide GENPROTIMG=${GENPROTIMG-genprotimg} HOST_KEY_DOCUMENT=$host_key_document +CONFIG_DUMP=$enable_dump CONFIG_EFI=$efi CONFIG_WERROR=$werror GEN_SE_HEADER=$gen_se_header
s390x/Makefile +17 -9
@@ -176,18 +176,26 @@ $(comm-key): %.bin: %.elf $(OBJCOPY) -O binary $< $@ -# The genprotimg arguments for the cck changed over time so we need to -# figure out which argument to use in order to set the cck -GENPROTIMG_HAS_COMM_KEY = $(shell $(GENPROTIMG) --help | grep -q -- --comm-key && echo yes) -ifeq ($(GENPROTIMG_HAS_COMM_KEY),yes) - GENPROTIMG_COMM_KEY = --comm-key $(comm-key) -else - GENPROTIMG_COMM_KEY = --x-comm-key $(comm-key) +# Will only be filled when dump has been enabled +GENPROTIMG_COMM_KEY = +# allow PCKMO +genprotimg_pcf = 0x000000e0 + +ifeq ($(CONFIG_DUMP),yes) + # The genprotimg arguments for the cck changed over time so we need to + # figure out which argument to use in order to set the cck + GENPROTIMG_HAS_COMM_KEY = $(shell $(GENPROTIMG) --help | grep -q -- --comm-key && echo yes) + ifeq ($(GENPROTIMG_HAS_COMM_KEY),yes) + GENPROTIMG_COMM_KEY = --comm-key $(comm-key) + else + GENPROTIMG_COMM_KEY = --x-comm-key $(comm-key) + endif + + # allow dumping + PCKMO + genprotimg_pcf = 0x200000e0 endif # use x-pcf to be compatible with old genprotimg versions -# allow dumping + PCKMO -genprotimg_pcf = 0x200000e0 genprotimg_args = --host-key-document $(HOST_KEY_DOCUMENT) --no-verify $(GENPROTIMG_COMM_KEY) --x-pcf $(genprotimg_pcf) %selftest.pv.bin: %selftest.bin $(HOST_KEY_DOCUMENT) $(patsubst %.pv.bin,%.parmfile,$@) $(comm-key)
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 09/22] s390x: uv-host: Test uv immediate parameter
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
Let's check if we get a specification PGM exception if we set a non-zero i3 when doing a UV call.
Message-Id: <[email protected]>
--- s390x/uv-host.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
s390x/uv-host.c +23 -0
@@ -90,6 +90,28 @@ static struct cmd_list cmds[] = { { NULL, 0, 0 }, }; +static void test_i3 (void ) +{ +struct uv_cb_header uvcb = { + .cmd =UVC_CMD_INIT_UV , + .len =sizeof (struct uv_cb_init ), + }; +unsigned long r1 =0 ; +int cc; + +report_prefix_push ("i3" ); +expect_pgm_int (); + asmvolatile ( +"0: .insn rrf,0xB9A40000,%[r1],%[r2],4,2\n" +" ipm %[cc]\n" +" srl %[cc],28\n" + : [cc]"=d" (cc) + : [r1]"a" (r1), [r2]"a" (&uvcb) + :"memory" ,"cc" ); +check_pgm_int_code (PGM_INT_CODE_SPECIFICATION ); +report_prefix_pop (); +} +static void test_priv (void ) {struct uv_cb_header uvcb = {};
@@ -585,6 +607,7 @@ int main(void) goto done; } +test_i3 ();test_priv ();test_invalid ();test_uv_uninitialized ();
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 10/22] s390x: uv-host: Add access exception test
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
Let's check that we get access exceptions if the UVCB is on an invalid page or starts at a valid page and crosses into an invalid one.
Message-Id: <[email protected]>
--- s390x/uv-host.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
s390x/uv-host.c +52 -0
@@ -15,12 +15,14 @@#include <sclp.h> #include <smp.h> #include <uv.h> +#include <mmu.h> #include <asm/page.h> #include <asm/sigp.h> #include <asm/pgtable.h> #include <asm/asm-offsets.h> #include <asm/interrupt.h> #include <asm/facility.h> +#include <asm/pgtable.h> #include <asm/uv.h> #include <asm-generic/barrier.h>
@@ -150,6 +152,54 @@ static void test_uv_uninitialized(void)report_prefix_pop (); } +static void test_access (void ) +{ +struct uv_cb_header *uvcb; +void *pages =alloc_pages (1 ); +uint16_t pgm; +int i; + +/* Put UVCB on second page which we will protect later */ + uvcb = pages +PAGE_SIZE ; + +report_prefix_push ("access" ); + +report_prefix_push ("non-crossing" ); +protect_page (uvcb,PAGE_ENTRY_I ); +for (i =0 ; cmds[i].name; i++) { +expect_pgm_int (); +mb (); +uv_call_once (0 , (uint64_t )uvcb); + pgm =clear_pgm_int (); +report (pgm ==PGM_INT_CODE_PAGE_TRANSLATION ,"%s" , cmds[i].name); + } +report_prefix_pop (); + +report_prefix_push ("crossing" ); +/* +* Put the header into the readable page 1, everything after +* the header will be on the second, invalid page. +*/ + uvcb -=1 ; +for (i =0 ; cmds[i].name; i++) { + uvcb->cmd = cmds[i].cmd; + uvcb->len = cmds[i].len; + +expect_pgm_int (); +mb (); +uv_call_once (0 , (uint64_t )uvcb); + pgm =clear_pgm_int (); +report (pgm ==PGM_INT_CODE_PAGE_TRANSLATION ,"%s" , cmds[i].name); + } +report_prefix_pop (); + + uvcb +=1 ; +unprotect_page (uvcb,PAGE_ENTRY_I ); + +free_pages (pages); +report_prefix_pop (); +} +static void test_config_destroy (void ) {int rc;
@@ -615,6 +665,8 @@ int main(void)test_init ();setup_vmem (); +test_access (); +test_config_create ();test_cpu_create ();test_cpu_destroy ();
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 05/22] s390x: add exittime tests
In reply to Claudio ImbrendaFrom: Nico Boehr <[email protected]>
Add a test to measure the execution time of several instructions. This can be helpful in finding performance regressions in hypervisor code.
All tests are currently reported as PASS, since the baseline for their execution time depends on the respective environment and since needs to be determined on a case-by-case basis.
Message-Id: <[email protected]>
--- s390x/Makefile | 1 + s390x/exittime.c | 296 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 + 3 files changed, 301 insertions(+) create mode 100644 s390x/exittime.c
s390x/Makefile +1 -0
@@ -38,6 +38,7 @@ tests += $(TEST_DIR)/migration-skey.elf tests += $(TEST_DIR)/panic-loop-extint.elf tests += $(TEST_DIR)/panic-loop-pgm.elf tests += $(TEST_DIR)/migration-sck.elf +tests += $(TEST_DIR)/exittime.elf pv-tests += $(TEST_DIR)/pv-diags.elf
s390x/exittime.c new file +296 -0
296 lines not on this page · raw message
s390x/unittests.cfg +4 -0
@@ -204,3 +204,7 @@ timeout = 5 [migration-sck] file = migration-sck.elf groups = migration + +[exittime] +file = exittime.elf +smp = 2
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 11/22] s390x: uv-host: Add a set secure config parameters test function
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
Time for more tests.
Message-Id: <[email protected]>
--- s390x/uv-host.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
s390x/uv-host.c +48 -0
@@ -256,6 +256,53 @@ static void test_cpu_destroy(void)report_prefix_pop (); } +static void test_set_se_header (void ) +{ +struct uv_cb_ssc uvcb = { + .header.cmd =UVC_CMD_SET_SEC_CONF_PARAMS , + .header.len =sizeof (uvcb), + .guest_handle = uvcb_cgc.guest_handle, + .sec_header_origin =0 , + .sec_header_len =0x1000 , + }; +void *pages =alloc_pages (1 ); +void *inv; +int rc; + +report_prefix_push ("sscp" ); + + uvcb.header.len -=8 ; + rc =uv_call (0 , (uint64_t )&uvcb); +report (rc ==1 && uvcb.header.rc ==UVC_RC_INV_LEN , +"hdr invalid length" ); + uvcb.header.len +=8 ; + + uvcb.guest_handle +=1 ; + rc =uv_call (0 , (uint64_t )&uvcb); +report (rc ==1 && uvcb.header.rc ==UVC_RC_INV_GHANDLE ,"invalid handle" ); + uvcb.guest_handle -=1 ; + + inv = pages +PAGE_SIZE ; + uvcb.sec_header_origin = (uint64_t )inv; +protect_page (inv,PAGE_ENTRY_I ); + rc =uv_call (0 , (uint64_t )&uvcb); +report (rc ==1 && uvcb.header.rc ==0x103 , +"se hdr access exception" ); + +/* +* Shift the ptr so the first few DWORDs are accessible but +* the following are on an invalid page. +*/ + uvcb.sec_header_origin -=0x20 ; + rc =uv_call (0 , (uint64_t )&uvcb); +report (rc ==1 && uvcb.header.rc ==0x103 , +"se hdr access exception crossing" ); +unprotect_page (inv,PAGE_ENTRY_I ); + +free_pages (pages); +report_prefix_pop (); +} +static void test_cpu_create (void ) {int rc;
@@ -669,6 +716,7 @@ int main(void)test_config_create ();test_cpu_create (); +test_set_se_header ();test_cpu_destroy ();test_config_destroy ();test_clear ();
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 12/22] s390x: uv-host: Remove duplicated +
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
One + is definitely enough here.
Message-Id: <[email protected]>
--- s390x/uv-host.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
s390x/uv-host.c +1 -1
@@ -451,7 +451,7 @@ static void test_config_create(void) uvcb_cgc.guest_sca = tmp; tmp = uvcb_cgc.guest_sca; - uvcb_cgc.guest_sca =get_max_ram_size () + +PAGE_SIZE *4 ; + uvcb_cgc.guest_sca =get_max_ram_size () +PAGE_SIZE *4 ; rc =uv_call (0 , (uint64_t )&uvcb_cgc);report (uvcb_cgc.header.rc ==0x10d && rc ==1 ,"sca inaccessible" );
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 16/22] s390x: uv-host: fix allocation of UV memory
In reply to Claudio ImbrendaAllocate the donated storage with 1M alignment from the normal pool, to force it to be above 2G without wasting a whole 2G block of memory.
Message-Id: <[email protected]>
--- s390x/uv-host.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
s390x/uv-host.c +1 -1
@@ -504,7 +504,7 @@ static void test_init(void)struct psw psw;/* Donated storage needs to be over 2GB */ - mem = (uint64_t )memalign (1UL <<31 , uvcb_qui.uv_base_stor_len); + mem = (uint64_t )memalign_pages_flags (SZ_1M , uvcb_qui.uv_base_stor_len,AREA_NORMAL ); uvcb_init.header.len =sizeof (uvcb_init); uvcb_init.header.cmd =UVC_CMD_INIT_UV ;
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 15/22] lib: s390x: terminate if PGM interrupt in interrupt handler
In reply to Claudio ImbrendaIf a program interrupt is received while in an interrupt handler, terminate immediately, stopping all CPUs and leaving the last CPU in disabled wait with a specific PSW code.
This will aid debugging by not cluttering the output, avoiding further interrupts (that would be needed to write to the output), and providing an indication of the cause of the termination.
Message-Id: <[email protected]>
--- lib/s390x/asm/arch_def.h | 11 +++++++++++ lib/s390x/interrupt.c | 20 ++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-)
lib/s390x/asm/arch_def.h +11 -0
@@ -56,6 +56,7 @@ struct cpu {bool active;bool pgm_int_expected;bool ext_int_expected; +bool in_interrupt_handler; };#define AS_PRIM 0
@@ -336,6 +337,16 @@ static inline void load_psw_mask(uint64_t mask) : "+r" (tmp) : "a" (&psw) : "memory", "cc" ); } +static inline void disabled_wait (uint64_t message) +{ +struct psw psw = { + .mask =PSW_MASK_WAIT ,/* Disabled wait */ + .addr = message, + }; + + asmvolatile (" lpswe 0(%0)\n" : :"a" (&psw) :"memory" ,"cc" ); +} +/** * psw_mask_clear_bits - clears bits from the current PSW mask * @clear: bitmask of bits that will be cleared
lib/s390x/interrupt.c +16 -4
@@ -14,6 +14,7 @@#include <sie.h> #include <fault.h> #include <asm/page.h> +#include "smp.h" /** * expect_pgm_int - Expect a program interrupt on the current CPU.
@@ -226,6 +227,11 @@ static void print_pgm_info(struct stack_frame_int *stack)void handle_pgm_int (struct stack_frame_int *stack) { +if (THIS_CPU ->in_interrupt_handler) { +/* Something went very wrong, stop everything now without printing anything */ +smp_teardown (); +disabled_wait (0xfa12edbad21 ); + }if (!THIS_CPU ->pgm_int_expected) {/* Force sclp_busy to false, otherwise we will loop forever */ sclp_handle_ext ();
@@ -233,15 +239,18 @@ void handle_pgm_int(struct stack_frame_int *stack) }THIS_CPU ->pgm_int_expected = false; +THIS_CPU ->in_interrupt_handler = true;if (THIS_CPU ->pgm_cleanup_func)THIS_CPU ->pgm_cleanup_func (stack);else fixup_pgm_int (stack); +THIS_CPU ->in_interrupt_handler = false; }void handle_ext_int (struct stack_frame_int *stack) { +THIS_CPU ->in_interrupt_handler = true;if (!THIS_CPU ->ext_int_expected && lowcore.ext_int_code !=EXT_IRQ_SERVICE_SIG ) {report_abort ("Unexpected external call interrupt (code %#x): on cpu %d at %#lx" , lowcore.ext_int_code,stap (), lowcore.ext_old_psw.addr);
@@ -260,6 +269,7 @@ void handle_ext_int(struct stack_frame_int *stack)if (THIS_CPU ->ext_cleanup_func)THIS_CPU ->ext_cleanup_func (stack); +THIS_CPU ->in_interrupt_handler = false; }void handle_mcck_int (void )
@@ -272,11 +282,13 @@ static void (*io_int_func)(void);void handle_io_int (void ) { +THIS_CPU ->in_interrupt_handler = true;if (io_int_func) -return io_int_func (); - -report_abort ("Unexpected io interrupt: on cpu %d at %#lx" , -stap (), lowcore.io_old_psw.addr); +io_int_func (); +else +report_abort ("Unexpected io interrupt: on cpu %d at %#lx" , +stap (), lowcore.io_old_psw.addr); +THIS_CPU ->in_interrupt_handler = false; }int register_io_int_func (void (*f)(void ))
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 14/22] s390x: uv-host: Fix init storage origin and length check
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
The origin and length are masked with the HPAGE_MASK and PAGE_MASK respectively so adding a few bytes doesn't matter at all.
Message-Id: <[email protected]>
--- s390x/uv-host.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
s390x/uv-host.c +12 -7
@@ -524,17 +524,22 @@ static void test_init(void) "storage invalid length"); uvcb_init.stor_len +=8 ; - uvcb_init.stor_origin =get_max_ram_size () +8 ; +/* Storage origin is 1MB aligned, the length is 4KB aligned */ + uvcb_init.stor_origin =get_max_ram_size (); rc =uv_call (0 , (uint64_t )&uvcb_init); -report (rc ==1 && uvcb_init.header.rc ==0x104 , +report (rc ==1 && (uvcb_init.header.rc ==0x104 || uvcb_init.header.rc ==0x105 ),"storage origin invalid" ); uvcb_init.stor_origin = mem; - uvcb_init.stor_origin =get_max_ram_size () -8 ; - rc =uv_call (0 , (uint64_t )&uvcb_init); -report (rc ==1 && uvcb_init.header.rc ==0x105 , -"storage + length invalid" ); - uvcb_init.stor_origin = mem; +if (uvcb_init.stor_len >=HPAGE_SIZE ) { + uvcb_init.stor_origin =get_max_ram_size () -HPAGE_SIZE ; + rc =uv_call (0 , (uint64_t )&uvcb_init); +report (rc ==1 && uvcb_init.header.rc ==0x105 , +"storage + length invalid" ); + uvcb_init.stor_origin = mem; + }else { +report_skip ("storage + length invalid, stor_len < HPAGE_SIZE" ); + } uvcb_init.stor_origin =1UL <<30 ; rc =uv_call (0 , (uint64_t )&uvcb_init);
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 13/22] s390x: uv-host: Fence against being run as a PV guest
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
This test checks the UV host API so we should skip it if we're a PV guest.
Message-Id: <[email protected]>
--- s390x/uv-host.c | 4 ++++ 1 file changed, 4 insertions(+)
s390x/uv-host.c +4 -0
@@ -703,6 +703,10 @@ int main(void)report_skip ("Ultravisor call facility is not available" ); goto done; } +if (!uv_os_is_host ()) { +report_skip ("This test needs to be run in a UV host environment" ); + goto done; + }test_i3 ();test_priv ();
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 17/22] s390x: snippets: asm: Add a macro to write an exception PSW
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
Setting exception new PSWs is commonly needed so let's add a macro for that.
Message-Id: <[email protected]>
--- s390x/snippets/asm/macros.S | 28 ++++++++++++++++++++++++ s390x/snippets/asm/snippet-pv-diag-288.S | 4 ++-- s390x/snippets/asm/snippet-pv-diag-500.S | 6 ++--- 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 s390x/snippets/asm/macros.S
s390x/snippets/asm/macros.S new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Commonly used assembly macros + * + * Copyright (c) 2022 IBM Corp + * + * Authors: + * Janosch Frank <[email protected]> + */ +#include <asm/asm-offsets.h> + +/* + * Writes a PSW to addr_psw, useful for exception PSWs in lowcore + * + * reg is the scratch register used for temporary storage, it's NOT restored + * The psw address part is defined via psw_new_addr + * The psw mask part is always 64 bit + */ +.macro SET_PSW_NEW_ADDR reg, psw_new_addr, addr_psw +larl \reg, psw_mask_64 +stg \reg, \addr_psw +larl \reg, \psw_new_addr +stg \reg, \addr_psw + 8 +.endm + +.section .rodata +psw_mask_64: + .quad 0x0000000180000000
s390x/snippets/asm/snippet-pv-diag-288.S +2 -2
@@ -8,6 +8,7 @@ * Janosch Frank <[email protected]> */ #include <asm/asm-offsets.h> +#include "macros.S" .section .text /* Clean and pre-load registers that are used for diag 288 */
@@ -19,8 +20,7 @@ lghi %r1, 2 lghi %r2, 3 /* Let's jump to the pgm exit label on a PGM */ -larl %r4, exit_pgm -stg %r4, GEN_LC_PGM_NEW_PSW + 8 +SET_PSW_NEW_ADDR 4, exit_pgm, GEN_LC_PGM_NEW_PSW /* Execute the diag288 */ diag %r0, %r2, 0x288
s390x/snippets/asm/snippet-pv-diag-500.S +2 -4
@@ -8,6 +8,7 @@ * Janosch Frank <[email protected]> */ #include <asm/asm-offsets.h> +#include "macros.S" .section .text /* Clean and pre-load registers that are used for diag 500 */
@@ -21,10 +22,7 @@ lghi %r3, 3 lghi %r4, 4 /* Let's jump to the next label on a PGM */ -xgr %r5, %r5 -stg %r5, GEN_LC_PGM_NEW_PSW -larl %r5, next -stg %r5, GEN_LC_PGM_NEW_PSW + 8 +SET_PSW_NEW_ADDR 5, next, GEN_LC_PGM_NEW_PSW /* Execute the diag500 */ diag 0, 0, 0x500
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 20/22] lib: s390x: Use a new asce for each PV guest
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
Every PV guest needs its own ASCE so let's copy the topmost table designated by CR1 to create a new ASCE for the PV guest. Before and after SIE we now need to switch ASCEs to and from the PV guest / test ASCE. The SIE assembly function does that automatically.
Message-Id: <[email protected]>
--- lib/s390x/sie.h | 2 ++ lib/s390x/uv.h | 5 ++--- lib/s390x/asm-offsets.c | 2 ++ lib/s390x/sie.c | 2 ++ lib/s390x/uv.c | 24 +++++++++++++++++++++++- s390x/cpu.S | 6 ++++++ 6 files changed, 37 insertions(+), 4 deletions(-)
lib/s390x/sie.h +2 -0
@@ -205,12 +205,14 @@ union {struct vm_uv {uint64_t vm_handle;uint64_t vcpu_handle; +uint64_t asce;void *conf_base_stor;void *conf_var_stor;void *cpu_stor; };struct vm_save_regs { +uint64_t asce;uint64_t grs[16 ];uint64_t fprs[16 ];uint32_t fpc;
lib/s390x/uv.h +2 -3
@@ -28,9 +28,8 @@ static inline void uv_setup_asces(void)/* We need to have a valid primary ASCE to run guests. */ setup_vm (); -/* Set P bit in ASCE as it is required for PV guests */ - asce =stctg (1 ) |ASCE_P ; -lctlg (1 , asce); +/* Grab the ASCE which setup_vm() just set up */ + asce =stctg (1 );/* Copy ASCE into home space CR */ lctlg (13 , asce);
lib/s390x/asm-offsets.c +2 -0
@@ -75,9 +75,11 @@ int main(void)OFFSET (SIE_SAVEAREA_HOST_GRS , vm_save_area, host.grs[0 ]);OFFSET (SIE_SAVEAREA_HOST_FPRS , vm_save_area, host.fprs[0 ]);OFFSET (SIE_SAVEAREA_HOST_FPC , vm_save_area, host.fpc); +OFFSET (SIE_SAVEAREA_HOST_ASCE , vm_save_area, host.asce);OFFSET (SIE_SAVEAREA_GUEST_GRS , vm_save_area, guest.grs[0 ]);OFFSET (SIE_SAVEAREA_GUEST_FPRS , vm_save_area, guest.fprs[0 ]);OFFSET (SIE_SAVEAREA_GUEST_FPC , vm_save_area, guest.fpc); +OFFSET (SIE_SAVEAREA_GUEST_ASCE , vm_save_area, guest.asce);OFFSET (STACK_FRAME_INT_BACKCHAIN , stack_frame_int, back_chain);OFFSET (STACK_FRAME_INT_FPC , stack_frame_int, fpc);OFFSET (STACK_FRAME_INT_FPRS , stack_frame_int, fprs);
lib/s390x/sie.c +2 -0
@@ -85,6 +85,8 @@ void sie_guest_create(struct vm *vm, uint64_t guest_mem, uint64_t guest_mem_len)/* Guest memory chunks are always 1MB */ assert (!(guest_mem_len & ~HPAGE_MASK )); +/* For non-PV guests we re-use the host's ASCE for ease of use */ + vm->save_area.guest.asce =stctg (1 );/* Currently MSO/MSL is the easiest option */ vm->sblk->mso = (uint64_t )guest_mem; vm->sblk->msl = (uint64_t )guest_mem + ((guest_mem_len -1 ) &HPAGE_MASK );
lib/s390x/uv.c +23 -1
@@ -90,6 +90,25 @@ void uv_init(void) initialized = true; } +/* +* Create a new ASCE for the UV config because they can't be shared +* for security reasons. We just simply copy the top most table into a +* fresh set of allocated pages and use those pages as the asce. +*/ +static uint64_t create_asce (void ) +{ +void *pgd_new, *pgd_old; +uint64_t asce =stctg (1 ); + + pgd_new =memalign_pages (PAGE_SIZE ,PAGE_SIZE *4 ); + pgd_old = (void *)(asce &PAGE_MASK ); + +memcpy (pgd_new, pgd_old,PAGE_SIZE *4 ); + + asce =__pa (pgd_new) |ASCE_P | (asce & (ASCE_DT |ASCE_TL )); +return asce; +} +void uv_create_guest (struct vm *vm) {struct uv_cb_cgc uvcb_cgc = {
@@ -125,7 +144,8 @@ void uv_create_guest(struct vm *vm) vm->uv.cpu_stor =memalign_pages_flags (PAGE_SIZE , uvcb_qui.cpu_stor_len,0 ); uvcb_csc.stor_origin = (uint64_t )vm->uv.cpu_stor; - uvcb_cgc.guest_asce = (uint64_t )stctg (1 ); + uvcb_cgc.guest_asce =create_asce (); + vm->save_area.guest.asce = uvcb_cgc.guest_asce; uvcb_cgc.guest_sca = (uint64_t )vm->sca; cc =uv_call (0 , (uint64_t )&uvcb_cgc);
@@ -166,6 +186,8 @@ void uv_destroy_guest(struct vm *vm)assert (cc ==0 );free_pages (vm->uv.conf_base_stor);free_pages (vm->uv.conf_var_stor); + +free_pages ((void *)(vm->uv.asce &PAGE_MASK )); }int uv_unpack (struct vm *vm,uint64_t addr,uint64_t len,uint64_t tweak)
s390x/cpu.S +6 -0
@@ -76,6 +76,9 @@ sie64a: .endr stfpc SIE_SAVEAREA_HOST_FPC(%r3) + stctg %c1, %c1, SIE_SAVEAREA_HOST_ASCE(%r3) + lctlg %c1, %c1, SIE_SAVEAREA_GUEST_ASCE(%r3) + # Store scb and save_area pointer into stack frame stg %r2,__SF_SIE_CONTROL(%r15) # save control block pointer stg %r3,__SF_SIE_SAVEAREA(%r15) # save guest register save area
@@ -102,6 +105,9 @@ sie_exit: # Load guest register save area lg %r14,__SF_SIE_SAVEAREA(%r15) + # Restore the host asce + lctlg %c1, %c1, SIE_SAVEAREA_HOST_ASCE(%r14) + # Store guest's gprs, fprs and fpc stmg %r0,%r13,SIE_SAVEAREA_GUEST_GRS(%r14) # save guest gprs 0-13 .irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 19/22] lib: s390x: sie: Improve validity handling and make it vm specific
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
The current library doesn't support running multiple vms at once as it stores the validity once and not per vm. Let's move the validity handling into the vm and introduce a new function to retrieve the vir.
Message-Id: <[email protected]>
--- lib/s390x/sie.h | 6 ++++-- lib/s390x/sie.c | 25 +++++++++++++------------ 2 files changed, 17 insertions(+), 14 deletions(-)
lib/s390x/sie.h +4 -2
@@ -233,14 +233,16 @@ struct vm {struct vm_uv uv;/* PV UV information */ /* Ptr to first guest page */ uint8_t *guest_mem; +bool validity_expected; };extern void sie_entry (void );extern void sie_exit (void );extern void sie64a (struct kvm_s390_sie_block *sblk,struct vm_save_area *save_area);void sie (struct vm *vm); -void sie_expect_validity (void ); -void sie_check_validity (uint16_t vir_exp); +void sie_expect_validity (struct vm *vm); +uint16_t sie_get_validity (struct vm *vm); +void sie_check_validity (struct vm *vm,uint16_t vir_exp);void sie_handle_validity (struct vm *vm);void sie_guest_sca_create (struct vm *vm);void sie_guest_create (struct vm *vm,uint64_t guest_mem,uint64_t guest_mem_len);
lib/s390x/sie.c +13 -12
@@ -15,19 +15,22 @@#include <libcflat.h> #include <alloc_page.h> -static bool validity_expected; -static uint16_t vir;/* Validity interception reason */ +void sie_expect_validity (struct vm *vm) +{ + vm->validity_expected = true; +} -void sie_expect_validity (void ) +uint16_t sie_get_validity (struct vm *vm) { - validity_expected = true; - vir =0 ; +assert (vm->sblk->icptcode ==ICPT_VALIDITY ); +return vm->sblk->ipb >>16 ; } -void sie_check_validity (uint16_t vir_exp) +void sie_check_validity (struct vm *vm,uint16_t vir_exp) { +uint16_t vir =sie_get_validity (vm); +report (vir_exp == vir,"VALIDITY: %x" , vir); - vir =0 ; }void sie_handle_validity (struct vm *vm)
@@ -35,11 +38,9 @@ void sie_handle_validity(struct vm *vm)if (vm->sblk->icptcode !=ICPT_VALIDITY )return ; - vir = vm->sblk->ipb >>16 ; - -if (!validity_expected) -report_abort ("VALIDITY: %x" , vir); - validity_expected = false; +if (!vm->validity_expected) +report_abort ("VALIDITY: %x" ,sie_get_validity (vm)); + vm->validity_expected = false; }void sie (struct vm *vm)
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 21/22] lib: s390x: Enable reusability of VMs that were in PV mode
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
Convert the sblk to non-PV when the PV guest is destroyed.
Early return in uv_init() instead of running into the assert. This is necessary since snippet_pv_init() will always call uv_init().
Message-Id: <[email protected]>
--- lib/s390x/uv.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
lib/s390x/uv.c +10 -1
@@ -76,7 +76,8 @@ void uv_init(void)int cc;/* Let's not do this twice */ -assert (!initialized); +if (initialized) +return ;/* Query is done on initialization but let's check anyway */ assert (uvcb_qui.header.rc ==1 || uvcb_qui.header.rc ==0x100 );
@@ -188,6 +189,14 @@ void uv_destroy_guest(struct vm *vm)free_pages (vm->uv.conf_var_stor);free_pages ((void *)(vm->uv.asce &PAGE_MASK )); +memset (&vm->uv,0 ,sizeof (vm->uv)); + +/* Convert the sblk back to non-PV */ + vm->save_area.guest.asce =stctg (1 ); + vm->sblk->sdf =0 ; + vm->sblk->sidad =0 ; + vm->sblk->pv_handle_cpu =0 ; + vm->sblk->pv_handle_config =0 ; }int uv_unpack (struct vm *vm,uint64_t addr,uint64_t len,uint64_t tweak)
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 22/22] lib: s390x: sie: Properly populate SCA
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
CPU0 is the only cpu that's being used but we should still mark it as online and set the SDA in the SCA.
Message-Id: <[email protected]>
--- lib/s390x/sie.h | 35 ++++++++++++++++++++++++++++++++++- lib/s390x/sie.c | 8 ++++++++ 2 files changed, 42 insertions(+), 1 deletion(-)
lib/s390x/sie.h +34 -1
@@ -202,6 +202,39 @@ union {uint64_t pv_grregs[16 ];/* 0x0380 */ } __attribute__((packed)); +union esca_sigp_ctrl { +uint16_t value; +struct { +uint8_t c :1 ; +uint8_t reserved:7 ; +uint8_t scn; + }; +}; + +struct esca_entry { +union esca_sigp_ctrl sigp_ctrl; +uint16_t reserved1[3 ]; +uint64_t sda; +uint64_t reserved2[6 ]; +}; + +union ipte_control { +unsigned long val; +struct { +unsigned long k :1 ; +unsigned long kh :31 ; +unsigned long kg :32 ; + }; +}; + +struct esca_block { +union ipte_control ipte_control; +uint64_t reserved1[7 ]; +uint64_t mcn[4 ]; +uint64_t reserved2[20 ]; +struct esca_entry cpu[256 ]; +}; +struct vm_uv {uint64_t vm_handle;uint64_t vcpu_handle;
@@ -230,7 +263,7 @@ struct vm_save_area {struct vm {struct kvm_s390_sie_block *sblk;struct vm_save_area save_area; -void *sca;/* System Control Area */ +struct esca_block *sca;/* System Control Area */ uint8_t *crycb;/* Crypto Control Block */ struct vm_uv uv;/* PV UV information */ /* Ptr to first guest page */
lib/s390x/sie.c +8 -0
@@ -9,6 +9,7 @@*/ #include <asm/barrier.h> +#include <bitops.h> #include <libcflat.h> #include <sie.h> #include <asm/page.h>
@@ -72,6 +73,13 @@ void sie_guest_sca_create(struct vm *vm) vm->sblk->scaoh = ((uint64_t )vm->sca >>32 ); vm->sblk->scaol = (uint64_t )vm->sca & ~0x3fU ; vm->sblk->ecb2 |=ECB2_ESCA ; + +/* Enable SIGP sense running interpretation */ + vm->sblk->ecb |=ECB_SRSI ; + +/* We assume that cpu 0 is always part of the vm */ + vm->sca->mcn[0 ] =BIT (63 ); + vm->sca->cpu[0 ].sda = (uint64_t )vm->sblk; }/* Initializes the struct vm members like the SIE control block. */
Signature · 1 line
2.37.3
[kvm-unit-tests GIT PULL 18/22] s390x: MAKEFILE: Use $< instead of pathsubst
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
No need to mangle strings if we already have the value at hand.
Message-Id: <[email protected]>
--- s390x/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
s390x/Makefile +1 -1
@@ -139,7 +139,7 @@ $(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o truncate -s '%4096' $@ $(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_lib) $(FLATLIBS) - $(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/snippets/c/flat.lds $(patsubst %.gbin,%.o,$@) $(snippet_lib) $(FLATLIBS) + $(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/snippets/c/flat.lds $< $(snippet_lib) $(FLATLIBS) $(OBJCOPY) -O binary -j ".rodata" -j ".lowcore" -j ".text" -j ".data" -j ".bss" --set-section-flags .bss=alloc,load,contents $@ $@ truncate -s '%4096' $@
Signature · 1 line
2.37.3
Quoted 4 lines · Claudio Imbrenda
* library fixes to allow multi-cpu PV guests
* additional tests and fixes for uv-host
* timing tests and library improvements
* misc fixes
Merged, thanks!
Paolo