s390x: More storage key instruction
cover s390x: More storage key instruction
Add test cases similar to those testing the effect of storage keys on instructions emulated by KVM, but test instructions emulated by user space/qemu instead.
Additionally, check the transaction exception identification on protection exceptions
Based on the previous storage key test series.
Janis Schoetterl-Glausch (3):
s390x: Fix sclp facility bit numbers
s390x: Test TEID values in storage key test
s390x: Test effect of storage keys on some more instructions
lib/s390x/asm/facility.h | 21 +++ lib/s390x/sclp.h | 18 ++- lib/s390x/sclp.c | 2 + s390x/skey.c | 337 ++++++++++++++++++++++++++++++++++++++- s390x/unittests.cfg | 1 + 5 files changed, 366 insertions(+), 13 deletions(-)
base-commit: 6a7a83ed106211fc0ee530a3a05f171f6a4c4e66
prerequisite-patch-id: fbcb3161ffa816cec4edea484bd9d9b22b11518b
prerequisite-patch-id: f7e97c6d2555ac61a603fa9054ba5ad391aa5dbf
prerequisite-patch-id: 14c928967e08fb48de955ccd37d5698c972e54f9
Signature · 1 line
2.33.1
PATCH 1/3 s390x: Fix sclp facility bit numbers
sclp_feat_check takes care of adjusting the bit numbering such that they can be defined as they are in the documentation.
--- lib/s390x/sclp.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
lib/s390x/sclp.h +9 -7
@@ -134,13 +134,15 @@ struct sclp_facilities { };/* bit number within a certain byte */ -#define SCLP_FEAT_85_BIT_GSLS 7 -#define SCLP_FEAT_98_BIT_KSS 0 -#define SCLP_FEAT_116_BIT_64BSCAO 7 -#define SCLP_FEAT_116_BIT_CMMA 6 -#define SCLP_FEAT_116_BIT_ESCA 3 -#define SCLP_FEAT_117_BIT_PFMFI 6 -#define SCLP_FEAT_117_BIT_IBS 5 +#define SCLP_FEAT_80_BIT_SOP 2 +#define SCLP_FEAT_85_BIT_GSLS 0 +#define SCLP_FEAT_85_BIT_ESOP 6 +#define SCLP_FEAT_98_BIT_KSS 7 +#define SCLP_FEAT_116_BIT_64BSCAO 0 +#define SCLP_FEAT_116_BIT_CMMA 1 +#define SCLP_FEAT_116_BIT_ESCA 4 +#define SCLP_FEAT_117_BIT_PFMFI 1 +#define SCLP_FEAT_117_BIT_IBS 2 typedef struct ReadInfo { SCCBHeader h;
Signature · 1 line
2.33.1
Re: [kvm-unit-tests PATCH 1/3] s390x: Fix sclp facility bit numbers
Quoted 2 lines · On Thu, 5 May 2022 14:46:54 +0200 Janis Schoetterl-Glausch…
sclp_feat_checktakes care of adjusting the bit numbering such that they can be defined as they are in the documentation.
this means we had it wrong all along and we somehow never noticed
ooops!
anyway:
Quoted 34 lines
Fixes 4dd649c8 ("lib: s390x: sclp: Extend feature probing")Signed-off-by Janis Schoetterl-Glausch <[email protected]>--- lib/s390x/sclp.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)lib/s390x/sclp.h +9
-7@@ -134,13 +134,15 @@ struct sclp_facilities { };/* bit number within a certain byte */ -#define SCLP_FEAT_85_BIT_GSLS 7 -#define SCLP_FEAT_98_BIT_KSS 0 -#define SCLP_FEAT_116_BIT_64BSCAO 7 -#define SCLP_FEAT_116_BIT_CMMA 6 -#define SCLP_FEAT_116_BIT_ESCA 3 -#define SCLP_FEAT_117_BIT_PFMFI 6 -#define SCLP_FEAT_117_BIT_IBS 5 +#define SCLP_FEAT_80_BIT_SOP 2 +#define SCLP_FEAT_85_BIT_GSLS 0 +#define SCLP_FEAT_85_BIT_ESOP 6 +#define SCLP_FEAT_98_BIT_KSS 7 +#define SCLP_FEAT_116_BIT_64BSCAO 0 +#define SCLP_FEAT_116_BIT_CMMA 1 +#define SCLP_FEAT_116_BIT_ESCA 4 +#define SCLP_FEAT_117_BIT_PFMFI 1 +#define SCLP_FEAT_117_BIT_IBS 2 typedef struct ReadInfo { SCCBHeader h;
Re: [kvm-unit-tests PATCH 1/3] s390x: Fix sclp facility bit numbers
Quoted 7 lines · Claudio Imbrenda
Quoted 2 lines · On Thu, 5 May 2022 14:46:54 +0200 Janis Schoetterl-Glausch…
sclp_feat_checktakes care of adjusting the bit numbering such that they can be defined as they are in the documentation.this means we had it wrong all along and we somehow never noticed
That tends to happen when you add definitions and never actually use them. :)
Quoted 42 lines
ooops!
anyway:
Reviewed-by Claudio Imbrenda <[email protected]>Quoted 34 lines
Fixes 4dd649c8 ("lib: s390x: sclp: Extend feature probing")Signed-off-by Janis Schoetterl-Glausch <[email protected]>--- lib/s390x/sclp.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)lib/s390x/sclp.h +9
-7@@ -134,13 +134,15 @@ struct sclp_facilities { };/* bit number within a certain byte */ -#define SCLP_FEAT_85_BIT_GSLS 7 -#define SCLP_FEAT_98_BIT_KSS 0 -#define SCLP_FEAT_116_BIT_64BSCAO 7 -#define SCLP_FEAT_116_BIT_CMMA 6 -#define SCLP_FEAT_116_BIT_ESCA 3 -#define SCLP_FEAT_117_BIT_PFMFI 6 -#define SCLP_FEAT_117_BIT_IBS 5 +#define SCLP_FEAT_80_BIT_SOP 2 +#define SCLP_FEAT_85_BIT_GSLS 0 +#define SCLP_FEAT_85_BIT_ESOP 6 +#define SCLP_FEAT_98_BIT_KSS 7 +#define SCLP_FEAT_116_BIT_64BSCAO 0 +#define SCLP_FEAT_116_BIT_CMMA 1 +#define SCLP_FEAT_116_BIT_ESCA 4 +#define SCLP_FEAT_117_BIT_PFMFI 1 +#define SCLP_FEAT_117_BIT_IBS 2 typedef struct ReadInfo { SCCBHeader h;
Re: [kvm-unit-tests PATCH 1/3] s390x: Fix sclp facility bit numbers
In reply to Janis Schoetterl-GlauschQuoted 5 lines · Janis Schoetterl-Glausch
sclp_feat_checktakes care of adjusting the bit numbering such that they can be defined as they are in the documentation.Fixes 4dd649c8 ("lib: s390x: sclp: Extend feature probing")Signed-off-by Janis Schoetterl-Glausch <[email protected]>
The fixing part of this is:
But please add the (E)SOP bits in the other patches.
Quoted 31 lines
--- lib/s390x/sclp.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)lib/s390x/sclp.h +9
-7@@ -134,13 +134,15 @@ struct sclp_facilities { };/* bit number within a certain byte */ -#define SCLP_FEAT_85_BIT_GSLS 7 -#define SCLP_FEAT_98_BIT_KSS 0 -#define SCLP_FEAT_116_BIT_64BSCAO 7 -#define SCLP_FEAT_116_BIT_CMMA 6 -#define SCLP_FEAT_116_BIT_ESCA 3 -#define SCLP_FEAT_117_BIT_PFMFI 6 -#define SCLP_FEAT_117_BIT_IBS 5 +#define SCLP_FEAT_80_BIT_SOP 2 +#define SCLP_FEAT_85_BIT_GSLS 0 +#define SCLP_FEAT_85_BIT_ESOP 6 +#define SCLP_FEAT_98_BIT_KSS 7 +#define SCLP_FEAT_116_BIT_64BSCAO 0 +#define SCLP_FEAT_116_BIT_CMMA 1 +#define SCLP_FEAT_116_BIT_ESCA 4 +#define SCLP_FEAT_117_BIT_PFMFI 1 +#define SCLP_FEAT_117_BIT_IBS 2 typedef struct ReadInfo { SCCBHeader h;
Re: [kvm-unit-tests PATCH 1/3] s390x: Fix sclp facility bit numbers
Quoted 11 lines · Janosch Frank
Quoted 5 lines · Janis Schoetterl-Glausch
sclp_feat_checktakes care of adjusting the bit numbering such that they can be defined as they are in the documentation.Fixes 4dd649c8 ("lib: s390x: sclp: Extend feature probing")Signed-off-by Janis Schoetterl-Glausch <[email protected]>The fixing part of this is:
Reviewed-by Janosch Frank <[email protected]>But please add the (E)SOP bits in the other patches.
Oh, yeah, that slipped by me.
Quoted 31 lines
Quoted 30 lines
---
lib/s390x/sclp.h| 16 +++++++++-------1 file changed, 9 insertions(+), 7 deletions(-)lib/s390x/sclp.h +9
-7@@ -134,13 +134,15 @@ struct sclp_facilities { }; /* bit number within a certain byte */ -#define SCLP_FEAT_85_BIT_GSLS 7 -#define SCLP_FEAT_98_BIT_KSS 0 -#define SCLP_FEAT_116_BIT_64BSCAO 7 -#define SCLP_FEAT_116_BIT_CMMA 6 -#define SCLP_FEAT_116_BIT_ESCA 3 -#define SCLP_FEAT_117_BIT_PFMFI 6 -#define SCLP_FEAT_117_BIT_IBS 5 +#define SCLP_FEAT_80_BIT_SOP 2 +#define SCLP_FEAT_85_BIT_GSLS 0 +#define SCLP_FEAT_85_BIT_ESOP 6 +#define SCLP_FEAT_98_BIT_KSS 7 +#define SCLP_FEAT_116_BIT_64BSCAO 0 +#define SCLP_FEAT_116_BIT_CMMA 1 +#define SCLP_FEAT_116_BIT_ESCA 4 +#define SCLP_FEAT_117_BIT_PFMFI 1 +#define SCLP_FEAT_117_BIT_IBS 2 typedef struct ReadInfo { SCCBHeader h;
PATCH 2/3 s390x: Test TEID values in storage key test
In reply to Janis Schoetterl-GlauschOn a protection exception, test that the Translation-Exception Identification (TEID) values are correct given the circumstances of the particular test.
The meaning of the TEID values is dependent on the installed suppression-on-protection facility.
--- lib/s390x/asm/facility.h | 21 ++++++++++++++ lib/s390x/sclp.h | 2 ++ lib/s390x/sclp.c | 2 ++ s390x/skey.c | 60 ++++++++++++++++++++++++++++++++++++---- 4 files changed, 79 insertions(+), 6 deletions(-)
lib/s390x/asm/facility.h +21 -0
@@ -12,6 +12,7 @@#include <asm/facility.h> #include <asm/arch_def.h> #include <bitops.h> +#include <sclp.h> #define NB_STFL_DOUBLEWORDS 32extern uint64_t stfl_doublewords[];
@@ -44,4 +45,24 @@ static inline void setup_facilities(void) stfle(stfl_doublewords, NB_STFL_DOUBLEWORDS); } +enum supp_on_prot_facility { +SOP_NONE , +SOP_BASIC , +SOP_ENHANCED_1 , +SOP_ENHANCED_2 , +}; + +static inline enum supp_on_prot_facility get_supp_on_prot_facility (void ) +{ +if (sclp_facilities.has_esop) { +if (test_facility (131 ))/* side-effect-access facility */ +return SOP_ENHANCED_2 ; +else +return SOP_ENHANCED_1 ; + } +if (sclp_facilities.has_sop) +return SOP_BASIC ; +return SOP_NONE ; +} +#endif
lib/s390x/sclp.h +2 -0
@@ -123,7 +123,9 @@ struct sclp_facilities { uint64_t has_cei : 1; uint64_t has_diag318 : 1; + uint64_t has_sop : 1; uint64_t has_gsls : 1; + uint64_t has_esop : 1; uint64_t has_cmma : 1; uint64_t has_64bscao : 1; uint64_t has_esca : 1;
lib/s390x/sclp.c +2 -0
@@ -152,7 +152,9 @@ void sclp_facilities_setup(void) cpu =sclp_get_cpu_entries ();if (read_info->offset_cpu >134 ) sclp_facilities.has_diag318 = read_info->byte_134_diag318; + sclp_facilities.has_sop =sclp_feat_check (80 ,SCLP_FEAT_80_BIT_SOP ); sclp_facilities.has_gsls =sclp_feat_check (85 ,SCLP_FEAT_85_BIT_GSLS ); + sclp_facilities.has_esop =sclp_feat_check (85 ,SCLP_FEAT_85_BIT_ESOP ); sclp_facilities.has_kss =sclp_feat_check (98 ,SCLP_FEAT_98_BIT_KSS ); sclp_facilities.has_cmma =sclp_feat_check (116 ,SCLP_FEAT_116_BIT_CMMA ); sclp_facilities.has_64bscao =sclp_feat_check (116 ,SCLP_FEAT_116_BIT_64BSCAO );
s390x/skey.c +54 -6
108 lines not on this page · raw message
Signature · 1 line
2.33.1
Re: [kvm-unit-tests PATCH 2/3] s390x: Test TEID values in storage key test
Quoted 92 lines · On Thu, 5 May 2022 14:46:55 +0200 Janis Schoetterl-Glausch…
On a protection exception, test that the Translation-Exception Identification (TEID) values are correct given the circumstances of the particular test.
The meaning of the TEID values is dependent on the installed suppression-on-protection facility.Signed-off-by Janis Schoetterl-Glausch <[email protected]>--- lib/s390x/asm/facility.h | 21 ++++++++++++++ lib/s390x/sclp.h | 2 ++ lib/s390x/sclp.c | 2 ++ s390x/skey.c | 60 ++++++++++++++++++++++++++++++++++++---- 4 files changed, 79 insertions(+), 6 deletions(-)lib/s390x/asm/facility.h +21
-0@@ -12,6 +12,7 @@#include <asm/facility.h> #include <asm/arch_def.h> #include <bitops.h> +#include <sclp.h> #define NB_STFL_DOUBLEWORDS 32extern uint64_t stfl_doublewords[];@@ -44,4 +45,24 @@ static inline void setup_facilities(void) stfle(stfl_doublewords, NB_STFL_DOUBLEWORDS); } +enum supp_on_prot_facility { +SOP_NONE , +SOP_BASIC , +SOP_ENHANCED_1 , +SOP_ENHANCED_2 , +}; + +static inline enum supp_on_prot_facility get_supp_on_prot_facility (void ) +{ +if (sclp_facilities.has_esop) { +if (test_facility (131 ))/* side-effect-access facility */ +return SOP_ENHANCED_2 ; +else +return SOP_ENHANCED_1 ; + } +if (sclp_facilities.has_sop) +return SOP_BASIC ; +return SOP_NONE ; +} +#endif lib/s390x/sclp.h +2
-0@@ -123,7 +123,9 @@ struct sclp_facilities { uint64_t has_cei : 1; uint64_t has_diag318 : 1; + uint64_t has_sop : 1; uint64_t has_gsls : 1; + uint64_t has_esop : 1; uint64_t has_cmma : 1; uint64_t has_64bscao : 1; uint64_t has_esca : 1;lib/s390x/sclp.c +2
-0@@ -152,7 +152,9 @@ void sclp_facilities_setup(void) cpu =sclp_get_cpu_entries ();if (read_info->offset_cpu >134 ) sclp_facilities.has_diag318 = read_info->byte_134_diag318; + sclp_facilities.has_sop =sclp_feat_check (80 ,SCLP_FEAT_80_BIT_SOP ); sclp_facilities.has_gsls =sclp_feat_check (85 ,SCLP_FEAT_85_BIT_GSLS ); + sclp_facilities.has_esop =sclp_feat_check (85 ,SCLP_FEAT_85_BIT_ESOP ); sclp_facilities.has_kss =sclp_feat_check (98 ,SCLP_FEAT_98_BIT_KSS ); sclp_facilities.has_cmma =sclp_feat_check (116 ,SCLP_FEAT_116_BIT_CMMA ); sclp_facilities.has_64bscao =sclp_feat_check (116 ,SCLP_FEAT_116_BIT_64BSCAO );s390x/skey.c +1
-0@@ -8,6 +8,7 @@* Janosch Frank <[email protected]> */ #include <libcflat.h> +#include <bitops.h> #include <asm/asm-offsets.h> #include <asm/interrupt.h> #include <vmalloc.h>
s390x/skey.c static void test_test_protection(void) · line 166
Quoted 8 lines
s390x/skey.c +5
-0@@ -158,6 +159,53 @@ static void test_test_protection(void)report_prefix_pop (); } +enum access { +ACC_FETCH =2 , +ACC_STORE =1 , +ACC_UPDATE =3 , +};
why not in numerical order?
s390x/skey.c static void test_test_protection(void) · line 171
Quoted 5 lines
s390x/skey.c +5
-0+ +enum protection { +PROT_STORE =1 , +PROT_FETCH_STORE =3 , +};
what happened to 2?
Quoted 5 lines
s390x/skey.c +5
-0+ +static void check_key_prot_exc (enum access access,enum protection prot) +{ +struct lowcore *lc =0 ; +union teid teid;
s390x/skey.c static void test_test_protection(void) · line 186
Quoted 10 lines
s390x/skey.c +10
-0+ +check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +report_prefix_push ("TEID" ); + teid.val = lc->trans_exc_id; +switch (get_supp_on_prot_facility ()) { +case SOP_NONE : +case SOP_BASIC : +break ; +case SOP_ENHANCED_1 : +if ((teid.val & (BIT (63 -61 ))) ==0 )
why not teid.m?
s390x/skey.c static void test_test_protection(void) · line 190
Quoted 4 lines
s390x/skey.c +4
-0+report_pass ("key-controlled protection" ); +break ; +case SOP_ENHANCED_2 : +if ((teid.val & (BIT (63 -56 ) |BIT (63 -61 ))) ==0 ) {
maybe here you need to expand struct teid a little to accomodate for bit 56.
s390x/skey.c static void test_test_protection(void) · line 195
Quoted 5 lines
s390x/skey.c +5
-0+report_pass ("key-controlled protection" ); +if (teid.val &BIT (63 -60 )) { +int access_code = teid.fetch <<1 | teid.store; + +report_info ("access code: %d" , access_code);
I don't like an unconditional report_info (it's ok to aid debugging if something fails)
s390x/skey.c static void test_test_protection(void) · line 201
Quoted 6 lines
s390x/skey.c +6
-0+if (access_code ==2 ) +report ((access &2 ) && (prot &2 ), +"exception due to fetch" ); +if (access_code ==1 ) +report ((access &1 ) && (prot &1 ), +"exception due to store" );
what about cases 0 and 3?
if they should never happen, handle it properly
and if they can happen... handle it properly
Quoted 64 lines
s390x/skey.c +13
-6+ } + } +break ; + } +report_prefix_pop (); +} +/* * Perform STORE CPU ADDRESS (STAP) instruction while temporarily executing * with access key 1. @@ -199,7 +247,7 @@ static void test_store_cpu_address(void)expect_pgm_int (); *out =0xbeef ;store_cpu_address_key_1 (out); -check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +check_key_prot_exc (ACC_STORE ,PROT_STORE );report (*out ==0xbeef ,"no store occurred" );report_prefix_pop ();@@ -210,7 +258,7 @@ static void test_store_cpu_address(void)expect_pgm_int (); *out =0xbeef ;store_cpu_address_key_1 (out); -check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +check_key_prot_exc (ACC_STORE ,PROT_STORE );report (*out ==0xbeef ,"no store occurred" );report_prefix_pop ();@@ -228,7 +276,7 @@ static void test_store_cpu_address(void)expect_pgm_int (); *out =0xbeef ;store_cpu_address_key_1 (out); -check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +check_key_prot_exc (ACC_STORE ,PROT_STORE );report (*out ==0xbeef ,"no store occurred" );report_prefix_pop ();@@ -314,7 +362,7 @@ static void test_set_prefix(void)set_storage_key (pagebuf,0x28 ,0 );expect_pgm_int ();set_prefix_key_1 (prefix_ptr); -check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +check_key_prot_exc (ACC_FETCH ,PROT_FETCH_STORE );report (get_prefix () == old_prefix,"did not set prefix" );report_prefix_pop ();@@ -327,7 +375,7 @@ static void test_set_prefix(void)install_page (root,virt_to_pte_phys (root, pagebuf),0 );set_prefix_key_1 ((uint32_t *)0 );install_page (root,0 ,0 ); -check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +check_key_prot_exc (ACC_FETCH ,PROT_FETCH_STORE );report (get_prefix () == old_prefix,"did not set prefix" );report_prefix_pop ();@@ -351,7 +399,7 @@ static void test_set_prefix(void)install_page (root,virt_to_pte_phys (root, pagebuf),0 );set_prefix_key_1 ((uint32_t *)2048 );install_page (root,0 ,0 ); -check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +check_key_prot_exc (ACC_FETCH ,PROT_FETCH_STORE );report (get_prefix () == old_prefix,"did not set prefix" );report_prefix_pop ();
Re: [kvm-unit-tests PATCH 2/3] s390x: Test TEID values in storage key test
Quoted 17 lines · Claudio Imbrenda
Quoted 14 lines · On Thu, 5 May 2022 14:46:55 +0200 Janis Schoetterl-Glausch…
On a protection exception, test that the Translation-Exception Identification (TEID) values are correct given the circumstances of the particular test.
The meaning of the TEID values is dependent on the installed suppression-on-protection facility.Signed-off-by Janis Schoetterl-Glausch <[email protected]>--- lib/s390x/asm/facility.h | 21 ++++++++++++++ lib/s390x/sclp.h | 2 ++ lib/s390x/sclp.c | 2 ++ s390x/skey.c | 60 ++++++++++++++++++++++++++++++++++++---- 4 files changed, 79 insertions(+), 6 deletions(-)
[...]
Quoted 8 lines
s390x/skey.c static void test_test_protection(void) · line 166
Quoted 6 lines
s390x/skey.c +5
-0+enum access { +ACC_FETCH =2 , +ACC_STORE =1 , +ACC_UPDATE =3 , +};why not in numerical order?
The numbers are chosen such that the bit masking in the function below is nicer, but the ordering is basically arbitrary.
Somehow fetch, store, update seems natural to me, but I can sort it. I had ACC_NONE for a bit, but as I don't need it, I removed it.
Quoted 8 lines
s390x/skey.c static void test_test_protection(void) · line 171
Quoted 6 lines
s390x/skey.c +5
-0+ +enum protection { +PROT_STORE =1 , +PROT_FETCH_STORE =3 , +};what happened to 2?
There is no such thing as fetch only protection, so that's a result of the choice of values for masking.
Quoted 10 lines
Quoted 10 lines
s390x/skey.c +9
-0+ +static void check_key_prot_exc (enum access access,enum protection prot) +{ +struct lowcore *lc =0 ; +union teid teid; + +check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +report_prefix_push ("TEID" ); + teid.val = lc->trans_exc_id;
Quoted 8 lines
s390x/skey.c static void test_test_protection(void) · line 186
Quoted 6 lines
s390x/skey.c +6
-0+switch (get_supp_on_prot_facility ()) { +case SOP_NONE : +case SOP_BASIC : +break ; +case SOP_ENHANCED_1 : +if ((teid.val & (BIT (63 -61 ))) ==0 )why not teid.m?
I considered using .m, but the name does not contain any more information on the meaning than just the number.
The PoP talks of the bits by their numbers in the suppression on detection chapter, so this is the most straight forward translation into code.
Quoted 8 lines
s390x/skey.c static void test_test_protection(void) · line 190
Quoted 5 lines
s390x/skey.c +4
-0+report_pass ("key-controlled protection" ); +break ; +case SOP_ENHANCED_2 : +if ((teid.val & (BIT (63 -56 ) |BIT (63 -61 ))) ==0 ) {maybe here you need to expand struct teid a little to accomodate for bit 56.
I could not think of a good name.
Quoted 9 lines
s390x/skey.c static void test_test_protection(void) · line 195
Quoted 6 lines
s390x/skey.c +5
-0+report_pass ("key-controlled protection" ); +if (teid.val &BIT (63 -60 )) { +int access_code = teid.fetch <<1 | teid.store; + +report_info ("access code: %d" , access_code);I don't like an unconditional
report_info(it's ok to aid debugging if something fails)
In the case of update references the value you get is unspecified, so I found it interesting to see what happens in LPAR.
I could only print it for update references, but I'm also fine with just dropping it. What do you think?
Quoted 9 lines
s390x/skey.c static void test_test_protection(void) · line 201
Quoted 7 lines
s390x/skey.c +6
-0+if (access_code ==2 ) +report ((access &2 ) && (prot &2 ), +"exception due to fetch" ); +if (access_code ==1 ) +report ((access &1 ) && (prot &1 ), +"exception due to store" );what about cases 0 and 3?
Case 0 is specified to not contain any information and 3 is reserved, so also no information.
Quoted 68 lines
if they should never happen, handle it properly
and if they can happen... handle it properlyQuoted 64 lines
s390x/skey.c +13
-6+ } + } +break ; + } +report_prefix_pop (); +} +/* * Perform STORE CPU ADDRESS (STAP) instruction while temporarily executing * with access key 1. @@ -199,7 +247,7 @@ static void test_store_cpu_address(void)expect_pgm_int (); *out =0xbeef ;store_cpu_address_key_1 (out); -check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +check_key_prot_exc (ACC_STORE ,PROT_STORE );report (*out ==0xbeef ,"no store occurred" );report_prefix_pop ();@@ -210,7 +258,7 @@ static void test_store_cpu_address(void)expect_pgm_int (); *out =0xbeef ;store_cpu_address_key_1 (out); -check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +check_key_prot_exc (ACC_STORE ,PROT_STORE );report (*out ==0xbeef ,"no store occurred" );report_prefix_pop ();@@ -228,7 +276,7 @@ static void test_store_cpu_address(void)expect_pgm_int (); *out =0xbeef ;store_cpu_address_key_1 (out); -check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +check_key_prot_exc (ACC_STORE ,PROT_STORE );report (*out ==0xbeef ,"no store occurred" );report_prefix_pop ();@@ -314,7 +362,7 @@ static void test_set_prefix(void)set_storage_key (pagebuf,0x28 ,0 );expect_pgm_int ();set_prefix_key_1 (prefix_ptr); -check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +check_key_prot_exc (ACC_FETCH ,PROT_FETCH_STORE );report (get_prefix () == old_prefix,"did not set prefix" );report_prefix_pop ();@@ -327,7 +375,7 @@ static void test_set_prefix(void)install_page (root,virt_to_pte_phys (root, pagebuf),0 );set_prefix_key_1 ((uint32_t *)0 );install_page (root,0 ,0 ); -check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +check_key_prot_exc (ACC_FETCH ,PROT_FETCH_STORE );report (get_prefix () == old_prefix,"did not set prefix" );report_prefix_pop ();@@ -351,7 +399,7 @@ static void test_set_prefix(void)install_page (root,virt_to_pte_phys (root, pagebuf),0 );set_prefix_key_1 ((uint32_t *)2048 );install_page (root,0 ,0 ); -check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +check_key_prot_exc (ACC_FETCH ,PROT_FETCH_STORE );report (get_prefix () == old_prefix,"did not set prefix" );report_prefix_pop ();
PATCH 3/3 s390x: Test effect of storage keys on some more instructions
In reply to Janis Schoetterl-GlauschTest correctness of some instructions handled by user space instead of KVM with regards to storage keys.
Test success and error conditions, including coverage of storage and fetch protection override.
--- s390x/skey.c | 277 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 1 + 2 files changed, 278 insertions(+)
s390x/skey.c +277 -0
@@ -12,6 +12,7 @@#include <asm/asm-offsets.h> #include <asm/interrupt.h> #include <vmalloc.h> +#include <css.h> #include <asm/page.h> #include <asm/facility.h> #include <asm/mem.h>
@@ -284,6 +285,114 @@ static void test_store_cpu_address(void)report_prefix_pop (); } +/* +* Perform CHANNEL SUBSYSTEM CALL (CHSC) instruction while temporarily executing +* with access key 1. +*/ +static unsigned int channel_subsystem_call_key_1 (void *communication_block) +{ +uint32_t program_mask; + + asmvolatile ( +"spka 0x10\n\t" +".insn rre,0xb25f0000,%[communication_block],0\n\t" +"spka 0\n\t" +"ipm %[program_mask]\n" + : [program_mask]"=d" (program_mask) + : [communication_block]"d" (communication_block) + :"memory" + ); +return program_mask >>28 ; +} + +static void init_store_channel_subsystem_characteristics (uint16_t *communication_block) +{ +memset (communication_block,0 ,PAGE_SIZE ); + communication_block[0 ] =0x10 ; + communication_block[1 ] =0x10 ; + communication_block[9 ] =0 ; +} + +static void test_channel_subsystem_call (void ) +{ +static const char request_name[] ="Store channel-subsystem-characteristics" ; +uint16_t *communication_block = (uint16_t *)&pagebuf; +unsigned int cc; + +report_prefix_push ("CHANNEL SUBSYSTEM CALL" ); + +report_prefix_push ("zero key" ); +init_store_channel_subsystem_characteristics (communication_block); +set_storage_key (communication_block,0x10 ,0 ); + asmvolatile ( +".insn rre,0xb25f0000,%[communication_block],0\n\t" +"ipm %[cc]\n" + : [cc]"=d" (cc) + : [communication_block]"d" (communication_block) + :"memory" + ); + cc = cc >>28 ; +report (cc ==0 && communication_block[9 ], request_name); +report_prefix_pop (); + +report_prefix_push ("matching key" ); +init_store_channel_subsystem_characteristics (communication_block); +set_storage_key (communication_block,0x10 ,0 ); + cc =channel_subsystem_call_key_1 (communication_block); +report (cc ==0 && communication_block[9 ], request_name); +report_prefix_pop (); + +report_prefix_push ("mismatching key" ); + +report_prefix_push ("no fetch protection" ); +init_store_channel_subsystem_characteristics (communication_block); +set_storage_key (communication_block,0x20 ,0 ); +expect_pgm_int (); +channel_subsystem_call_key_1 (communication_block); +check_key_prot_exc (ACC_UPDATE ,PROT_STORE ); +report_prefix_pop (); + +report_prefix_push ("fetch protection" ); +init_store_channel_subsystem_characteristics (communication_block); +set_storage_key (communication_block,0x28 ,0 ); +expect_pgm_int (); +channel_subsystem_call_key_1 (communication_block); +check_key_prot_exc (ACC_UPDATE ,PROT_FETCH_STORE ); +report_prefix_pop (); + +ctl_set_bit (0 ,CTL0_STORAGE_PROTECTION_OVERRIDE ); + +report_prefix_push ("storage-protection override, invalid key" ); +set_storage_key (communication_block,0x20 ,0 ); +init_store_channel_subsystem_characteristics (communication_block); +expect_pgm_int (); +channel_subsystem_call_key_1 (communication_block); +check_key_prot_exc (ACC_UPDATE ,PROT_STORE ); +report_prefix_pop (); + +report_prefix_push ("storage-protection override, override key" ); +init_store_channel_subsystem_characteristics (communication_block); +set_storage_key (communication_block,0x90 ,0 ); + cc =channel_subsystem_call_key_1 (communication_block); +report (cc ==0 && communication_block[9 ], request_name); +report_prefix_pop (); + +ctl_clear_bit (0 ,CTL0_STORAGE_PROTECTION_OVERRIDE ); + +report_prefix_push ("storage-protection override disabled, override key" ); +init_store_channel_subsystem_characteristics (communication_block); +set_storage_key (communication_block,0x90 ,0 ); +expect_pgm_int (); +channel_subsystem_call_key_1 (communication_block); +check_key_prot_exc (ACC_UPDATE ,PROT_STORE ); +report_prefix_pop (); + +report_prefix_pop (); + +set_storage_key (communication_block,0x00 ,0 ); +report_prefix_pop (); +} +/* * Perform SET PREFIX (SPX) instruction while temporarily executing * with access key 1.
@@ -410,6 +519,172 @@ static void test_set_prefix(void)report_prefix_pop (); } +/* +* Perform MODIFY SUBCHANNEL (MSCH) instruction while temporarily executing +* with access key 1. +*/ +static uint32_t modify_subchannel_key_1 (uint32_t sid,struct schib *schib) +{ +uint32_t program_mask; + + asmvolatile ( +"lr %%r1,%[sid]\n\t" +"spka 0x10\n\t" +"msch %[schib]\n\t" +"spka 0\n\t" +"ipm %[program_mask]\n" + : [program_mask]"=d" (program_mask) + : [sid]"d" (sid), + [schib]"Q" (*schib) + :"%r1" + ); +return program_mask >>28 ; +} + +static void test_msch (void ) +{ +struct schib *schib = (struct schib *)pagebuf; +struct schib *no_override_schib; +int test_device_sid; +pgd_t *root; +int cc; + +report_prefix_push ("MSCH" ); + root = (pgd_t *)(stctg (1 ) &PAGE_MASK ); + test_device_sid =css_enumerate (); + +if (!(test_device_sid &SCHID_ONE )) { +report_fail ("no I/O device found" ); +return ; + } + + cc =stsch (test_device_sid, schib); +if (cc) { +report_fail ("could not store SCHIB" ); +return ; + } + +report_prefix_push ("zero key" ); + schib->pmcw.intparm =100 ; +set_storage_key (schib,0x28 ,0 ); + cc =msch (test_device_sid, schib); +if (!cc) { +WRITE_ONCE (schib->pmcw.intparm,0 ); + cc =stsch (test_device_sid, schib); +report (!cc && schib->pmcw.intparm ==100 ,"fetched from SCHIB" ); + }else { +report_fail ("MSCH cc != 0" ); + } +report_prefix_pop (); + +report_prefix_push ("matching key" ); + schib->pmcw.intparm =200 ; +set_storage_key (schib,0x18 ,0 ); + cc =modify_subchannel_key_1 (test_device_sid, schib); +if (!cc) { +WRITE_ONCE (schib->pmcw.intparm,0 ); + cc =stsch (test_device_sid, schib); +report (!cc && schib->pmcw.intparm ==200 ,"fetched from SCHIB" ); + }else { +report_fail ("MSCH cc != 0" ); + } +report_prefix_pop (); + +report_prefix_push ("mismatching key" ); + +report_prefix_push ("no fetch protection" ); + schib->pmcw.intparm =300 ; +set_storage_key (schib,0x20 ,0 ); + cc =modify_subchannel_key_1 (test_device_sid, schib); +if (!cc) { +WRITE_ONCE (schib->pmcw.intparm,0 ); + cc =stsch (test_device_sid, schib); +report (!cc && schib->pmcw.intparm ==300 ,"fetched from SCHIB" ); + }else { +report_fail ("MSCH cc != 0" ); + } +report_prefix_pop (); + + schib->pmcw.intparm =0 ; +if (!msch (test_device_sid, schib)) { +report_prefix_push ("fetch protection" ); + schib->pmcw.intparm =400 ; +set_storage_key (schib,0x28 ,0 ); +expect_pgm_int (); +modify_subchannel_key_1 (test_device_sid, schib); +check_key_prot_exc (ACC_FETCH ,PROT_FETCH_STORE ); +WRITE_ONCE (schib->pmcw.intparm,0 ); + cc =stsch (test_device_sid, schib); +report (!cc && schib->pmcw.intparm ==0 ,"did not modify subchannel" ); +report_prefix_pop (); + }else { +report_fail ("could not reset SCHIB" ); + } + +register_pgm_cleanup_func (dat_fixup_pgm_int); + + schib->pmcw.intparm =0 ; +if (!msch (test_device_sid, schib)) { +report_prefix_push ("remapped page, fetch protection" ); + schib->pmcw.intparm =500 ; +set_storage_key (pagebuf,0x28 ,0 ); +expect_pgm_int (); +install_page (root,virt_to_pte_phys (root, pagebuf),0 ); +modify_subchannel_key_1 (test_device_sid, (struct schib *)0 ); +install_page (root,0 ,0 ); +check_key_prot_exc (ACC_FETCH ,PROT_FETCH_STORE ); +WRITE_ONCE (schib->pmcw.intparm,0 ); + cc =stsch (test_device_sid, schib); +report (!cc && schib->pmcw.intparm ==0 ,"did not modify subchannel" ); +report_prefix_pop (); + }else { +report_fail ("could not reset SCHIB" ); + } + +ctl_set_bit (0 ,CTL0_FETCH_PROTECTION_OVERRIDE ); + +report_prefix_push ("fetch-protection override applies" ); + schib->pmcw.intparm =600 ; +set_storage_key (pagebuf,0x28 ,0 ); +install_page (root,virt_to_pte_phys (root, pagebuf),0 ); + cc =modify_subchannel_key_1 (test_device_sid, (struct schib *)0 ); +install_page (root,0 ,0 ); +if (!cc) { +WRITE_ONCE (schib->pmcw.intparm,0 ); + cc =stsch (test_device_sid, schib); +report (!cc && schib->pmcw.intparm ==600 ,"fetched from SCHIB" ); + }else { +report_fail ("MSCH cc != 0" ); + } +report_prefix_pop (); + + schib->pmcw.intparm =0 ; +if (!msch (test_device_sid, schib)) { +report_prefix_push ("fetch-protection override does not apply" ); + schib->pmcw.intparm =700 ; + no_override_schib = (struct schib *)(pagebuf +2048 ); +memcpy (no_override_schib, schib,sizeof (struct schib )); +set_storage_key (pagebuf,0x28 ,0 ); +expect_pgm_int (); +install_page (root,virt_to_pte_phys (root, pagebuf),0 ); +modify_subchannel_key_1 (test_device_sid, (struct schib *)2048 ); +install_page (root,0 ,0 ); +check_key_prot_exc (ACC_FETCH ,PROT_FETCH_STORE ); +WRITE_ONCE (schib->pmcw.intparm,0 ); + cc =stsch (test_device_sid, schib); +report (!cc && schib->pmcw.intparm ==0 ,"did not modify subchannel" ); +report_prefix_pop (); + }else { +report_fail ("could not reset SCHIB" ); + } + +ctl_clear_bit (0 ,CTL0_FETCH_PROTECTION_OVERRIDE ); +register_pgm_cleanup_func (NULL ); +report_prefix_pop (); +set_storage_key (schib,0x00 ,0 ); +report_prefix_pop (); +} +int main (void ) {report_prefix_push ("skey" );
@@ -424,9 +699,11 @@ int main(void)test_chg ();test_test_protection ();test_store_cpu_address (); +test_channel_subsystem_call ();setup_vm ();test_set_prefix (); +test_msch (); done:report_prefix_pop ();return report_summary ();
s390x/unittests.cfg +1 -0
@@ -41,6 +41,7 @@ file = sthyi.elf [skey] file = skey.elf +extra_params = -device virtio-net-ccw [diag10] file = diag10.elf
Signature · 1 line
2.33.1
Re: [kvm-unit-tests PATCH 3/3] s390x: Test effect of storage keys on some more instructions
Quoted 24 lines · On Thu, 5 May 2022 14:46:56 +0200 Janis Schoetterl-Glausch…
Test correctness of some instructions handled by user space instead of KVM with regards to storage keys.
Test success and error conditions, including coverage of storage and fetch protection override.Signed-off-by Janis Schoetterl-Glausch <[email protected]>--- s390x/skey.c | 277 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 1 + 2 files changed, 278 insertions(+)s390x/skey.c +1
-0@@ -12,6 +12,7 @@#include <asm/asm-offsets.h> #include <asm/interrupt.h> #include <vmalloc.h> +#include <css.h> #include <asm/page.h> #include <asm/facility.h> #include <asm/mem.h>
s390x/skey.c static void test_store_cpu_address(void) · line 292
Quoted 8 lines
s390x/skey.c +5
-0@@ -284,6 +285,114 @@ static void test_store_cpu_address(void)report_prefix_pop (); } +/* +* Perform CHANNEL SUBSYSTEM CALL (CHSC) instruction while temporarily executing +* with access key 1. +*/ +static unsigned int channel_subsystem_call_key_1 (void *communication_block)
this function name is very long (maybe chsc_with_key_1 instead?)
Quoted 6 lines
s390x/skey.c +6
-0+{ +uint32_t program_mask; + + asmvolatile ( +"spka 0x10\n\t" + ".insn rre,0xb25f0000,%[communication_block],0\n\t"
s390x/skey.c static void test_store_cpu_address(void) · line 308
Quoted 10 lines
s390x/skey.c +10
-0+"spka 0\n\t" +"ipm %[program_mask]\n" + : [program_mask] "=d" (program_mask) + : [communication_block] "d" (communication_block) + : "memory" + ); +return program_mask >>28 ; +} + +static void init_store_channel_subsystem_characteristics (uint16_t *communication_block)
same here (init_comm_block?)
s390x/skey.c static void test_store_cpu_address(void) · line 318
Quoted 10 lines
s390x/skey.c +10
-0+{ +memset (communication_block,0 ,PAGE_SIZE ); + communication_block[0 ] =0x10 ; + communication_block[1 ] =0x10 ; + communication_block[9 ] =0 ; +} + +static void test_channel_subsystem_call (void ) +{ +static const char request_name[] ="Store channel-subsystem-characteristics" ;
so this "request_name" is for when CHSC succeeds? why not just "Success" then?
s390x/skey.c static void test_store_cpu_address(void) · line 319
Quoted 1 line
s390x/skey.c +1
-0+uint16_t *communication_block = (uint16_t *)&pagebuf;
long name (consider comm_block, or even cb)
s390x/skey.c static void test_store_cpu_address(void) · line 325
Quoted 6 lines
s390x/skey.c +6
-0+unsigned int cc; + +report_prefix_push ("CHANNEL SUBSYSTEM CALL" ); + +report_prefix_push ("zero key" ); +init_store_channel_subsystem_characteristics (communication_block);
see what I mean when I say that the names are too long? ^
Quoted 5 lines
s390x/skey.c +5
-0+set_storage_key (communication_block,0x10 ,0 ); + asmvolatile ( +".insn rre,0xb25f0000,%[communication_block],0\n\t" +"ipm %[cc]\n" + : [cc] "=d" (cc)
s390x/skey.c static void test_store_cpu_address(void) · line 340
Quoted 10 lines
s390x/skey.c +10
-0+ : [communication_block] "d" (communication_block) + : "memory" + ); + cc = cc >>28 ; +report (cc ==0 && communication_block[9 ], request_name); +report_prefix_pop (); + +report_prefix_push ("matching key" ); +init_store_channel_subsystem_characteristics (communication_block); +set_storage_key (communication_block,0x10 ,0 );
you just set the storage key in the previous test, and you did not set it back to 0, why do you need to set it again?
Quoted 103 lines
s390x/skey.c +96
-0+ cc =channel_subsystem_call_key_1 (communication_block); +report (cc ==0 && communication_block[9 ], request_name); +report_prefix_pop (); + +report_prefix_push ("mismatching key" ); + +report_prefix_push ("no fetch protection" ); +init_store_channel_subsystem_characteristics (communication_block); +set_storage_key (communication_block,0x20 ,0 ); +expect_pgm_int (); +channel_subsystem_call_key_1 (communication_block); +check_key_prot_exc (ACC_UPDATE ,PROT_STORE ); +report_prefix_pop (); + +report_prefix_push ("fetch protection" ); +init_store_channel_subsystem_characteristics (communication_block); +set_storage_key (communication_block,0x28 ,0 ); +expect_pgm_int (); +channel_subsystem_call_key_1 (communication_block); +check_key_prot_exc (ACC_UPDATE ,PROT_FETCH_STORE ); +report_prefix_pop (); + +ctl_set_bit (0 ,CTL0_STORAGE_PROTECTION_OVERRIDE ); + +report_prefix_push ("storage-protection override, invalid key" ); +set_storage_key (communication_block,0x20 ,0 ); +init_store_channel_subsystem_characteristics (communication_block); +expect_pgm_int (); +channel_subsystem_call_key_1 (communication_block); +check_key_prot_exc (ACC_UPDATE ,PROT_STORE ); +report_prefix_pop (); + +report_prefix_push ("storage-protection override, override key" ); +init_store_channel_subsystem_characteristics (communication_block); +set_storage_key (communication_block,0x90 ,0 ); + cc =channel_subsystem_call_key_1 (communication_block); +report (cc ==0 && communication_block[9 ], request_name); +report_prefix_pop (); + +ctl_clear_bit (0 ,CTL0_STORAGE_PROTECTION_OVERRIDE ); + +report_prefix_push ("storage-protection override disabled, override key" ); +init_store_channel_subsystem_characteristics (communication_block); +set_storage_key (communication_block,0x90 ,0 ); +expect_pgm_int (); +channel_subsystem_call_key_1 (communication_block); +check_key_prot_exc (ACC_UPDATE ,PROT_STORE ); +report_prefix_pop (); + +report_prefix_pop (); + +set_storage_key (communication_block,0x00 ,0 ); +report_prefix_pop (); +} +/* * Perform SET PREFIX (SPX) instruction while temporarily executing * with access key 1. @@ -410,6 +519,172 @@ static void test_set_prefix(void)report_prefix_pop (); } +/* +* Perform MODIFY SUBCHANNEL (MSCH) instruction while temporarily executing +* with access key 1. +*/ +static uint32_t modify_subchannel_key_1 (uint32_t sid,struct schib *schib) +{ +uint32_t program_mask; + + asmvolatile ( +"lr %%r1,%[sid]\n\t" +"spka 0x10\n\t" +"msch %[schib]\n\t" +"spka 0\n\t" +"ipm %[program_mask]\n" + : [program_mask]"=d" (program_mask) + : [sid]"d" (sid), + [schib]"Q" (*schib) + :"%r1" + ); +return program_mask >>28 ; +} + +static void test_msch (void ) +{ +struct schib *schib = (struct schib *)pagebuf; +struct schib *no_override_schib; +int test_device_sid; +pgd_t *root; +int cc; + +report_prefix_push ("MSCH" ); + root = (pgd_t *)(stctg (1 ) &PAGE_MASK ); + test_device_sid =css_enumerate (); + +if (!(test_device_sid &SCHID_ONE )) { +report_fail ("no I/O device found" ); +return ; + } + + cc =stsch (test_device_sid, schib); +if (cc) {
s390x/skey.c static void test_set_prefix(void) · line 572
Quoted 10 lines
s390x/skey.c +10
-0+report_fail ("could not store SCHIB" ); +return ; + } + +report_prefix_push ("zero key" ); + schib->pmcw.intparm =100 ; +set_storage_key (schib,0x28 ,0 ); + cc =msch (test_device_sid, schib); +if (!cc) { +WRITE_ONCE (schib->pmcw.intparm,0 );
why are you using WRITE_ONCE here?
Quoted 142 lines
s390x/skey.c +117
-0+ cc =stsch (test_device_sid, schib); +report (!cc && schib->pmcw.intparm ==100 ,"fetched from SCHIB" ); + }else { +report_fail ("MSCH cc != 0" ); + } +report_prefix_pop (); + +report_prefix_push ("matching key" ); + schib->pmcw.intparm =200 ; +set_storage_key (schib,0x18 ,0 ); + cc =modify_subchannel_key_1 (test_device_sid, schib); +if (!cc) { +WRITE_ONCE (schib->pmcw.intparm,0 ); + cc =stsch (test_device_sid, schib); +report (!cc && schib->pmcw.intparm ==200 ,"fetched from SCHIB" ); + }else { +report_fail ("MSCH cc != 0" ); + } +report_prefix_pop (); + +report_prefix_push ("mismatching key" ); + +report_prefix_push ("no fetch protection" ); + schib->pmcw.intparm =300 ; +set_storage_key (schib,0x20 ,0 ); + cc =modify_subchannel_key_1 (test_device_sid, schib); +if (!cc) { +WRITE_ONCE (schib->pmcw.intparm,0 ); + cc =stsch (test_device_sid, schib); +report (!cc && schib->pmcw.intparm ==300 ,"fetched from SCHIB" ); + }else { +report_fail ("MSCH cc != 0" ); + } +report_prefix_pop (); + + schib->pmcw.intparm =0 ; +if (!msch (test_device_sid, schib)) { +report_prefix_push ("fetch protection" ); + schib->pmcw.intparm =400 ; +set_storage_key (schib,0x28 ,0 ); +expect_pgm_int (); +modify_subchannel_key_1 (test_device_sid, schib); +check_key_prot_exc (ACC_FETCH ,PROT_FETCH_STORE ); +WRITE_ONCE (schib->pmcw.intparm,0 ); + cc =stsch (test_device_sid, schib); +report (!cc && schib->pmcw.intparm ==0 ,"did not modify subchannel" ); +report_prefix_pop (); + }else { +report_fail ("could not reset SCHIB" ); + } + +register_pgm_cleanup_func (dat_fixup_pgm_int); + + schib->pmcw.intparm =0 ; +if (!msch (test_device_sid, schib)) { +report_prefix_push ("remapped page, fetch protection" ); + schib->pmcw.intparm =500 ; +set_storage_key (pagebuf,0x28 ,0 ); +expect_pgm_int (); +install_page (root,virt_to_pte_phys (root, pagebuf),0 ); +modify_subchannel_key_1 (test_device_sid, (struct schib *)0 ); +install_page (root,0 ,0 ); +check_key_prot_exc (ACC_FETCH ,PROT_FETCH_STORE ); +WRITE_ONCE (schib->pmcw.intparm,0 ); + cc =stsch (test_device_sid, schib); +report (!cc && schib->pmcw.intparm ==0 ,"did not modify subchannel" ); +report_prefix_pop (); + }else { +report_fail ("could not reset SCHIB" ); + } + +ctl_set_bit (0 ,CTL0_FETCH_PROTECTION_OVERRIDE ); + +report_prefix_push ("fetch-protection override applies" ); + schib->pmcw.intparm =600 ; +set_storage_key (pagebuf,0x28 ,0 ); +install_page (root,virt_to_pte_phys (root, pagebuf),0 ); + cc =modify_subchannel_key_1 (test_device_sid, (struct schib *)0 ); +install_page (root,0 ,0 ); +if (!cc) { +WRITE_ONCE (schib->pmcw.intparm,0 ); + cc =stsch (test_device_sid, schib); +report (!cc && schib->pmcw.intparm ==600 ,"fetched from SCHIB" ); + }else { +report_fail ("MSCH cc != 0" ); + } +report_prefix_pop (); + + schib->pmcw.intparm =0 ; +if (!msch (test_device_sid, schib)) { +report_prefix_push ("fetch-protection override does not apply" ); + schib->pmcw.intparm =700 ; + no_override_schib = (struct schib *)(pagebuf +2048 ); +memcpy (no_override_schib, schib,sizeof (struct schib )); +set_storage_key (pagebuf,0x28 ,0 ); +expect_pgm_int (); +install_page (root,virt_to_pte_phys (root, pagebuf),0 ); +modify_subchannel_key_1 (test_device_sid, (struct schib *)2048 ); +install_page (root,0 ,0 ); +check_key_prot_exc (ACC_FETCH ,PROT_FETCH_STORE ); +WRITE_ONCE (schib->pmcw.intparm,0 ); + cc =stsch (test_device_sid, schib); +report (!cc && schib->pmcw.intparm ==0 ,"did not modify subchannel" ); +report_prefix_pop (); + }else { +report_fail ("could not reset SCHIB" ); + } + +ctl_clear_bit (0 ,CTL0_FETCH_PROTECTION_OVERRIDE ); +register_pgm_cleanup_func (NULL ); +report_prefix_pop (); +set_storage_key (schib,0x00 ,0 ); +report_prefix_pop (); +} +int main (void ) {report_prefix_push ("skey" );@@ -424,9 +699,11 @@ int main(void)test_chg ();test_test_protection ();test_store_cpu_address (); +test_channel_subsystem_call ();setup_vm ();test_set_prefix (); +test_msch (); done:report_prefix_pop ();return report_summary ();s390x/unittests.cfg +1
-0@@ -41,6 +41,7 @@ file = sthyi.elf [skey] file = skey.elf +extra_params = -device virtio-net-ccw [diag10] file = diag10.elf
Re: [kvm-unit-tests PATCH 3/3] s390x: Test effect of storage keys on some more instructions
Quoted 30 lines · Claudio Imbrenda
Quoted 27 lines · On Thu, 5 May 2022 14:46:56 +0200 Janis Schoetterl-Glausch…
Test correctness of some instructions handled by user space instead of KVM with regards to storage keys.
Test success and error conditions, including coverage of storage and fetch protection override.Signed-off-by Janis Schoetterl-Glausch <[email protected]>--- s390x/skey.c | 277 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 1 + 2 files changed, 278 insertions(+)s390x/skey.c +1
-0@@ -12,6 +12,7 @@#include <asm/asm-offsets.h> #include <asm/interrupt.h> #include <vmalloc.h> +#include <css.h> #include <asm/page.h> #include <asm/facility.h> #include <asm/mem.h> @@ -284,6 +285,114 @@ static void test_store_cpu_address(void)report_prefix_pop (); }
Quoted 7 lines
s390x/skey.c static void test_store_cpu_address(void) · line 292
Quoted 5 lines
s390x/skey.c +5
-0+/* +* Perform CHANNEL SUBSYSTEM CALL (CHSC) instruction while temporarily executing +* with access key 1. +*/ +static unsigned int channel_subsystem_call_key_1 (void *communication_block)this function name is very long (maybe
chsc_with_key_1instead?)
It's because of consistency with set_prefix_key_1 where I spelled out the instruction name too. Granted the name of chsc is longer.
When in doubt I go for what seems more readable/contains more information.
Quoted 11 lines
Quoted 11 lines
s390x/skey.c +10
-0+{ +uint32_t program_mask; + + asmvolatile ( +"spka 0x10\n\t" +".insn rre,0xb25f0000,%[communication_block],0\n\t" +"spka 0\n\t" +"ipm %[program_mask]\n" + : [program_mask]"=d" (program_mask) + : [communication_block] "d" (communication_block)
Quoted 8 lines
s390x/skey.c static void test_store_cpu_address(void) · line 308
Quoted 6 lines
s390x/skey.c +6
-0+ : "memory" + ); +return program_mask >>28 ; +} + +static void init_store_channel_subsystem_characteristics (uint16_t *communication_block)same here (
init_comm_block?)
Since we're only performing one kind of operation in this test, that is fine, but I'll add a comment saying how we initialize the communication block then.
Quoted 14 lines
s390x/skey.c static void test_store_cpu_address(void) · line 318
Quoted 11 lines
s390x/skey.c +10
-0+{ +memset (communication_block,0 ,PAGE_SIZE ); + communication_block[0 ] =0x10 ; + communication_block[1 ] =0x10 ; + communication_block[9 ] =0 ; +} + +static void test_channel_subsystem_call (void ) +{ +static const char request_name[] ="Store channel-subsystem-characteristics" ;so this "
request_name" is for when CHSC succeeds? why not just "Success" then?
That's the operation being performed. So maybe I should change it to msg[] = "Performed store channel-subsystem-characteristics" ?
Quoted 5 lines
s390x/skey.c static void test_store_cpu_address(void) · line 319
Quoted 2 lines
s390x/skey.c +1
-0+uint16_t *communication_block = (uint16_t *)&pagebuf;long name (consider
comm_block, or even cb)
Quoted 8 lines
s390x/skey.c static void test_store_cpu_address(void) · line 325
Quoted 6 lines
s390x/skey.c +6
-0+unsigned int cc; + +report_prefix_push ("CHANNEL SUBSYSTEM CALL" ); + +report_prefix_push ("zero key" ); +init_store_channel_subsystem_characteristics (communication_block);see what I mean when I say that the names are too long? ^
Fits in 80 columns ;-)
Quoted 11 lines
Quoted 11 lines
s390x/skey.c +10
-0+set_storage_key (communication_block,0x10 ,0 ); + asmvolatile ( +".insn rre,0xb25f0000,%[communication_block],0\n\t" +"ipm %[cc]\n" + : [cc]"=d" (cc) + : [communication_block]"d" (communication_block) + :"memory" + ); + cc = cc >>28 ; +report (cc ==0 && communication_block[9 ], request_name);
Quoted 8 lines
s390x/skey.c static void test_store_cpu_address(void) · line 340
Quoted 5 lines
s390x/skey.c +5
-0+report_prefix_pop (); + +report_prefix_push ("matching key" ); +init_store_channel_subsystem_characteristics (communication_block); +set_storage_key (communication_block,0x10 ,0 );you just set the storage key in the previous test, and you did not set it back to 0, why do you need to set it again?
It's not necessary, but I want the tests to be independent from each other, so you can remove/reorder/add ones without having to think.
Quoted 5 lines
Quoted 5 lines
s390x/skey.c +4
-0+ cc =channel_subsystem_call_key_1 (communication_block); +report (cc ==0 && communication_block[9 ], request_name); +report_prefix_pop (); +
[...]
Quoted 7 lines
Quoted 7 lines
s390x/skey.c +7
-0+ + cc =stsch (test_device_sid, schib); +if (cc) { +report_fail ("could not store SCHIB" ); +return ; + } +
Quoted 8 lines
s390x/skey.c static void test_set_prefix(void) · line 572
Quoted 6 lines
s390x/skey.c +6
-0+report_prefix_push ("zero key" ); + schib->pmcw.intparm =100 ; +set_storage_key (schib,0x28 ,0 ); + cc =msch (test_device_sid, schib); +if (!cc) { +WRITE_ONCE (schib->pmcw.intparm,0 );why are you using
WRITE_ONCEhere?
It's a dead store because of the stsch below.
That line is just for good measure so we know stsch really overwrote the value.
Quoted 3 lines
Quoted 3 lines
s390x/skey.c +2
-0+ cc =stsch (test_device_sid, schib); +report (!cc && schib->pmcw.intparm ==100 ,"fetched from SCHIB" );
[...]