s390x: Add PV SIE intercepts and ipl tests
v5 cover s390x: Add PV SIE intercepts and ipl tests
Extend the coverage of the UVC interface.
The patches might be a bit dusty, they've been on a branch for a while.
v5:
- Added "lib: s390x: uv: Introduce UV validity function"
- Added "groups = pv-host" to unittests.cfg entries
- Added pv-icptcode wrong vm handle test
- Smaller fixes due to review
- Added revs/acks
v4:
- Renamed uv_guest_requirement_checks() to uv_host_requirement_checks()
- Now using report_prefix_pushf()
- Smaller fixes due to review
v3:
- Reworked a large portion of the tests
- Introduced a new function that checks for required facilities and memory for tests that start PV guests
- Shortened snippet file names
- Moved checks from report to asserts to decrease test noise
- Introduced diag PV intercept data check function
v2:
- Re-worked the cpu timer tests
- Testing both pages for 112 intercept
- Added skip on insufficient memory
- Fixed comments in pv-ipl.c
Janosch Frank (8):
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
lib/s390x/pv_icptdata.h | 42 ++
lib/s390x/sie.c | 8 +-
lib/s390x/snippet.h | 7 +
lib/s390x/uv.c | 20 +
lib/s390x/uv.h | 8 +
s390x/Makefile | 13 +-
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 +
.../{snippet-pv-diag-288.S => pv-diag-288.S} | 0
s390x/snippets/asm/pv-diag-308.S | 51 +++
.../{snippet-pv-diag-500.S => pv-diag-500.S} | 0
...nippet-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/unittests.cfg | 16 +
18 files changed, 841 insertions(+), 43 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.SSignature · 1 line
2.34.1
PATCH v5 1/8 lib: s390x: sie: Fix sie_get_validity() no validity handling
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.34.1
Re: [kvm-unit-tests PATCH v5 1/8] lib: s390x: sie: Fix sie_get_validity() no validity handling
Quoting Janosch Frank (2023-06-19 10:33:22)
Quoted 7 lines
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
0xffffas a validity code so let's just use that constant.Signed-off-by Janosch Frank <[email protected]>
That's a good solution.
PATCH v5 2/8 lib: s390x: uv: Introduce UV validity function
In reply to Janosch FrankPV 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.34.1
PATCH v5 3/8 lib: s390x: uv: Add intercept data check library function
In reply to Janosch FrankWhen 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.34.1
PATCH v5 4/8 s390x: pv-diags: Drop snippet from snippet names
In reply to Janosch FrankIt's a bit redundant.
---
s390x/Makefile | 6 +--
s390x/pv-diags.c | 48 +++++++++----------
.../{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
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/pv-diags.c +24 -24
75 lines not on this page · raw message
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
Signature · 1 line
2.34.1
PATCH v5 5/8 lib: s390x: uv: Add pv host requirement check function
In reply to Janosch FrankWhen 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.c | 20 ++++++++++++++++++++ lib/s390x/uv.h | 1 + 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.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 /1024 /1024 ); +return false; + } + +return true; +} +bool uv_query_test_call (unsigned int nr) {/* Query needs to be called first */
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 );
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.34.1
Re: [kvm-unit-tests PATCH v5 5/8] lib: s390x: uv: Add pv host requirement check function
Quoted 10 lines · Janosch Frank
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.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Nico Boehr <[email protected]>
[...]
lib/s390x/uv.c bool uv_os_is_host(void) · line 54
Quoted 13 lines
lib/s390x/uv.c +13
-0+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 /1024 /1024 );
I've just replaced the 1024 divisions with SZ_1M i nthe second series. Feel free to do that here when picking if I don't need to send a new version.
PATCH v5 6/8 s390x: pv: Add sie entry intercept and validity test
In reply to Janosch FrankThe 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/pv-icptcode.c | 376 ++++++++++++++++++++++++ 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/unittests.cfg | 6 + 7 files changed, 517 insertions(+) create mode 100644 s390x/pv-icptcode.c 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
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/pv-icptcode.c new file +376 -0
376 lines not on this page · raw message
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/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.34.1
PATCH v5 7/8 s390x: pv: Add IPL reset tests
In reply to Janosch FrankThe 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/pv-ipl.c | 143 +++++++++++++++++++++++++++++++ s390x/snippets/asm/pv-diag-308.S | 51 +++++++++++ s390x/unittests.cfg | 5 ++ 4 files changed, 201 insertions(+) create mode 100644 s390x/pv-ipl.c create mode 100644 s390x/snippets/asm/pv-diag-308.S
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/pv-ipl.c new file +143 -0
143 lines not on this page · raw message
s390x/snippets/asm/pv-diag-308.S new file +51 -0
51 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.34.1
PATCH v5 8/8 s390x: pv-diags: Add the test to unittests.conf
In reply to Janosch FrankBetter 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.34.1