s390x: new edat, diag258 and STFLE tests; fixes for genprotimg >= 2.36.0; cleanups for snippets and makefiles
Hi Paolo and/or Thomas,
Changes in this pull request:
- cpacf query function were reworked in the kernel, that fix was cherry-picked by Nina. This fixes issues with possible incorrect instruction format
- Claudio extended the edat test for a special case with a 2G page at the end of memory to ensure the correct addressing exception happens.
- I added a test for diag258 where we had some issues with virtual-physical address confusion.
- Nina took the time to add library functions that help exiting from a snippet s390x.
- Nina contributed a test for STFLE interpretive execution. Thank you!
- Marc did a lot of magic fixing issues in our Makefiles. This fixes several issues with out-of-tree-builds. We now also build out-of-tree in our downstream CI to avoid unpleasant surprises for maintainers :) Marc, thanks for contributing your Makefile knowledge and for turning my complaints into something productive
- Janosch also invested some time to clean up snippets and Makefiles, which made the code a lot nicer, thanks for that as well!
- we have a compatibility issue with genprotimg
versions >= 2.36.0. Thanks Marc to fixing that. You should upgrade kvm-unit-tests if you use genprotimg >= 2.36.0!
Note that there are two checkpatch errors:
Quoted 1 line
ERROR: space prohibited before that ':' (ctx:WxW)
I would suggest to ignore them, the code really looks ugly otherwise.
Thanks
Nico
MERGE: https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/merge_requests/73
PIPELINE: https://gitlab.com/Nico-Boehr/kvm-unit-tests/-/pipelines/1650287644
PULL: https://gitlab.com/Nico-Boehr/kvm-unit-tests.git pr-2025-01-31
----
The following changes since commit 2e66bb4b9423970ceb6ea195bd8697733bcd9071:
Makefile: Use 'vpath' for out-of-source builds and not 'VPATH' (2025-01-31 10:40:51 +0100)
are available in the Git repository at:
https://gitlab.com/Nico-Boehr/kvm-unit-tests.git pr-2025-01-31
for you to fetch changes up to 12b23c79ac6c5af4f9351c7502c4a3ffccf4b8eb:
s390x/Makefile: Add auxinfo.o to cflatobjs (2025-01-31 13:02:25 +0100)
----------------------------------------------------------------
Claudio Imbrenda (1):
s390x: edat: test 2G large page spanning end of memory
Janosch Frank (4):
s390x/Makefile: Split snippet makefile rules into new file
s390x/Makefile: Add more comments
s390x: Move SIE assembly into new file
lib: s390x: Split SIE fw structs from lib structsMarc Hartmayer (4):
s390x/Makefile: snippets: Add separate target for the ELF snippets
s390x: Support newer version of genprotimg
s390x/Makefile: Make sure the linker script is generated in the build directory
s390x/Makefile: Add auxinfo.o to cflatobjsNico Boehr (2):
s390x: edat: move LC_SIZE to arch_def.h
s390x: add test for diag258Nina Schoetterl-Glausch (7):
s390x: Split and rework cpacf query functions
s390x: lib: Remove double include
s390x: Add sie_is_pv
s390x: Add function for checking diagnose intercepts
s390x: Add library functions for exiting from snippet
s390x: Use library functions for snippet exit
s390x: Add test for STFLE interpretive execution (format-0)lib/s390x/asm/arch_def.h | 17 +++ lib/s390x/asm/cpacf.h | 77 ++++++++++-- lib/s390x/asm/facility.h | 10 +- lib/s390x/asm/sie-arch.h | 238 +++++++++++++++++++++++++++++++++++ lib/s390x/pv_icptdata.h | 42 ------- lib/s390x/sie-icpt.c | 60 +++++++++ lib/s390x/sie-icpt.h | 39 ++++++ lib/s390x/sie.c | 5 +- lib/s390x/sie.h | 237 ++-------------------------------- lib/s390x/snippet-exit.h | 45 +++++++ s390x/Makefile | 75 ++++++----- s390x/cpu-sie.S | 74 +++++++++++ s390x/cpu.S | 64 ---------- s390x/diag258.c | 259 ++++++++++++++++++++++++++++++++++++++ s390x/edat.c | 19 ++- s390x/pv-diags.c | 9 +- s390x/pv-icptcode.c | 12 +- s390x/pv-ipl.c | 8 +- s390x/sie-dat.c | 12 +- s390x/snippets/Makefile | 35 ++++++ s390x/snippets/c/sie-dat.c | 19 +-- s390x/snippets/c/stfle.c | 29 +++++ s390x/snippets/lib/snippet-exit.h | 28 +++++ s390x/stfle-sie.c | 138 ++++++++++++++++++++ s390x/unittests.cfg | 6 + 25 files changed, 1124 insertions(+), 433 deletions(-) create mode 100644 lib/s390x/asm/sie-arch.h delete mode 100644 lib/s390x/pv_icptdata.h create mode 100644 lib/s390x/sie-icpt.c create mode 100644 lib/s390x/sie-icpt.h create mode 100644 lib/s390x/snippet-exit.h create mode 100644 s390x/cpu-sie.S create mode 100644 s390x/diag258.c create mode 100644 s390x/snippets/Makefile create mode 100644 s390x/snippets/c/stfle.c create mode 100644 s390x/snippets/lib/snippet-exit.h create mode 100644 s390x/stfle-sie.c
[kvm-unit-tests GIT PULL 01/18] s390x: Split and rework cpacf query functions
From: Nina Schoetterl-Glausch <[email protected]>
Cherry-pick 830999bd7e72 ("s390/cpacf: Split and rework cpacf query functions") from the kernel:
Rework the cpacf query functions to use the correct RRE or RRF instruction formats and set register fields within instructions correctly.
--- lib/s390x/asm/cpacf.h | 77 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 10 deletions(-)
lib/s390x/asm/cpacf.h +67 -10
@@ -137,19 +137,76 @@typedef struct {unsigned char bytes[16 ]; }cpacf_mask_t ; -static __always_inline void __cpacf_query(unsigned int opcode, cpacf_mask_t *mask) +static __always_inline void __cpacf_query_rre(u32 opc, u8 r1, u8 r2, +cpacf_mask_t *mask) { - register unsigned long r0 asm("0") = 0; /* query function */ - register unsigned long r1 asm("1") = (unsigned long) mask; + asmvolatile ( +" la %%r1,%[mask]\n" +" xgr %%r0,%%r0\n" +" .insn rre,%[opc] << 16,%[r1],%[r2]\n" + : [mask]"=R" (*mask) + : [opc]"i" (opc), + [r1]"i" (r1), [r2]"i" (r2) + :"cc" ,"r0" ,"r1" ); +} +static __always_inline void __cpacf_query_rrf(u32 opc, +u8 r1,u8 r2,u8 r3,u8 m4, +cpacf_mask_t *mask) +{ asmvolatile ( -" spm 0\n" /* pckmo doesn't change the cc */ -/* Parameter regs are ignored, but must be nonzero and unique */ -"0: .insn rrf,%[opc] << 16,2,4,6,0\n" -" brc 1,0b\n" /* handle partial completion */ - :"=m" (*mask) - : [fc]"d" (r0), [pba]"a" (r1), [opc]"i" (opcode) - :"cc" ); +" la %%r1,%[mask]\n" +" xgr %%r0,%%r0\n" +" .insn rrf,%[opc] << 16,%[r1],%[r2],%[r3],%[m4]\n" + : [mask]"=R" (*mask) + : [opc]"i" (opc), [r1]"i" (r1), [r2]"i" (r2), + [r3]"i" (r3), [m4]"i" (m4) + :"cc" ,"r0" ,"r1" ); +} + +static __always_inline void __cpacf_query(unsigned int opcode, +cpacf_mask_t *mask) +{ +switch (opcode) { +case CPACF_KIMD : +__cpacf_query_rre (CPACF_KIMD ,0 ,2 , mask); +break ; +case CPACF_KLMD : +__cpacf_query_rre (CPACF_KLMD ,0 ,2 , mask); +break ; +case CPACF_KM : +__cpacf_query_rre (CPACF_KM ,2 ,4 , mask); +break ; +case CPACF_KMA : +__cpacf_query_rrf (CPACF_KMA ,2 ,4 ,6 ,0 , mask); +break ; +case CPACF_KMAC : +__cpacf_query_rre (CPACF_KMAC ,0 ,2 , mask); +break ; +case CPACF_KMC : +__cpacf_query_rre (CPACF_KMC ,2 ,4 , mask); +break ; +case CPACF_KMCTR : +__cpacf_query_rrf (CPACF_KMCTR ,2 ,4 ,6 ,0 , mask); +break ; +case CPACF_KMF : +__cpacf_query_rre (CPACF_KMF ,2 ,4 , mask); +break ; +case CPACF_KMO : +__cpacf_query_rre (CPACF_KMO ,2 ,4 , mask); +break ; +case CPACF_PCC : +__cpacf_query_rre (CPACF_PCC ,0 ,0 , mask); +break ; +case CPACF_PCKMO : +__cpacf_query_rre (CPACF_PCKMO ,0 ,0 , mask); +break ; +case CPACF_PRNO : +__cpacf_query_rre (CPACF_PRNO ,2 ,4 , mask); +break ; +default : + asmvolatile (".error \"bad opcode\"" ); + } }static inline int __cpacf_check_opcode (unsigned int opcode)
Signature · 1 line
2.47.1
[kvm-unit-tests GIT PULL 05/18] s390x: lib: Remove double include
In reply to Nico BoehrFrom: Nina Schoetterl-Glausch <[email protected]>
libcflat.h was included twice.
--- lib/s390x/sie.c | 1 - 1 file changed, 1 deletion(-)
lib/s390x/sie.c +0 -1
@@ -14,7 +14,6 @@#include <sie.h> #include <asm/page.h> #include <asm/interrupt.h> -#include <libcflat.h> #include <alloc_page.h> #include <vmalloc.h> #include <sclp.h>
Signature · 1 line
2.47.1
[kvm-unit-tests GIT PULL 04/18] s390x: add test for diag258
In reply to Nico BoehrThis adds a test for diag258 (page ref service/async page fault).
There recently was a virtual-real address confusion bug, so we should test:
- diag258 parameter Rx is a real adress
- crossing the end of RAM with the parameter list yields an addressing exception
- invalid diagcode in the parameter block yields an specification exception
- diag258 correctly applies prefixing.
Note that we're just testing error cases as of now.
--- s390x/Makefile | 1 + s390x/diag258.c | 259 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 3 + 3 files changed, 263 insertions(+) create mode 100644 s390x/diag258.c
s390x/Makefile +1 -0
@@ -44,6 +44,7 @@ tests += $(TEST_DIR)/exittime.elf tests += $(TEST_DIR)/ex.elf tests += $(TEST_DIR)/topology.elf tests += $(TEST_DIR)/sie-dat.elf +tests += $(TEST_DIR)/diag258.elf pv-tests += $(TEST_DIR)/pv-diags.elf pv-tests += $(TEST_DIR)/pv-icptcode.elf
s390x/diag258.c new file +259 -0
259 lines not on this page · raw message
s390x/unittests.cfg +3 -0
@@ -392,3 +392,6 @@ file = sie-dat.elf [pv-attest] file = pv-attest.elf + +[diag258] +file = diag258.elf
Signature · 1 line
2.47.1
[kvm-unit-tests GIT PULL 06/18] s390x: Add sie_is_pv
In reply to Nico BoehrFrom: Nina Schoetterl-Glausch <[email protected]>
Add a function to check if a guest VM is currently running protected.
--- lib/s390x/sie.h | 6 ++++++ lib/s390x/sie.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-)
lib/s390x/sie.h +6 -0
@@ -281,6 +281,12 @@ void sie_expect_validity(struct vm *vm);uint16_t sie_get_validity (struct vm *vm);void sie_check_validity (struct vm *vm,uint16_t vir_exp);void sie_handle_validity (struct vm *vm); + +static inline bool sie_is_pv (struct vm *vm) +{ +return vm->sblk->sdf ==2 ; +} +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 +2 -2
@@ -59,7 +59,7 @@ void sie(struct vm *vm)/* When a pgm int code is set, we'll never enter SIE below. */ assert (!read_pgm_int_code ()); -if (vm->sblk->sdf ==2 ) +if (sie_is_pv (vm))memcpy (vm->sblk->pv_grregs, vm->save_area.guest.grs,sizeof (vm->save_area.guest.grs));
@@ -98,7 +98,7 @@ void sie(struct vm *vm)/* restore the old CR 13 */ lctlg (13 , old_cr13); -if (vm->sblk->sdf ==2 ) +if (sie_is_pv (vm))memcpy (vm->save_area.guest.grs, vm->sblk->pv_grregs,sizeof (vm->save_area.guest.grs)); }
Signature · 1 line
2.47.1
[kvm-unit-tests GIT PULL 07/18] s390x: Add function for checking diagnose intercepts
In reply to Nico BoehrFrom: Nina Schoetterl-Glausch <[email protected]>
sie_is_diag_icpt() checks if the intercept is due to an expected diagnose call and is valid.
It subsumes pv_icptdata_check_diag.
--- s390x/Makefile | 1 + lib/s390x/pv_icptdata.h | 42 ----------------------------- lib/s390x/sie-icpt.h | 39 +++++++++++++++++++++++++++ lib/s390x/sie-icpt.c | 60 +++++++++++++++++++++++++++++++++++++++++ s390x/pv-diags.c | 9 +++---- s390x/pv-icptcode.c | 12 ++++----- s390x/pv-ipl.c | 8 +++--- 7 files changed, 114 insertions(+), 57 deletions(-) delete mode 100644 lib/s390x/pv_icptdata.h create mode 100644 lib/s390x/sie-icpt.h create mode 100644 lib/s390x/sie-icpt.c
s390x/Makefile +1 -0
@@ -112,6 +112,7 @@ cflatobjs += lib/s390x/css_lib.o cflatobjs += lib/s390x/malloc_io.o cflatobjs += lib/s390x/uv.o cflatobjs += lib/s390x/sie.o +cflatobjs += lib/s390x/sie-icpt.o cflatobjs += lib/s390x/fault.o OBJDIRS += lib/s390x
lib/s390x/pv_icptdata.h deleted +0 -42
42 lines not on this page · raw message
lib/s390x/sie-icpt.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Functionality for SIE interception handling. +* +* Copyright IBM Corp. 2024 +*/ + +#ifndef _S390X_SIE_ICPT_H_ +#define _S390X_SIE_ICPT_H_ + +#include <libcflat.h> +#include <sie.h> + +struct diag_itext { +uint64_t opcode :8 ; +uint64_t r_1 :4 ; +uint64_t r_2 :4 ; +uint64_t r_base :4 ; +uint64_t displace :12 ; +uint64_t zero :16 ; + uint64_t : 16; +}; + +struct diag_itext sblk_ip_as_diag (struct kvm_s390_sie_block *sblk); + +/** +* sie_is_diag_icpt() - Check if intercept is due to diagnose instruction +* @vm: the guest +* @diag: the expected diagnose code +* +* Check that the intercept is due to diagnose @diag and valid. +* For protected virtualization, check that the intercept data meets additional +* constraints. +* +* Returns: true if intercept is due to a valid and has matching diagnose code +*/ +bool sie_is_diag_icpt (struct vm *vm,unsigned int diag); + +#endif /* _S390X_SIE_ICPT_H_ */
lib/s390x/sie-icpt.c new file +60 -0
60 lines not on this page · raw message
s390x/pv-diags.c +4 -5
@@ -9,7 +9,7 @@*/ #include <libcflat.h> #include <snippet.h> -#include <pv_icptdata.h> +#include <sie-icpt.h> #include <sie.h> #include <sclp.h> #include <asm/facility.h>
@@ -32,8 +32,7 @@ static void test_diag_500(void) size_gbin, size_hdr, SNIPPET_UNPACK_OFF);sie (&vm); -report (pv_icptdata_check_diag (&vm,0x500 ), -"intercept values" ); +report (sie_is_diag_icpt (&vm,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 &&
@@ -45,7 +44,7 @@ static void test_diag_500(void)*/ vm.sblk->iictl =IICTL_CODE_OPERAND ;sie (&vm); -report (pv_icptdata_check_diag (&vm,0x9c ) && +report (sie_is_diag_icpt (&vm,0x9c ) && vm.save_area.guest.grs[0 ] ==PGM_INT_CODE_OPERAND ,"operand exception" );
@@ -57,7 +56,7 @@ static void test_diag_500(void) vm.sblk->iictl =IICTL_CODE_SPECIFICATION ;/* Inject PGM, next exit should be 9c */ sie (&vm); -report (pv_icptdata_check_diag (&vm,0x9c ) && +report (sie_is_diag_icpt (&vm,0x9c ) && vm.save_area.guest.grs[0 ] ==PGM_INT_CODE_SPECIFICATION ,"specification exception" );
s390x/pv-icptcode.c +6 -6
@@ -13,7 +13,7 @@#include <smp.h> #include <sclp.h> #include <snippet.h> -#include <pv_icptdata.h> +#include <sie-icpt.h> #include <asm/facility.h> #include <asm/barrier.h> #include <asm/sigp.h>
@@ -47,7 +47,7 @@ static void test_validity_timing(void) size_gbin, size_hdr, SNIPPET_UNPACK_OFF);sie (&vm); -report (pv_icptdata_check_diag (&vm,0x44 ),"spt done" ); +report (sie_is_diag_icpt (&vm,0x44 ),"spt done" );stck (&time_exit); tmp = vm.sblk->cputm;mb ();
@@ -258,7 +258,7 @@ static void test_validity_asce(void)/* Try if we can still do an entry with the correct asce */ sie (&vm); -report (pv_icptdata_check_diag (&vm,0x44 ),"re-entry with valid CR1" ); +report (sie_is_diag_icpt (&vm,0x44 ),"re-entry with valid CR1" );uv_destroy_guest (&vm);free_pages (pgd_new);report_prefix_pop ();
@@ -294,7 +294,7 @@ static void run_icpt_122_tests_prefix(unsigned long prefix)sie (&vm);/* Guest indicates that it has been setup via the diag 0x44 */ -assert (pv_icptdata_check_diag (&vm,0x44 )); +assert (sie_is_diag_icpt (&vm,0x44 ));/* If the pages have not been shared these writes will cause exceptions */ ptr = (uint32_t *)prefix;WRITE_ONCE (ptr,0 );
@@ -328,7 +328,7 @@ static void test_icpt_112(void)/* Setup of the guest's state for 0x0 prefix */ sie (&vm); -assert (pv_icptdata_check_diag (&vm,0x44 )); +assert (sie_is_diag_icpt (&vm,0x44 ));/* Test on standard 0x0 prefix */ run_icpt_122_tests_prefix (0 );
@@ -348,7 +348,7 @@ static void test_icpt_112(void)/* Try a re-entry after everything has been imported again */ sie (&vm); -report (pv_icptdata_check_diag (&vm,0x9c ) && +report (sie_is_diag_icpt (&vm,0x9c ) && vm.save_area.guest.grs[0 ] ==42 ,"re-entry successful" );report_prefix_pop ();
s390x/pv-ipl.c +4 -4
@@ -11,7 +11,7 @@#include <sie.h> #include <sclp.h> #include <snippet.h> -#include <pv_icptdata.h> +#include <sie-icpt.h> #include <asm/facility.h> #include <asm/uv.h>
@@ -35,7 +35,7 @@ static void test_diag_308(int subcode)/* First exit is a diag 0x500 */ sie (&vm); -assert (pv_icptdata_check_diag (&vm,0x500 )); +assert (sie_is_diag_icpt (&vm,0x500 ));/* * The snippet asked us for the subcode and we answer by
@@ -46,7 +46,7 @@ static void test_diag_308(int subcode)/* Continue after diag 0x500, next icpt should be the 0x308 */ sie (&vm); -assert (pv_icptdata_check_diag (&vm,0x308 )); +assert (sie_is_diag_icpt (&vm,0x308 ));assert (vm.save_area.guest.grs[2 ] == subcode);/*
@@ -118,7 +118,7 @@ static void test_diag_308(int subcode)* see a diagnose 0x9c PV instruction notification. */ sie (&vm); -report (pv_icptdata_check_diag (&vm,0x9c ) && +report (sie_is_diag_icpt (&vm,0x9c ) && vm.save_area.guest.grs[0 ] ==42 ,"continue after load" );
Signature · 1 line
2.47.1
[kvm-unit-tests GIT PULL 10/18] s390x: Add test for STFLE interpretive execution (format-0)
In reply to Nico BoehrFrom: Nina Schoetterl-Glausch <[email protected]>
The STFLE instruction indicates installed facilities. SIE can interpretively execute STFLE.
Use a snippet guest executing STFLE to get the result of interpretive execution and check the result.
--- s390x/Makefile | 2 + lib/s390x/asm/facility.h | 10 ++- s390x/snippets/c/stfle.c | 29 ++++++++ s390x/stfle-sie.c | 138 +++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 3 + 5 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 s390x/snippets/c/stfle.c create mode 100644 s390x/stfle-sie.c
s390x/Makefile +2 -0
@@ -45,6 +45,7 @@ tests += $(TEST_DIR)/ex.elf tests += $(TEST_DIR)/topology.elf tests += $(TEST_DIR)/sie-dat.elf tests += $(TEST_DIR)/diag258.elf +tests += $(TEST_DIR)/stfle-sie.elf pv-tests += $(TEST_DIR)/pv-diags.elf pv-tests += $(TEST_DIR)/pv-icptcode.elf
@@ -132,6 +133,7 @@ snippet_lib = $(snippet_asmlib) lib/auxinfo.o $(TEST_DIR)/mvpg-sie.elf: snippets = $(SNIPPET_DIR)/c/mvpg-snippet.gbin $(TEST_DIR)/sie-dat.elf: snippets = $(SNIPPET_DIR)/c/sie-dat.gbin $(TEST_DIR)/spec_ex-sie.elf: snippets = $(SNIPPET_DIR)/c/spec_ex.gbin +$(TEST_DIR)/stfle-sie.elf: snippets = $(SNIPPET_DIR)/c/stfle.gbin $(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-yield.gbin $(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-288.gbin
lib/s390x/asm/facility.h +9 -1
@@ -27,12 +27,20 @@ static inline void stfl(void) asmvolatile (" stfl 0(0)\n" : : :"memory" ); } -static inline void stfle (uint64_t *fac,unsigned int nb_doublewords) +static inline unsigned int stfle (uint64_t *fac,unsigned int nb_doublewords) { register unsigned long r0 asm("0") = nb_doublewords - 1; asmvolatile (" .insn s,0xb2b00000,0(%1)\n" :"+d" (r0) :"a" (fac) :"memory" ,"cc" ); +return r0 +1 ; +} + +static inline unsigned long stfle_size (void ) +{ +uint64_t dummy; + +return stfle (&dummy,1 ); }static inline void setup_facilities (void )
s390x/snippets/c/stfle.c new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright IBM Corp. 2023 +* +* Snippet used by the STLFE interpretive execution facilities test. +*/ +#include <libcflat.h> +#include <snippet-exit.h> + +int main (void ) +{ +const unsigned int max_fac_len =8 ; +uint64_t len_arg = max_fac_len -1 ; +uint64_t res[max_fac_len +1 ]; +uint64_t fac[max_fac_len]; + + asmvolatile (" lgr 0,%[len]\n" +" stfle %[fac]\n" +" lgr %[len],0\n" + : [fac]"=Q" (fac), + [len]"+d" (len_arg) + : + :"%r0" ,"cc" + ); + res[0 ] = len_arg; +memcpy (&res[1 ], fac,sizeof (fac)); +force_exit_value ((uint64_t )&res); +return 0 ; +}
s390x/stfle-sie.c new file +138 -0
138 lines not on this page · raw message
s390x/unittests.cfg +3 -0
@@ -395,3 +395,6 @@ file = pv-attest.elf [diag258] file = diag258.elf + +[stfle-sie] +file = stfle-sie.elf
Signature · 1 line
2.47.1
[kvm-unit-tests GIT PULL 02/18] s390x: edat: test 2G large page spanning end of memory
In reply to Nico BoehrFrom: Claudio Imbrenda <[email protected]>
Create a region 3 table with fc=1 (i.e. a 2G large page) mapping across the end of memory.
Check that the part of the large page before the end of memory is accessible, and the part that is after the end of memory is not.
Also fix a typo in the existing edat2 test.
--- s390x/edat.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
s390x/edat.c +17 -1
@@ -196,6 +196,8 @@ static void test_edat1(void)static void test_edat2 (void ) { +uint64_t mem_end, i; +report_prefix_push ("edat2" ); p[0 ] =42 ;
@@ -206,7 +208,21 @@ static void test_edat2(void)/* Prefixing should not work with huge pages, just like large pages */ report (!memcmp (0 ,VIRT (prefix_buf),LC_SIZE ) && !memcmp (prefix_buf,VIRT (0 ),LC_SIZE ), -"pmd, large, prefixing" ); +"pud, large, prefixing" ); + + mem_end =get_ram_size (); +if (mem_end >=BIT_ULL (REGION3_SHIFT )) { +report_skip ("pud spanning end of memory" ); + }else { +for (i =0 ; i < mem_end; i +=PAGE_SIZE ) +READ_ONCE (*(uint64_t *)VIRT (i)); +for (i = mem_end; i <BIT_ULL (REGION3_SHIFT ); i +=PAGE_SIZE ) { +expect_pgm_int (); +READ_ONCE (*(uint64_t *)VIRT (i)); +assert (clear_pgm_int () ==PGM_INT_CODE_ADDRESSING ); + } +report_pass ("pud spanning end of memory" ); + }report_prefix_pop (); }
Signature · 1 line
2.47.1
[kvm-unit-tests GIT PULL 03/18] s390x: edat: move LC_SIZE to arch_def.h
In reply to Nico Boehrstruct lowcore is defined in arch_def.h and LC_SIZE is useful to other tests as well, therefore move it to arch_def.h.
--- lib/s390x/asm/arch_def.h | 1 + s390x/edat.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-)
lib/s390x/asm/arch_def.h +1 -0
@@ -119,6 +119,7 @@ enum address_space {#define CTL2_GUARDED_STORAGE (63 - 59) +#define LC_SIZE (2 * PAGE_SIZE)struct lowcore {uint8_t pad_0x0000[0x0080 -0x0000 ];/* 0x0000 */ uint32_t ext_int_param;/* 0x0080 */
s390x/edat.c +0 -1
@@ -17,7 +17,6 @@#define PGD_PAGE_SHIFT (REGION1_SHIFT - PAGE_SHIFT) -#define LC_SIZE (2 * PAGE_SIZE)#define VIRT (x) ((void *)((unsigned long)(x) + (unsigned long)mem)) static uint8_t prefix_buf[LC_SIZE] __attribute__((aligned(LC_SIZE)));
Signature · 1 line
2.47.1
[kvm-unit-tests GIT PULL 08/18] s390x: Add library functions for exiting from snippet
In reply to Nico BoehrFrom: Nina Schoetterl-Glausch <[email protected]>
It is useful to be able to force an exit to the host from the snippet, as well as do so while returning a value.
Add this functionality, also add helper functions for the host to check for an exit and get or check the value.
Use diag 0x44 and 0x9c for this.
Add a guest specific snippet header file and rename snippet.h to reflect that it is host specific.
--- s390x/Makefile | 7 +++-- lib/s390x/asm/arch_def.h | 16 +++++++++++ lib/s390x/snippet-exit.h | 45 +++++++++++++++++++++++++++++++ s390x/snippets/lib/snippet-exit.h | 28 +++++++++++++++++++ 4 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 lib/s390x/snippet-exit.h create mode 100644 s390x/snippets/lib/snippet-exit.h
s390x/Makefile +5 -2
@@ -71,7 +71,8 @@ test_cases: $(tests) test_cases_binary: $(tests_binary) test_cases_pv: $(tests_pv_binary) -INCLUDE_PATHS = $(SRCDIR)/lib $(SRCDIR)/lib/s390x $(SRCDIR)/s390x +SNIPPET_INCLUDE := +INCLUDE_PATHS = $(SNIPPET_INCLUDE) $(SRCDIR)/lib $(SRCDIR)/lib/s390x $(SRCDIR)/s390x # Include generated header files (e.g. in case of out-of-source builds) INCLUDE_PATHS += lib CPPFLAGS = $(addprefix -I,$(INCLUDE_PATHS))
@@ -122,6 +123,7 @@ asmlib = $(TEST_DIR)/cstart64.o $(TEST_DIR)/cpu.o FLATLIBS = $(libcflat) SNIPPET_DIR = $(TEST_DIR)/snippets +SNIPPET_SRC_DIR = $(SRCDIR)/s390x/snippets snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o snippet_lib = $(snippet_asmlib) lib/auxinfo.o
@@ -149,9 +151,10 @@ 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) +$(SNIPPET_DIR)/asm/%.o: $(SNIPPET_SRC_DIR)/asm/%.S $(asm-offsets) $(CC) $(CFLAGS) -c -nostdlib -o $@ $< +$(SNIPPET_DIR)/c/%.o: SNIPPET_INCLUDE := $(SNIPPET_SRC_DIR)/lib $(SNIPPET_DIR)/c/%.o: $(SNIPPET_DIR)/c/%.c $(asm-offsets) $(CC) $(CFLAGS) -c -nostdlib -o $@ $<
lib/s390x/asm/arch_def.h +16 -0
@@ -505,4 +505,20 @@ static inline uint32_t get_prefix(void) return current_prefix; } +static inline void diag44 (void ) +{ + asmvolatile ("diag 0,0,0x44\n" ); +} + +static inline void diag500 (uint64_t val) +{ + asmvolatile ( +"lgr 2,%[val]\n" +"diag 0,0,0x500\n" + : + : [val]"d" (val) + :"r2" + ); +} +#endif
lib/s390x/snippet-exit.h new file +45 -0
45 lines not on this page · raw message
s390x/snippets/lib/snippet-exit.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Functionality for exiting the snippet. +* +* Copyright IBM Corp. 2023 +*/ + +#ifndef _S390X_SNIPPET_LIB_EXIT_H_ +#define _S390X_SNIPPET_LIB_EXIT_H_ + +#include <asm/arch_def.h> +#include <asm/barrier.h> + +static inline void force_exit (void ) +{ +mb ();/* host may read any memory written by the guest before */ +diag44 (); +mb ();/* allow host to modify guest memory */ +} + +static inline void force_exit_value (uint64_t val) +{ +mb ();/* host may read any memory written by the guest before */ +diag500 (val); +mb ();/* allow host to modify guest memory */ +} + +#endif /* _S390X_SNIPPET_LIB_EXIT_H_ */
Signature · 1 line
2.47.1
[kvm-unit-tests GIT PULL 12/18] s390x/Makefile: Split snippet makefile rules into new file
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
It's time to move the snippet related Makefile parts into a new file to make s390x/Makefile less busy.
--- s390x/Makefile | 39 ++++----------------------------------- s390x/snippets/Makefile | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 35 deletions(-) create mode 100644 s390x/snippets/Makefile
s390x/Makefile +4 -35
@@ -123,10 +123,12 @@ asmlib = $(TEST_DIR)/cstart64.o $(TEST_DIR)/cpu.o FLATLIBS = $(libcflat) +# Snippets SNIPPET_DIR = $(TEST_DIR)/snippets SNIPPET_SRC_DIR = $(SRCDIR)/s390x/snippets snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o snippet_lib = $(snippet_asmlib) lib/auxinfo.o +include $(SNIPPET_SRC_DIR)/Makefile # perquisites (=guests) for the snippet hosts. # $(TEST_DIR)/<snippet-host>.elf: snippets = $(SNIPPET_DIR)/<c/asm>/<snippet>.gbin
@@ -152,39 +154,6 @@ else snippet-hdr-obj = endif -# the asm/c snippets %.o have additional generated files as dependencies -$(SNIPPET_DIR)/asm/%.o: $(SNIPPET_SRC_DIR)/asm/%.S $(asm-offsets) - $(CC) $(CFLAGS) -c -nostdlib -o $@ $< - -$(SNIPPET_DIR)/c/%.o: SNIPPET_INCLUDE := $(SNIPPET_SRC_DIR)/lib -$(SNIPPET_DIR)/c/%.o: $(SNIPPET_DIR)/c/%.c $(asm-offsets) - $(CC) $(CFLAGS) -c -nostdlib -o $@ $< - -$(SNIPPET_DIR)/asm/%.elf: $(SNIPPET_DIR)/asm/%.o $(SNIPPET_DIR)/asm/flat.lds - $(CC) $(LDFLAGS) -o $@ -T $(SNIPPET_DIR)/asm/flat.lds $< - -$(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.elf - $(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)/c/%.elf: $(SNIPPET_DIR)/c/%.o $(snippet_lib) $(FLATLIBS) $(SNIPPET_DIR)/c/flat.lds - $(CC) $(LDFLAGS) -o $@ -T $(SNIPPET_DIR)/c/flat.lds $< $(snippet_lib) $(FLATLIBS) - -$(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.elf - $(OBJCOPY) -O binary -j ".rodata" -j ".lowcore" -j ".text" -j ".data" -j ".bss" --set-section-flags .bss=alloc,load,contents $< $@ - truncate -s '%4096' $@ - -%.hdr: %.gbin $(HOST_KEY_DOCUMENT) - $(GEN_SE_HEADER) -k $(HOST_KEY_DOCUMENT) -c $<,0x0,0x00000000000000420000000000000000 --psw-addr 0x4000 -o $@ - -.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" $< $@ - lds-autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d -MT $@ %.lds: %.lds.S $(asm-offsets) $(CPP) $(lds-autodepend-flags) $(CPPFLAGS) -P -C -o $@ $<
@@ -238,8 +207,8 @@ $(snippet_asmlib): $$(patsubst %.o,%.S,$$@) $(asm-offsets) $(CC) $(CFLAGS) -c -nostdlib -o $@ $< -arch_clean: asm_offsets_clean - $(RM) $(TEST_DIR)/*.{o,elf,bin,lds} $(SNIPPET_DIR)/*/*.{o,elf,*bin,*obj,hdr,lds} $(SNIPPET_DIR)/asm/.*.d $(TEST_DIR)/.*.d lib/s390x/.*.d $(comm-key) +arch_clean: asm_offsets_clean snippet_clean + $(RM) $(TEST_DIR)/*.{o,elf,bin,lds} $(TEST_DIR)/.*.d lib/s390x/.*.d $(comm-key) generated-files = $(asm-offsets) $(tests:.elf=.o) $(asmlib) $(cflatobjs): $(generated-files)
s390x/snippets/Makefile new file +35 -0
@@ -0,0 +1,35 @@ +# the asm/c snippets %.o have additional generated files as dependencies +$(SNIPPET_DIR)/asm/%.o: $(SNIPPET_SRC_DIR)/asm/%.S $(asm-offsets) + $(CC) $(CFLAGS) -c -nostdlib -o $@ $< + +$(SNIPPET_DIR)/c/%.o: SNIPPET_INCLUDE := $(SNIPPET_SRC_DIR)/lib +$(SNIPPET_DIR)/c/%.o: $(SNIPPET_SRC_DIR)/c/%.c $(asm-offsets) + $(CC) $(CFLAGS) -c -nostdlib -o $@ $< + +$(SNIPPET_DIR)/asm/%.elf: $(SNIPPET_DIR)/asm/%.o $(SNIPPET_DIR)/asm/flat.lds + $(CC) $(LDFLAGS) -o $@ -T $(SNIPPET_SRC_DIR)/asm/flat.lds $< + +$(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.elf + $(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)/c/%.elf: $(SNIPPET_DIR)/c/%.o $(snippet_lib) $(FLATLIBS) $(SNIPPET_DIR)/c/flat.lds + $(CC) $(LDFLAGS) -o $@ -T $(SNIPPET_DIR)/c/flat.lds $< $(snippet_lib) $(FLATLIBS) + +$(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.elf + $(OBJCOPY) -O binary -j ".rodata" -j ".lowcore" -j ".text" -j ".data" -j ".bss" --set-section-flags .bss=alloc,load,contents $< $@ + truncate -s '%4096' $@ + +%.hdr: %.gbin $(HOST_KEY_DOCUMENT) + $(GEN_SE_HEADER) -k $(HOST_KEY_DOCUMENT) -c $<,0x0,0x00000000000000420000000000000000 --psw-addr 0x4000 -o $@ + +.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_clean: + $(RM) $(SNIPPET_DIR)/*/*.{o,elf,*bin,*obj,hdr,lds} $(SNIPPET_DIR)/asm/.*.d
Signature · 1 line
2.47.1
[kvm-unit-tests GIT PULL 14/18] s390x: Move SIE assembly into new file
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
In contrast to the other functions in cpu.S it's quite lengthy so let's split it off.
--- s390x/Makefile | 2 +- s390x/cpu-sie.S | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ s390x/cpu.S | 64 ------------------------------------------ 3 files changed, 75 insertions(+), 65 deletions(-) create mode 100644 s390x/cpu-sie.S
s390x/Makefile +1 -1
@@ -122,7 +122,7 @@ cflatobjs += lib/s390x/fault.o OBJDIRS += lib/s390x -asmlib = $(TEST_DIR)/cstart64.o $(TEST_DIR)/cpu.o +asmlib = $(TEST_DIR)/cstart64.o $(TEST_DIR)/cpu.o $(TEST_DIR)/cpu-sie.o FLATLIBS = $(libcflat)
s390x/cpu-sie.S new file +74 -0
74 lines not on this page · raw message
s390x/cpu.S +0 -64
70 lines not on this page · raw message
Signature · 1 line
2.47.1
[kvm-unit-tests GIT PULL 16/18] s390x: Support newer version of genprotimg
In reply to Nico BoehrFrom: Marc Hartmayer <[email protected]>
Since s390-tools commit f4cf4ae6ebb1 ("rust: Add a new tool called 'pvimg'") the genprotimg command checks if a given image/kernel is a s390x Linux kernel, and it does no longer overwrite the output file by default. Disable the component check, since a KUT test is being prepared, and use the '--overwrite' option to overwrite the output.
--- s390x/Makefile | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
s390x/Makefile +15 -6
@@ -182,17 +182,26 @@ $(comm-key): %.bin: %.elf $(OBJCOPY) -O binary $< $@ +define test_genprotimg_opt +$(shell $(GENPROTIMG) --help | grep -q -- "$1" && echo yes || echo no) +endef + +GENPROTIMG_DEFAULT_ARGS := --no-verify +ifneq ($(HOST_KEY_DOCUMENT),) # The genprotimg arguments for the cck changed over time so we need to # figure out which argument to use in order to set the cck -ifneq ($(HOST_KEY_DOCUMENT),) -GENPROTIMG_HAS_COMM_KEY = $(shell $(GENPROTIMG) --help | grep -q -- --comm-key && echo yes) -ifeq ($(GENPROTIMG_HAS_COMM_KEY),yes) +ifeq ($(call test_genprotimg_opt,--comm-key),yes) GENPROTIMG_COMM_OPTION := --comm-key else GENPROTIMG_COMM_OPTION := --x-comm-key endif -else -GENPROTIMG_HAS_COMM_KEY = +# Newer version of the genprotimg command checks if the given image/kernel is a +# s390x Linux kernel and it does not overwrite the output file by default. +# Disable the component check, since a KUT test is being prepared, and always +# overwrite the output. +ifeq ($(call test_genprotimg_opt,--overwrite),yes) + GENPROTIMG_DEFAULT_ARGS += --overwrite --no-component-check +endif endif ifeq ($(CONFIG_DUMP),yes)
@@ -206,7 +215,7 @@ endif $(patsubst %.parmfile,%.pv.bin,$(wildcard s390x/*.parmfile)): %.pv.bin: %.parmfile %.pv.bin: %.bin $(HOST_KEY_DOCUMENT) $(comm-key) $(eval parmfile_args = $(if $(filter %.parmfile,$^),--parmfile $(filter %.parmfile,$^),)) - $(GENPROTIMG) --host-key-document $(HOST_KEY_DOCUMENT) --no-verify $(GENPROTIMG_COMM_OPTION) $(comm-key) --x-pcf $(GENPROTIMG_PCF) $(parmfile_args) --image $(filter %.bin,$^) -o $@ + $(GENPROTIMG) $(GENPROTIMG_DEFAULT_ARGS) --host-key-document $(HOST_KEY_DOCUMENT) $(GENPROTIMG_COMM_OPTION) $(comm-key) --x-pcf $(GENPROTIMG_PCF) $(parmfile_args) --image $(filter %.bin,$^) -o $@ $(snippet_asmlib): $$(patsubst %.o,%.S,$$@) $(asm-offsets) $(CC) $(CFLAGS) -c -nostdlib -o $@ $<
Signature · 1 line
2.47.1
[kvm-unit-tests GIT PULL 11/18] s390x/Makefile: snippets: Add separate target for the ELF snippets
In reply to Nico BoehrFrom: Marc Hartmayer <[email protected]>
It's unusual to create multiple files in one target rule, and it's even more unusual to create an ELF file with a .gbin file extension first, and then overwrite it in the next step. It might even lead to errors as the input file path is also used as the output file path - but this depends on the objcopy implementation. Therefore, create an extra target for the ELF files and list it as a prerequisite for the *.gbin targets.
--- s390x/Makefile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
s390x/Makefile +8 -4
@@ -160,14 +160,18 @@ $(SNIPPET_DIR)/c/%.o: SNIPPET_INCLUDE := $(SNIPPET_SRC_DIR)/lib $(SNIPPET_DIR)/c/%.o: $(SNIPPET_DIR)/c/%.c $(asm-offsets) $(CC) $(CFLAGS) -c -nostdlib -o $@ $< -$(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o $(SNIPPET_DIR)/asm/flat.lds +$(SNIPPET_DIR)/asm/%.elf: $(SNIPPET_DIR)/asm/%.o $(SNIPPET_DIR)/asm/flat.lds $(CC) $(LDFLAGS) -o $@ -T $(SNIPPET_DIR)/asm/flat.lds $< - $(OBJCOPY) -O binary -j ".rodata" -j ".lowcore" -j ".text" -j ".data" -j ".bss" --set-section-flags .bss=alloc,load,contents $@ $@ + +$(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.elf + $(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)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_lib) $(FLATLIBS) $(SNIPPET_DIR)/c/flat.lds +$(SNIPPET_DIR)/c/%.elf: $(SNIPPET_DIR)/c/%.o $(snippet_lib) $(FLATLIBS) $(SNIPPET_DIR)/c/flat.lds $(CC) $(LDFLAGS) -o $@ -T $(SNIPPET_DIR)/c/flat.lds $< $(snippet_lib) $(FLATLIBS) - $(OBJCOPY) -O binary -j ".rodata" -j ".lowcore" -j ".text" -j ".data" -j ".bss" --set-section-flags .bss=alloc,load,contents $@ $@ + +$(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.elf + $(OBJCOPY) -O binary -j ".rodata" -j ".lowcore" -j ".text" -j ".data" -j ".bss" --set-section-flags .bss=alloc,load,contents $< $@ truncate -s '%4096' $@ %.hdr: %.gbin $(HOST_KEY_DOCUMENT)
Signature · 1 line
2.47.1
[kvm-unit-tests GIT PULL 15/18] lib: s390x: Split SIE fw structs from lib structs
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
The SIE control block is huge and takes up too much space.
Let's split the hardware definitions from sie.h into its own header, so that sie.h will only contain library functions and structs
--- lib/s390x/asm/sie-arch.h | 238 +++++++++++++++++++++++++++++++++++++++ lib/s390x/sie.h | 231 +------------------------------------ 2 files changed, 239 insertions(+), 230 deletions(-) create mode 100644 lib/s390x/asm/sie-arch.h
lib/s390x/asm/sie-arch.h new file +238 -0
@@ -0,0 +1,238 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _S390X_SIE_ARCH_H_ +#define _S390X_SIE_ARCH_H_ + +#include <stdint.h> +#include <asm/arch_def.h> + +#define CPUSTAT_STOPPED 0x80000000 +#define CPUSTAT_WAIT 0x10000000 +#define CPUSTAT_ECALL_PEND 0x08000000 +#define CPUSTAT_STOP_INT 0x04000000 +#define CPUSTAT_IO_INT 0x02000000 +#define CPUSTAT_EXT_INT 0x01000000 +#define CPUSTAT_RUNNING 0x00800000 +#define CPUSTAT_RETAINED 0x00400000 +#define CPUSTAT_TIMING_SUB 0x00020000 +#define CPUSTAT_SIE_SUB 0x00010000 +#define CPUSTAT_RRF 0x00008000 +#define CPUSTAT_SLSV 0x00004000 +#define CPUSTAT_SLSR 0x00002000 +#define CPUSTAT_ZARCH 0x00000800 +#define CPUSTAT_MCDS 0x00000100 +#define CPUSTAT_KSS 0x00000200 +#define CPUSTAT_SM 0x00000080 +#define CPUSTAT_IBS 0x00000040 +#define CPUSTAT_GED2 0x00000010 +#define CPUSTAT_G 0x00000008 +#define CPUSTAT_GED 0x00000004 +#define CPUSTAT_J 0x00000002 +#define CPUSTAT_P 0x00000001 + +struct kvm_s390_sie_block { +uint32_t cpuflags;/* 0x0000 */ + uint32_t : 1; /* 0x0004 */ +uint32_t prefix :18 ; + uint32_t : 1; +uint32_t ibc :12 ; +uint8_t reserved08[4 ];/* 0x0008 */ +#define PROG_IN_SIE (1<<0) +uint32_t prog0c;/* 0x000c */ +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 */ +uint8_t reserved24[4 ];/* 0x0024 */ +uint64_t cputm;/* 0x0028 */ +uint64_t ckc;/* 0x0030 */ +uint64_t epoch;/* 0x0038 */ +uint32_t svcc;/* 0x0040 */ +#define LCTL_CR0 0x8000 +#define LCTL_CR6 0x0200 +#define LCTL_CR9 0x0040 +#define LCTL_CR10 0x0020 +#define LCTL_CR11 0x0010 +#define LCTL_CR14 0x0002 +uint16_t lctl;/* 0x0044 */ +int16_t icpua;/* 0x0046 */ +#define ICTL_OPEREXC 0x80000000 +#define ICTL_PINT 0x20000000 +#define ICTL_LPSW 0x00400000 +#define ICTL_STCTL 0x00040000 +#define ICTL_ISKE 0x00004000 +#define ICTL_SSKE 0x00002000 +#define ICTL_RRBE 0x00001000 +#define ICTL_TPROT 0x00000200 +uint32_t ictl;/* 0x0048 */ +#define ECA_CEI 0x80000000 +#define ECA_IB 0x40000000 +#define ECA_SIGPI 0x10000000 +#define ECA_MVPGI 0x01000000 +#define ECA_AIV 0x00200000 +#define ECA_VX 0x00020000 +#define ECA_PROTEXCI 0x00002000 +#define ECA_APIE 0x00000008 +#define ECA_SII 0x00000001 +uint32_t eca;/* 0x004c */ +#define ICPT_INST 0x04 +#define ICPT_PROGI 0x08 +#define ICPT_INSTPROGI 0x0C +#define ICPT_EXTREQ 0x10 +#define ICPT_EXTINT 0x14 +#define ICPT_IOREQ 0x18 +#define ICPT_WAIT 0x1c +#define ICPT_VALIDITY 0x20 +#define ICPT_STOP 0x28 +#define ICPT_OPEREXC 0x2C +#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 0x70 +uint8_t icptcode;/* 0x0050 */ +uint8_t icptstatus;/* 0x0051 */ +uint16_t ihcpu;/* 0x0052 */ +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 */ +#define FPF_BPBC 0x20 +uint8_t fpf;/* 0x0060 */ +#define ECB_GS 0x40 +#define ECB_TE 0x10 +#define ECB_SPECI 0x08 +#define ECB_SRSI 0x04 +#define ECB_HOSTPROTINT 0x02 +uint8_t ecb;/* 0x0061 */ +#define ECB2_CMMA 0x80 +#define ECB2_IEP 0x20 +#define ECB2_PFMFI 0x08 +#define ECB2_ESCA 0x04 +uint8_t ecb2;/* 0x0062 */ +#define ECB3_DEA 0x08 +#define ECB3_AES 0x04 +#define ECB3_RI 0x01 +uint8_t ecb3;/* 0x0063 */ +uint32_t scaol;/* 0x0064 */ +uint8_t sdf;/* 0x0068 */ +uint8_t epdx;/* 0x0069 */ +uint8_t reserved6a[2 ];/* 0x006a */ +uint32_t todpr;/* 0x006c */ +#define GISA_FORMAT1 0x00000001 +uint32_t gd;/* 0x0070 */ +uint8_t reserved74[12 ];/* 0x0074 */ +uint64_t mso;/* 0x0080 */ +uint64_t msl;/* 0x0088 */ +struct psw gpsw;/* 0x0090 */ +uint64_t gg14;/* 0x00a0 */ +uint64_t gg15;/* 0x00a8 */ +uint8_t reservedb0[8 ];/* 0x00b0 */ +#define HPID_KVM 0x4 +#define HPID_VSIE 0x5 +uint8_t hpid;/* 0x00b8 */ +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 */ +uint32_t dxc;/* 0x00d0 */ +uint16_t mcn;/* 0x00d4 */ +uint8_t perc;/* 0x00d6 */ +uint8_t peratmid;/* 0x00d7 */ +uint64_t peraddr;/* 0x00d8 */ +uint8_t eai;/* 0x00e0 */ +uint8_t peraid;/* 0x00e1 */ +uint8_t oai;/* 0x00e2 */ +uint8_t armid;/* 0x00e3 */ +uint8_t reservede4[4 ];/* 0x00e4 */ +uint64_t tecmc;/* 0x00e8 */ +uint8_t reservedf0[12 ];/* 0x00f0 */ +#define CRYCB_FORMAT_MASK 0x00000003 +#define CRYCB_FORMAT0 0x00000000 +#define CRYCB_FORMAT1 0x00000001 +#define CRYCB_FORMAT2 0x00000003 +uint32_t crycbd;/* 0x00fc */ +uint64_t gcr[16 ];/* 0x0100 */ +union { +uint64_t gbea;/* 0x0180 */ +uint64_t sidad; + }; +uint8_t reserved188[8 ];/* 0x0188 */ +uint64_t sdnxo;/* 0x0190 */ +uint8_t reserved198[8 ];/* 0x0198 */ +uint32_t fac;/* 0x01a0 */ +uint8_t reserved1a4[20 ];/* 0x01a4 */ +uint64_t cbrlo;/* 0x01b8 */ +uint8_t reserved1c0[8 ];/* 0x01c0 */ +#define ECD_HOSTREGMGMT 0x20000000 +#define ECD_MEF 0x08000000 +#define ECD_ETOKENF 0x02000000 +#define ECD_ECC 0x00200000 +uint32_t ecd;/* 0x01c8 */ +uint8_t reserved1cc[18 ];/* 0x01cc */ +uint64_t pp;/* 0x01de */ +uint8_t reserved1e6[2 ];/* 0x01e6 */ +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)); + +union esca_sigp_ctrl { +uint16_t value; +struct { +uint8_t c :1 ; +uint8_t reserved:7 ; +uint8_t scn; + }; +}; + +struct esca_entry { +union esca_sigp_ctrl sigp_ctrl; +uint16_t reserved1[3 ]; +uint64_t sda; +uint64_t reserved2[6 ]; +}; + +union ipte_control { +unsigned long val; +struct { +unsigned long k :1 ; +unsigned long kh :31 ; +unsigned long kg :32 ; + }; +}; + +struct esca_block { +union ipte_control ipte_control; +uint64_t reserved1[7 ]; +uint64_t mcn[4 ]; +uint64_t reserved2[20 ]; +struct esca_entry cpu[256 ]; +}; + +#endif /* _S390X_SIE_ARCH_H_ */
lib/s390x/sie.h +1 -230
237 lines not on this page · raw message
Signature · 1 line
2.47.1
[kvm-unit-tests GIT PULL 17/18] s390x/Makefile: Make sure the linker script is generated in the build directory
In reply to Nico BoehrFrom: Marc Hartmayer <[email protected]>
This change makes sure that the 'flat.lds' linker script is actually generated in the build directory and not source directory - this makes a difference in case of an out-of-source build.
--- s390x/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
s390x/Makefile +2 -2
@@ -167,8 +167,8 @@ lds-autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d -MT $@ $(CC) $(CFLAGS) -c -o $@ $< -DPROGNAME=\"$(@:.aux.o=.elf)\" .SECONDEXPANSION: -%.elf: $(FLATLIBS) $(asmlib) $(SRCDIR)/s390x/flat.lds $$(snippets-obj) $$(snippet-hdr-obj) %.o %.aux.o - @$(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/flat.lds \ +%.elf: $(FLATLIBS) $(asmlib) $(TEST_DIR)/flat.lds $$(snippets-obj) $$(snippet-hdr-obj) %.o %.aux.o + @$(CC) $(LDFLAGS) -o $@ -T $(TEST_DIR)/flat.lds \ $(filter %.o, $^) $(FLATLIBS) $(snippets-obj) $(snippet-hdr-obj) || \ { echo "Failure probably caused by missing definition of gen-se-header executable"; exit 1; } @chmod a-x $@
Signature · 1 line
2.47.1
[kvm-unit-tests GIT PULL 18/18] s390x/Makefile: Add auxinfo.o to cflatobjs
In reply to Nico BoehrFrom: Marc Hartmayer <[email protected]>
This makes sure that the file is removed in case of make clean as the top Makefile cleans all objects defined in 'cflagsobjs'.
AFAICT, the computed sh256sum values of the generated .elf and .bin files did not change.
--- s390x/Makefile | 1 + 1 file changed, 1 insertion(+)
s390x/Makefile +1 -0
@@ -96,6 +96,7 @@ LDFLAGS += -Wl,--build-id=none asm-offsets = lib/$(ARCH)/asm-offsets.h include $(SRCDIR)/scripts/asm-offsets.mak +cflatobjs += lib/auxinfo.o cflatobjs += lib/util.o cflatobjs += lib/alloc.o cflatobjs += lib/alloc_phys.o
Signature · 1 line
2.47.1
[kvm-unit-tests GIT PULL 09/18] s390x: Use library functions for snippet exit
In reply to Nico BoehrFrom: Nina Schoetterl-Glausch <[email protected]>
Replace the existing code for exiting from snippets with the newly introduced library functionality.
--- s390x/sie-dat.c | 12 ++++-------- s390x/snippets/c/sie-dat.c | 19 +------------------ 2 files changed, 5 insertions(+), 26 deletions(-)
s390x/sie-dat.c +4 -8
@@ -17,6 +17,7 @@#include <sclp.h> #include <sie.h> #include <snippet.h> +#include <snippet-exit.h> #include "snippets/c/sie-dat.h" static struct vm vm;
@@ -27,23 +28,18 @@ static void test_sie_dat(void)uint64_t test_page_gpa, test_page_hpa;uint8_t *test_page_hva, expected_val;bool contents_match; -uint8_t r1;/* guest will tell us the guest physical address of the test buffer */ sie (&vm); -assert (vm.sblk->icptcode ==ICPT_INST && - (vm.sblk->ipa &0xff00 ) ==0x8300 && vm.sblk->ipb ==0x9c0000 ); - - r1 = (vm.sblk->ipa &0xf0 ) >>4 ; - test_page_gpa = vm.save_area.guest.grs[r1]; +assert (snippet_is_force_exit_value (&vm)); + test_page_gpa =snippet_get_force_exit_value (&vm); test_page_hpa =virt_to_pte_phys (guest_root, (void *)test_page_gpa); test_page_hva =__va (test_page_hpa);report_info ("test buffer gpa=0x%lx hva=%p" , test_page_gpa, test_page_hva);/* guest will now write to the test buffer and we verify the contents */ sie (&vm); -assert (vm.sblk->icptcode ==ICPT_INST && - vm.sblk->ipa ==0x8300 && vm.sblk->ipb ==0x440000 ); +assert (snippet_is_force_exit (&vm)); contents_match = true;for (unsigned int i =0 ; i <GUEST_TEST_PAGE_COUNT ; i++) {
s390x/snippets/c/sie-dat.c +1 -18
@@ -10,28 +10,11 @@#include <libcflat.h> #include <asm-generic/page.h> #include <asm/mem.h> +#include <snippet-exit.h> #include "sie-dat.h" static uint8_t test_pages[GUEST_TEST_PAGE_COUNT * PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE))); -static inline void force_exit (void ) -{ - asmvolatile ("diag 0,0,0x44\n" - : - : - :"memory" - ); -} - -static inline void force_exit_value (uint64_t val) -{ - asmvolatile ("diag %[val],0,0x9c\n" - : - : [val]"d" (val) - :"memory" - ); -} -int main (void ) {uint8_t *invalid_ptr;
Signature · 1 line
2.47.1
[kvm-unit-tests GIT PULL 13/18] s390x/Makefile: Add more comments
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
More comments in Makefiles can only make them more approachable.
--- s390x/Makefile | 5 +++++ 1 file changed, 5 insertions(+)
s390x/Makefile +5 -0
@@ -51,12 +51,15 @@ pv-tests += $(TEST_DIR)/pv-diags.elf pv-tests += $(TEST_DIR)/pv-icptcode.elf pv-tests += $(TEST_DIR)/pv-ipl.elf +# Add PV host tests if we're able to generate them +# The host key document and a tool to generate SE headers are the prerequisite ifneq ($(HOST_KEY_DOCUMENT),) ifneq ($(GEN_SE_HEADER),) tests += $(pv-tests) endif endif +# Add binary flat images for use in non-KVM hypervisors tests_binary = $(patsubst %.elf,%.bin,$(tests)) ifneq ($(HOST_KEY_DOCUMENT),) tests_pv_binary = $(patsubst %.bin,%.pv.bin,$(tests_binary))
@@ -146,6 +149,7 @@ $(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/loop.gbin $(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-icpt-vir-timing.gbin $(TEST_DIR)/pv-ipl.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-308.gbin +# Add PV tests and snippets if GEN_SE_HEADER is set ifneq ($(GEN_SE_HEADER),) snippets += $(pv-snippets) tests += $(pv-tests)
@@ -154,6 +158,7 @@ else snippet-hdr-obj = endif +# Generate loader script lds-autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d -MT $@ %.lds: %.lds.S $(asm-offsets) $(CPP) $(lds-autodepend-flags) $(CPPFLAGS) -P -C -o $@ $<
Signature · 1 line
2.47.1
Quoted 24 lines · Nico Boehr
Hi Paolo and/or Thomas,
Changes in this pull request:
- cpacf query function were reworked in the kernel, that fix was cherry-picked by Nina. This fixes issues with possible incorrect instruction format
- Claudio extended the edat test for a special case with a 2G page at the end of memory to ensure the correct addressing exception happens.
- I added a test for diag258 where we had some issues with virtual-physical address confusion.
- Nina took the time to add library functions that help exiting from a snippet s390x.
- Nina contributed a test for STFLE interpretive execution. Thank you!
- Marc did a lot of magic fixing issues in our Makefiles. This fixes several issues with out-of-tree-builds. We now also build out-of-tree in our downstream CI to avoid unpleasant surprises for maintainers :) Marc, thanks for contributing yourMakefileknowledge and for turning my complaints into something productive
- Janosch also invested some time to clean up snippets and Makefiles, which made the code a lot nicer, thanks for that as well!
- we have a compatibility issue with genprotimg
versions >= 2.36.0. Thanks Marc to fixing that. You should upgrade kvm-unit-tests if you use genprotimg >= 2.36.0!
Quoted 6 lines
Note that there are two checkpatch errors:
Quoted 1 line
ERROR: space prohibited before that ':' (ctx:WxW)
I would suggest to ignore them, the code really looks ugly otherwise.
Thanks
Nico
Thanks, merged now.
Thomas