s390x: Add PV SIE intercepts and ipl tests
v4 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.
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 (7):
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/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 | 373 ++++++++++++++++++
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 | 13 +
17 files changed, 828 insertions(+), 42 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 v4 1/7 lib: s390x: uv: Introduce UV validity function
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.34.1
PATCH v4 2/7 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 v4 3/7 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 v4 4/7 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
PATCH v4 5/7 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 | 373 ++++++++++++++++++++++++ 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 | 5 + 7 files changed, 513 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 +373 -0
373 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 +5 -0
@@ -218,3 +218,8 @@ extra_params = -append '--parallel' [execute] file = ex.elf + +[pv-icptcode] +file = pv-icptcode.elf +smp = 3 +extra_params = -m 2200
Signature · 1 line
2.34.1
Re: [kvm-unit-tests PATCH v4 5/7] s390x: pv: Add sie entry intercept and validity test
Quoting Janosch Frank (2023-05-02 13:59:29)
[...]
Quoted 5 lines
s390x/pv-icptcode.c new file +0
-0
[...]
Quoted 7 lines
s390x/pv-icptcode.c new file +7
-0+static void test_validity_timing (void ) +{ +extern const char SNIPPET_NAME_START (asm ,pv_icpt_vir_timing )[]; +extern const char SNIPPET_NAME_END (asm ,pv_icpt_vir_timing )[]; +extern const char SNIPPET_HDR_START (asm ,pv_icpt_vir_timing )[]; +extern const char SNIPPET_HDR_END (asm ,pv_icpt_vir_timing )[]; + int size_hdr = SNIPPET_HDR_LEN(asm, pv_icpt_vir_timing);
s390x/pv-icptcode.c line 50
Quoted 10 lines
s390x/pv-icptcode.c new file +10
-0+ int size_gbin = SNIPPET_LEN(asm, pv_icpt_vir_timing); +uint64_t time_exit, time_entry; + +report_prefix_push ("manipulated cpu time" ); + snippet_pv_init(&vm, SNIPPET_NAME_START(asm, pv_icpt_vir_timing), + SNIPPET_HDR_START(asm, pv_icpt_vir_timing), + size_gbin, size_hdr,SNIPPET_UNPACK_OFF ); + +sie (&vm); +report (pv_icptdata_check_diag (&vm,0x44 ),"stp done" );
s/stp/spt/
s390x/pv-icptcode.c line 59
Quoted 9 lines
s390x/pv-icptcode.c new file +9
-0+stck (&time_exit); +mb (); + +/* Cpu timer counts down so adding a ms should lead to a validity */ + vm.sblk->cputm +=S390_CLOCK_SHIFT_US *1000 ; +sie_expect_validity (&vm); +sie (&vm); +report (uv_validity_check (&vm),"validity entry cput > exit cput" ); + vm.sblk->cputm -=S390_CLOCK_SHIFT_US ;
Did you mean S390_CLOCK_SHIFT_US * 1000 here? if so, maybe you want to backup cputm and restore it here so your intention is clear.
[...]
s390x/pv-icptcode.c line 272
Quoted 8 lines
s390x/pv-icptcode.c new file +8
-0+static void run_icpt_122_tests (unsigned long lc_off) +{ +uv_export (vm.sblk->mso + lc_off); +sie (&vm); +report (vm.sblk->icptcode ==ICPT_PV_PREF ,"Intercept 112 for page 0" ); +uv_import (vm.uv.vm_handle, vm.sblk->mso + lc_off); + +uv_export (vm.sblk->mso + lc_off +PAGE_SIZE );
You are likely missing a sie(&vm) here.
PATCH v5 1/1 s390x: pv: Add sie entry intercept and validity test
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
---
- Added missing sie() call
- Fixed S390_CLOCK_SHIFT_US * 1000
- Fixed stp/spt confusion
--- 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 | 5 + 7 files changed, 516 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 +5 -0
@@ -218,3 +218,8 @@ extra_params = -append '--parallel' [execute] file = ex.elf + +[pv-icptcode] +file = pv-icptcode.elf +smp = 3 +extra_params = -m 2200
Signature · 1 line
2.34.1
Re: [kvm-unit-tests PATCH v5] s390x: pv: Add sie entry intercept and validity test
Quoting Janosch Frank (2023-05-15 13:53:11)
Quoted 15 lines
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.
Quoted 7 lines
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-useSigned-off-by Janosch Frank <[email protected]>
PATCH v4 6/7 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 | 4 + 4 files changed, 200 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 +4 -0
@@ -223,3 +223,7 @@ file = ex.elf file = pv-icptcode.elf smp = 3 extra_params = -m 2200 + +[pv-ipl] +file = pv-ipl.elf +extra_params = -m 2200
Signature · 1 line
2.34.1
Re: [kvm-unit-tests PATCH v4 6/7] s390x: pv: Add IPL reset tests
Quoting Janosch Frank (2023-05-02 13:59:30)
Quoted 7 lines
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.
Signed-off-by Janosch Frank <[email protected]>
PATCH v4 7/7 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 | 4 ++++ 1 file changed, 4 insertions(+)
s390x/unittests.cfg +4 -0
@@ -227,3 +227,7 @@ extra_params = -m 2200 [pv-ipl] file = pv-ipl.elf extra_params = -m 2200 + +[pv-diags] +file = pv-diags.elf +extra_params = -m 2200
Signature · 1 line
2.34.1
Re: [kvm-unit-tests PATCH v4 7/7] s390x: pv-diags: Add the test to unittests.conf
Quoting Janosch Frank (2023-05-02 13:59:31)
Quoted 3 lines
Better to have it run into a skip than to not run it at all.
Signed-off-by Janosch Frank <[email protected]>
Quoting Janosch Frank (2023-05-02 13:59:24)
Quoted 2 lines
Extend the coverage of the UVC interface.
The patches might be a bit dusty, they've been on a branch for a while.
As discussed offline, adding tests which require gen-se-header to unittests.cfg is not a good idea since we will have fails when it is not available.
My suggested fix is here:
https://lore.kernel.org/kvm/[email protected]/
I've added this series to our CI and took the liberty of adding the missing groups = pv-host
in the relevant patches. I can carry that along when picking for the PR, if that's OK with you (provided the patch above is accepted in common code).