s390x: sie: Add PV snippet support
cover s390x: sie: Add PV snippet support
Adding PV virtualization support was only a matter of time so here it is.
The biggest problem that needed solving was having the SE header as a separate file. The genprotimg tool generates the header and adds a short bit of code to the image which will put the guest into PV mode via the diagnose 308 PV subcodes. We don't have and want an emulation for the diagnose so we don't support this way of starting a PV guest.
Therefore we needed a new tool that generates the PV image separate from the SE header so we can link both as binary blobs. Marc created this tool by writing a library which lets users create a SE header and has bindings to multiple languages. Unfortunately we didn't yet have time to upstream this but we plan to publish it once we find some.
The first PV snippet test checks the "easy" diagnose calls 0x44, 0x9c, 0x288 and 0x500. We check register contents and responses to PGM injects.
A huge thanks goes out to Steffen and Marc who helped me make this possible.
Janosch Frank (8):
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
s390x: sie: Add PV diag test
.gitignore | 2 + configure | 8 + lib/s390x/asm/uv.h | 99 +++++++++ lib/s390x/sie.c | 20 ++ lib/s390x/sie.h | 54 ++++- lib/s390x/snippet.h | 7 + lib/s390x/uv.c | 128 +++++++++++ lib/s390x/uv.h | 7 + s390x/Makefile | 74 ++++++- s390x/pv-diags.c | 240 +++++++++++++++++++++ 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 + 13 files changed, 692 insertions(+), 18 deletions(-) create mode 100644 s390x/pv-diags.c 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
Signature · 1 line
2.32.0
PATCH 1/8 lib: s390x: sie: Add sca allocation and freeing
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.c | 12 ++++++++++++ lib/s390x/sie.h | 2 ++ 2 files changed, 14 insertions(+)
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); }
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);
Signature · 1 line
2.32.0
Re: [kvm-unit-tests PATCH 1/8] lib: s390x: sie: Add sca allocation and freeing
Quoted 6 lines · On Tue, 23 Nov 2021 10:39:49 +0000 Janosch Frank <[email protected]> wrote:
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.
Signed-off-by Janosch Frank <[email protected]>
Quoted 53 lines
--- lib/s390x/sie.c | 12 ++++++++++++ lib/s390x/sie.h | 2 ++ 2 files changed, 14 insertions(+)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); }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);
PATCH 2/8 s390x: sie: Add PV fields to SIE control block
In reply to Janosch FrankWe 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.32.0
Re: [kvm-unit-tests PATCH 2/8] s390x: sie: Add PV fields to SIE control block
Quoted 3 lines · On Tue, 23 Nov 2021 10:39:50 +0000 Janosch Frank <[email protected]> wrote:
We need those fields for format 4 SIE tests (protected VMs).
Signed-off-by Janosch Frank <[email protected]>
Quoted 87 lines
--- 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 */
PATCH 3/8 s390x: sie: Add UV information into VM struct
In reply to Janosch FrankWe 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.32.0
Re: [kvm-unit-tests PATCH 3/8] s390x: sie: Add UV information into VM struct
Quoted 2 lines · On Tue, 23 Nov 2021 10:39:51 +0000 Janosch Frank <[email protected]> wrote:
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
multiple guest CPUs will be needed for testing some functions, but I guess that's something for me to do :)
Quoted 3 lines
cpu only we only save one vcpu handle.
Signed-off-by Janosch Frank <[email protected]>
Quoted 28 lines
--- 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; };
Re: [kvm-unit-tests PATCH 3/8] s390x: sie: Add UV information into VM struct
Quoted 8 lines · Claudio Imbrenda
Quoted 2 lines · On Tue, 23 Nov 2021 10:39:51 +0000 Janosch Frank <[email protected]> wrote:
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
multiple guest CPUs will be needed for testing some functions, but I guess that's something for me to do :)
I would be happy if someone picks this up. Just let me know if you do so I can plan accordingly.
Quoted 6 lines
Quoted 4 lines
cpu only we only save one vcpu handle.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Claudio Imbrenda <[email protected]>
Thanks!
Quoted 30 lines
Quoted 29 lines
--- 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; };
PATCH 4/8 s390x: uv: Add more UV call functions
In reply to Janosch FrankTo 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.32.0
Re: [kvm-unit-tests PATCH 4/8] s390x: uv: Add more UV call functions
Quoted 7 lines · On Tue, 23 Nov 2021 10:39:52 +0000 Janosch Frank <[email protected]> wrote:
To manage protected guests we need a few more UV calls:
* import / export
* destroy page
* set SE header
* set cpu stateSigned-off-by Janosch Frank <[email protected]>
Quoted 112 lines
--- 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
PATCH 5/8 s390x: lib: Extend UV library with PV guest management
In reply to Janosch FrankLet'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.c | 128 +++++++++++++++++++++++++++++++++++++++++++++ lib/s390x/uv.h | 7 +++ 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.c +128 -0
142 lines not on this page · raw message
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 */
Signature · 1 line
2.32.0
Re: [kvm-unit-tests PATCH 5/8] s390x: lib: Extend UV library with PV guest management
Quoted 4 lines · On Tue, 23 Nov 2021 10:39:53 +0000 Janosch Frank <[email protected]> wrote:
Let's extend the UV lib with guest 1 code to be able to manage protected VMs in the future.
Signed-off-by Janosch Frank <[email protected]>
Quoted 213 lines
--- lib/s390x/asm/uv.h | 14 +++++ lib/s390x/sie.h | 3 ++ lib/s390x/uv.c | 128 +++++++++++++++++++++++++++++++++++++++++++++ lib/s390x/uv.h | 7 +++ 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.c +128
-0@@ -17,11 +17,14 @@#include <asm/facility.h> #include <asm/uv.h> #include <uv.h> +#include <sie.h> static struct uv_cb_qui uvcb_qui = { .header.cmd =UVC_CMD_QUI , .header.len =sizeof (uvcb_qui), }; +static uint64_t uv_init_mem; +bool uv_os_is_guest (void ) {@@ -54,3 +57,128 @@ int uv_setup(void)assert (uvcb_qui.header.rc ==1 || uvcb_qui.header.rc ==0x100 );return 1 ; } + +void uv_init (void ) +{ +struct uv_cb_init uvcb_init = { + .header.len =sizeof (uvcb_init), + .header.cmd =UVC_CMD_INIT_UV , + }; +static bool initialized; +int cc; + +/* Let's not do this twice */ +assert (!initialized); +/* Query is done on initialization but let's check anyway */ +assert (uvcb_qui.header.rc ==1 || uvcb_qui.header.rc ==0x100 ); + +/* Donated storage needs to be over 2GB aligned to 1MB */ + uv_init_mem = (uint64_t )memalign_pages_flags (HPAGE_SIZE , uvcb_qui.uv_base_stor_len,AREA_NORMAL ); + uvcb_init.stor_origin = uv_init_mem; + uvcb_init.stor_len = uvcb_qui.uv_base_stor_len; + + cc =uv_call (0 , (uint64_t )&uvcb_init); +assert (cc ==0 ); + initialized = true; +} + +void uv_create_guest (struct vm *vm) +{ +struct uv_cb_cgc uvcb_cgc = { + .header.cmd =UVC_CMD_CREATE_SEC_CONF , + .header.len =sizeof (uvcb_cgc), + }; +struct uv_cb_csc uvcb_csc = { + .header.len =sizeof (uvcb_csc), + .header.cmd =UVC_CMD_CREATE_SEC_CPU , + .state_origin = (uint64_t )vm->sblk, + .num =0 , + }; +unsigned long vsize; +int cc; + + uvcb_cgc.guest_stor_origin = vm->sblk->mso; + uvcb_cgc.guest_stor_len = vm->sblk->msl; + +/* Config allocation */ + vsize = uvcb_qui.conf_base_virt_stor_len + + ((uvcb_cgc.guest_stor_len /HPAGE_SIZE ) * uvcb_qui.conf_virt_var_stor_len); + + vm->uv.conf_base_stor =memalign_pages_flags (PAGE_SIZE *4 , uvcb_qui.conf_base_phys_stor_len,0 ); +/* +* This allocation needs to be below the max guest storage +* address so let's simply put it into the physical memory +*/ + vm->uv.conf_var_stor =memalign_pages_flags (PAGE_SIZE , vsize,0 ); + uvcb_cgc.conf_base_stor_origin = (uint64_t )vm->uv.conf_base_stor; + uvcb_cgc.conf_var_stor_origin = (uint64_t )vm->uv.conf_var_stor; + +/* CPU allocation */ + vm->uv.cpu_stor =memalign_pages_flags (PAGE_SIZE , uvcb_qui.cpu_stor_len,0 ); + uvcb_csc.stor_origin = (uint64_t )vm->uv.cpu_stor; + + uvcb_cgc.guest_asce = (uint64_t )stctg (1 ); + uvcb_cgc.guest_sca = (uint64_t )vm->sca; + + cc =uv_call (0 , (uint64_t )&uvcb_cgc); +assert (!cc); + + vm->uv.vm_handle = uvcb_cgc.guest_handle; + uvcb_csc.guest_handle = uvcb_cgc.guest_handle; + cc =uv_call (0 , (uint64_t )&uvcb_csc); + vm->uv.vcpu_handle = uvcb_csc.cpu_handle; +assert (!cc); + +/* +* Convert guest to format 4: +* +* - Set format 4 +* - Write UV handles into sblk +* - Allocate and set SIDA +*/ + vm->sblk->sdf =2 ; + vm->sblk->sidad = (uint64_t )alloc_page (); + vm->sblk->pv_handle_cpu = uvcb_csc.cpu_handle; + vm->sblk->pv_handle_config = uvcb_cgc.guest_handle; +} + +void uv_destroy_guest (struct vm *vm) +{ +int cc; +u16 rc, rrc; + + cc =uv_cmd_nodata (vm->sblk->pv_handle_cpu, +UVC_CMD_DESTROY_SEC_CPU , &rc, &rrc); +assert (cc ==0 ); +free_page ((void *)vm->sblk->sidad); +free_pages (vm->uv.cpu_stor); + + cc =uv_cmd_nodata (vm->sblk->pv_handle_config, +UVC_CMD_DESTROY_SEC_CONF , &rc, &rrc); +assert (cc ==0 ); +free_pages (vm->uv.conf_base_stor); +free_pages (vm->uv.conf_var_stor); +} + +int uv_unpack (struct vm *vm,uint64_t addr,uint64_t len,uint64_t tweak) +{ +int i, cc; + +for (i =0 ; i < len /PAGE_SIZE ; i++) { + cc =uv_unp_page (vm->uv.vm_handle, addr, tweak, i *PAGE_SIZE ); +assert (!cc); + addr +=PAGE_SIZE ; + } +return cc; +} + +void uv_verify_load (struct vm *vm) +{ +uint16_t rc, rrc; +int cc; + + cc =uv_cmd_nodata (vm->uv.vm_handle,UVC_CMD_VERIFY_IMG , &rc, &rrc); +assert (!cc); + cc =uv_set_cpu_state (vm->uv.vcpu_handle,PV_CPU_STATE_OPR_LOAD ); +assert (!cc); +}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 */
PATCH 6/8 lib: s390: sie: Add PV guest register handling
In reply to Janosch FrankProtected 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.c | 8 ++++++++ lib/s390x/sie.h | 2 ++ 2 files changed, 10 insertions(+)
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)
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 {
Signature · 1 line
2.32.0
Re: [kvm-unit-tests PATCH 6/8] lib: s390: sie: Add PV guest register handling
Quoted 5 lines · On Tue, 23 Nov 2021 10:39:54 +0000 Janosch Frank <[email protected]> wrote:
Protected guests have their registers stored to / loaded from offset
0x380of 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.Signed-off-by Janosch Frank <[email protected]>
Quoted 44 lines
--- lib/s390x/sie.c | 8 ++++++++ lib/s390x/sie.h | 2 ++ 2 files changed, 10 insertions(+)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)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 {
PATCH 7/8 s390x: snippets: Add PV support
In reply to Janosch FrankTo 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)
--- .gitignore | 2 ++ configure | 8 ++++++ lib/s390x/snippet.h | 7 +++++ s390x/Makefile | 67 +++++++++++++++++++++++++++++++++++++-------- 4 files changed, 73 insertions(+), 11 deletions(-)
.gitignore +2 -0
@@ -25,3 +25,5 @@ cscope.* /api/dirty-log-perf /s390x/*.bin /s390x/snippets/*/*.gbin +/s390x/snippets/*/*.hdr +/s390x/snippets/*/*.*obj
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
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
s390x/Makefile +56 -11
102 lines not on this page · raw message
Signature · 1 line
2.32.0
Re: [kvm-unit-tests PATCH 7/8] s390x: snippets: Add PV support
Quoted 15 lines · On Tue, 23 Nov 2021 10:39:55 +0000 Janosch Frank <[email protected]> wrote:
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
genprotimgwith 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.
Quoted 5 lines
The host-snippet relation can be specified using the
pv-snippetsvariable in s390x/Makefile, similar to the non-pv-snippets in2f6fdb4a(s390x: snippets: Add snippet compilation, 2021-06-22)Signed-off-by Steffen Eiden <[email protected]>
but see a comment below
Quoted 140 lines
--- .gitignore | 2 ++ configure | 8 ++++++ lib/s390x/snippet.h | 7 +++++ s390x/Makefile | 67 +++++++++++++++++++++++++++++++++++++-------- 4 files changed, 73 insertions(+), 11 deletions(-).gitignore +2
-0@@ -25,3 +25,5 @@ cscope.* /api/dirty-log-perf /s390x/*.bin /s390x/snippets/*/*.gbin +/s390x/snippets/*/*.hdr +/s390x/snippets/*/*.*objconfigure +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.maklib/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 s390x/Makefile +29
-4@@ -26,12 +26,20 @@ tests += $(TEST_DIR)/edat.elf tests += $(TEST_DIR)/mvpg-sie.elf tests += $(TEST_DIR)/spec_ex-sie.elf +ifneq ($(HOST_KEY_DOCUMENT),) +ifneq ($(GEN_SE_HEADER),) +tests += $(pv-tests) +endif +endif + tests_binary = $(patsubst %.elf,%.bin,$(tests)) ifneq ($(HOST_KEY_DOCUMENT),) tests_pv_binary = $(patsubst %.bin,%.pv.bin,$(tests_binary)) else tests_pv_binary = +GEN_SE_HEADER = endif +snippets-obj = $(patsubst %.gbin,%.gobj,$(snippets)) all: directories test_cases test_cases_binary test_cases_pv@@ -82,26 +90,59 @@ asmlib = $(TEST_DIR)/cstart64.o $(TEST_DIR)/cpu.o FLATLIBS = $(libcflat) SNIPPET_DIR = $(TEST_DIR)/snippets -snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o lib/auxinfo.o +snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o +snippet_lib = $(snippet_asmlib) lib/auxinfo.o # perquisites (=guests) for the snippet hosts. # $(TEST_DIR)/<snippet-host>.elf: snippets = $(SNIPPET_DIR)/<c/asm>/<snippet>.gbin $(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 -$(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o $(FLATLIBS) - $(OBJCOPY) -O binary $(patsubst %.gbin,%.o,$@) $@ - $(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $@ $@ +ifneq ($(GEN_SE_HEADER),) +snippets += $(pv-snippets) +tests += $(pv-tests) +snippet-hdr-obj = $(patsubst %.gbin,%.hdr.obj,$(pv-snippets)) +else +snippet-hdr-obj = +endif + +# the asm/c snippets %.o have additional generated files as dependencies +$(SNIPPET_DIR)/asm/%.o: $(SNIPPET_DIR)/asm/%.S $(asm-offsets) + $(CC) $(CFLAGS) -c -nostdlib -o $@ $< + +$(SNIPPET_DIR)/c/%.o: $(SNIPPET_DIR)/c/%.c $(asm-offsets) + $(CC) $(CFLAGS) -c -nostdlib -o $@ $< + +$(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o + $(OBJCOPY) -O binary -j ".rodata" -j ".text" -j ".data" -j ".bss" --set-section-flags .bss=alloc,load,contents $(patsubst %.gbin,%.o,$@) $@ + truncate -s '%4096' $@ +
s390x/Makefile asmlib = $(TEST_DIR)/cstart64.o $(TEST_DIR)/cpu.o · line 129
Quoted 10 lines
s390x/Makefile +10
-0+$(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_lib) $(FLATLIBS) + $(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/snippets/c/flat.lds $(patsubst %.gbin,%.o,$@) $(snippet_lib) $(FLATLIBS) + $(OBJCOPY) -O binary -j ".rodata" -j ".lowcore" -j ".text" -j ".data" -j ".bss" --set-section-flags .bss=alloc,load,contents $@ $@ + truncate -s '%4096' $@ + +$(SNIPPET_DIR)/asm/%.hdr: $(SNIPPET_DIR)/asm/%.gbin $(HOST_KEY_DOCUMENT) + $(GEN_SE_HEADER) -k $(HOST_KEY_DOCUMENT) -c $<,0x4000,0x00000000000000420000000000000000 --psw-addr 0x4000 -o $@ + +$(SNIPPET_DIR)/c/%.hdr: $(SNIPPET_DIR)/c/%.gbin $(HOST_KEY_DOCUMENT) + $(GEN_SE_HEADER) -k $(HOST_KEY_DOCUMENT) -c $<,0x0,0x00000000000000420000000000000000 --psw-addr 0x4000 -o $@
are they supposed to have different addresses? the C files start at 0x4000, while the asm ones at 0
Quoted 39 lines
s390x/Makefile +17
-7+ +.SECONDARY: +%.gobj: %.gbin + $(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@ + +.SECONDARY: +%.hdr.obj: %.hdr + $(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@ -$(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_asmlib) $(FLATLIBS) - $(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/snippets/c/flat.lds $(patsubst %.gbin,%.o,$@) $(snippet_asmlib) $(FLATLIBS) - $(OBJCOPY) -O binary $@ $@ - $(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $@ $@ .SECONDEXPANSION: -%.elf: $$(snippets) %.o $(FLATLIBS) $(SRCDIR)/s390x/flat.lds $(asmlib) +%.elf: $(FLATLIBS) $(asmlib) $(SRCDIR)/s390x/flat.lds $$(snippets-obj) $$(snippet-hdr-obj) %.o $(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(SRCDIR)/lib/auxinfo.c -DPROGNAME=\"$@\" - $(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/flat.lds $(filter %.o, $^) $(FLATLIBS) $(snippets) $(@:.elf=.aux.o) + @$(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/flat.lds \ + $(filter %.o, $^) $(FLATLIBS) $(snippets-obj) $(snippet-hdr-obj) $(@:.elf=.aux.o) || \ + { echo "Failure probably caused by missing definition of gen-se-header executable"; exit 1; } $(RM) $(@:.elf=.aux.o) @chmod a-x $@@@ -114,8 +155,12 @@ $(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_asmlib) $(FLATLIBS) %.pv.bin: %.bin $(HOST_KEY_DOCUMENT) $(GENPROTIMG) --host-key-document $(HOST_KEY_DOCUMENT) --no-verify --image $< -o $@ +$(snippet_asmlib): $$(patsubst %.o,%.S,$$@) $(asm-offsets) + $(CC) $(CFLAGS) -c -nostdlib -o $@ $< + + arch_clean: asm_offsets_clean - $(RM) $(TEST_DIR)/*.{o,elf,bin} $(TEST_DIR)/.*.d $(SNIPPET_DIR)/c/*.{o,gbin} $(SNIPPET_DIR)/c/.*.d lib/s390x/.*.d + $(RM) $(TEST_DIR)/*.{o,elf,bin} $(SNIPPET_DIR)/*/*.{o,elf,*bin,*obj,hdr} $(SNIPPET_DIR)/asm/.*.d $(TEST_DIR)/.*.d lib/s390x/.*.d generated-files = $(asm-offsets) $(tests:.elf=.o) $(asmlib) $(cflatobjs): $(generated-files)
Re: [kvm-unit-tests PATCH 7/8] s390x: snippets: Add PV support
Quoted 173 lines · Claudio Imbrenda
Quoted 15 lines · On Tue, 23 Nov 2021 10:39:55 +0000 Janosch Frank <[email protected]> wrote:
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
genprotimgwith 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.Quoted 5 lines
The host-snippet relation can be specified using the
pv-snippetsvariable in s390x/Makefile, similar to the non-pv-snippets in2f6fdb4a(s390x: snippets: Add snippet compilation, 2021-06-22)Signed-off-by Steffen Eiden <[email protected]>Reviewed-by Claudio Imbrenda <[email protected]>but see a comment below
Quoted 145 lines
--- .gitignore | 2 ++ configure | 8 ++++++ lib/s390x/snippet.h | 7 +++++ s390x/Makefile | 67 +++++++++++++++++++++++++++++++++++++-------- 4 files changed, 73 insertions(+), 11 deletions(-).gitignore +2
-0@@ -25,3 +25,5 @@ cscope.* /api/dirty-log-perf /s390x/*.bin /s390x/snippets/*/*.gbin +/s390x/snippets/*/*.hdr +/s390x/snippets/*/*.*objconfigure +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.maklib/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 s390x/Makefile +34
-4@@ -26,12 +26,20 @@ tests += $(TEST_DIR)/edat.elf tests += $(TEST_DIR)/mvpg-sie.elf tests += $(TEST_DIR)/spec_ex-sie.elf +ifneq ($(HOST_KEY_DOCUMENT),) +ifneq ($(GEN_SE_HEADER),) +tests += $(pv-tests) +endif +endif + tests_binary = $(patsubst %.elf,%.bin,$(tests)) ifneq ($(HOST_KEY_DOCUMENT),) tests_pv_binary = $(patsubst %.bin,%.pv.bin,$(tests_binary)) else tests_pv_binary = +GEN_SE_HEADER = endif +snippets-obj = $(patsubst %.gbin,%.gobj,$(snippets)) all: directories test_cases test_cases_binary test_cases_pv@@ -82,26 +90,59 @@ asmlib = $(TEST_DIR)/cstart64.o $(TEST_DIR)/cpu.o FLATLIBS = $(libcflat) SNIPPET_DIR = $(TEST_DIR)/snippets -snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o lib/auxinfo.o +snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o +snippet_lib = $(snippet_asmlib) lib/auxinfo.o # perquisites (=guests) for the snippet hosts. # $(TEST_DIR)/<snippet-host>.elf: snippets = $(SNIPPET_DIR)/<c/asm>/<snippet>.gbin $(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 -$(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o $(FLATLIBS) - $(OBJCOPY) -O binary $(patsubst %.gbin,%.o,$@) $@ - $(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $@ $@ +ifneq ($(GEN_SE_HEADER),) +snippets += $(pv-snippets) +tests += $(pv-tests) +snippet-hdr-obj = $(patsubst %.gbin,%.hdr.obj,$(pv-snippets)) +else +snippet-hdr-obj = +endif + +# the asm/c snippets %.o have additional generated files as dependencies +$(SNIPPET_DIR)/asm/%.o: $(SNIPPET_DIR)/asm/%.S $(asm-offsets) + $(CC) $(CFLAGS) -c -nostdlib -o $@ $< + +$(SNIPPET_DIR)/c/%.o: $(SNIPPET_DIR)/c/%.c $(asm-offsets) + $(CC) $(CFLAGS) -c -nostdlib -o $@ $< + +$(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o + $(OBJCOPY) -O binary -j ".rodata" -j ".text" -j ".data" -j ".bss" --set-section-flags .bss=alloc,load,contents $(patsubst %.gbin,%.o,$@) $@ + truncate -s '%4096' $@ + +$(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_lib) $(FLATLIBS) + $(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/snippets/c/flat.lds $(patsubst %.gbin,%.o,$@) $(snippet_lib) $(FLATLIBS) + $(OBJCOPY) -O binary -j ".rodata" -j ".lowcore" -j ".text" -j ".data" -j ".bss" --set-section-flags .bss=alloc,load,contents $@ $@ + truncate -s '%4096' $@ +
Quoted 8 lines
s390x/Makefile asmlib = $(TEST_DIR)/cstart64.o $(TEST_DIR)/cpu.o · line 129
Quoted 5 lines
s390x/Makefile +5
-0+$(SNIPPET_DIR)/asm/%.hdr: $(SNIPPET_DIR)/asm/%.gbin $(HOST_KEY_DOCUMENT) + $(GEN_SE_HEADER) -k $(HOST_KEY_DOCUMENT) -c $<,0x4000,0x00000000000000420000000000000000 --psw-addr 0x4000 -o $@ + +$(SNIPPET_DIR)/c/%.hdr: $(SNIPPET_DIR)/c/%.gbin $(HOST_KEY_DOCUMENT) + $(GEN_SE_HEADER) -k $(HOST_KEY_DOCUMENT) -c $<,0x0,0x00000000000000420000000000000000 --psw-addr 0x4000 -o $@are they supposed to have different addresses? the C files start at
0x4000, while the asm ones at 0
That's a mistake I'll need to fix.
Quoted 41 lines
Quoted 40 lines
s390x/Makefile +17
-7+ +.SECONDARY: +%.gobj: %.gbin + $(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@ + +.SECONDARY: +%.hdr.obj: %.hdr + $(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@ -$(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_asmlib) $(FLATLIBS) - $(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/snippets/c/flat.lds $(patsubst %.gbin,%.o,$@) $(snippet_asmlib) $(FLATLIBS) - $(OBJCOPY) -O binary $@ $@ - $(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $@ $@ .SECONDEXPANSION: -%.elf: $$(snippets) %.o $(FLATLIBS) $(SRCDIR)/s390x/flat.lds $(asmlib) +%.elf: $(FLATLIBS) $(asmlib) $(SRCDIR)/s390x/flat.lds $$(snippets-obj) $$(snippet-hdr-obj) %.o $(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(SRCDIR)/lib/auxinfo.c -DPROGNAME=\"$@\" - $(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/flat.lds $(filter %.o, $^) $(FLATLIBS) $(snippets) $(@:.elf=.aux.o) + @$(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/flat.lds \ + $(filter %.o, $^) $(FLATLIBS) $(snippets-obj) $(snippet-hdr-obj) $(@:.elf=.aux.o) || \ + { echo "Failure probably caused by missing definition of gen-se-header executable"; exit 1; } $(RM) $(@:.elf=.aux.o) @chmod a-x $@@@ -114,8 +155,12 @@ $(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_asmlib) $(FLATLIBS) %.pv.bin: %.bin $(HOST_KEY_DOCUMENT) $(GENPROTIMG) --host-key-document $(HOST_KEY_DOCUMENT) --no-verify --image $< -o $@ +$(snippet_asmlib): $$(patsubst %.o,%.S,$$@) $(asm-offsets) + $(CC) $(CFLAGS) -c -nostdlib -o $@ $< + + arch_clean: asm_offsets_clean - $(RM) $(TEST_DIR)/*.{o,elf,bin} $(TEST_DIR)/.*.d $(SNIPPET_DIR)/c/*.{o,gbin} $(SNIPPET_DIR)/c/.*.d lib/s390x/.*.d + $(RM) $(TEST_DIR)/*.{o,elf,bin} $(SNIPPET_DIR)/*/*.{o,elf,*bin,*obj,hdr} $(SNIPPET_DIR)/asm/.*.d $(TEST_DIR)/.*.d lib/s390x/.*.d generated-files = $(asm-offsets) $(tests:.elf=.o) $(asmlib) $(cflatobjs): $(generated-files)
Re: [kvm-unit-tests PATCH 7/8] s390x: snippets: Add PV support
Quoted 183 lines · Janosch Frank
Quoted 173 lines · Claudio Imbrenda
Quoted 15 lines · On Tue, 23 Nov 2021 10:39:55 +0000 Janosch Frank <[email protected]> wrote:
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
genprotimgwith 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.Quoted 5 lines
The host-snippet relation can be specified using the
pv-snippetsvariable in s390x/Makefile, similar to the non-pv-snippets in2f6fdb4a(s390x: snippets: Add snippet compilation, 2021-06-22)Signed-off-by Steffen Eiden <[email protected]>Reviewed-by Claudio Imbrenda <[email protected]>but see a comment below
Quoted 145 lines
--- .gitignore | 2 ++ configure | 8 ++++++ lib/s390x/snippet.h | 7 +++++ s390x/Makefile | 67 +++++++++++++++++++++++++++++++++++++-------- 4 files changed, 73 insertions(+), 11 deletions(-).gitignore +2
-0@@ -25,3 +25,5 @@ cscope.* /api/dirty-log-perf /s390x/*.bin /s390x/snippets/*/*.gbin +/s390x/snippets/*/*.hdr +/s390x/snippets/*/*.*objconfigure +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.maklib/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 s390x/Makefile +34
-4@@ -26,12 +26,20 @@ tests += $(TEST_DIR)/edat.elf tests += $(TEST_DIR)/mvpg-sie.elf tests += $(TEST_DIR)/spec_ex-sie.elf +ifneq ($(HOST_KEY_DOCUMENT),) +ifneq ($(GEN_SE_HEADER),) +tests += $(pv-tests) +endif +endif + tests_binary = $(patsubst %.elf,%.bin,$(tests)) ifneq ($(HOST_KEY_DOCUMENT),) tests_pv_binary = $(patsubst %.bin,%.pv.bin,$(tests_binary)) else tests_pv_binary = +GEN_SE_HEADER = endif +snippets-obj = $(patsubst %.gbin,%.gobj,$(snippets)) all: directories test_cases test_cases_binary test_cases_pv@@ -82,26 +90,59 @@ asmlib = $(TEST_DIR)/cstart64.o $(TEST_DIR)/cpu.o FLATLIBS = $(libcflat) SNIPPET_DIR = $(TEST_DIR)/snippets -snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o lib/auxinfo.o +snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o +snippet_lib = $(snippet_asmlib) lib/auxinfo.o # perquisites (=guests) for the snippet hosts. # $(TEST_DIR)/<snippet-host>.elf: snippets = $(SNIPPET_DIR)/<c/asm>/<snippet>.gbin $(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 -$(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o $(FLATLIBS) - $(OBJCOPY) -O binary $(patsubst %.gbin,%.o,$@) $@ - $(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $@ $@ +ifneq ($(GEN_SE_HEADER),) +snippets += $(pv-snippets) +tests += $(pv-tests) +snippet-hdr-obj = $(patsubst %.gbin,%.hdr.obj,$(pv-snippets)) +else +snippet-hdr-obj = +endif + +# the asm/c snippets %.o have additional generated files as dependencies +$(SNIPPET_DIR)/asm/%.o: $(SNIPPET_DIR)/asm/%.S $(asm-offsets) + $(CC) $(CFLAGS) -c -nostdlib -o $@ $< + +$(SNIPPET_DIR)/c/%.o: $(SNIPPET_DIR)/c/%.c $(asm-offsets) + $(CC) $(CFLAGS) -c -nostdlib -o $@ $< + +$(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o + $(OBJCOPY) -O binary -j ".rodata" -j ".text" -j ".data" -j ".bss" --set-section-flags .bss=alloc,load,contents $(patsubst %.gbin,%.o,$@) $@ + truncate -s '%4096' $@ + +$(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_lib) $(FLATLIBS) + $(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/snippets/c/flat.lds $(patsubst %.gbin,%.o,$@) $(snippet_lib) $(FLATLIBS) + $(OBJCOPY) -O binary -j ".rodata" -j ".lowcore" -j ".text" -j ".data" -j ".bss" --set-section-flags .bss=alloc,load,contents $@ $@ + truncate -s '%4096' $@ +Quoted 8 lines
s390x/Makefile asmlib = $(TEST_DIR)/cstart64.o $(TEST_DIR)/cpu.o · line 129
Quoted 5 lines
s390x/Makefile +5
-0+$(SNIPPET_DIR)/asm/%.hdr: $(SNIPPET_DIR)/asm/%.gbin $(HOST_KEY_DOCUMENT) + $(GEN_SE_HEADER) -k $(HOST_KEY_DOCUMENT) -c $<,0x4000,0x00000000000000420000000000000000 --psw-addr 0x4000 -o $@ + +$(SNIPPET_DIR)/c/%.hdr: $(SNIPPET_DIR)/c/%.gbin $(HOST_KEY_DOCUMENT) + $(GEN_SE_HEADER) -k $(HOST_KEY_DOCUMENT) -c $<,0x0,0x00000000000000420000000000000000 --psw-addr 0x4000 -o $@are they supposed to have different addresses? the C files start at
0x4000, while the asm ones at 0
Quoted 1 line
That's a mistake I'll need to fix.
On second thought this is correct since it's the starting address of the component and not the PSW entry. The psw entry is the next argument. The C snippets currently have data in the first 4 pages so we can encrypt from offset 0.
The question that remains is: do we need the data at 0x0 - 0x4000?
The reset and restart PSWs are not really necessary since we don't start the snippets as a lpar or in simulation where we use these PSWs. The stackptr is just that, a ptr AFAIK so there shouldn't be data on 0x3000 (but I'll look that up anyway).
Quoted 43 lines
Quoted 42 lines
Quoted 41 lines
s390x/Makefile +17
-7+ +.SECONDARY: +%.gobj: %.gbin + $(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@ + +.SECONDARY: +%.hdr.obj: %.hdr + $(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@ -$(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_asmlib) $(FLATLIBS) - $(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/snippets/c/flat.lds $(patsubst %.gbin,%.o,$@) $(snippet_asmlib) $(FLATLIBS) - $(OBJCOPY) -O binary $@ $@ - $(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $@ $@ .SECONDEXPANSION: -%.elf: $$(snippets) %.o $(FLATLIBS) $(SRCDIR)/s390x/flat.lds $(asmlib) +%.elf: $(FLATLIBS) $(asmlib) $(SRCDIR)/s390x/flat.lds $$(snippets-obj) $$(snippet-hdr-obj) %.o $(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(SRCDIR)/lib/auxinfo.c -DPROGNAME=\"$@\" - $(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/flat.lds $(filter %.o, $^) $(FLATLIBS) $(snippets) $(@:.elf=.aux.o) + @$(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/flat.lds \ + $(filter %.o, $^) $(FLATLIBS) $(snippets-obj) $(snippet-hdr-obj) $(@:.elf=.aux.o) || \ + { echo "Failure probably caused by missing definition of gen-se-header executable"; exit 1; } $(RM) $(@:.elf=.aux.o) @chmod a-x $@@@ -114,8 +155,12 @@ $(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_asmlib) $(FLATLIBS) %.pv.bin: %.bin $(HOST_KEY_DOCUMENT) $(GENPROTIMG) --host-key-document $(HOST_KEY_DOCUMENT) --no-verify --image $< -o $@ +$(snippet_asmlib): $$(patsubst %.o,%.S,$$@) $(asm-offsets) + $(CC) $(CFLAGS) -c -nostdlib -o $@ $< + + arch_clean: asm_offsets_clean - $(RM) $(TEST_DIR)/*.{o,elf,bin} $(TEST_DIR)/.*.d $(SNIPPET_DIR)/c/*.{o,gbin} $(SNIPPET_DIR)/c/.*.d lib/s390x/.*.d + $(RM) $(TEST_DIR)/*.{o,elf,bin} $(SNIPPET_DIR)/*/*.{o,elf,*bin,*obj,hdr} $(SNIPPET_DIR)/asm/.*.d $(TEST_DIR)/.*.d lib/s390x/.*.d generated-files = $(asm-offsets) $(tests:.elf=.o) $(asmlib) $(cflatobjs): $(generated-files)
Re: [kvm-unit-tests PATCH 7/8] s390x: snippets: Add PV support
Quoted 5 lines · Janosch Frank
Quoted 4 lines · Janosch Frank
Quoted 3 lines · Claudio Imbrenda
On Tue, 23 Nov 2021 10:39:55 +0000
Janosch Frank <[email protected]> wrote:
[...]
Quoted 10 lines
Quoted 4 lines
Quoted 2 lines
are they supposed to have different addresses? the C files start at
0x4000, while the asm ones at 0That's a mistake I'll need to fix.
On second thought this is correct since it's the starting address of the component and not the PSW entry. The psw entry is the next argument. The C snippets currently have data in the first 4 pages so we can encrypt from offset 0.
Quoted 5 lines
The question that remains is: do we need the data at
0x0-0x4000? The reset and restart PSWs are not really necessary since we don't start the snippets as a lpar or in simulation where we use these PSWs. The stackptr is just that, a ptr AFAIK so there shouldn't be data on0x3000(but I'll look that up anyway).
Colleagues have used the C PV snippets over the last few weeks and haven't reported any issues. It's time that we bring this into master since a lot of upcoming tests are currently based on this series.
@Claudio: Any further comments?
Quoted 44 lines
Quoted 43 lines
Quoted 42 lines
Quoted 41 lines
s390x/Makefile +17
-7+ +.SECONDARY: +%.gobj: %.gbin + $(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@ + +.SECONDARY: +%.hdr.obj: %.hdr + $(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@ -$(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_asmlib) $(FLATLIBS) - $(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/snippets/c/flat.lds $(patsubst %.gbin,%.o,$@) $(snippet_asmlib) $(FLATLIBS) - $(OBJCOPY) -O binary $@ $@ - $(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $@ $@ .SECONDEXPANSION: -%.elf: $$(snippets) %.o $(FLATLIBS) $(SRCDIR)/s390x/flat.lds $(asmlib) +%.elf: $(FLATLIBS) $(asmlib) $(SRCDIR)/s390x/flat.lds $$(snippets-obj) $$(snippet-hdr-obj) %.o $(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(SRCDIR)/lib/auxinfo.c -DPROGNAME=\"$@\" - $(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/flat.lds $(filter %.o, $^) $(FLATLIBS) $(snippets) $(@:.elf=.aux.o) + @$(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/flat.lds \ + $(filter %.o, $^) $(FLATLIBS) $(snippets-obj) $(snippet-hdr-obj) $(@:.elf=.aux.o) || \ + { echo "Failure probably caused by missing definition of gen-se-header executable"; exit 1; } $(RM) $(@:.elf=.aux.o) @chmod a-x $@@@ -114,8 +155,12 @@ $(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_asmlib) $(FLATLIBS) %.pv.bin: %.bin $(HOST_KEY_DOCUMENT) $(GENPROTIMG) --host-key-document $(HOST_KEY_DOCUMENT) --no-verify --image $< -o $@ +$(snippet_asmlib): $$(patsubst %.o,%.S,$$@) $(asm-offsets) + $(CC) $(CFLAGS) -c -nostdlib -o $@ $< + + arch_clean: asm_offsets_clean - $(RM) $(TEST_DIR)/*.{o,elf,bin} $(TEST_DIR)/.*.d $(SNIPPET_DIR)/c/*.{o,gbin} $(SNIPPET_DIR)/c/.*.d lib/s390x/.*.d + $(RM) $(TEST_DIR)/*.{o,elf,bin} $(SNIPPET_DIR)/*/*.{o,elf,*bin,*obj,hdr} $(SNIPPET_DIR)/asm/.*.d $(TEST_DIR)/.*.d lib/s390x/.*.d generated-files = $(asm-offsets) $(tests:.elf=.o) $(asmlib) $(cflatobjs): $(generated-files)
Re: [kvm-unit-tests PATCH 7/8] s390x: snippets: Add PV support
Quoted 23 lines · On Thu, 13 Jan 2022 14:10:01 +0100 Janosch Frank <[email protected]> wrote:
Quoted 5 lines · Janosch Frank
Quoted 4 lines · Janosch Frank
Quoted 3 lines · Claudio Imbrenda
On Tue, 23 Nov 2021 10:39:55 +0000
Janosch Frank <[email protected]> wrote:[...]
Quoted 10 lines
Quoted 4 lines
Quoted 2 lines
are they supposed to have different addresses? the C files start at
0x4000, while the asm ones at 0That's a mistake I'll need to fix.
On second thought this is correct since it's the starting address of the component and not the PSW entry. The psw entry is the next argument. The C snippets currently have data in the first 4 pages so we can encrypt from offset 0.
Quoted 5 lines
The question that remains is: do we need the data at
0x0-0x4000? The reset and restart PSWs are not really necessary since we don't start the snippets as a lpar or in simulation where we use these PSWs. The stackptr is just that, a ptr AFAIK so there shouldn't be data on0x3000(but I'll look that up anyway).
Quoted 5 lines
Colleagues have used the C PV snippets over the last few weeks and haven't reported any issues. It's time that we bring this into master since a lot of upcoming tests are currently based on this series.
@Claudio: Any further comments?
no, let's bring this into master
PATCH 8/8 s390x: sie: Add PV diag test
In reply to Janosch FrankLet'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 | 7 + s390x/pv-diags.c | 240 +++++++++++++++++++++ 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 + 5 files changed, 318 insertions(+) create mode 100644 s390x/pv-diags.c 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
s390x/Makefile +7 -0
@@ -26,6 +26,8 @@ tests += $(TEST_DIR)/edat.elf tests += $(TEST_DIR)/mvpg-sie.elf tests += $(TEST_DIR)/spec_ex-sie.elf +pv-tests += $(TEST_DIR)/pv-diags.elf + ifneq ($(HOST_KEY_DOCUMENT),) ifneq ($(GEN_SE_HEADER),) tests += $(pv-tests)
@@ -98,6 +100,11 @@ 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/pv-diags.c new file +240 -0
240 lines not on this page · raw message
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
Signature · 1 line
2.32.0
Re: [kvm-unit-tests PATCH 8/8] s390x: sie: Add PV diag test
Quoted 8 lines · On Tue, 23 Nov 2021 10:39:56 +0000 Janosch Frank <[email protected]> wrote:
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.
Signed-off-by Janosch Frank <[email protected]>
Quoted 372 lines
--- s390x/Makefile | 7 + s390x/pv-diags.c | 240 +++++++++++++++++++++ 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 + 5 files changed, 318 insertions(+) create mode 100644 s390x/pv-diags.c 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.Ss390x/Makefile +7
-0@@ -26,6 +26,8 @@ tests += $(TEST_DIR)/edat.elf tests += $(TEST_DIR)/mvpg-sie.elf tests += $(TEST_DIR)/spec_ex-sie.elf +pv-tests += $(TEST_DIR)/pv-diags.elf + ifneq ($(HOST_KEY_DOCUMENT),) ifneq ($(GEN_SE_HEADER),) tests += $(pv-tests)@@ -98,6 +100,11 @@ 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/pv-diags.c new file +240
-0@@ -0,0 +1,240 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* PV virtualization interception tests for diagnose instructions. +* +* Copyright (c) 2021 IBM Corp +* +* Authors: +* Janosch Frank <[email protected]> +*/ +#include <libcflat.h> +#include <asm/asm-offsets.h> +#include <asm-generic/barrier.h> +#include <asm/interrupt.h> +#include <asm/pgtable.h> +#include <mmu.h> +#include <asm/page.h> +#include <asm/facility.h> +#include <asm/mem.h> +#include <asm/sigp.h> +#include <smp.h> +#include <alloc_page.h> +#include <vm.h> +#include <vmalloc.h> +#include <sclp.h> +#include <snippet.h> +#include <sie.h> +#include <uv.h> +#include <asm/uv.h> + +static u8 *guest; +static u8 *guest_instr; +static struct vm vm; + +uint64_t tweak[2 ] = {0x42 ,0x00 }; + +static void setup_vmem (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 SE guests */ + asce =stctg (1 ) |ASCE_P ; +lctlg (1 , asce); + +/* Copy ASCE into home space CR */ +lctlg (13 , asce); +} + + +static void init_guest (const char *gbin,const char *hdr,uint64_t gbin_len, +uint64_t hdr_len) +{ +uv_create_guest (&vm); +uv_set_se_hdr (vm.uv.vm_handle, (void *)hdr, hdr_len); + +/* Copy test image to guest memory */ +memcpy (guest_instr, gbin, gbin_len); + +uv_unpack (&vm,SNIPPET_ENTRY_ADDR , gbin_len, tweak[0 ]); +uv_verify_load (&vm); + +/* Manually import lowcore */ +uv_import (vm.uv.vm_handle, (uint64_t )guest); +uv_import (vm.uv.vm_handle, (uint64_t )(guest +PAGE_SIZE )); +} + +static void setup_guest (void ) +{ +setup_vmem (); + +/* Allocate 1MB as guest memory */ + guest =alloc_pages (8 ); +memset (guest,0 ,HPAGE_SIZE ); +/* The first two pages are the lowcore */ + guest_instr = guest +SNIPPET_ENTRY_ADDR ; + +sie_guest_create (&vm, (uint64_t )guest,HPAGE_SIZE ); +/* FMT4 needs a ESCA */ +sie_guest_sca_create (&vm); + +uv_init (); +} + +static void test_diag_500 (void ) +{ +extern const char SNIPPET_NAME_START (asm ,snippet_pv_diag_500 )[]; +extern const char SNIPPET_NAME_END (asm ,snippet_pv_diag_500 )[]; +extern const char SNIPPET_HDR_START (asm ,snippet_pv_diag_500 )[]; +extern const char SNIPPET_HDR_END (asm ,snippet_pv_diag_500 )[]; + int size_hdr = SNIPPET_HDR_LEN(asm, snippet_pv_diag_500); + int size_gbin = SNIPPET_LEN(asm, snippet_pv_diag_500); + +report_prefix_push ("diag 0x500" ); + + init_guest(SNIPPET_NAME_START(asm, snippet_pv_diag_500), +SNIPPET_HDR_START (asm ,snippet_pv_diag_500 ), + size_gbin, size_hdr); + +sie (&vm); +report (vm.sblk->icptcode ==ICPT_PV_INSTR && vm.sblk->ipa ==0x8302 && + vm.sblk->ipb ==0x50000000 && vm.save_area.guest.grs[5 ] ==0x500 , +"intercept values" ); +report (vm.save_area.guest.grs[1 ] ==1 && + vm.save_area.guest.grs[2 ] ==2 && + vm.save_area.guest.grs[3 ] ==3 && + vm.save_area.guest.grs[4 ] ==4 , +"register values" ); +/* +* Check if we can inject a PGM operand which we are always +* allowed to do after a diag500 exit. +*/ + 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 , +"operand exception" ); + +/* +* Check if we can inject a PGM specification which we are always +* allowed to do after a diag500 exit. +*/ +sie (&vm); + 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 , +"specification exception" ); + +/* No need for cleanup, just tear down the VM */ +uv_destroy_guest (&vm); + +report_prefix_pop (); +} + + +static void test_diag_288 (void ) +{ +extern const char SNIPPET_NAME_START (asm ,snippet_pv_diag_288 )[]; +extern const char SNIPPET_NAME_END (asm ,snippet_pv_diag_288 )[]; +extern const char SNIPPET_HDR_START (asm ,snippet_pv_diag_288 )[]; +extern const char SNIPPET_HDR_END (asm ,snippet_pv_diag_288 )[]; + int size_hdr = SNIPPET_HDR_LEN(asm, snippet_pv_diag_288); + int size_gbin = SNIPPET_LEN(asm, snippet_pv_diag_288); + +report_prefix_push ("diag 0x288" ); + + init_guest(SNIPPET_NAME_START(asm, snippet_pv_diag_288), +SNIPPET_HDR_START (asm ,snippet_pv_diag_288 ), + size_gbin, size_hdr); + +sie (&vm); +report (vm.sblk->icptcode ==ICPT_PV_INSTR && vm.sblk->ipa ==0x8302 && + vm.sblk->ipb ==0x50000000 && vm.save_area.guest.grs[5 ] ==0x288 , +"intercept values" ); +report (vm.save_area.guest.grs[0 ] ==1 && + vm.save_area.guest.grs[1 ] ==2 && + vm.save_area.guest.grs[2 ] ==3 , +"register values" ); + +/* +* Check if we can inject a PGM spec which we are always +* allowed to do after a diag288 exit. +*/ + vm.sblk->iictl =IICTL_CODE_SPECIFICATION ; +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 , +"specification exception" ); + +/* No need for cleanup, just tear down the VM */ +uv_destroy_guest (&vm); + +report_prefix_pop (); +} + +static void test_diag_yield (void ) +{ +extern const char SNIPPET_NAME_START (asm ,snippet_pv_diag_yield )[]; +extern const char SNIPPET_NAME_END (asm ,snippet_pv_diag_yield )[]; +extern const char SNIPPET_HDR_START (asm ,snippet_pv_diag_yield )[]; +extern const char SNIPPET_HDR_END (asm ,snippet_pv_diag_yield )[]; + int size_hdr = SNIPPET_HDR_LEN(asm, snippet_pv_diag_yield); + int size_gbin = SNIPPET_LEN(asm, snippet_pv_diag_yield); + +report_prefix_push ("diag yield" ); + + init_guest(SNIPPET_NAME_START(asm, snippet_pv_diag_yield), +SNIPPET_HDR_START (asm ,snippet_pv_diag_yield ), + size_gbin, size_hdr); + +/* 0x44 */ +report_prefix_push ("0x44" ); +sie (&vm); +report (vm.sblk->icptcode ==ICPT_PV_NOTIFY && vm.sblk->ipa ==0x8302 && + vm.sblk->ipb ==0x50000000 && vm.save_area.guest.grs[5 ] ==0x44 , +"intercept values" ); +report_prefix_pop (); + +/* 0x9c */ +report_prefix_push ("0x9c" ); +sie (&vm); +report (vm.sblk->icptcode ==ICPT_PV_NOTIFY && vm.sblk->ipa ==0x8302 && + vm.sblk->ipb ==0x50000000 && vm.save_area.guest.grs[5 ] ==0x9c , +"intercept values" ); +report (vm.save_area.guest.grs[0 ] ==42 ,"r1 correct" ); +report_prefix_pop (); + +uv_destroy_guest (&vm); +report_prefix_pop (); +} + + +int main (void ) +{ +report_prefix_push ("pv-diags" ); +if (!test_facility (158 )) { +report_skip ("UV Call facility unavailable" ); + goto done; + } +if (!sclp_facilities.has_sief2) { +report_skip ("SIEF2 facility unavailable" ); + goto done; + } + +setup_guest (); +test_diag_yield (); +test_diag_288 (); +test_diag_500 (); +sie_guest_destroy (&vm); + +done: +report_prefix_pop (); +return report_summary (); +}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, 0x9cs390x/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, 0x9cs390x/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