s390x update 2022-01-17
Hi Paolo,
please merge the following changes:
* snippet support for PV (Janosch)
* DMA31 allocation fixes (Janosch)
MERGE:
https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/merge_requests/22
PIPELINE:
https://gitlab.com/imbrenda/kvm-unit-tests/-/pipelines/449739146
PULL:
https://gitlab.com/imbrenda/kvm-unit-tests.git s390x-next-20220117
Janosch Frank (13):
s390x: snippets: mvpg-snippet: Remove unneeded includes
lib: s390x: sie: Add sca allocation and freeing
s390x: sie: Add PV fields to SIE control block
s390x: sie: Add UV information into VM struct
s390x: uv: Add more UV call functions
s390x: lib: Extend UV library with PV guest management
lib: s390: sie: Add PV guest register handling
s390x: snippets: Add PV support
lib: s390x: Introduce snippet helpers
s390x: mvpg-sie: Use snippet helpers
s390x: sie: Add PV diag test
s390x: smp: Allocate memory in DMA31 space
s390x: firq: Fix sclp buffer allocation
configure | 8 + s390x/Makefile | 73 ++++++-- lib/s390x/asm/uv.h | 99 +++++++++++ lib/s390x/sie.h | 54 +++++- lib/s390x/snippet.h | 110 ++++++++++++ lib/s390x/uv.h | 28 +++ lib/s390x/sie.c | 20 +++ lib/s390x/uv.c | 128 ++++++++++++++ s390x/snippets/asm/snippet-pv-diag-288.S | 25 +++ s390x/snippets/asm/snippet-pv-diag-500.S | 39 +++++ s390x/snippets/asm/snippet-pv-diag-yield.S | 7 + s390x/firq.c | 2 +- s390x/mvpg-sie.c | 24 +-- s390x/pv-diags.c | 187 +++++++++++++++++++++ s390x/smp.c | 4 +- s390x/snippets/c/mvpg-snippet.c | 1 - .gitignore | 2 + 17 files changed, 773 insertions(+), 38 deletions(-) create mode 100644 s390x/snippets/asm/snippet-pv-diag-288.S create mode 100644 s390x/snippets/asm/snippet-pv-diag-500.S create mode 100644 s390x/snippets/asm/snippet-pv-diag-yield.S create mode 100644 s390x/pv-diags.c
Signature · 1 line
2.31.1
[kvm-unit-tests GIT PULL 01/13] s390x: snippets: mvpg-snippet: Remove unneeded includes
From: Janosch Frank <[email protected]>
None of those headers is used, let's remove them.
--- s390x/snippets/c/mvpg-snippet.c | 1 - 1 file changed, 1 deletion(-)
s390x/snippets/c/mvpg-snippet.c +0 -1
@@ -7,7 +7,6 @@* Authors: * Janosch Frank <[email protected]> */ -#include <libcflat.h> static inline void force_exit (void ) {
Signature · 1 line
2.31.1
[kvm-unit-tests GIT PULL 02/13] lib: s390x: sie: Add sca allocation and freeing
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
For protected guests we always need a ESCA so let's add functions to create and destroy SCAs on demand. We don't have scheduling and I don't expect multiple VCPU SIE in the next few months so SCA content handling is not added.
--- lib/s390x/sie.h | 2 ++ lib/s390x/sie.c | 12 ++++++++++++ 2 files changed, 14 insertions(+)
lib/s390x/sie.h +2 -0
@@ -191,6 +191,7 @@ struct vm_save_area {struct vm {struct kvm_s390_sie_block *sblk;struct vm_save_area save_area; +void *sca;/* System Control Area */ uint8_t *crycb;/* Crypto Control Block */ /* Ptr to first guest page */ uint8_t *guest_mem;
@@ -203,6 +204,7 @@ void sie(struct vm *vm);void sie_expect_validity (void );void sie_check_validity (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);void sie_guest_destroy (struct vm *vm);
lib/s390x/sie.c +12 -0
@@ -55,6 +55,16 @@ void sie(struct vm *vm) vm->save_area.guest.grs[15 ] = vm->sblk->gg15; } +void sie_guest_sca_create (struct vm *vm) +{ + vm->sca = (struct esca_block *)alloc_page (); + +/* Let's start out with one page of ESCA for now */ + vm->sblk->scaoh = ((uint64_t )vm->sca >>32 ); + vm->sblk->scaol = (uint64_t )vm->sca & ~0x3fU ; + vm->sblk->ecb2 |=ECB2_ESCA ; +} +/* Initializes the struct vm members like the SIE control block. */ void sie_guest_create (struct vm *vm,uint64_t guest_mem,uint64_t guest_mem_len) {
@@ -80,4 +90,6 @@ void sie_guest_destroy(struct vm *vm) {free_page (vm->crycb);free_page (vm->sblk); +if (vm->sblk->ecb2 &ECB2_ESCA ) +free_page (vm->sca); }
Signature · 1 line
2.31.1
[kvm-unit-tests GIT PULL 07/13] lib: s390: sie: Add PV guest register handling
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
Protected guests have their registers stored to / loaded from offset 0x380 of the sie control block. So we need to copy over the GRs to/from that offset for format 4 (PV) guests before and after we enter SIE.
--- lib/s390x/sie.h | 2 ++ lib/s390x/sie.c | 8 ++++++++ 2 files changed, 10 insertions(+)
lib/s390x/sie.h +2 -0
@@ -198,6 +198,8 @@ union {uint64_t itdba;/* 0x01e8 */ uint64_t riccbd;/* 0x01f0 */ uint64_t gvrd;/* 0x01f8 */ +uint64_t reserved200[48 ];/* 0x0200 */ +uint64_t pv_grregs[16 ];/* 0x0380 */ } __attribute__((packed));struct vm_uv {
lib/s390x/sie.c +8 -0
@@ -44,6 +44,10 @@ void sie_handle_validity(struct vm *vm)void sie (struct vm *vm) { +if (vm->sblk->sdf ==2 ) +memcpy (vm->sblk->pv_grregs, vm->save_area.guest.grs, +sizeof (vm->save_area.guest.grs)); +/* Reset icptcode so we don't trip over it below */ vm->sblk->icptcode =0 ;
@@ -53,6 +57,10 @@ void sie(struct vm *vm) } vm->save_area.guest.grs[14 ] = vm->sblk->gg14; vm->save_area.guest.grs[15 ] = vm->sblk->gg15; + +if (vm->sblk->sdf ==2 ) +memcpy (vm->save_area.guest.grs, vm->sblk->pv_grregs, +sizeof (vm->save_area.guest.grs)); }void sie_guest_sca_create (struct vm *vm)
Signature · 1 line
2.31.1
[kvm-unit-tests GIT PULL 09/13] lib: s390x: Introduce snippet helpers
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
These helpers reduce code duplication for PV snippet tests.
--- lib/s390x/snippet.h | 103 ++++++++++++++++++++++++++++++++++++++++++++ lib/s390x/uv.h | 21 +++++++++ 2 files changed, 124 insertions(+)
lib/s390x/snippet.h +103 -0
@@ -9,6 +9,10 @@#ifndef _S390X_SNIPPET_H_#define _S390X_SNIPPET_H_ +#include <sie.h> +#include <uv.h> +#include <asm/uv.h> +/* This macro cuts down the length of the pointers to snippets */ #define SNIPPET_NAME_START (type, file) \ _binary_s390x_snippets_##type##_##file##_gbin_start
@@ -26,6 +30,12 @@#define SNIPPET_HDR_LEN (type, file) \ ((uintptr_t)SNIPPET_HDR_END(type, file) - (uintptr_t)SNIPPET_HDR_START(type, file)) +#define SNIPPET_PV_TWEAK0 0x42UL +#define SNIPPET_PV_TWEAK1 0UL +#define SNIPPET_OFF_C 0 +#define SNIPPET_OFF_ASM 0x4000 + +/* * C snippet instructions start at 0x4000 due to the prefix and the * stack being before that. ASM snippets don't strictly need a stack
@@ -38,4 +48,97 @@ static const struct psw snippet_psw = { .mask = PSW_MASK_64, .addr = SNIPPET_ENTRY_ADDR, }; + +/* +* Sets up a snippet guest on top of an existing and initialized SIE +* vm struct. +* Once this function has finished without errors the guest can be started. +* +* @vm: VM that this function will populated, has to be initialized already +* @gbin: Snippet gbin data pointer +* @gbin_len: Length of the gbin data +* @off: Offset from guest absolute 0x0 where snippet is copied to +*/ +static inline void snippet_init (struct vm *vm,const char *gbin, +uint64_t gbin_len,uint64_t off) +{ +uint64_t mso = vm->sblk->mso; + +/* Copy test image to guest memory */ +memcpy ((void *)mso + off, gbin, gbin_len); + +/* Setup guest PSW */ + vm->sblk->gpsw = snippet_psw; + +/* +* We want to exit on PGM exceptions so we don't need +* exception handlers in the guest. +*/ + vm->sblk->ictl =ICTL_OPEREXC |ICTL_PINT ; +} + +/* +* Sets up a snippet UV/PV guest on top of an existing and initialized +* SIE vm struct. +* Once this function has finished without errors the guest can be started. +* +* @vm: VM that this function will populated, has to be initialized already +* @gbin: Snippet gbin data pointer +* @hdr: Snippet SE header data pointer +* @gbin_len: Length of the gbin data +* @hdr_len: Length of the hdr data +* @off: Offset from guest absolute 0x0 where snippet is copied to +*/ +static inline void snippet_pv_init (struct vm *vm,const char *gbin, +const char *hdr,uint64_t gbin_len, +uint64_t hdr_len,uint64_t off) +{ +uint64_t tweak[2 ] = {SNIPPET_PV_TWEAK0 ,SNIPPET_PV_TWEAK1 }; +uint64_t mso = vm->sblk->mso; +int i; + +snippet_init (vm, gbin, gbin_len, off); + +uv_create_guest (vm); +uv_set_se_hdr (vm->uv.vm_handle, (void *)hdr, hdr_len); + +/* Unpack works on guest addresses so we only need off */ +uv_unpack (vm, off, gbin_len, tweak[0 ]); +uv_verify_load (vm); + +/* +* Manually import: +* - lowcore 0x0 - 0x1000 (asm) +* - stack 0x3000 (C) +*/ +for (i =0 ; i <4 ; i++) { +uv_import (vm->uv.vm_handle, mso +PAGE_SIZE * i); + } +} + +/* Allocates and sets up a snippet based guest */ +static inline void snippet_setup_guest (struct vm *vm,bool is_pv) +{ +u8 *guest; + +/* Allocate 1MB as guest memory */ + guest =alloc_pages (8 ); +memset (guest,0 ,HPAGE_SIZE ); + +/* Initialize the vm struct and allocate control blocks */ +sie_guest_create (vm, (uint64_t )guest,HPAGE_SIZE ); + +if (is_pv) { +/* FMT4 needs a ESCA */ +sie_guest_sca_create (vm); + +/* +* Initialize UV and setup the address spaces needed +* to run a PV guest. +*/ +uv_init (); +uv_setup_asces (); + } +} +#endif
lib/s390x/uv.h +21 -0
@@ -3,6 +3,7 @@#define _S390X_UV_H_#include <sie.h> +#include <asm/pgtable.h> bool uv_os_is_guest (void );bool uv_os_is_host (void );
@@ -14,4 +15,24 @@ void uv_destroy_guest(struct vm *vm);int uv_unpack (struct vm *vm,uint64_t addr,uint64_t len,uint64_t tweak);void uv_verify_load (struct vm *vm); +/* +* To run PV guests we need to setup a few things: +* - A valid primary ASCE that contains the guest memory and has the P bit set. +* - A valid home space ASCE for the UV calls that use home space addresses. +*/ +static inline void uv_setup_asces (void ) +{ +uint64_t asce; + +/* 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); + +/* Copy ASCE into home space CR */ +lctlg (13 , asce); +} +#endif /* UV_H */
Signature · 1 line
2.31.1
[kvm-unit-tests GIT PULL 08/13] s390x: snippets: Add PV support
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
To create a pv-snippet we need to generate an se-header. This can be done using a currently not released tool. This tool creates a se-header similar to genprotimg with the difference that the image itself will not be encrypted.
The image for which we want to create a header must be a binary and padded to 4k. Therefore, we convert the compiled snippet to a binary, padd it to 4k, generate the header and convert it back to s390-64bit elf.
The name of the tool can be specified using the config argument --gen-se-header=. The pv-snipptes will only be built when this option is specified. Furthermore, the Hostkey-Document must be specified. If not the build will be skipped.
The host-snippet relation can be specified using the pv-snippets variable in s390x/Makefile, similar to the non-pv-snippets in 2f6fdb4a (s390x: snippets: Add snippet compilation, 2021-06-22)
--- configure | 8 ++++++ s390x/Makefile | 67 +++++++++++++++++++++++++++++++++++++-------- lib/s390x/snippet.h | 7 +++++ .gitignore | 2 ++ 4 files changed, 73 insertions(+), 11 deletions(-)
configure +8 -0
@@ -26,6 +26,7 @@ target= errata_force=0 erratatxt="$srcdir/errata.txt" host_key_document= +gen_se_header= page_size= earlycon=
@@ -54,6 +55,9 @@ usage() { --host-key-document=HOST_KEY_DOCUMENT Specify the machine-specific host-key document for creating a PVM image with 'genprotimg' (s390x only) + --gen-se-header=GEN_SE_HEADER + Provide an executable to generate a PV header + requires --host-key-document. (s390x-snippets only) --page-size=PAGE_SIZE Specify the page size (translation granule) (4k, 16k or 64k, default is 64k, arm64 only)
@@ -127,6 +131,9 @@ while [[ "$1" = -* ]]; do --host-key-document) host_key_document="$arg" ;; + --gen-se-header) + gen_se_header="$arg" + ;; --page-size) page_size="$arg" ;;
@@ -341,6 +348,7 @@ U32_LONG_FMT=$u32_long WA_DIVIDE=$wa_divide GENPROTIMG=${GENPROTIMG-genprotimg} HOST_KEY_DOCUMENT=$host_key_document +GEN_SE_HEADER=$gen_se_header EOF if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then echo "TARGET=$target" >> config.mak
s390x/Makefile +56 -11
102 lines not on this page · raw message
lib/s390x/snippet.h +7 -0
@@ -14,10 +14,17 @@ _binary_s390x_snippets_##type##_##file##_gbin_start#define SNIPPET_NAME_END (type, file) \ _binary_s390x_snippets_##type##_##file##_gbin_end +#define SNIPPET_HDR_START (type, file) \ + _binary_s390x_snippets_##type##_##file##_hdr_start +#define SNIPPET_HDR_END (type, file) \ + _binary_s390x_snippets_##type##_##file##_hdr_end +/* Returns the length of the snippet */ #define SNIPPET_LEN (type, file) \ ((uintptr_t)SNIPPET_NAME_END(type, file) - (uintptr_t)SNIPPET_NAME_START(type, file)) +#define SNIPPET_HDR_LEN (type, file) \ + ((uintptr_t)SNIPPET_HDR_END(type, file) - (uintptr_t)SNIPPET_HDR_START(type, file))/* * C snippet instructions start at 0x4000 due to the prefix and the
.gitignore +2 -0
@@ -25,3 +25,5 @@ cscope.* /api/dirty-log-perf /s390x/*.bin /s390x/snippets/*/*.gbin +/s390x/snippets/*/*.hdr +/s390x/snippets/*/*.*obj
Signature · 1 line
2.31.1
[kvm-unit-tests GIT PULL 04/13] s390x: sie: Add UV information into VM struct
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
We need to save the handles for the VM and the VCPU so we can retrieve them easily after their creation. Since the SIE lib is single guest cpu only we only save one vcpu handle.
--- lib/s390x/sie.h | 6 ++++++ 1 file changed, 6 insertions(+)
lib/s390x/sie.h +6 -0
@@ -200,6 +200,11 @@ union {uint64_t gvrd;/* 0x01f8 */ } __attribute__((packed)); +struct vm_uv { +uint64_t vm_handle; +uint64_t vcpu_handle; +}; +struct vm_save_regs {uint64_t grs[16 ];uint64_t fprs[16 ];
@@ -220,6 +225,7 @@ struct vm {struct vm_save_area save_area;void *sca;/* System Control Area */ uint8_t *crycb;/* Crypto Control Block */ +struct vm_uv uv;/* PV UV information */ /* Ptr to first guest page */ uint8_t *guest_mem; };
Signature · 1 line
2.31.1
[kvm-unit-tests GIT PULL 06/13] s390x: lib: Extend UV library with PV guest management
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
Let's extend the UV lib with guest 1 code to be able to manage protected VMs in the future.
--- lib/s390x/asm/uv.h | 14 +++++ lib/s390x/sie.h | 3 ++ lib/s390x/uv.h | 7 +++ lib/s390x/uv.c | 128 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 152 insertions(+)
lib/s390x/asm/uv.h +14 -0
@@ -355,4 +355,18 @@ static inline int uv_set_se_hdr(uint64_t handle, void *hdr, size_t len) return uv_call(0, (uint64_t)&uvcb); } +static inline int uv_unp_page (uint64_t handle,uint64_t gaddr,uint64_t tweak1,uint64_t tweak2) +{ +struct uv_cb_unp uvcb = { + .header.cmd =UVC_CMD_UNPACK_IMG , + .header.len =sizeof (uvcb), + .guest_handle = handle, + .gaddr = gaddr, + .tweak[0 ] = tweak1, + .tweak[1 ] = tweak2, + }; + +return uv_call (0 , (uint64_t )&uvcb); +} +#endif
lib/s390x/sie.h +3 -0
@@ -203,6 +203,9 @@ union {struct vm_uv {uint64_t vm_handle;uint64_t vcpu_handle; +void *conf_base_stor; +void *conf_var_stor; +void *cpu_stor; };struct vm_save_regs {
lib/s390x/uv.h +7 -0
@@ -2,9 +2,16 @@#ifndef _S390X_UV_H_#define _S390X_UV_H_ +#include <sie.h> +bool uv_os_is_guest (void );bool uv_os_is_host (void );bool uv_query_test_call (unsigned int nr); +void uv_init (void );int uv_setup (void ); +void uv_create_guest (struct vm *vm); +void uv_destroy_guest (struct vm *vm); +int uv_unpack (struct vm *vm,uint64_t addr,uint64_t len,uint64_t tweak); +void uv_verify_load (struct vm *vm);#endif /* UV_H */
lib/s390x/uv.c +128 -0
142 lines not on this page · raw message
Signature · 1 line
2.31.1
[kvm-unit-tests GIT PULL 03/13] s390x: sie: Add PV fields to SIE control block
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
We need those fields for format 4 SIE tests (protected VMs).
--- lib/s390x/sie.h | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-)
lib/s390x/sie.h +34 -7
@@ -38,7 +38,13 @@ struct kvm_s390_sie_block {uint8_t reserved08[4 ];/* 0x0008 */ #define PROG_IN_SIE (1<<0)uint32_t prog0c;/* 0x000c */ -uint8_t reserved10[16 ];/* 0x0010 */ +union { +uint8_t reserved10[16 ];/* 0x0010 */ +struct { +uint64_t pv_handle_cpu; +uint64_t pv_handle_config; + }; + };#define PROG_BLOCK_SIE (1<<0)#define PROG_REQUEST (1<<1)uint32_t prog20;/* 0x0020 */
@@ -87,10 +93,22 @@ struct kvm_s390_sie_block {#define ICPT_PARTEXEC 0x38#define ICPT_IOINST 0x40#define ICPT_KSS 0x5c +#define ICPT_INT_ENABLE 0x64 +#define ICPT_PV_INSTR 0x68 +#define ICPT_PV_NOTIFY 0x6c +#define ICPT_PV_PREF 0x70uint8_t icptcode;/* 0x0050 */ uint8_t icptstatus;/* 0x0051 */ uint16_t ihcpu;/* 0x0052 */ -uint8_t reserved54[2 ];/* 0x0054 */ +uint8_t reserved54;/* 0x0054 */ +#define IICTL_CODE_NONE 0x00 +#define IICTL_CODE_MCHK 0x01 +#define IICTL_CODE_EXT 0x02 +#define IICTL_CODE_IO 0x03 +#define IICTL_CODE_RESTART 0x04 +#define IICTL_CODE_SPECIFICATION 0x10 +#define IICTL_CODE_OPERAND 0x11 +uint8_t iictl;/* 0x0055 */ uint16_t ipa;/* 0x0056 */ uint32_t ipb;/* 0x0058 */ uint32_t scaoh;/* 0x005c */
@@ -112,7 +130,7 @@ struct kvm_s390_sie_block {#define ECB3_RI 0x01uint8_t ecb3;/* 0x0063 */ uint32_t scaol;/* 0x0064 */ -uint8_t reserved68;/* 0x0068 */ +uint8_t sdf;/* 0x0068 */ uint8_t epdx;/* 0x0069 */ uint8_t reserved6a[2 ];/* 0x006a */ uint32_t todpr;/* 0x006c */
@@ -128,9 +146,15 @@ struct kvm_s390_sie_block {#define HPID_KVM 0x4#define HPID_VSIE 0x5uint8_t hpid;/* 0x00b8 */ -uint8_t reservedb9[11 ];/* 0x00b9 */ -uint16_t extcpuaddr;/* 0x00c4 */ -uint16_t eic;/* 0x00c6 */ +uint8_t reservedb9[7 ];/* 0x00b9 */ +union { +struct { +uint32_t eiparams;/* 0x00c0 */ +uint16_t extcpuaddr;/* 0x00c4 */ +uint16_t eic;/* 0x00c6 */ + }; +uint64_t mcic;/* 0x00c0 */ + } __attribute__ ((__packed__ ));uint32_t reservedc8;/* 0x00c8 */ uint16_t pgmilc;/* 0x00cc */ uint16_t iprcc;/* 0x00ce */
@@ -152,7 +176,10 @@ struct kvm_s390_sie_block {#define CRYCB_FORMAT2 0x00000003uint32_t crycbd;/* 0x00fc */ uint64_t gcr[16 ];/* 0x0100 */ -uint64_t gbea;/* 0x0180 */ +union { +uint64_t gbea;/* 0x0180 */ +uint64_t sidad; + };uint8_t reserved188[8 ];/* 0x0188 */ uint64_t sdnxo;/* 0x0190 */ uint8_t reserved198[8 ];/* 0x0198 */
Signature · 1 line
2.31.1
[kvm-unit-tests GIT PULL 10/13] s390x: mvpg-sie: Use snippet helpers
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
Time to use our shiny new snippet helpers.
--- s390x/mvpg-sie.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-)
s390x/mvpg-sie.c +8 -16
@@ -21,17 +21,12 @@#include <sie.h> #include <snippet.h> -static u8 *guest;static struct vm vm;static uint8_t *src;static uint8_t *dst;static uint8_t *cmp; -extern const char SNIPPET_NAME_START (c ,mvpg_snippet )[]; -extern const char SNIPPET_NAME_END (c ,mvpg_snippet )[]; -int binary_size; -static void test_mvpg_pei (void ) {uint64_t **pei_dst = (uint64_t **)((uintptr_t ) vm.sblk +0xc0 );
@@ -78,9 +73,6 @@ static void test_mvpg_pei(void)static void test_mvpg (void ) { -int binary_size =SNIPPET_LEN (c, mvpg_snippet); - -memcpy (guest,SNIPPET_NAME_START (c, mvpg_snippet), binary_size);memset (src,0x42 ,PAGE_SIZE );memset (dst,0x43 ,PAGE_SIZE );sie (&vm);
@@ -89,20 +81,20 @@ static void test_mvpg(void)static void setup_guest (void ) { -setup_vm (); +extern const char SNIPPET_NAME_START (c ,mvpg_snippet )[]; +extern const char SNIPPET_NAME_END (c ,mvpg_snippet )[]; -/* Allocate 1MB as guest memory */ - guest =alloc_pages (8 ); +setup_vm (); -sie_guest_create (&vm, (uint64_t )guest,HPAGE_SIZE ); +snippet_setup_guest (&vm, false); +snippet_init (&vm,SNIPPET_NAME_START (c, mvpg_snippet), +SNIPPET_LEN (c, mvpg_snippet),SNIPPET_OFF_C ); - vm.sblk->gpsw = snippet_psw; - vm.sblk->ictl =ICTL_OPEREXC |ICTL_PINT ;/* Enable MVPG interpretation as we want to test KVM and not ourselves */ vm.sblk->eca =ECA_MVPGI ; - src = guest +PAGE_SIZE *6 ; - dst = guest +PAGE_SIZE *5 ; + src = (uint8_t *) vm.sblk->mso +PAGE_SIZE *6 ; + dst = (uint8_t *) vm.sblk->mso +PAGE_SIZE *5 ; cmp =alloc_page ();memset (cmp,0 ,PAGE_SIZE ); }
Signature · 1 line
2.31.1
[kvm-unit-tests GIT PULL 11/13] s390x: sie: Add PV diag test
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
Let's start testing the format 4 (PV) SIE via the diagnose instructions since most of them are pretty simple to handle.
The tests check for the intercept values like ipa/ipb and icptcode as well as the values in the registers and handling of the exception injection.
--- s390x/Makefile | 6 + s390x/snippets/asm/snippet-pv-diag-288.S | 25 +++ s390x/snippets/asm/snippet-pv-diag-500.S | 39 +++++ s390x/snippets/asm/snippet-pv-diag-yield.S | 7 + s390x/pv-diags.c | 187 +++++++++++++++++++++ 5 files changed, 264 insertions(+) create mode 100644 s390x/snippets/asm/snippet-pv-diag-288.S create mode 100644 s390x/snippets/asm/snippet-pv-diag-500.S create mode 100644 s390x/snippets/asm/snippet-pv-diag-yield.S create mode 100644 s390x/pv-diags.c
s390x/Makefile +6 -0
@@ -27,6 +27,8 @@ tests += $(TEST_DIR)/mvpg-sie.elf tests += $(TEST_DIR)/spec_ex-sie.elf tests += $(TEST_DIR)/firq.elf +pv-tests += $(TEST_DIR)/pv-diags.elf + ifneq ($(HOST_KEY_DOCUMENT),) ifneq ($(GEN_SE_HEADER),) tests += $(pv-tests)
@@ -99,6 +101,10 @@ 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 + ifneq ($(GEN_SE_HEADER),) snippets += $(pv-snippets) tests += $(pv-tests)
s390x/snippets/asm/snippet-pv-diag-288.S new file +25 -0
@@ -0,0 +1,25 @@ +#include <asm/asm-offsets.h> +.section .text + +/* Clean and pre-load registers that are used for diag 288 */ +xgr %r0, %r0 +xgr %r1, %r1 +xgr %r3, %r3 +lghi %r0, 1 +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 + +/* Execute the diag288 */ +diag %r0, %r2, 0x288 + +/* Force exit if we don't get a PGM */ +diag 0, 0, 0x44 + +/* Communicate the PGM code via diag9c(easiest) */ +exit_pgm: +lh %r1, GEN_LC_PGM_INT_CODE +diag %r1, 0, 0x9c
s390x/snippets/asm/snippet-pv-diag-500.S new file +39 -0
@@ -0,0 +1,39 @@ +#include <asm/asm-offsets.h> +.section .text + +/* Clean and pre-load registers that are used for diag 500 */ +xgr %r1, %r1 +xgr %r2, %r2 +xgr %r3, %r3 +xgr %r4, %r4 +lghi %r1, 1 +lghi %r2, 2 +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 + +/* Execute the diag500 */ +diag 0, 0, 0x500 + +/* Should never be executed because of the PGM */ +diag 0, 0, 0x44 + +/* Execute again to test spec PGM injection*/ +next: +lh %r1, GEN_LC_PGM_INT_CODE +diag %r1, 0, 0x9c +larl %r5, done +stg %r5, GEN_LC_PGM_NEW_PSW + 8 +diag 0, 0, 0x500 + +/* Should never be executed because of the PGM */ +diag 0, 0, 0x44 + +done: +lh %r1, GEN_LC_PGM_INT_CODE +diag %r1, 0, 0x9c
s390x/snippets/asm/snippet-pv-diag-yield.S new file +7 -0
@@ -0,0 +1,7 @@ +.section .text + +xgr %r0, %r0 +xgr %r1, %r1 +diag 0,0,0x44 +lghi %r1, 42 +diag 1,0,0x9c
s390x/pv-diags.c new file +187 -0
187 lines not on this page · raw message
Signature · 1 line
2.31.1
[kvm-unit-tests GIT PULL 12/13] s390x: smp: Allocate memory in DMA31 space
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
The store status at address order works with 31 bit addresses so let's use them.
--- s390x/smp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
s390x/smp.c +2 -2
@@ -121,7 +121,7 @@ static void test_stop_store_status(void)static void test_store_status (void ) { -struct cpu_status *status =alloc_pages (1 ); +struct cpu_status *status =alloc_pages_flags (1 ,AREA_DMA31 );uint32_t r;report_prefix_push ("store status at address" );
@@ -241,7 +241,7 @@ static void test_func_initial(void)static void test_reset_initial (void ) { -struct cpu_status *status =alloc_pages (0 ); +struct cpu_status *status =alloc_pages_flags (0 ,AREA_DMA31 );struct psw psw;int i;
Signature · 1 line
2.31.1
[kvm-unit-tests GIT PULL 13/13] s390x: firq: Fix sclp buffer allocation
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
We need a 32 bit address for the sclp buffer so let's use a page from the first 31 bits.
--- s390x/firq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
s390x/firq.c +1 -1
@@ -87,7 +87,7 @@ static void test_wait_state_delivery(void)*/ while (smp_sense_running_status (1 )); - h =alloc_page (); + h =alloc_pages_flags (0 ,AREA_DMA31 ); h->length =4096 ; ret =servc (SCLP_CMDW_READ_CPU_INFO ,__pa (h));if (ret) {
Signature · 1 line
2.31.1
[kvm-unit-tests GIT PULL 05/13] s390x: uv: Add more UV call functions
In reply to Claudio ImbrendaFrom: Janosch Frank <[email protected]>
To manage protected guests we need a few more UV calls:
* import / export
* destroy page
* set SE header
* set cpu state
--- lib/s390x/asm/uv.h | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+)
lib/s390x/asm/uv.h +85 -0
@@ -33,6 +33,7 @@#define UVC_CMD_DESTROY_SEC_CPU 0x0121#define UVC_CMD_CONV_TO_SEC_STOR 0x0200#define UVC_CMD_CONV_FROM_SEC_STOR 0x0201 +#define UVC_CMD_DESTR_SEC_STOR 0x0202#define UVC_CMD_SET_SEC_CONF_PARAMS 0x0300#define UVC_CMD_UNPACK_IMG 0x0301#define UVC_CMD_VERIFY_IMG 0x0302
@@ -256,6 +257,63 @@ static inline int uv_remove_shared(unsigned long addr)return share (addr,UVC_CMD_REMOVE_SHARED_ACCESS ); } +static inline int uv_cmd_nodata (uint64_t handle,uint16_t cmd,uint16_t *rc,uint16_t *rrc) +{ +struct uv_cb_nodata uvcb = { + .header.cmd = cmd, + .header.len =sizeof (uvcb), + .handle = handle, + }; +int cc; + +assert (handle); + cc =uv_call (0 , (uint64_t )&uvcb); + *rc = uvcb.header.rc; + *rrc = uvcb.header.rrc; +return cc; +} + +static inline int uv_import (uint64_t handle,unsigned long gaddr) +{ +struct uv_cb_cts uvcb = { + .header.cmd =UVC_CMD_CONV_TO_SEC_STOR , + .header.len =sizeof (uvcb), + .guest_handle = handle, + .gaddr = gaddr, + }; + +return uv_call (0 , (uint64_t )&uvcb); +} + +static inline int uv_export (unsigned long paddr) +{ +struct uv_cb_cfs uvcb = { + .header.cmd =UVC_CMD_CONV_FROM_SEC_STOR , + .header.len =sizeof (uvcb), + .paddr = paddr + }; + +return uv_call (0 , (u64)&uvcb); +} + +/* +* Requests the Ultravisor to destroy a guest page and make it +* accessible to the host. The destroy clears the page instead of +* exporting. +* +* @paddr: Absolute host address of page to be destroyed +*/ +static inline int uv_destroy_page (unsigned long paddr) +{ +struct uv_cb_cfs uvcb = { + .header.cmd =UVC_CMD_DESTR_SEC_STOR , + .header.len =sizeof (uvcb), + .paddr = paddr + }; + +return uv_call (0 , (uint64_t )&uvcb); +} +struct uv_cb_cpu_set_state {struct uv_cb_header header;u64 reserved08[2 ];
@@ -270,4 +328,31 @@ struct uv_cb_cpu_set_state {#define PV_CPU_STATE_CHKSTP 3#define PV_CPU_STATE_OPR_LOAD 5 +static inline int uv_set_cpu_state (uint64_t handle,uint8_t state) +{ +struct uv_cb_cpu_set_state uvcb = { + .header.cmd =UVC_CMD_CPU_SET_STATE , + .header.len =sizeof (uvcb), + .cpu_handle = handle, + .state = state, + }; + +assert (handle); +return uv_call (0 , (uint64_t )&uvcb); +} + +static inline int uv_set_se_hdr (uint64_t handle,void *hdr,size_t len) +{ +struct uv_cb_ssc uvcb = { + .header.cmd =UVC_CMD_SET_SEC_CONF_PARAMS , + .header.len =sizeof (uvcb), + .sec_header_origin = (uint64_t )hdr, + .sec_header_len = len, + .guest_handle = handle, + }; + +assert (handle); +return uv_call (0 , (uint64_t )&uvcb); +} +#endif
Signature · 1 line
2.31.1