s390x: Improvement of CMM test, lot of small bugfixes and two refactorings
Hi Paolo and/or Thomas,
not much has happened, but a few smaller things have accumulated, so time for a PR.
Changes in this pull request:
Just a single new test:
* test CMM no-translate bit after reset
A lot of smaller fixes:
* fix for secure guest size by Claudio
* fixes for shell script issues by Nicholas
* fix in error path of emulator test by Christian
* dirty condition code fixes by Janosch
* pv-attest missing from unittests.cfg
And, last but not least, two refactorings:
* simplification of secure boot image creation by Marc
* name inline assembly arguments in sigp lib by Janosch
Thanks
Nico
MERGE: https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/merge_requests/58
PIPELINE: https://gitlab.com/Nico-Boehr/kvm-unit-tests/-/pipelines/1264518225
PULL: https://gitlab.com/Nico-Boehr/kvm-unit-tests.git pr-2024-04-22
----
The following changes since commit 69ee03b0598ee49f75ebab5cd0fe39bf18c1146e:
Merge branch 'arm/queue' into 'master' (2024-04-19 10:41:39 +0000)
are available in the Git repository at:
https://gitlab.com/Nico-Boehr/kvm-unit-tests.git pr-2024-04-22
for you to fetch changes up to 7315fc8a182e50e5c2f387812cd178b433a40cea:
s390x: cmm: test no-translate bit after reset (2024-04-23 15:10:35 +0200)
----------------------------------------------------------------
Christian Borntraeger (1):
s390x: emulator: Fix error path of invalid function code
Claudio Imbrenda (1):
lib: s390: fix guest length in uv_create_guest()
Janosch Frank (6):
lib: s390x: sigp: Dirty CC before sigp execution
lib: s390x: uv: Dirty CC before uvc execution
lib: s390x: css: Dirty CC before css instructions
s390x: mvpg: Dirty CC before mvpg execution
s390x: sclp: Dirty CC before sclp execution
lib: s390x: sigp: Name inline assembly argumentsMarc Hartmayer (1):
s390x/Makefile: simplify Secure Execution boot image generation
Nicholas Piggin (2):
s390x: Fix is_pv check in run script
s390x: Use local accel variable in arch_cmd_s390xNico Boehr (2):
s390x: add pv-attest to unittests.cfg
s390x: cmm: test no-translate bit after resetlib/s390x/asm/sigp.h | 12 ++++++++---- lib/s390x/asm/uv.h | 4 +++- lib/s390x/css.h | 16 ++++++++++++---- lib/s390x/uv.c | 2 +- s390x/Makefile | 36 +++++++++++++++--------------------- s390x/cmm.c | 34 ++++++++++++++++++++++++++++++++++ s390x/emulator.c | 2 +- s390x/mvpg.c | 6 ++++-- s390x/run | 8 ++++---- s390x/sclp.c | 5 ++++- s390x/unittests.cfg | 3 +++ scripts/s390x/func.bash | 2 +- 12 files changed, 90 insertions(+), 40 deletions(-)
[kvm-unit-tests GIT PULL 10/13] s390x: Fix is_pv check in run script
From: Nicholas Piggin <[email protected]>
Shellcheck reports "is_pv references arguments, but none are ever passed." and suggests "use is_pv "$@" if function's $1 should mean script's $1."
The is_pv test does not evaluate to true for .pv.bin file names, only for _PV suffix test names. The arch_cmd_s390x() function appends .pv.bin to the file name AND _PV to the test name, so this does not affect run_tests.sh runs, but it might prevent PV tests from being run directly with the s390x-run command.
--- s390x/run | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
s390x/run +4 -4
@@ -21,12 +21,12 @@ is_pv() { return 1 } -if is_pv && [ "$ACCEL" = "tcg" ]; then +if is_pv "$@" && [ "$ACCEL" = "tcg" ]; then echo "Protected Virtualization isn't supported under TCG" exit 2 fi -if is_pv && [ "$MIGRATION" = "yes" ]; then +if is_pv "$@" && [ "$MIGRATION" = "yes" ]; then echo "Migration isn't supported under Protected Virtualization" exit 2 fi
@@ -34,12 +34,12 @@ fi M='-machine s390-ccw-virtio' M+=",accel=$ACCEL$ACCEL_PROPS" -if is_pv; then +if is_pv "$@"; then M+=",confidential-guest-support=pv0" fi command="$qemu -nodefaults -nographic $M" -if is_pv; then +if is_pv "$@"; then command+=" -object s390-pv-guest,id=pv0" fi command+=" -chardev stdio,id=con0 -device sclpconsole,chardev=con0"
Signature · 1 line
2.44.0
[kvm-unit-tests GIT PULL 13/13] s390x: cmm: test no-translate bit after reset
In reply to Nico BoehrKVM did not properly reset the no-translate bit after reset, see
https://lore.kernel.org/kvm/[email protected]/
Add a test which performs a load normal reset (includes a subsystem reset) and verify that this clears the no-translate bit.
--- s390x/cmm.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
s390x/cmm.c +34 -0
@@ -9,13 +9,17 @@*/ #include <libcflat.h> +#include <bitops.h> #include <asm/asm-offsets.h> #include <asm/interrupt.h> #include <asm/page.h> #include <asm/cmm.h> +#include <asm/facility.h> static uint8_t pagebuf[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); +extern int diag308_load_reset (u64 ); +static void test_params (void ) {report_prefix_push ("invalid ORC 8" );
@@ -35,6 +39,35 @@ static void test_priv(void)report_prefix_pop (); } +static void test_reset_no_translate (void ) +{ +const uint64_t mask_no_translate =BIT (63 -58 ); +unsigned long state; + +if (!test_facility (147 )) { +report_prefix_push ("no-translate unavailable" ); +expect_pgm_int (); +essa (ESSA_SET_STABLE_NODAT , (unsigned long )pagebuf); +check_pgm_int_code (PGM_INT_CODE_SPECIFICATION ); +report_prefix_pop (); +return ; + } + +report_prefix_push ("reset no-translate" ); +essa (ESSA_SET_STABLE_NODAT , (unsigned long )pagebuf); + + state =essa (ESSA_GET_STATE , (unsigned long )pagebuf); +report (state & mask_no_translate,"no-translate bit set before reset" ); + +/* Load normal reset - includes subsystem reset */ +diag308_load_reset (1 ); + + state =essa (ESSA_GET_STATE , (unsigned long )pagebuf); +report (!(state & mask_no_translate),"no-translate bit unset after reset" ); + +report_prefix_pop (); +} +int main (void ) {bool has_essa =check_essa_available ();
@@ -47,6 +80,7 @@ int main(void)test_priv ();test_params (); +test_reset_no_translate (); done:report_prefix_pop ();return report_summary ();
Signature · 1 line
2.44.0
[kvm-unit-tests GIT PULL 01/13] s390x/Makefile: simplify Secure Execution boot image generation
In reply to Nico BoehrFrom: Marc Hartmayer <[email protected]>
Changes:
+ merge Makefile rules for the generation of the Secure Execution boot image
+ fix parmfile dependency for the selftest.pv.bin target
+ rename genprotimg_pcf to GENPROTIMG_PCF to match the coding style in the file
+ always provide a customer communication key - not only for the confidential dump case. Makes the code little easier and doesn't hurt.
--- s390x/Makefile | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-)
s390x/Makefile +15 -21
@@ -197,33 +197,27 @@ $(comm-key): %.bin: %.elf $(OBJCOPY) -O binary $< $@ -# Will only be filled when dump has been enabled -GENPROTIMG_COMM_KEY = -# allow PCKMO -genprotimg_pcf = 0x000000e0 +# 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 +GENPROTIMG_HAS_COMM_KEY = $(shell $(GENPROTIMG) --help | grep -q -- --comm-key && echo yes) +ifeq ($(GENPROTIMG_HAS_COMM_KEY),yes) + GENPROTIMG_COMM_OPTION := --comm-key +else + GENPROTIMG_COMM_OPTION := --x-comm-key +endif ifeq ($(CONFIG_DUMP),yes) - # 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 - GENPROTIMG_HAS_COMM_KEY = $(shell $(GENPROTIMG) --help | grep -q -- --comm-key && echo yes) - ifeq ($(GENPROTIMG_HAS_COMM_KEY),yes) - GENPROTIMG_COMM_KEY = --comm-key $(comm-key) - else - GENPROTIMG_COMM_KEY = --x-comm-key $(comm-key) - endif - # allow dumping + PCKMO - genprotimg_pcf = 0x200000e0 + GENPROTIMG_PCF := 0x200000e0 +else + # allow PCKMO + GENPROTIMG_PCF := 0x000000e0 endif -# use x-pcf to be compatible with old genprotimg versions -genprotimg_args = --host-key-document $(HOST_KEY_DOCUMENT) --no-verify $(GENPROTIMG_COMM_KEY) --x-pcf $(genprotimg_pcf) - -%selftest.pv.bin: %selftest.bin $(HOST_KEY_DOCUMENT) $(patsubst %.pv.bin,%.parmfile,$@) $(comm-key) - $(GENPROTIMG) $(genprotimg_args) --parmfile $(patsubst %.pv.bin,%.parmfile,$@) --image $< -o $@ - +$(patsubst %.parmfile,%.pv.bin,$(wildcard s390x/*.parmfile)): %.pv.bin: %.parmfile %.pv.bin: %.bin $(HOST_KEY_DOCUMENT) $(comm-key) - $(GENPROTIMG) $(genprotimg_args) --image $< -o $@ + $(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 $@ $(snippet_asmlib): $$(patsubst %.o,%.S,$$@) $(asm-offsets) $(CC) $(CFLAGS) -c -nostdlib -o $@ $<
Signature · 1 line
2.44.0
[kvm-unit-tests GIT PULL 05/13] s390x: mvpg: Dirty CC before mvpg execution
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
Dirtying the CC allows us to find missing CC changes when mvpg is emulated.
--- s390x/mvpg.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
s390x/mvpg.c +4 -2
@@ -40,12 +40,14 @@ static uint8_t *fresh;static inline int mvpg (unsigned long r0,void *dest,void *src) { register unsigned long reg0 asm ("0") = r0; +uint64_t bogus_cc =3 ;int cc; - asmvolatile (" mvpg %1,%2\n" + asmvolatile (" tmll %[bogus_cc],3\n" +" mvpg %1,%2\n" " ipm %0\n" " srl %0,28" - :"=&d" (cc) :"a" (dest),"a" (src),"d" (reg0) + :"=&d" (cc) :"a" (dest),"a" (src),"d" (reg0), [bogus_cc]"d" (bogus_cc) :"memory" ,"cc" );return cc; }
Signature · 1 line
2.44.0
[kvm-unit-tests GIT PULL 07/13] lib: s390x: sigp: Name inline assembly arguments
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
Less need to count the operands makes the code easier to read.
--- lib/s390x/asm/sigp.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
lib/s390x/asm/sigp.h +5 -5
@@ -54,11 +54,11 @@ static inline int sigp(uint16_t addr, uint8_t order, unsigned long parm, asmvolatile (" tmll %[bogus_cc],3\n" -" sigp %1,%2,0(%3)\n" -" ipm %0\n" -" srl %0,28\n" - :"=d" (cc),"+d" (reg1) - :"d" (addr),"a" (order), [bogus_cc]"d" (bogus_cc) +" sigp %[reg1],%[addr],0(%[order])\n" +" ipm %[cc]\n" +" srl %[cc],28\n" + : [cc]"=d" (cc), [reg1]"+d" (reg1) + : [addr]"d" (addr), [order]"a" (order), [bogus_cc]"d" (bogus_cc) :"cc" );if (status) *status = reg1;
Signature · 1 line
2.44.0
[kvm-unit-tests GIT PULL 09/13] s390x: emulator: Fix error path of invalid function code
In reply to Nico BoehrFrom: Christian Borntraeger <[email protected]>
When 127 is not an invalid function code we should not wait for the program check. Move this check into the else branch.
--- s390x/emulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
s390x/emulator.c +1 -1
@@ -130,8 +130,8 @@ static __always_inline void __test_cpacf_invalid_func(unsigned int opcode)report_skip ("127 not invalid" ); }else {__test_cpacf (opcode,127 ,2 ,4 ,6 ); +check_pgm_int_code (PGM_INT_CODE_SPECIFICATION ); } -check_pgm_int_code (PGM_INT_CODE_SPECIFICATION );report_prefix_pop (); }
Signature · 1 line
2.44.0
[kvm-unit-tests GIT PULL 03/13] lib: s390x: uv: Dirty CC before uvc execution
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
Dirtying the CC allows us to find missing CC changes.
--- lib/s390x/asm/uv.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/s390x/asm/uv.h +3 -1
@@ -216,14 +216,16 @@ struct uv_cb_ssc {static inline int uv_call_once (unsigned long r1,unsigned long r2) { +uint64_t bogus_cc =1 ;int cc; asmvolatile ( +" tmll %[bogus_cc],3\n" "0: .insn rrf,0xB9A40000,%[r1],%[r2],0,0\n" " ipm %[cc]\n" " srl %[cc],28\n" : [cc]"=d" (cc) - : [r1]"a" (r1), [r2]"a" (r2) + : [r1]"a" (r1), [r2]"a" (r2), [bogus_cc]"d" (bogus_cc) :"memory" ,"cc" );if (UVC_ERR_DEBUG && cc ==1 )
Signature · 1 line
2.44.0
[kvm-unit-tests GIT PULL 04/13] lib: s390x: css: Dirty CC before css instructions
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
Dirtying the CC allows us to find missing CC changes when css instructions are emulated.
--- lib/s390x/css.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
lib/s390x/css.h +12 -4
@@ -147,14 +147,16 @@ static inline int ssch(unsigned long schid, struct orb *addr)static inline int stsch (unsigned long schid,struct schib *addr) { register unsigned long reg1 asm ("1") = schid; +uint64_t bogus_cc =1 ;int cc; asmvolatile ( +" tmll %[bogus_cc],3\n" " stsch 0(%3)\n" " ipm %0\n" " srl %0,28" :"=d" (cc),"=m" (*addr) - :"d" (reg1),"a" (addr) + :"d" (reg1),"a" (addr), [bogus_cc]"d" (bogus_cc) :"cc" );return cc; }
@@ -177,14 +179,16 @@ static inline int msch(unsigned long schid, struct schib *addr)static inline int tsch (unsigned long schid,struct irb *addr) { register unsigned long reg1 asm ("1") = schid; +uint64_t bogus_cc =2 ;int cc; asmvolatile ( +" tmll %[bogus_cc],3\n" " tsch 0(%3)\n" " ipm %0\n" " srl %0,28" :"=d" (cc),"=m" (*addr) - :"d" (reg1),"a" (addr) + :"d" (reg1),"a" (addr), [bogus_cc]"d" (bogus_cc) :"cc" );return cc; }
@@ -252,28 +256,32 @@ static inline int rsch(unsigned long schid)static inline int rchp (unsigned long chpid) { register unsigned long reg1 asm("1") = chpid; +uint64_t bogus_cc =1 ;int cc; asmvolatile ( +" tmll %[bogus_cc],3\n" " rchp\n" " ipm %0\n" " srl %0,28" :"=d" (cc) - :"d" (reg1) + :"d" (reg1), [bogus_cc]"d" (bogus_cc) :"cc" );return cc; }static inline int stcrw (uint32_t *crw) { +uint64_t bogus_cc =1 ;int cc; asmvolatile ( +" tmll %[bogus_cc],3\n" " stcrw %[crw]\n" " ipm %[cc]\n" " srl %[cc],28" : [cc]"=d" (cc) - : [crw]"Q" (*crw) + : [crw]"Q" (*crw), [bogus_cc]"d" (bogus_cc) :"cc" ,"memory" );return cc; }
Signature · 1 line
2.44.0
[kvm-unit-tests GIT PULL 06/13] s390x: sclp: Dirty CC before sclp execution
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
Dirtying the CC allows us to find missing CC changes when sclp is emulated.
--- s390x/sclp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
s390x/sclp.c +4 -1
@@ -399,6 +399,7 @@ out:static void test_instbits (void ) {SCCBHeader *h = (SCCBHeader *)pagebuf; +uint64_t bogus_cc =1 ;int cc;sclp_mark_busy ();
@@ -406,10 +407,12 @@ static void test_instbits(void)sclp_setup_int (); asmvolatile ( +" tmll %[bogus_cc],3\n" " .insn rre,0xb2204200,%1,%2\n" /* servc %1,%2 */ " ipm %0\n" " srl %0,28" - :"=&d" (cc) :"d" (valid_code),"a" (__pa (pagebuf)) + :"=&d" (cc) + :"d" (valid_code),"a" (__pa (pagebuf)), [bogus_cc]"d" (bogus_cc) :"cc" ,"memory" );/* No exception, but also no command accepted, so no interrupt is * expected. We need to clear the flag manually otherwise we will
Signature · 1 line
2.44.0
[kvm-unit-tests GIT PULL 12/13] lib: s390: fix guest length in uv_create_guest()
In reply to Nico BoehrFrom: Claudio Imbrenda <[email protected]>
The current code creates secure guests with significantly more memory than expected, but since none of that memory is ever touched, everything still works.
Fix the issue by specifying the actual guest length.
The MSL does not contain the length of the guest, but the address of the last 1M block of guest memory. In order to get the length, MSO needs to be subtracted, and 1M needs to be added.
--- lib/s390x/uv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/s390x/uv.c +1 -1
@@ -146,7 +146,7 @@ void uv_create_guest(struct vm *vm)int cc; uvcb_cgc.guest_stor_origin = vm->sblk->mso; - uvcb_cgc.guest_stor_len = vm->sblk->msl; + uvcb_cgc.guest_stor_len = vm->sblk->msl - vm->sblk->mso +SZ_1M ;/* Config allocation */ vsize = uvcb_qui.conf_base_virt_stor_len +
Signature · 1 line
2.44.0
[kvm-unit-tests GIT PULL 02/13] lib: s390x: sigp: Dirty CC before sigp execution
In reply to Nico BoehrFrom: Janosch Frank <[email protected]>
Dirtying the CC allows us to find missing CC changes when sigp is emulated.
--- lib/s390x/asm/sigp.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
lib/s390x/asm/sigp.h +5 -1
@@ -49,13 +49,17 @@ static inline int sigp(uint16_t addr, uint8_t order, unsigned long parm, uint32_t *status) { register unsigned long reg1 asm ("1") = parm; +uint64_t bogus_cc =SIGP_CC_NOT_OPERATIONAL ;int cc; asmvolatile ( +" tmll %[bogus_cc],3\n" " sigp %1,%2,0(%3)\n" " ipm %0\n" " srl %0,28\n" - :"=d" (cc),"+d" (reg1) :"d" (addr),"a" (order) :"cc" ); + :"=d" (cc),"+d" (reg1) + :"d" (addr),"a" (order), [bogus_cc]"d" (bogus_cc) + :"cc" );if (status) *status = reg1;return cc;
Signature · 1 line
2.44.0
[kvm-unit-tests GIT PULL 11/13] s390x: Use local accel variable in arch_cmd_s390x
In reply to Nico BoehrFrom: Nicholas Piggin <[email protected]>
By the time we end up in arch_cmd_s390x() the global ACCEL variable has already been processed and is passed to arch_cmd_s390x() as an argument. We should use the local argument to achieve the correct behavior and not rely on global variables.
Fix this by changing ACCEL to lower case.
Message-ID: <[email protected]>
--- scripts/s390x/func.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/s390x/func.bash +1 -1
@@ -21,7 +21,7 @@ function arch_cmd_s390x() "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" # run PV test case - if [ "$ACCEL" = 'tcg' ] || grep -q "migration" <<< "$groups"; then + if [ "$accel" = 'tcg' ] || grep -q "migration" <<< "$groups"; then return fi kernel=${kernel%.elf}.pv.bin
Signature · 1 line
2.44.0
[kvm-unit-tests GIT PULL 08/13] s390x: add pv-attest to unittests.cfg
In reply to Nico BoehrThere seems to be no obvious reason why it shouldn't be there.
--- s390x/unittests.cfg | 3 +++ 1 file changed, 3 insertions(+)
s390x/unittests.cfg +3 -0
@@ -389,3 +389,6 @@ extra_params = """-cpu max,ctop=on -smp cpus=1,drawers=2,books=2,sockets=2,cores [sie-dat] file = sie-dat.elf + +[pv-attest] +file = pv-attest.elf
Signature · 1 line
2.44.0
Thomas Huth
AppliedQuoted 60 lines · Nico Boehr
Hi Paolo and/or Thomas,
not much has happened, but a few smaller things have accumulated, so time for a PR.
Changes in this pull request:
Just a single new test:
* test CMM no-translate bit after resetA lot of smaller fixes:
* fix for secure guest size by Claudio
* fixes for shell script issues by Nicholas
* fix in error path of emulator test by Christian
* dirty condition code fixes by Janosch
* pv-attest missing from unittests.cfgAnd, last but not least, two refactorings:
* simplification of secure boot image creation by Marc
* name inline assembly arguments in sigp lib by JanoschThanks
NicoMERGE: https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/merge_requests/58
PIPELINE: https://gitlab.com/Nico-Boehr/kvm-unit-tests/-/pipelines/1264518225
PULL: https://gitlab.com/Nico-Boehr/kvm-unit-tests.git pr-2024-04-22
----
The following changes since commit69ee03b0598ee49f75ebab5cd0fe39bf18c1146e:Merge branch 'arm/queue' into 'master' (2024-04-19 10:41:39 +0000)are available in the Git repository at:
https://gitlab.com/Nico-Boehr/kvm-unit-tests.git pr-2024-04-22for you to fetch changes up to
7315fc8a182e50e5c2f387812cd178b433a40cea:s390x: cmm: test no-translate bit after reset (2024-04-23 15:10:35 +0200)----------------------------------------------------------------
Christian Borntraeger (1):s390x: emulator: Fix error path of invalid function codeClaudio Imbrenda (1):
lib: s390: fix guest length inuv_create_guest()Janosch Frank (6):
lib: s390x: sigp: Dirty CC before sigp execution lib: s390x: uv: Dirty CC before uvc execution lib: s390x: css: Dirty CC before css instructions s390x: mvpg: Dirty CC before mvpg execution s390x: sclp: Dirty CC before sclp execution lib: s390x: sigp: Name inline assembly argumentsMarc Hartmayer (1):
s390x/Makefile: simplify Secure Execution boot image generation
Quoted 7 lines
Nicholas Piggin (2):
s390x: Fix is_pv check in run script s390x: Use local accel variable in arch_cmd_s390xNico Boehr (2):
s390x: add pv-attest to unittests.cfg s390x: cmm: test no-translate bit after reset
Thanks, applied!
Thomas