s390x: topology tests, SCLP fixes, UV host test improvements, PV test improvements and validity/IPL test and some small maintanence fixes
cover s390x: topology tests, SCLP fixes, UV host test improvements, PV test improvements and validity/IPL test and some small maintanence fixes
Hi Paolo and/or Thomas,
quite few tests have accumulated since the last pull request, so it's time for another one.
Changes in this pull request:
* Pierre contributed tests for his topology work. The QEMU related changes[1] aren't merged yet, so it's mostly skips right now. Since things seem to converge in QEMU and the kernel part[2] is merged, it makes sense to include this now in kvm-unit-tests.
* Pierre also contributed some fixes to the SCLP code when the size of the SCCV exceeds a page, e.g. when a certain number of vCPUs is exceeded. This also resolves an ugly loop of asserts() we can run into when SCLP fails early.
* Janosch contributed enhancements for the ultravisor host interface test, which fix some bugs
* Janosch also contributed more PV tests which cover certain vailidties the host can encounter when it tries to mess with the guest state, i.e. during IPL or SIE entry
* Finally, two small fixes from me fix compile with GCC 13 and a change in the runtime makes sure pv-host tests are only run when the respective tooling is available.
MERGE: https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/merge_requests/45
PIPELINE: https://gitlab.com/Nico-Boehr/kvm-unit-tests/-/pipelines/927485818
PULL: https://gitlab.com/Nico-Boehr/kvm-unit-tests.git s390x-2023-07
[1] https://lore.kernel.org/kvm/[email protected]/
[2] https://lore.kernel.org/kvm/[email protected]/
---
The following changes since commit e7324a48acdf3776e9bd9d727e0c2319bc5bf356:
powerpc/spapr_vpa: Add basic VPA tests (2023-07-03 15:15:45 +0200)
are available in the Git repository at:
https://gitlab.com/Nico-Boehr/kvm-unit-tests.git s390x-2023-07
for you to fetch changes up to 6f33f0b7912953a2f8e6fde5a441dfef2d850cae:
s390x: topology: Checking Configuration Topology Information (2023-07-11 13:13:36 +0200)
----------------------------------------------------------------
Janosch Frank (16):
lib: s390x: sie: Fix sie_get_validity() no validity handling
lib: s390x: uv: Introduce UV validity function
lib: s390x: uv: Add intercept data check library function
s390x: pv-diags: Drop snippet from snippet names
lib: s390x: uv: Add pv host requirement check function
s390x: pv: Add sie entry intercept and validity test
s390x: pv: Add IPL reset tests
s390x: pv-diags: Add the test to unittests.conf
s390x: uv-host: Fix UV init test memory allocation
s390x: uv-host: Check for sufficient amount of memory
s390x: uv-host: Beautify code
s390x: uv-host: Add cpu number check to test_init
s390x: uv-host: Remove create guest variable storage prefix check
s390x: uv-host: Properly handle config creation errors
s390x: uv-host: Fence access checks when UV debug is enabled
s390x: uv-host: Add the test to unittests.confNico Boehr (2):
lib: s390x: mmu: fix conflicting types for get_dat_entry
runtime: don't run pv-host tests when gen-se-header is unavailable
Pierre Morel (4):
s390x: sclp: treat system as single processor when read_info is NULL
s390x: sclp: Implement extended-length-SCCB facility
s390x: topology: Check the Perform Topology Function
s390x: topology: Checking Configuration Topology Information lib/s390x/asm/uv.h | 1 +
lib/s390x/mmu.h | 2 +-
lib/s390x/pv_icptdata.h | 42 ++
lib/s390x/sclp.c | 23 +-
lib/s390x/sclp.h | 4 +-
lib/s390x/sie.c | 8 +-
lib/s390x/snippet.h | 7 +
lib/s390x/stsi.h | 36 ++
lib/s390x/uv.c | 20 +
lib/s390x/uv.h | 8 +
s390x/Makefile | 14 +-
s390x/pv-diags.c | 70 ++-
s390x/pv-icptcode.c | 376 +++++++++++++++
s390x/pv-ipl.c | 143 ++++++
s390x/snippets/asm/icpt-loop.S | 15 +
s390x/snippets/asm/loop.S | 13 +
.../asm/{snippet-pv-diag-288.S => pv-diag-288.S} | 0
s390x/snippets/asm/pv-diag-308.S | 51 ++
.../asm/{snippet-pv-diag-500.S => pv-diag-500.S} | 0
.../{snippet-pv-diag-yield.S => pv-diag-yield.S} | 0
s390x/snippets/asm/pv-icpt-112.S | 81 ++++
s390x/snippets/asm/pv-icpt-vir-timing.S | 21 +
s390x/topology.c | 514 +++++++++++++++++++++
s390x/unittests.cfg | 29 ++
s390x/uv-host.c | 134 ++++--
scripts/runtime.bash | 5 +
26 files changed, 1533 insertions(+), 84 deletions(-)
create mode 100644 lib/s390x/pv_icptdata.h
create mode 100644 s390x/pv-icptcode.c
create mode 100644 s390x/pv-ipl.c
create mode 100644 s390x/snippets/asm/icpt-loop.S
create mode 100644 s390x/snippets/asm/loop.S
rename s390x/snippets/asm/{snippet-pv-diag-288.S => pv-diag-288.S} (100%)
create mode 100644 s390x/snippets/asm/pv-diag-308.S
rename s390x/snippets/asm/{snippet-pv-diag-500.S => pv-diag-500.S} (100%)
rename s390x/snippets/asm/{snippet-pv-diag-yield.S => pv-diag-yield.S} (100%)
create mode 100644 s390x/snippets/asm/pv-icpt-112.S
create mode 100644 s390x/snippets/asm/pv-icpt-vir-timing.S
create mode 100644 s390x/topology.cSignature · 1 line
2.41.0
PATCH 1/22 lib: s390x: mmu: fix conflicting types for get_dat_entry
This causes compilation to fail with GCC 13:
gcc -std=gnu99 -ffreestanding -I/kut/lib -I/kut/lib/s390x -Ilib -O2 -march=zEC12 -mbackchain -fno-delete-null-pointer-checks -g -MMD -MF lib/s390x/.mmu.d -fno-strict-aliasing -fno-common -Wall -Wwrite-strings -Wempty-body -Wuninitialized -Wignored-qualifiers -Wno-missing-braces -Werror -fomit-frame-pointer -fno-stack-protector -Wno-frame-address -fno-pic -no-pie -Wclobbered -Wunused-but-set-parameter -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -Wmissing-prototypes -Wstrict-prototypes -I/kut/lib -I/kut/lib/s390x -Ilib -c -o lib/s390x/mmu.o lib/s390x/mmu.clib/s390x/mmu.c:132:7: error: conflicting types for ‘get_dat_entry’ due to enum/integer mismatch; have ‘void *(pgd_t *, void *, enum pgt_level)’ [-Werror=enum-int-mismatch]
132 | void *get_dat_entry(pgd_t *pgtable, void *vaddr, enum pgt_level level)
| ^~~~~~~~~~~~~
In file included from lib/s390x/mmu.c:16:
lib/s390x/mmu.h:96:7: note: previous declaration of ‘get_dat_entry’ with type ‘void *(pgd_t *, void *, unsigned int)’
96 | void *get_dat_entry(pgd_t *pgtable, void *vaddr, unsigned int level);
| ^~~~~~~~~~~~~--- lib/s390x/mmu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/s390x/mmu.h +1 -1
@@ -93,6 +93,6 @@ static inline void unprotect_page(void *vaddr, unsigned long prot) unprotect_dat_entry(vaddr, prot, pgtable_level_pte); } -void *get_dat_entry (pgd_t *pgtable,void *vaddr,unsigned int level); +void *get_dat_entry (pgd_t *pgtable,void *vaddr,enum pgt_level level);#endif /* _ASMS390X_MMU_H_ */
Signature · 1 line
2.41.0
PATCH 2/22 runtime: don't run pv-host tests when gen-se-header is unavailable
In reply to Nico BoehrWhen the gen-se-header tool is not given as an argument to configure, all tests which act as a PV host will not be built by the makefiles.
run_tests.sh will fail when a test binary is missing. This means when we add the pv-host tests to unittest.cfg we will have FAILs when gen-se-header is missing.
Since it is desirable to have the tests in unittest.cfg, add a new group pv-host which designates tests that act as a PV host. These will only run if the gen-se-header tool is available.
The pv-host group is currently not used, but will be with Janoschs series "s390x: Add PV SIE intercepts and ipl tests" here:
https://lore.kernel.org/all/[email protected]/
--- scripts/runtime.bash | 5 +++++ 1 file changed, 5 insertions(+)
scripts/runtime.bash +5 -0
@@ -98,6 +98,11 @@ function run() return fi + if [ -z "$GEN_SE_HEADER" ] && find_word "pv-host" "$groups"; then + print_result "SKIP" $testname "" "no gen-se-header available for pv-host test" + return + fi + if [ -z "$only_group" ] && find_word nodefault "$groups" && skip_nodefault; then print_result "SKIP" $testname "" "test marked as manual run only"
Signature · 1 line
2.41.0
PATCH 3/22 lib: s390x: sie: Fix sie_get_validity() no validity handling
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
Rather than asserting, we can return a value that's designated as a programming only value to indicate that there has been no validity.
The SIE instruction will never write 0xffff as a validity code so let's just use that constant.
--- lib/s390x/sie.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
lib/s390x/sie.c +7 -1
@@ -23,7 +23,13 @@ void sie_expect_validity(struct vm *vm)uint16_t sie_get_validity (struct vm *vm) { -assert (vm->sblk->icptcode ==ICPT_VALIDITY ); +/* +* 0xffff will never be returned by SIE, so we can indicate a +* missing validity via this value. +*/ +if (vm->sblk->icptcode !=ICPT_VALIDITY ) +return 0xffff ; +return vm->sblk->ipb >>16 ; }
Signature · 1 line
2.41.0
PATCH 4/22 lib: s390x: uv: Introduce UV validity function
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
PV related validities are in the 0x20** range but the last byte might be implementation specific, so everytime we check for a UV validity we need to mask the last byte.
Let's add a function that checks for a UV validity and returns a boolean.
--- lib/s390x/uv.h | 7 +++++++ 1 file changed, 7 insertions(+)
lib/s390x/uv.h +7 -0
@@ -35,4 +35,11 @@ static inline void uv_setup_asces(void) lctlg(13, asce); } +static inline bool uv_validity_check (struct vm *vm) +{ +uint16_t vir =sie_get_validity (vm); + +return vm->sblk->icptcode ==ICPT_VALIDITY && (vir &0xff00 ) ==0x2000 ; +} +#endif /* UV_H */
Signature · 1 line
2.41.0
PATCH 5/22 lib: s390x: uv: Add intercept data check library function
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
When working with guests it's essential to check the SIE intercept data for the correct values. Fortunately on PV guests these values are constants so we can create check functions which test for the constants.
While we're at it let's make pv-diags.c use this new function.
--- lib/s390x/pv_icptdata.h | 42 +++++++++++++++++++++++++++++++++++++++++ s390x/pv-diags.c | 14 ++++++-------- 2 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 lib/s390x/pv_icptdata.h
lib/s390x/pv_icptdata.h new file +42 -0
@@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Commonly used checks for PV SIE intercept data +* +* Copyright IBM Corp. 2023 +* Author: Janosch Frank <[email protected]> +*/ + +#ifndef _S390X_PV_ICPTDATA_H_ +#define _S390X_PV_ICPTDATA_H_ + +#include <sie.h> + +/* +* Checks the diagnose instruction intercept data for consistency with +* the constants defined by the PV SIE architecture +* +* Supports: 0x44, 0x9c, 0x288, 0x308, 0x500 +*/ +static bool pv_icptdata_check_diag (struct vm *vm,int diag) +{ +int icptcode; + +switch (diag) { +case 0x44 : +case 0x9c : +case 0x288 : +case 0x308 : + icptcode =ICPT_PV_NOTIFY ; +break ; +case 0x500 : + icptcode =ICPT_PV_INSTR ; +break ; +default : +/* If a new diag is introduced add it to the cases above! */ +assert (0 ); + } + +return vm->sblk->icptcode == icptcode && vm->sblk->ipa ==0x8302 && + vm->sblk->ipb ==0x50000000 && vm->save_area.guest.grs[5 ] == diag; +} +#endif
s390x/pv-diags.c +6 -8
@@ -9,6 +9,7 @@*/ #include <libcflat.h> #include <snippet.h> +#include <pv_icptdata.h> #include <sie.h> #include <sclp.h> #include <asm/facility.h>
@@ -31,8 +32,7 @@ static void test_diag_500(void) size_gbin, size_hdr, SNIPPET_UNPACK_OFF);sie (&vm); -report (vm.sblk->icptcode ==ICPT_PV_INSTR && vm.sblk->ipa ==0x8302 && - vm.sblk->ipb ==0x50000000 && vm.save_area.guest.grs[5 ] ==0x500 , +report (pv_icptdata_check_diag (&vm,0x500 ),"intercept values" ); report(vm.save_area.guest.grs[1] == 1 && vm.save_area.guest.grs[2] == 2 &&
@@ -45,9 +45,8 @@ static void test_diag_500(void)*/ vm.sblk->iictl =IICTL_CODE_OPERAND ;sie (&vm); -report (vm.sblk->icptcode ==ICPT_PV_NOTIFY && vm.sblk->ipa ==0x8302 && - vm.sblk->ipb ==0x50000000 && vm.save_area.guest.grs[5 ] ==0x9c - && vm.save_area.guest.grs[0 ] ==PGM_INT_CODE_OPERAND , +report (pv_icptdata_check_diag (&vm,0x9c ) && + vm.save_area.guest.grs[0 ] ==PGM_INT_CODE_OPERAND ,"operand exception" );/*
@@ -58,9 +57,8 @@ static void test_diag_500(void) vm.sblk->iictl =IICTL_CODE_SPECIFICATION ;/* Inject PGM, next exit should be 9c */ sie (&vm); -report (vm.sblk->icptcode ==ICPT_PV_NOTIFY && vm.sblk->ipa ==0x8302 && - vm.sblk->ipb ==0x50000000 && vm.save_area.guest.grs[5 ] ==0x9c - && vm.save_area.guest.grs[0 ] ==PGM_INT_CODE_SPECIFICATION , +report (pv_icptdata_check_diag (&vm,0x9c ) && + vm.save_area.guest.grs[0 ] ==PGM_INT_CODE_SPECIFICATION ,"specification exception" );/* No need for cleanup, just tear down the VM */
Signature · 1 line
2.41.0
PATCH 6/22 s390x: pv-diags: Drop snippet from snippet names
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
It's a bit redundant.
---
s390x/Makefile | 6 +--
.../{snippet-pv-diag-288.S => pv-diag-288.S} | 0
.../{snippet-pv-diag-500.S => pv-diag-500.S} | 0
...nippet-pv-diag-yield.S => pv-diag-yield.S} | 0
s390x/pv-diags.c | 48 +++++++++----------
5 files changed, 27 insertions(+), 27 deletions(-)
rename s390x/snippets/asm/{snippet-pv-diag-288.S => pv-diag-288.S} (100%)
rename s390x/snippets/asm/{snippet-pv-diag-500.S => pv-diag-500.S} (100%)
rename s390x/snippets/asm/{snippet-pv-diag-yield.S => pv-diag-yield.S} (100%)s390x/Makefile +3 -3
@@ -122,9 +122,9 @@ snippet_lib = $(snippet_asmlib) lib/auxinfo.o $(TEST_DIR)/mvpg-sie.elf: snippets = $(SNIPPET_DIR)/c/mvpg-snippet.gbin $(TEST_DIR)/spec_ex-sie.elf: snippets = $(SNIPPET_DIR)/c/spec_ex.gbin -$(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/snippet-pv-diag-yield.gbin -$(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/snippet-pv-diag-288.gbin -$(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/snippet-pv-diag-500.gbin +$(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-yield.gbin +$(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-288.gbin +$(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-500.gbin ifneq ($(GEN_SE_HEADER),) snippets += $(pv-snippets)
s390x/snippets/asm/pv-diag-288.S renamed from s390x/snippets/asm/snippet-pv-diag-288.S +0 -0
s390x/snippets/asm/pv-diag-500.S renamed from s390x/snippets/asm/snippet-pv-diag-500.S +0 -0
s390x/snippets/asm/pv-diag-yield.S renamed from s390x/snippets/asm/snippet-pv-diag-yield.S +0 -0
s390x/pv-diags.c +24 -24
75 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH 7/22 lib: s390x: uv: Add pv host requirement check function
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
When running PV guests some of the UV memory needs to be allocated with > 31 bit addresses which means tests with PV guests will always need a lot more memory than other tests.
Additionally facilities nr 158 and sclp.sief2 need to be available.
Let's add a function that checks for these requirements and prints a helpful skip message.
--- lib/s390x/snippet.h | 7 +++++++ lib/s390x/uv.h | 1 + lib/s390x/uv.c | 20 ++++++++++++++++++++ s390x/pv-diags.c | 8 +------- 4 files changed, 29 insertions(+), 7 deletions(-)
lib/s390x/snippet.h +7 -0
@@ -30,6 +30,13 @@#define SNIPPET_HDR_LEN (type, file) \ ((uintptr_t)SNIPPET_HDR_END(type, file) - (uintptr_t)SNIPPET_HDR_START(type, file)) +/* +* Some of the UV memory needs to be allocated with >31 bit +* addresses which means we need a lot more memory than other +* tests. +*/ +#define SNIPPET_PV_MIN_MEM_SIZE (SZ_1M * 2200UL) +#define SNIPPET_PV_TWEAK0 0x42UL#define SNIPPET_PV_TWEAK1 0UL#define SNIPPET_UNPACK_OFF 0
lib/s390x/uv.h +1 -0
@@ -7,6 +7,7 @@bool uv_os_is_guest (void );bool uv_os_is_host (void ); +bool uv_host_requirement_checks (void );bool uv_query_test_call (unsigned int nr);const struct uv_cb_qui *uv_get_query_data (void );void uv_init (void );
lib/s390x/uv.c +20 -0
@@ -18,6 +18,7 @@#include <asm/uv.h> #include <uv.h> #include <sie.h> +#include <snippet.h> static struct uv_cb_qui uvcb_qui = { .header.cmd =UVC_CMD_QUI ,
@@ -38,6 +39,25 @@ bool uv_os_is_host(void)return test_facility (158 ) &&uv_query_test_call (BIT_UVC_CMD_INIT_UV ); } +bool uv_host_requirement_checks (void ) +{ +if (!test_facility (158 )) { +report_skip ("UV Call facility unavailable" ); +return false; + } +if (!sclp_facilities.has_sief2) { +report_skip ("SIEF2 facility unavailable" ); +return false; + } +if (get_ram_size () <SNIPPET_PV_MIN_MEM_SIZE ) { +report_skip ("Not enough memory. This test needs about %ld MB of memory" , +SNIPPET_PV_MIN_MEM_SIZE /SZ_1M ); +return false; + } + +return true; +} +bool uv_query_test_call (unsigned int nr) {/* Query needs to be called first */
s390x/pv-diags.c +1 -7
@@ -149,14 +149,8 @@ static void test_diag_yield(void)int main (void ) {report_prefix_push ("pv-diags" ); -if (!test_facility (158 )) { -report_skip ("UV Call facility unavailable" ); +if (!uv_host_requirement_checks ()) goto done; - } -if (!sclp_facilities.has_sief2) { -report_skip ("SIEF2 facility unavailable" ); - goto done; - }uv_setup_asces ();snippet_setup_guest (&vm, true);
Signature · 1 line
2.41.0
PATCH 8/22 s390x: pv: Add sie entry intercept and validity test
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
The lowcore is an important part of any s390 cpu so we need to make sure it's always available when we virtualize one. For non-PV guests that would mean ensuring that the lowcore page is read and writable by the guest.
For PV guests we additionally need to make sure that the page is owned by the guest as it is only allowed to access them if that's the case. The code 112 SIE intercept tells us if the lowcore pages aren't secure anymore.
Let's check if that intercept is reported by SIE if we export the lowcore pages. Additionally check if that's also the case if the guest shares the lowcore which will make it readable to the host but ownership of the page should not change.
Also we check for validities in these conditions:
* Manipulated cpu timer
* Double SIE for same vcpu
* Re-use of VCPU handle from another secure configuration
* ASCE re-use
--- s390x/Makefile | 5 + s390x/snippets/asm/icpt-loop.S | 15 + s390x/snippets/asm/loop.S | 13 + s390x/snippets/asm/pv-icpt-112.S | 81 +++++ s390x/snippets/asm/pv-icpt-vir-timing.S | 21 ++ s390x/pv-icptcode.c | 376 ++++++++++++++++++++++++ s390x/unittests.cfg | 6 + 7 files changed, 517 insertions(+) create mode 100644 s390x/snippets/asm/icpt-loop.S create mode 100644 s390x/snippets/asm/loop.S create mode 100644 s390x/snippets/asm/pv-icpt-112.S create mode 100644 s390x/snippets/asm/pv-icpt-vir-timing.S create mode 100644 s390x/pv-icptcode.c
s390x/Makefile +5 -0
@@ -42,6 +42,7 @@ tests += $(TEST_DIR)/exittime.elf tests += $(TEST_DIR)/ex.elf pv-tests += $(TEST_DIR)/pv-diags.elf +pv-tests += $(TEST_DIR)/pv-icptcode.elf ifneq ($(HOST_KEY_DOCUMENT),) ifneq ($(GEN_SE_HEADER),)
@@ -125,6 +126,10 @@ $(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 $(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-288.gbin $(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-500.gbin +$(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-icpt-112.gbin +$(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/icpt-loop.gbin +$(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/loop.gbin +$(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-icpt-vir-timing.gbin ifneq ($(GEN_SE_HEADER),) snippets += $(pv-snippets)
s390x/snippets/asm/icpt-loop.S new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Infinite loop snippet which can be used to test manipulated SIE + * control block intercepts. E.g. when manipulating the PV handles. + * + * Copyright (c) 2023 IBM Corp + * + * Authors: + * Janosch Frank <[email protected]> + */ +.section .text +xgr %r0, %r0 +retry: +diag 0,0,0x44 +j retry
s390x/snippets/asm/loop.S new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Infinite loop snippet with no exit + * + * Copyright (c) 2023 IBM Corp + * + * Authors: + * Janosch Frank <[email protected]> + */ +.section .text + +retry: +j retry
s390x/snippets/asm/pv-icpt-112.S new file +81 -0
81 lines not on this page · raw message
s390x/snippets/asm/pv-icpt-vir-timing.S new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Sets a cpu timer which the host can manipulate to check if it will + * receive a validity + * + * Copyright (c) 2023 IBM Corp + * + * Authors: + * Janosch Frank <[email protected]> + */ +.section .text +larl %r1, time_val +spt 0 (%r1) +diag 0, 0, 0x44 +lghi %r1, 42 +diag 1, 0, 0x9c + + +.align 8 +time_val: + .quad 0x280de80000
s390x/pv-icptcode.c new file +376 -0
376 lines not on this page · raw message
s390x/unittests.cfg +6 -0
@@ -218,3 +218,9 @@ extra_params = -append '--parallel' [execute] file = ex.elf + +[pv-icptcode] +file = pv-icptcode.elf +smp = 3 +groups = pv-host +extra_params = -m 2200
Signature · 1 line
2.41.0
PATCH 9/22 s390x: pv: Add IPL reset tests
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
The diag308 requires extensive cooperation between the hypervisor and the Ultravisor so the Ultravisor can make sure all necessary reset steps have been done.
Let's check if we get the correct validity errors.
--- s390x/Makefile | 2 + s390x/snippets/asm/pv-diag-308.S | 51 +++++++++++ s390x/pv-ipl.c | 143 +++++++++++++++++++++++++++++++ s390x/unittests.cfg | 5 ++ 4 files changed, 201 insertions(+) create mode 100644 s390x/snippets/asm/pv-diag-308.S create mode 100644 s390x/pv-ipl.c
s390x/Makefile +2 -0
@@ -43,6 +43,7 @@ tests += $(TEST_DIR)/ex.elf pv-tests += $(TEST_DIR)/pv-diags.elf pv-tests += $(TEST_DIR)/pv-icptcode.elf +pv-tests += $(TEST_DIR)/pv-ipl.elf ifneq ($(HOST_KEY_DOCUMENT),) ifneq ($(GEN_SE_HEADER),)
@@ -130,6 +131,7 @@ $(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-icpt-112.gbin $(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/icpt-loop.gbin $(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/loop.gbin $(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-icpt-vir-timing.gbin +$(TEST_DIR)/pv-ipl.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-308.gbin ifneq ($(GEN_SE_HEADER),) snippets += $(pv-snippets)
s390x/snippets/asm/pv-diag-308.S new file +51 -0
51 lines not on this page · raw message
s390x/pv-ipl.c new file +143 -0
143 lines not on this page · raw message
s390x/unittests.cfg +5 -0
@@ -224,3 +224,8 @@ file = pv-icptcode.elf smp = 3 groups = pv-host extra_params = -m 2200 + +[pv-ipl] +file = pv-ipl.elf +groups = pv-host +extra_params = -m 2200
Signature · 1 line
2.41.0
PATCH 10/22 s390x: pv-diags: Add the test to unittests.conf
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
Better to have it run into a skip than to not run it at all.
--- s390x/unittests.cfg | 5 +++++ 1 file changed, 5 insertions(+)
s390x/unittests.cfg +5 -0
@@ -229,3 +229,8 @@ extra_params = -m 2200 file = pv-ipl.elf groups = pv-host extra_params = -m 2200 + +[pv-diags] +file = pv-diags.elf +groups = pv-host +extra_params = -m 2200
Signature · 1 line
2.41.0
PATCH 11/22 s390x: uv-host: Fix UV init test memory allocation
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
The init memory has to be above 2G and 1M aligned but we're currently aligning on 2G which means the allocations need a lot of unused memory.
Also the second block of memory was never actually used for the double init test since its address is never put into the uvcb.
Let's fix that.
--- s390x/uv-host.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
s390x/uv-host.c +14 -9
@@ -500,14 +500,17 @@ static void test_config_create(void)static void test_init (void ) {int rc; -uint64_t mem; +uint64_t tmp; -/* Donated storage needs to be over 2GB */ - mem = (uint64_t )memalign_pages_flags (SZ_1M , uvcb_qui.uv_base_stor_len,AREA_NORMAL ); +/* +* Donated storage needs to be over 2GB, AREA_NORMAL does that +* on s390x. +*/ + tmp = (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 ; - uvcb_init.stor_origin = mem; + uvcb_init.stor_origin = tmp; uvcb_init.stor_len = uvcb_qui.uv_base_stor_len;report_prefix_push ("init" );
@@ -528,14 +531,14 @@ static void test_init(void) rc =uv_call (0 , (uint64_t )&uvcb_init);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 = tmp;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; + uvcb_init.stor_origin = tmp; }else {report_skip ("storage + length invalid, stor_len < HPAGE_SIZE" ); }
@@ -544,7 +547,7 @@ static void test_init(void) rc =uv_call (0 , (uint64_t )&uvcb_init);report (rc ==1 && uvcb_init.header.rc ==0x108 ,"storage below 2GB" ); - uvcb_init.stor_origin = mem; + uvcb_init.stor_origin = tmp;smp_cpu_setup (1 ,PSW_WITH_CUR_MASK (cpu_loop)); rc =uv_call (0 , (uint64_t )&uvcb_init);
@@ -555,10 +558,12 @@ static void test_init(void) rc =uv_call (0 , (uint64_t )&uvcb_init);report (rc ==0 && uvcb_init.header.rc ==UVC_RC_EXECUTED ,"successful" ); - mem = (uint64_t )memalign (1UL <<31 , uvcb_qui.uv_base_stor_len); + tmp = uvcb_init.stor_origin; + uvcb_init.stor_origin = (uint64_t )memalign_pages_flags (HPAGE_SIZE , uvcb_qui.uv_base_stor_len,AREA_NORMAL ); rc =uv_call (0 , (uint64_t )&uvcb_init);report (rc ==1 && uvcb_init.header.rc ==0x101 ,"double init" ); -free ((void *)mem); +free ((void *)uvcb_init.stor_origin); + uvcb_init.stor_origin = tmp;report_prefix_pop (); }
Signature · 1 line
2.41.0
PATCH 12/22 s390x: uv-host: Check for sufficient amount of memory
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
The UV init storage needs to be above 2G so we need a little over 2G of memory when running the test.
--- s390x/uv-host.c | 8 ++++++++ 1 file changed, 8 insertions(+)
s390x/uv-host.c +8 -0
@@ -15,6 +15,7 @@#include <sclp.h> #include <smp.h> #include <uv.h> +#include <snippet.h> #include <mmu.h> #include <asm/page.h> #include <asm/sigp.h>
@@ -720,6 +721,13 @@ int main(void)test_invalid ();test_uv_uninitialized ();test_query (); + +if (get_ram_size () <SNIPPET_PV_MIN_MEM_SIZE ) { +report_skip ("Not enough memory. This test needs about %ld MB of memory" , +SNIPPET_PV_MIN_MEM_SIZE /SZ_1M ); + goto done; + } +test_init ();setup_vmem ();
Signature · 1 line
2.41.0
PATCH 13/22 s390x: uv-host: Beautify code
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
Fixup top comment and add missing space.
--- s390x/uv-host.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
s390x/uv-host.c +2 -2
@@ -1,6 +1,6 @@/* SPDX-License-Identifier: GPL-2.0-only */ /* -* Guest Ultravisor Call tests +* Host Ultravisor Call tests * * Copyright (c) 2021 IBM Corp *
@@ -34,7 +34,7 @@ static struct uv_cb_csc uvcb_csc;extern int diag308_load_reset (u64 code); -struct cmd_list { +struct cmd_list {const char *name;uint16_t cmd;uint16_t len;
Signature · 1 line
2.41.0
PATCH 14/22 s390x: uv-host: Add cpu number check to test_init
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
We should only run a test that needs more than one cpu if a sufficient number of cpus are available.
--- s390x/uv-host.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
s390x/uv-host.c +9 -5
@@ -550,11 +550,15 @@ static void test_init(void) "storage below 2GB"); uvcb_init.stor_origin = tmp; -smp_cpu_setup (1 ,PSW_WITH_CUR_MASK (cpu_loop)); - rc =uv_call (0 , (uint64_t )&uvcb_init); -report (rc ==1 && uvcb_init.header.rc ==0x102 , -"too many running cpus" ); -smp_cpu_stop (1 ); +if (smp_query_num_cpus () >1 ) { +smp_cpu_setup (1 ,PSW_WITH_CUR_MASK (cpu_loop)); + rc =uv_call (0 , (uint64_t )&uvcb_init); +report (rc ==1 && uvcb_init.header.rc ==0x102 , +"too many running cpus" ); +smp_cpu_stop (1 ); + }else { +report_skip ("Not enough cpus for 0x102 test" ); + } rc =uv_call (0 , (uint64_t )&uvcb_init);report (rc ==0 && uvcb_init.header.rc ==UVC_RC_EXECUTED ,"successful" );
Signature · 1 line
2.41.0
PATCH 15/22 s390x: uv-host: Remove create guest variable storage prefix check
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
The test fails and we currently dont know why, so let's remove it so we can add it again once we understand the problem.
--- s390x/uv-host.c | 10 ---------- 1 file changed, 10 deletions(-)
s390x/uv-host.c +0 -10
@@ -18,7 +18,6 @@#include <snippet.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>
@@ -435,15 +434,6 @@ static void test_config_create(void) "base storage origin contains lowcore"); uvcb_cgc.conf_base_stor_origin = tmp; -if (smp_query_num_cpus () ==1 ) { -sigp_retry (1 ,SIGP_SET_PREFIX , - uvcb_cgc.conf_var_stor_origin +PAGE_SIZE ,NULL ); - rc =uv_call (0 , (uint64_t )&uvcb_cgc); -report (uvcb_cgc.header.rc ==0x10e && rc ==1 && - !uvcb_cgc.guest_handle,"variable storage area contains lowcore" ); -sigp_retry (1 ,SIGP_SET_PREFIX ,0x0 ,NULL ); - } - tmp = uvcb_cgc.guest_sca; uvcb_cgc.guest_sca =0 ; rc =uv_call (0 , (uint64_t )&uvcb_cgc);
Signature · 1 line
2.41.0
PATCH 16/22 s390x: uv-host: Properly handle config creation errors
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
If the first bit is set on a error rc, the hypervisor will need to destroy the config before trying again. Let's properly handle those cases so we're not using stale data.
--- lib/s390x/asm/uv.h | 1 + s390x/uv-host.c | 65 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 57 insertions(+), 9 deletions(-)
lib/s390x/asm/uv.h +1 -0
@@ -24,6 +24,7 @@#define UVC_RC_NO_RESUME 0x0007#define UVC_RC_INV_GHANDLE 0x0020#define UVC_RC_INV_CHANDLE 0x0021 +#define UVC_RC_DSTR_NEEDED_FLG 0x8000#define UVC_CMD_QUI 0x0001#define UVC_CMD_INIT_UV 0x000f
s390x/uv-host.c +56 -9
132 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH 17/22 s390x: uv-host: Fence access checks when UV debug is enabled
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
The debug print directly accesses the UV header which will result in a second accesses exception which will abort the test. Let's fence the access tests instead.
--- s390x/uv-host.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
s390x/uv-host.c +10 -0
@@ -164,6 +164,15 @@ static void test_access(void)report_prefix_push ("access" ); +/* +* If debug is enabled info from the uv header is printed +* which would lead to a second exception and a test abort. +*/ +if (UVC_ERR_DEBUG ) { +report_skip ("Debug doesn't work with access tests" ); + goto out; + } +report_prefix_push ("non-crossing" );protect_page (uvcb,PAGE_ENTRY_I );for (i =0 ; cmds[i].name; i++) {
@@ -196,6 +205,7 @@ static void test_access(void) uvcb +=1 ;unprotect_page (uvcb,PAGE_ENTRY_I ); +out:free_pages (pages);report_prefix_pop (); }
Signature · 1 line
2.41.0
PATCH 18/22 s390x: uv-host: Add the test to unittests.conf
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
Better to skip than to not run it at all.
--- s390x/unittests.cfg | 6 ++++++ 1 file changed, 6 insertions(+)
s390x/unittests.cfg +6 -0
@@ -234,3 +234,9 @@ extra_params = -m 2200 file = pv-diags.elf groups = pv-host extra_params = -m 2200 + +[uv-host] +file = uv-host.elf +smp = 2 +groups = pv-host +extra_params = -m 2200
Signature · 1 line
2.41.0
PATCH 19/22 s390x: sclp: treat system as single processor when read_info is NULL
In reply to Nico BoehrFrom: Pierre Morel <[email protected]>
When a test abort()s before SCLP read info is completed, the assertion on read_info in sclp_read_info() will fail. Since abort() eventually calls smp_teardown() which in turn calls sclp_get_cpu_num(), this will cause an infinite abort() chain, causing the test to hang.
Fix this by considering the system single processor when read_info is missing.
--- lib/s390x/sclp.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
lib/s390x/sclp.c +9 -2
@@ -119,8 +119,15 @@ void sclp_read_info(void)int sclp_get_cpu_num (void ) { -assert (read_info); -return read_info->entries_cpu; +if (read_info) +return read_info->entries_cpu; +/* +* Don't abort here if read_info is NULL since abort() calls +* smp_teardown() which eventually calls this function and thus +* causes an infinite abort() chain, causing the test to hang. +* Since we obviously have at least one CPU, just return one. +*/ +return 1 ; }CPUEntry *sclp_get_cpu_entries (void )
Signature · 1 line
2.41.0
PATCH 20/22 s390x: sclp: Implement extended-length-SCCB facility
In reply to Nico BoehrFrom: Pierre Morel <[email protected]>
When the extended-length-SCCB facility is present use a big buffer already at first try when calling sclp_read_scp_info() to avoid the SCLP_RC_INSUFFICIENT_SCCB_LENGTH error.
--- lib/s390x/sclp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
lib/s390x/sclp.c +4 -2
@@ -17,13 +17,14 @@#include "sclp.h" #include <alloc_phys.h> #include <alloc_page.h> +#include <asm/facility.h> extern unsigned long stacktop;static uint64_t storage_increment_size;static uint64_t max_ram_size;static uint64_t ram_size; -char _read_info[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE))); +char _read_info[2 * PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));static ReadInfo *read_info;struct sclp_facilities sclp_facilities;
@@ -113,7 +114,8 @@ static void sclp_read_scp_info(ReadInfo *ri, int length)void sclp_read_info (void ) { -sclp_read_scp_info ((void *)_read_info,SCCB_SIZE ); +sclp_read_scp_info ((void *)_read_info, +test_facility (140 ) ?sizeof (_read_info) :SCCB_SIZE ); read_info = (ReadInfo *)_read_info; }
Signature · 1 line
2.41.0
PATCH 21/22 s390x: topology: Check the Perform Topology Function
In reply to Nico BoehrFrom: Pierre Morel <[email protected]>
We check that the PTF instruction is working correctly when the cpu topology facility is available.
For KVM only, we test changing of the polarity between horizontal and vertical and that a reset set the horizontal polarity.
--- s390x/Makefile | 1 + s390x/topology.c | 188 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 3 + 3 files changed, 192 insertions(+) create mode 100644 s390x/topology.c
s390x/Makefile +1 -0
@@ -40,6 +40,7 @@ tests += $(TEST_DIR)/panic-loop-pgm.elf tests += $(TEST_DIR)/migration-sck.elf tests += $(TEST_DIR)/exittime.elf tests += $(TEST_DIR)/ex.elf +tests += $(TEST_DIR)/topology.elf pv-tests += $(TEST_DIR)/pv-diags.elf pv-tests += $(TEST_DIR)/pv-icptcode.elf
s390x/topology.c new file +188 -0
188 lines not on this page · raw message
s390x/unittests.cfg +3 -0
@@ -240,3 +240,6 @@ file = uv-host.elf smp = 2 groups = pv-host extra_params = -m 2200 + +[topology] +file = topology.elf
Signature · 1 line
2.41.0
PATCH 22/22 s390x: topology: Checking Configuration Topology Information
In reply to Nico BoehrFrom: Pierre Morel <[email protected]>
STSI with function code 15 is used to store the CPU configuration topology.
We retrieve the maximum nested level with SCLP and use the topology tree provided by sockets and cores only to stay compatible with qemu topology before topology extension with drawers and books.
arguments.
We check :
- if the topology stored is coherent between the QEMU -smp parameters and kernel parameters.
- the number of CPUs
- the maximum number of CPUs
- the number of containers of each levels for every STSI(15.1.x) instruction allowed by the machine.
--- lib/s390x/sclp.h | 4 +- lib/s390x/stsi.h | 36 +++++ lib/s390x/sclp.c | 6 + s390x/topology.c | 326 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 + 5 files changed, 375 insertions(+), 1 deletion(-)
lib/s390x/sclp.h +3 -1
@@ -150,7 +150,8 @@ typedef struct ReadInfo {SCCBHeader h;uint16_t rnmax;uint8_t rnsize; -uint8_t _reserved1[16 -11 ];/* 11-15 */ +uint8_t _reserved1[15 -11 ];/* 11-14 */ +uint8_t stsi_parm;/* 15-15 */ uint16_t entries_cpu;/* 16-17 */ uint16_t offset_cpu;/* 18-19 */ uint8_t _reserved2[24 -20 ];/* 20-23 */
@@ -341,5 +342,6 @@ int sclp_service_call(unsigned int command, void *sccb);void sclp_memory_setup (void );uint64_t get_ram_size (void );uint64_t get_max_ram_size (void ); +uint64_t sclp_get_stsi_mnest (void );#endif /* _S390X_SCLP_H_ */
lib/s390x/stsi.h +36 -0
@@ -29,4 +29,40 @@ struct sysinfo_3_2_2 { uint8_t ext_names[8][256]; }; +#define CPUS_TLE_RES_BITS 0x00fffffff8000000UL +struct topology_core { +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; +}; + +#define CONTAINER_TLE_RES_BITS 0x00ffffffffffff00UL +struct topology_container { +uint8_t nl; +uint8_t reserved[6 ]; +uint8_t id; +}; + +union topology_entry { +uint8_t nl; +struct topology_core cpu; +struct topology_container container; +}; + +#define CPU_TOPOLOGY_MAX_LEVEL 6 +struct sysinfo_15_1_x { +uint8_t reserved0[2 ]; +uint16_t length; +uint8_t mag[CPU_TOPOLOGY_MAX_LEVEL ]; +uint8_t reserved0a; +uint8_t mnest; +uint8_t reserved0c[4 ]; +union topology_entry tle[]; +}; +#endif /* _S390X_STSI_H_ */
lib/s390x/sclp.c +6 -0
@@ -247,3 +247,9 @@ uint64_t get_max_ram_size(void) {return max_ram_size; } + +uint64_t sclp_get_stsi_mnest (void ) +{ +assert (read_info); +return read_info->stsi_parm; +}
s390x/topology.c +326 -0
349 lines not on this page · raw message
s390x/unittests.cfg +4 -0
@@ -243,3 +243,7 @@ extra_params = -m 2200 [topology] 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'
Signature · 1 line
2.41.0