s390x: Extend instruction interception tests
v3 cover s390x: Extend instruction interception tests
This series extends the instruction interception tests for s390x.
For most instructions, there is already coverage in existing tests, but they are not covering some failure cases, e.g. bad alignment. In this case, the existing tests were extended.
SCK was not under test anywhere yet, hence a new test file was added.
The EPSW test gets it's own file, too, because it requires a I/O device, more details in the respective commit.
Changelog from v2:
----
- Don't run the sck test under PV
- Include commit of the QEMU PMCW fix in the MSCH and STSCH commit messages
Nico Boehr (8):
s390x: Add more tests for MSCH
s390x: Add test for PFMF low-address protection
s390x: Add sck tests
s390x: Add tests for STCRW
s390x: Add more tests for SSCH
s390x: Add more tests for STSCH
s390x: Add tests for TSCH
s390x: Add EPSW test
lib/s390x/css.h | 17 +++ lib/s390x/css_lib.c | 60 ++++++++++ s390x/Makefile | 2 + s390x/css.c | 278 ++++++++++++++++++++++++++++++++++++++++++++ s390x/epsw.c | 113 ++++++++++++++++++ s390x/pfmf.c | 29 +++++ s390x/sck.c | 134 +++++++++++++++++++++ s390x/unittests.cfg | 7 ++ 8 files changed, 640 insertions(+) create mode 100644 s390x/epsw.c create mode 100644 s390x/sck.c
Signature · 1 line
2.31.1
PATCH v3 1/8 s390x: Add more tests for MSCH
We already have some coverage for MSCH, but there are more cases to test for:
- invalid SCHIB structure. We cover that by setting reserved bits 0, 1, 6 and 7 in the flags of the PMCW.
Older QEMU versions require this bit to always be zero on msch, which is why this test may fail. A fix is available in QEMU master commit 2df59b73e086 ("s390x/css: fix PMCW invalid mask").
- a pointer to an unaligned SCHIB. We cover misalignment by 1 and 2 bytes. Using pointer to valid memory avoids messing up random memory in case of test failures.
Here's the QEMU PMCW invalid mask fix: https://lists.nongnu.org/archive/html/qemu-s390x/2021-12/msg00100.html
--- s390x/css.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
s390x/css.c +53 -0
@@ -27,6 +27,8 @@ static int test_device_sid;static struct senseid *senseid;struct ccw1 *ccw; +char alignment_test_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); +static void test_enumerate (void ) { test_device_sid =css_enumerate ();
@@ -331,6 +333,56 @@ static void test_schm_fmt1(void)free_io_mem (mb1,sizeof (struct measurement_block_format1 )); } +static void test_msch (void ) +{ +const int align_to =4 ; +int cc; +int invalid_pmcw_flags[] = {0 ,1 ,6 ,7 }; +int invalid_flag; +uint16_t old_pmcw_flags; + +if (!test_device_sid) { +report_skip ("No device" ); +return ; + } + + cc =stsch (test_device_sid, &schib); +if (cc) { +report_fail ("stsch: sch %08x failed with cc=%d" , test_device_sid, cc); +return ; + } + +report_prefix_push ("Unaligned" ); +for (int i =1 ; i < align_to; i *=2 ) { +report_prefix_pushf ("%d" , i); + +expect_pgm_int (); +msch (test_device_sid, (struct schib *)(alignment_test_page + i)); +check_pgm_int_code (PGM_INT_CODE_SPECIFICATION ); + +report_prefix_pop (); + } +report_prefix_pop (); + +report_prefix_push ("Invalid SCHIB" ); + old_pmcw_flags = schib.pmcw.flags; +for (int i =0 ; i <ARRAY_SIZE (invalid_pmcw_flags); i++) { + invalid_flag = invalid_pmcw_flags[i]; + +report_prefix_pushf ("PMCW flag bit %d set" , invalid_flag); + + schib.pmcw.flags = old_pmcw_flags |BIT (15 - invalid_flag); +expect_pgm_int (); +msch (test_device_sid, &schib); +check_pgm_int_code (PGM_INT_CODE_OPERAND ); + +report_prefix_pop (); + } +report_prefix_pop (); + + schib.pmcw.flags = old_pmcw_flags; +} + static struct { const char *name; void (*func)(void);
@@ -343,6 +395,7 @@ static struct { { "measurement block (schm)", test_schm }, { "measurement block format0", test_schm_fmt0 }, { "measurement block format1", test_schm_fmt1 }, + { "msch", test_msch }, { NULL, NULL } };
Signature · 1 line
2.31.1
PATCH v3 2/8 s390x: Add test for PFMF low-address protection
In reply to Nico BoehrPFMF should respect the low-address protection when clearing pages, hence add some tests for it.
When low-address protection fails, clearing frame 0 is a destructive operation. It messes up interrupts and thus printing test results won't work properly. Hence, we first attempt to clear frame 1 which is not as destructive.
Doing it this way around increases the chances for the user to see a proper failure message instead of QEMU randomly quitting in the middle of the test run.
--- s390x/pfmf.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
s390x/pfmf.c +29 -0
@@ -113,6 +113,34 @@ static void test_1m_clear(void)report_prefix_pop (); } +static void test_low_addr_prot (void ) +{ +union pfmf_r1 r1 = { + .reg.cf =1 , + .reg.fsc =PFMF_FSC_4K + }; + +report_prefix_push ("low-address protection" ); + +report_prefix_push ("0x1000" ); +expect_pgm_int (); +low_prot_enable (); +pfmf (r1.val, (void *)0x1000 ); +low_prot_disable (); +check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +report_prefix_pop (); + +report_prefix_push ("0x0" ); +expect_pgm_int (); +low_prot_enable (); +pfmf (r1.val,0 ); +low_prot_disable (); +check_pgm_int_code (PGM_INT_CODE_PROTECTION ); +report_prefix_pop (); + +report_prefix_pop (); +} +int main (void ) {bool has_edat =test_facility (8 );
@@ -124,6 +152,7 @@ int main(void) }test_priv (); +test_low_addr_prot ();/* Force the buffer pages in */ memset (pagebuf,0 ,PAGE_SIZE *256 );
Signature · 1 line
2.31.1
PATCH v3 3/8 s390x: Add sck tests
In reply to Nico BoehrSCK updates the guest's TOD clock. It needs to be intercepted, hence we should have some tests for it:
- its operand must be 8-byte aligned. We test for 1, 2 and 4 byte misalignment.
- it should actually update the clock value. As guests are unable to stop their clock, we can only check the clock value is at least higher than the value we set.
- it is a privileged call, so expect it to fail when in problem state. We also test the clock value is not changed in this case. We do so by first adjusting it (privileged) to a high value. We then attempt, in nonprivileged mode, to set the clock to a comparatively small value. We can then store the clock value and test its value is strictly higher than the high value we set previously.
--- s390x/Makefile | 1 + s390x/sck.c | 134 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 3 + 3 files changed, 138 insertions(+) create mode 100644 s390x/sck.c
s390x/Makefile +1 -0
@@ -17,6 +17,7 @@ tests += $(TEST_DIR)/stsi.elf tests += $(TEST_DIR)/skrf.elf tests += $(TEST_DIR)/smp.elf tests += $(TEST_DIR)/sclp.elf +tests += $(TEST_DIR)/sck.elf tests += $(TEST_DIR)/css.elf tests += $(TEST_DIR)/uv-guest.elf tests += $(TEST_DIR)/sie.elf
s390x/sck.c new file +134 -0
134 lines not on this page · raw message
s390x/unittests.cfg +3 -0
@@ -136,3 +136,6 @@ file = firq.elf timeout = 20 extra_params = -smp 1,maxcpus=3 -cpu qemu -device qemu-s390x-cpu,core-id=2 -device qemu-s390x-cpu,core-id=1 accel = tcg + +[sck] +file = sck.elf
Signature · 1 line
2.31.1
PATCH v3 4/8 s390x: Add tests for STCRW
In reply to Nico BoehrThe test consists of two parts: First a simple check to ensure we enforce an aligned address. We test misalignment by 1 and 2 bytes.
The second part tests the handling of pending Channel Reports (CR). We first assume no CR is initally pending and check STCRW returns accordingly. Then, we generate a CR by resetting a Channel Path using RCHP and make sure this results in exactly one CRW being generated which has a Reporting-Source Code (RSC) corresponding to the Channel Path facility.
--- lib/s390x/css.h | 17 ++++++++++ lib/s390x/css_lib.c | 60 +++++++++++++++++++++++++++++++++ s390x/css.c | 82 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+)
lib/s390x/css.h +17 -0
@@ -266,6 +266,20 @@ static inline int rchp(unsigned long chpid)return cc; } +static inline int stcrw (uint32_t *crw) +{ +int cc; + + asmvolatile ( +" stcrw %[crw]\n" +" ipm %[cc]\n" +" srl %[cc],28" + : [cc]"=d" (cc) + : [crw]"Q" (*crw) + :"cc" ,"memory" ); +return cc; +} +/* Debug functions */ char *dump_pmcw_flags (uint16_t f);char *dump_scsw_flags (uint32_t f);
@@ -294,6 +308,9 @@ int css_residual_count(unsigned int schid);void enable_io_isc (uint8_t isc);int wait_and_check_io_completion (int schid); +int css_find_installed_chpid (int sid,uint8_t *chpid_out); +int css_generate_crw (int sid); +/* * CHSC definitions */
lib/s390x/css_lib.c +60 -0
63 lines not on this page · raw message
s390x/css.c +82 -0
94 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 5/8 s390x: Add more tests for SSCH
In reply to Nico BoehrWe already have some coverage of SSCH due to its use in start_ccw1_chain() in css_lib, but two more cases deserve our attention:
- unaligned operand address. We check for misalignment by 1 and 2 bytes.
- an invalid ORB structure.
--- s390x/css.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
s390x/css.c +33 -0
@@ -464,6 +464,38 @@ static void test_stcrw(void)report_prefix_pop (); } +static void test_ssch (void ) +{ +const int align_to =4 ; +struct orb orb; + +if (!test_device_sid) { +report_skip ("No device" ); +return ; + } + +report_prefix_push ("Unaligned" ); +for (int i =1 ; i < align_to; i *=2 ) { +report_prefix_pushf ("%d" , i); + +expect_pgm_int (); +ssch (test_device_sid, (struct orb *)(alignment_test_page + i)); +check_pgm_int_code (PGM_INT_CODE_SPECIFICATION ); + +report_prefix_pop (); + } +report_prefix_pop (); + +report_prefix_push ("Invalid ORB" ); + +memset (&orb,0xff ,sizeof (orb)); +expect_pgm_int (); +ssch (test_device_sid, &orb); +check_pgm_int_code (PGM_INT_CODE_OPERAND ); + +report_prefix_pop (); +} + static struct { const char *name; void (*func)(void);
@@ -478,6 +510,7 @@ static struct { { "measurement block format1", test_schm_fmt1 }, { "msch", test_msch }, { "stcrw", test_stcrw }, + { "ssch", test_ssch }, { NULL, NULL } };
Signature · 1 line
2.31.1
PATCH v3 6/8 s390x: Add more tests for STSCH
In reply to Nico Boehrcss_lib extensively uses STSCH, but two more cases deserve their own tests:
- unaligned address for SCHIB. We check for misalignment by 1 and 2 bytes.
- channel not operational
- bit 47 in SID not set
- bit 5 of PMCW flags.
As per the principles of operation, bit 5 of the PMCW flags shall be ignored by msch and always stored as zero by stsch.
Older QEMU versions require this bit to always be zero on msch, which is why this test may fail. A fix is available in QEMU master commit 2df59b73e086 ("s390x/css: fix PMCW invalid mask").
Here's the QEMU PMCW invalid mask fix: https://lists.nongnu.org/archive/html/qemu-s390x/2021-12/msg00100.html
--- s390x/css.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+)
s390x/css.c +74 -0
@@ -496,6 +496,78 @@ static void test_ssch(void)report_prefix_pop (); } +static void test_stsch (void ) +{ +const int align_to =4 ; +struct schib schib; +int cc; + +if (!test_device_sid) { +report_skip ("No device" ); +return ; + } + +report_prefix_push ("Unaligned" ); +for (int i =1 ; i < align_to; i *=2 ) { +report_prefix_pushf ("%d" , i); + +expect_pgm_int (); +stsch (test_device_sid, (struct schib *)(alignment_test_page + i)); +check_pgm_int_code (PGM_INT_CODE_SPECIFICATION ); + +report_prefix_pop (); + } +report_prefix_pop (); + +report_prefix_push ("Invalid subchannel number" ); + cc =stsch (0x0001ffff , &schib); +report (cc ==3 ,"Channel not operational" ); +report_prefix_pop (); + +report_prefix_push ("Bit 47 in SID is zero" ); +expect_pgm_int (); +stsch (0x0000ffff , &schib); +check_pgm_int_code (PGM_INT_CODE_OPERAND ); +report_prefix_pop (); +} + +static void test_pmcw_bit5 (void ) +{ +int cc; +uint16_t old_pmcw_flags; + + cc =stsch (test_device_sid, &schib); +if (cc) { +report_fail ("stsch: sch %08x failed with cc=%d" , test_device_sid, cc); +return ; + } + old_pmcw_flags = schib.pmcw.flags; + +report_prefix_push ("Bit 5 set" ); + + schib.pmcw.flags = old_pmcw_flags |BIT (15 -5 ); + cc =msch (test_device_sid, &schib); +report (!cc,"MSCH cc == 0" ); + + cc =stsch (test_device_sid, &schib); +report (!cc,"STSCH cc == 0" ); +report (!(schib.pmcw.flags &BIT (15 -5 )),"STSCH PMCW Bit 5 is clear" ); + +report_prefix_pop (); + +report_prefix_push ("Bit 5 clear" ); + + schib.pmcw.flags = old_pmcw_flags & ~BIT (15 -5 ); + cc =msch (test_device_sid, &schib); +report (!cc,"MSCH cc == 0" ); + + cc =stsch (test_device_sid, &schib); +report (!cc,"STSCH cc == 0" ); +report (!(schib.pmcw.flags &BIT (15 -5 )),"STSCH PMCW Bit 5 is clear" ); + +report_prefix_pop (); +} + static struct { const char *name; void (*func)(void);
@@ -511,6 +583,8 @@ static struct { { "msch", test_msch }, { "stcrw", test_stcrw }, { "ssch", test_ssch }, + { "stsch", test_stsch }, + { "pmcw bit 5 ignored", test_pmcw_bit5 }, { NULL, NULL } };
Signature · 1 line
2.31.1
Re: [kvm-unit-tests PATCH v3 6/8] s390x: Add more tests for STSCH
Quoted 11 lines · On Wed, 23 Feb 2022 14:29:38 +0100 Nico Boehr <[email protected]> wrote:
css_libextensively uses STSCH, but two more cases deserve their own tests:- unaligned address for SCHIB. We check for misalignment by 1 and 2 bytes.
- channel not operational
- bit 47 in SID not set
- bit 5 of PMCW flags.
As per the principles of operation, bit 5 of the PMCW flags shall be ignored by msch and always stored as zero by stsch.
Quoted 7 lines
Older QEMU versions require this bit to always be zero on msch, which is why this test may fail. A fix is available in QEMU master commit
2df59b73e086("s390x/css: fix PMCW invalid mask").Here's the QEMU PMCW invalid mask fix: https://lists.nongnu.org/archive/html/qemu-s390x/2021-12/msg00100.html
Signed-off-by Nico Boehr <[email protected]>
Quoted 96 lines
--- s390x/css.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+)s390x/css.c +74
-0@@ -496,6 +496,78 @@ static void test_ssch(void)report_prefix_pop (); } +static void test_stsch (void ) +{ +const int align_to =4 ; +struct schib schib; +int cc; + +if (!test_device_sid) { +report_skip ("No device" ); +return ; + } + +report_prefix_push ("Unaligned" ); +for (int i =1 ; i < align_to; i *=2 ) { +report_prefix_pushf ("%d" , i); + +expect_pgm_int (); +stsch (test_device_sid, (struct schib *)(alignment_test_page + i)); +check_pgm_int_code (PGM_INT_CODE_SPECIFICATION ); + +report_prefix_pop (); + } +report_prefix_pop (); + +report_prefix_push ("Invalid subchannel number" ); + cc =stsch (0x0001ffff , &schib); +report (cc ==3 ,"Channel not operational" ); +report_prefix_pop (); + +report_prefix_push ("Bit 47 in SID is zero" ); +expect_pgm_int (); +stsch (0x0000ffff , &schib); +check_pgm_int_code (PGM_INT_CODE_OPERAND ); +report_prefix_pop (); +} + +static void test_pmcw_bit5 (void ) +{ +int cc; +uint16_t old_pmcw_flags; + + cc =stsch (test_device_sid, &schib); +if (cc) { +report_fail ("stsch: sch %08x failed with cc=%d" , test_device_sid, cc); +return ; + } + old_pmcw_flags = schib.pmcw.flags; + +report_prefix_push ("Bit 5 set" ); + + schib.pmcw.flags = old_pmcw_flags |BIT (15 -5 ); + cc =msch (test_device_sid, &schib); +report (!cc,"MSCH cc == 0" ); + + cc =stsch (test_device_sid, &schib); +report (!cc,"STSCH cc == 0" ); +report (!(schib.pmcw.flags &BIT (15 -5 )),"STSCH PMCW Bit 5 is clear" ); + +report_prefix_pop (); + +report_prefix_push ("Bit 5 clear" ); + + schib.pmcw.flags = old_pmcw_flags & ~BIT (15 -5 ); + cc =msch (test_device_sid, &schib); +report (!cc,"MSCH cc == 0" ); + + cc =stsch (test_device_sid, &schib); +report (!cc,"STSCH cc == 0" ); +report (!(schib.pmcw.flags &BIT (15 -5 )),"STSCH PMCW Bit 5 is clear" ); + +report_prefix_pop (); +} + static struct { const char *name; void (*func)(void);@@ -511,6 +583,8 @@ static struct { { "msch", test_msch }, { "stcrw", test_stcrw }, { "ssch", test_ssch }, + { "stsch", test_stsch }, + { "pmcw bit 5 ignored", test_pmcw_bit5 }, { NULL, NULL } };
Re: [kvm-unit-tests PATCH v3 6/8] s390x: Add more tests for STSCH
In reply to Nico BoehrQuoted 52 lines · Nico Boehr
css_libextensively uses STSCH, but two more cases deserve their own tests:- unaligned address for SCHIB. We check for misalignment by 1 and 2 bytes.
- channel not operational
- bit 47 in SID not set
- bit 5 of PMCW flags.
As per the principles of operation, bit 5 of the PMCW flags shall be ignored by msch and always stored as zero by stsch.Older QEMU versions require this bit to always be zero on msch,
which is why this test may fail. A fix is available in QEMU master
commit2df59b73e086("s390x/css: fix PMCW invalid mask"). >
Here's the QEMU PMCW invalid mask fix: https://lists.nongnu.org/archive/html/qemu-s390x/2021-12/msg00100.htmlSigned-off-by Nico Boehr <[email protected]>--- s390x/css.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+)s390x/css.c +23
-0@@ -496,6 +496,78 @@ static void test_ssch(void)report_prefix_pop (); } +static void test_stsch (void ) +{ +const int align_to =4 ; +struct schib schib; +int cc; + +if (!test_device_sid) { +report_skip ("No device" ); +return ; + } + +report_prefix_push ("Unaligned" ); +for (int i =1 ; i < align_to; i *=2 ) { +report_prefix_pushf ("%d" , i); + +expect_pgm_int (); +stsch (test_device_sid, (struct schib *)(alignment_test_page + i)); +check_pgm_int_code (PGM_INT_CODE_SPECIFICATION ); + +report_prefix_pop (); + } +report_prefix_pop (); +
s390x/css.c static void test_ssch(void) · line 531
Quoted 10 lines
s390x/css.c +10
-0+report_prefix_push ("Invalid subchannel number" ); + cc =stsch (0x0001ffff , &schib); +report (cc ==3 ,"Channel not operational" ); +report_prefix_pop (); + +report_prefix_push ("Bit 47 in SID is zero" ); +expect_pgm_int (); +stsch (0x0000ffff , &schib); +check_pgm_int_code (PGM_INT_CODE_OPERAND ); +report_prefix_pop ();
Add a comment:
No matter if the multiple-subchannel-set facility is installed or not, bit 47 always needs to be 1.
Do we have the MSS facility?
If yes, could we disable it to test the 32-47 == 0x0001 case?
s390x/css.c static void test_ssch(void) · line 537
Quoted 6 lines
s390x/css.c +6
-0+} + +static void test_pmcw_bit5 (void ) +{ +int cc; +uint16_t old_pmcw_flags;
I need a comment here for further reference since that behavior is documented at the description of the schib and not where STSCH is described:
According to architecture MSCH does ignore bit 5 of the second word but STSCH will store bit 5 as zero.
We could check if bits 0,1 and 6,7 are also zero but I'm not sure if that's interesting since MSCH does not ignore those bits and should result in an operand exception when trying to set them.
@Halil, @Pierre: Any opinions?
Quoted 45 lines
s390x/css.c +35
-0+ + cc =stsch (test_device_sid, &schib); +if (cc) { +report_fail ("stsch: sch %08x failed with cc=%d" , test_device_sid, cc); +return ; + } + old_pmcw_flags = schib.pmcw.flags; + +report_prefix_push ("Bit 5 set" ); + + schib.pmcw.flags = old_pmcw_flags |BIT (15 -5 ); + cc =msch (test_device_sid, &schib); +report (!cc,"MSCH cc == 0" ); + + cc =stsch (test_device_sid, &schib); +report (!cc,"STSCH cc == 0" ); +report (!(schib.pmcw.flags &BIT (15 -5 )),"STSCH PMCW Bit 5 is clear" ); + +report_prefix_pop (); + +report_prefix_push ("Bit 5 clear" ); + + schib.pmcw.flags = old_pmcw_flags & ~BIT (15 -5 ); + cc =msch (test_device_sid, &schib); +report (!cc,"MSCH cc == 0" ); + + cc =stsch (test_device_sid, &schib); +report (!cc,"STSCH cc == 0" ); +report (!(schib.pmcw.flags &BIT (15 -5 )),"STSCH PMCW Bit 5 is clear" ); + +report_prefix_pop (); +} + static struct { const char *name; void (*func)(void);@@ -511,6 +583,8 @@ static struct { { "msch", test_msch }, { "stcrw", test_stcrw }, { "ssch", test_ssch }, + { "stsch", test_stsch }, + { "pmcw bit 5 ignored", test_pmcw_bit5 }, { NULL, NULL } };
Re: [kvm-unit-tests PATCH v3 6/8] s390x: Add more tests for STSCH
Quoted 2 lines · Janosch Frank
Quoted 1 line · Nico Boehr
[...]
Quoted 4 lines
Quoted 4 lines
(quoted diff) +2
-0+static void test_stsch(void) +{
[...]
Quoted 10 lines
Quoted 5 lines
+ report_prefix_push("Bit 47 in SID is zero"); + expect_pgm_int();
+ stsch(0x0000ffff, &schib);
+ check_pgm_int_code(PGM_INT_CODE_OPERAND); + report_prefix_pop();Add a comment:
No matter if the multiple-subchannel-set facility is installed or not,
bit 47 always needs to be 1.
Will do.
Quoted 1 line
Do we have the MSS facility?
Not an IO expert, but it seems like it's enabled by QEMU in pc- bios/s390-ccw/main.c, css_setup(). The comment suggests it's always there.
Quoted 1 line
If yes, could we disable it to test the 32-47 ==
0x0001case?
I see ioinst_handle_chsc_sda() in QEMU to enable it. Disabling only works with a full reset of the CSS (see css_reset()) which can be triggered from a subsystem_reset(), which basically means we need to IPL. I think that's not really viable or do you see any other way?
Halil, Pierre, can you confirm?
Quoted 14 lines
s390x/css.c static void test_ssch(void) · line 537
Quoted 7 lines
s390x/css.c +6
-0+} + +static void test_pmcw_bit5 (void ) +{ + int cc; + uint16_t old_pmcw_flags;I need a comment here for further reference since that behavior is documented at the description of the schib and not where STSCH is described:
According to architecture MSCH does ignore bit 5 of the second word but
STSCH will store bit 5 as zero.
Will add the comment above the function, OK?
Quoted 3 lines
We could check if bits 0,1 and 6,7 are also zero but I'm not sure if that's interesting since MSCH does not ignore those bits and should result in an operand exception when trying to set them.
I already have a test in MSCH which checks for the operand exception. It's simple enough to extend it to do a STSCH after the MSCH and check the respective bits is clear. Will be added in v4.
Re: [kvm-unit-tests PATCH v3 6/8] s390x: Add more tests for STSCH
Quoted 20 lines · On Wed, 23 Feb 2022 18:33:17 +0100 Nico Boehr <[email protected]> wrote:
Quoted 2 lines · Janosch Frank
Quoted 1 line · Nico Boehr
[...]
Quoted 4 lines
Quoted 4 lines
(quoted diff) +2
-0+static void test_stsch(void) +{[...]
Quoted 10 lines
Quoted 5 lines
+ report_prefix_push("Bit 47 in SID is zero"); + expect_pgm_int();
+ stsch(0x0000ffff, &schib);
+ check_pgm_int_code(PGM_INT_CODE_OPERAND); + report_prefix_pop();Add a comment:
No matter if the multiple-subchannel-set facility is installed or not,
bit 47 always needs to be 1.
Quoted 8 lines
Will do.
Quoted 1 line
Do we have the MSS facility?
Not an IO expert, but it seems like it's enabled by QEMU in pc-
bios/s390-ccw/main.c,css_setup(). The comment suggests it's always there.
AFAIR. The MSS facility is unconditionally implemented by QEMU thus it is always indicated as installed, but lies dormant per default and needs to be enabled.
The idea is that a non-enlightened OS would not enable the facility, and thus effectively end up specifying zeros and using the subchannel-set 0, and would observe no changes whatsoever compared to running on a machine that does not have MSS facility installed.
Whether MSS is installed in some configuration or not can be detected via the facility bit 47 of Store Channel-Subsystem Characteristics.
Quoted 8 lines
Quoted 1 line
If yes, could we disable it to test the 32-47 ==
0x0001case?I see
ioinst_handle_chsc_sda()in QEMU to enable it. Disabling only works with a full reset of the CSS (seecss_reset()) which can be triggered from asubsystem_reset(), which basically means we need to IPL. I think that's not really viable or do you see any other way?Halil, Pierre, can you confirm?
I don't think there is an other way, and there is usually no good reason to attempt that. If your OS enables it is enlightened, and it won't become non-enlightened. It is basically an opt-in. Eventually you may want to IPL something different, and you are covered by the subsystem reset.
The best way to test this would be to not enable the facility. I have no idea if there is a way for a kvm-unit-test to accomplish that.
Regards,
Halil
Re: [kvm-unit-tests PATCH v3 6/8] s390x: Add more tests for STSCH
In reply to Janosch FrankQuoted 67 lines · Janosch Frank
Quoted 52 lines · Nico Boehr
css_libextensively uses STSCH, but two more cases deserve their own tests:- unaligned address for SCHIB. We check for misalignment by 1 and 2 bytes.
- channel not operational
- bit 47 in SID not set
- bit 5 of PMCW flags.
As per the principles of operation, bit 5 of the PMCW flags shall be ignored by msch and always stored as zero by stsch.Older QEMU versions require this bit to always be zero on msch,
which is why this test may fail. A fix is available in QEMU master
commit2df59b73e086("s390x/css: fix PMCW invalid mask"). >
Here's the QEMU PMCW invalid mask fix: https://lists.nongnu.org/archive/html/qemu-s390x/2021-12/msg00100.htmlSigned-off-by Nico Boehr <[email protected]>---
s390x/css.c| 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++1 file changed, 74 insertions(+)s390x/css.c +23
-0@@ -496,6 +496,78 @@ static void test_ssch(void) report_prefix_pop(); } +static void test_stsch (void ) +{ + const int align_to = 4; + struct schib schib; + int cc; + + if (!test_device_sid) { + report_skip("No device"); + return; + } + + report_prefix_push("Unaligned"); + for (int i = 1; i < align_to; i *= 2) { + report_prefix_pushf("%d", i); + + expect_pgm_int(); + stsch(test_device_sid, (struct schib *)(alignment_test_page + i)); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + + report_prefix_pop(); + } + report_prefix_pop(); +s390x/css.c static void test_ssch(void) · line 531
Quoted 10 lines
s390x/css.c +10
-0+ report_prefix_push("Invalid subchannel number"); + cc = stsch(0x0001ffff, &schib); + report(cc == 3, "Channel not operational"); + report_prefix_pop(); + + report_prefix_push("Bit 47 in SID is zero"); + expect_pgm_int(); + stsch(0x0000ffff, &schib); + check_pgm_int_code(PGM_INT_CODE_OPERAND); + report_prefix_pop();Add a comment:
No matter if the multiple-subchannel-set facility is installed or not, bit 47 always needs to be 1.
Quoted 1 line
Do we have the MSS facility?
yes
Quoted 1 line
If yes, could we disable it to test the 32-47 ==
0x0001case?
AFAIK it is not enabled in the KVM unit tests
We are able to enable it, it could be done with CHSC tests.
Quoted 12 lines
s390x/css.c static void test_ssch(void) · line 537
Quoted 7 lines
s390x/css.c +6
-0+} + +static void test_pmcw_bit5 (void ) +{ + int cc; + uint16_t old_pmcw_flags;I need a comment here for further reference since that behavior is documented at the description of the schib and not where STSCH is described:
According to architecture MSCH does ignore bit 5 of the second word but STSCH will store bit 5 as zero.
Quoted 3 lines
We could check if bits 0,1 and 6,7 are also zero but I'm not sure if that's interesting since MSCH does not ignore those bits and should result in an operand exception when trying to set them.
@Halil, @Pierre: Any opinions?
Yes we should check this.
We often do STSCH/MSCH in a row so I think it is interesting to check it.
Quoted 49 lines
Quoted 48 lines
s390x/css.c +33
-0+ + cc = stsch(test_device_sid, &schib); + if (cc) { + report_fail("stsch: sch %08x failed with cc=%d", test_device_sid, cc); + return; + } + old_pmcw_flags = schib.pmcw.flags; + + report_prefix_push("Bit 5 set"); + + schib.pmcw.flags = old_pmcw_flags | BIT(15 - 5); + cc = msch(test_device_sid, &schib); + report(!cc, "MSCH cc == 0"); + + cc = stsch(test_device_sid, &schib); + report(!cc, "STSCH cc == 0"); + report(!(schib.pmcw.flags & BIT(15 - 5)), "STSCH PMCW Bit 5 is clear"); + + report_prefix_pop(); + + report_prefix_push("Bit 5 clear"); + + schib.pmcw.flags = old_pmcw_flags & ~BIT(15 - 5); + cc = msch(test_device_sid, &schib); + report(!cc, "MSCH cc == 0"); + + cc = stsch(test_device_sid, &schib); + report(!cc, "STSCH cc == 0"); + report(!(schib.pmcw.flags & BIT(15 - 5)), "STSCH PMCW Bit 5 is clear"); + + report_prefix_pop(); +} +static struct {
const char *name;
void (*func)(void);s390x/css.c +2
-0@@ -511,6 +583,8 @@ static struct { { "msch", test_msch }, { "stcrw", test_stcrw }, { "ssch", test_ssch }, + { "stsch", test_stsch }, + { "pmcw bit 5 ignored", test_pmcw_bit5 }, { NULL, NULL } };
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [kvm-unit-tests PATCH v3 6/8] s390x: Add more tests for STSCH
Quoted 70 lines · Pierre Morel
Quoted 67 lines · Janosch Frank
Quoted 52 lines · Nico Boehr
css_libextensively uses STSCH, but two more cases deserve their own tests:- unaligned address for SCHIB. We check for misalignment by 1 and 2 bytes.
- channel not operational
- bit 47 in SID not set
- bit 5 of PMCW flags.
As per the principles of operation, bit 5 of the PMCW flags shall be ignored by msch and always stored as zero by stsch.Older QEMU versions require this bit to always be zero on msch,
which is why this test may fail. A fix is available in QEMU master
commit2df59b73e086("s390x/css: fix PMCW invalid mask"). >
Here's the QEMU PMCW invalid mask fix: https://lists.nongnu.org/archive/html/qemu-s390x/2021-12/msg00100.htmlSigned-off-by Nico Boehr <[email protected]>---
s390x/css.c| 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++1 file changed, 74 insertions(+)s390x/css.c +24
-0@@ -496,6 +496,78 @@ static void test_ssch(void) report_prefix_pop(); } +static void test_stsch (void ) +{ + const int align_to = 4; + struct schib schib; + int cc; + + if (!test_device_sid) { + report_skip("No device"); + return; + } + + report_prefix_push("Unaligned"); + for (int i = 1; i < align_to; i *= 2) { + report_prefix_pushf("%d", i); + + expect_pgm_int(); + stsch(test_device_sid, (struct schib *)(alignment_test_page + i)); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + + report_prefix_pop(); + } + report_prefix_pop(); +s390x/css.c static void test_ssch(void) · line 531
Quoted 10 lines
s390x/css.c +10
-0+ report_prefix_push("Invalid subchannel number"); + cc = stsch(0x0001ffff, &schib); + report(cc == 3, "Channel not operational"); + report_prefix_pop(); + + report_prefix_push("Bit 47 in SID is zero"); + expect_pgm_int(); + stsch(0x0000ffff, &schib); + check_pgm_int_code(PGM_INT_CODE_OPERAND); + report_prefix_pop();Add a comment:
No matter if the multiple-subchannel-set facility is installed or not, bit 47 always needs to be 1.
Quoted 8 lines
Quoted 1 line
Do we have the MSS facility?
yes
Quoted 1 line
If yes, could we disable it to test the 32-47 ==
0x0001case?AFAIK it is not enabled in the KVM unit tests
We are able to enable it, it could be done with CHSC tests.
I mean to check if it is enabled.
Quoted 71 lines
Quoted 13 lines
s390x/css.c static void test_ssch(void) · line 537
Quoted 8 lines
s390x/css.c +6
-0+} + +static void test_pmcw_bit5 (void ) +{ + int cc; + uint16_t old_pmcw_flags;I need a comment here for further reference since that behavior is documented at the description of the schib and not where STSCH is described:
According to architecture MSCH does ignore bit 5 of the second word but STSCH will store bit 5 as zero.Quoted 3 lines
We could check if bits 0,1 and 6,7 are also zero but I'm not sure if that's interesting since MSCH does not ignore those bits and should result in an operand exception when trying to set them.
@Halil, @Pierre: Any opinions?
Yes we should check this.
We often do STSCH/MSCH in a row so I think it is interesting to check it.Quoted 49 lines
Quoted 48 lines
s390x/css.c +33
-0+ + cc = stsch(test_device_sid, &schib); + if (cc) { + report_fail("stsch: sch %08x failed with cc=%d", test_device_sid, cc); + return; + } + old_pmcw_flags = schib.pmcw.flags; + + report_prefix_push("Bit 5 set"); + + schib.pmcw.flags = old_pmcw_flags | BIT(15 - 5); + cc = msch(test_device_sid, &schib); + report(!cc, "MSCH cc == 0"); + + cc = stsch(test_device_sid, &schib); + report(!cc, "STSCH cc == 0"); + report(!(schib.pmcw.flags & BIT(15 - 5)), "STSCH PMCW Bit 5 is clear"); + + report_prefix_pop(); + + report_prefix_push("Bit 5 clear"); + + schib.pmcw.flags = old_pmcw_flags & ~BIT(15 - 5); + cc = msch(test_device_sid, &schib); + report(!cc, "MSCH cc == 0"); + + cc = stsch(test_device_sid, &schib); + report(!cc, "STSCH cc == 0"); + report(!(schib.pmcw.flags & BIT(15 - 5)), "STSCH PMCW Bit 5 is clear"); + + report_prefix_pop(); +} +static struct {
const char *name;
void (*func)(void);s390x/css.c +2
-0@@ -511,6 +583,8 @@ static struct { { "msch", test_msch }, { "stcrw", test_stcrw }, { "ssch", test_ssch }, + { "stsch", test_stsch }, + { "pmcw bit 5 ignored", test_pmcw_bit5 }, { NULL, NULL } };
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [kvm-unit-tests PATCH v3 6/8] s390x: Add more tests for STSCH
In reply to Janosch FrankQuoted 5 lines · On Wed, 23 Feb 2022 16:39:07 +0100 Janosch Frank <[email protected]> wrote:
We could check if bits 0,1 and 6,7 are also zero but I'm not sure if that's interesting since MSCH does not ignore those bits and should result in an operand exception when trying to set them.
@Halil, @Pierre: Any opinions?
IMHO more testing doesn't hurt. But I don't have clarity on some aspect of how the architecture is extended. What I'm trying to say is: I'm not 100% certain these bits must stay 0 and no-semantics-defined forever.
Regards,
Halil
PATCH v3 7/8 s390x: Add tests for TSCH
In reply to Nico BoehrTSCH has two special cases which need to be tested:
- unaligned address. We test for misalignment by 1 and 2 bytes.
- channel not operational
- bit 47 in SID not set
--- s390x/css.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
s390x/css.c +36 -0
@@ -568,6 +568,41 @@ static void test_pmcw_bit5(void)report_prefix_pop (); } +static void test_tsch (void ) +{ +const int align_to =4 ; +struct irb irb; +int cc; + +if (!test_device_sid) { +report_skip ("No device" ); +return ; + } + +report_prefix_push ("Unaligned" ); +for (int i =1 ; i < align_to; i *=2 ) { +report_prefix_pushf ("%d" , i); + +expect_pgm_int (); +tsch (test_device_sid, (struct irb *)(alignment_test_page + i)); +check_pgm_int_code (PGM_INT_CODE_SPECIFICATION ); + +report_prefix_pop (); + } +report_prefix_pop (); + +report_prefix_push ("Invalid subchannel number" ); + cc =tsch (0x0001ffff , &irb); +report (cc ==3 ,"Channel not operational" ); +report_prefix_pop (); + +report_prefix_push ("Bit 47 in SID is zero" ); +expect_pgm_int (); +tsch (0x0000ffff , &irb); +check_pgm_int_code (PGM_INT_CODE_OPERAND ); +report_prefix_pop (); +} + static struct { const char *name; void (*func)(void);
@@ -585,6 +620,7 @@ static struct { { "ssch", test_ssch }, { "stsch", test_stsch }, { "pmcw bit 5 ignored", test_pmcw_bit5 }, + { "tsch", test_tsch }, { NULL, NULL } };
Signature · 1 line
2.31.1
PATCH v3 8/8 s390x: Add EPSW test
In reply to Nico BoehrEPSW is only intercepted in certain cases. One of these cases is if we have a CRW pending and machine check interrupts are masked. This can be achieved by issuing a RCHP on a valid channel path. This is why we need the CSS lib and an IO device in this test and hence need to skip it when not running under QEMU.
Three special cases deserve our attention:
- upper 32 bits of both operands are never modified,
- second operand is not modified if it is zero.
- when both operands are zero, bits 0-11 and 13-31 of the PSW are stored in r0.
We also verify we get the correct contents when the second operand is zero. To do so, we save the data stored at the first operand in the first case as a reference. As we don't mess with the PSW, the only thing that might change is the Condition Code (CC) due to some instruction in between, so we zero it out using zero_out_cc_from_epsw_op1().
This test must be fenced when running in non-QEMU.
--- s390x/Makefile | 1 + s390x/epsw.c | 113 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 ++ 3 files changed, 118 insertions(+) create mode 100644 s390x/epsw.c
s390x/Makefile +1 -0
@@ -27,6 +27,7 @@ tests += $(TEST_DIR)/edat.elf tests += $(TEST_DIR)/mvpg-sie.elf tests += $(TEST_DIR)/spec_ex-sie.elf tests += $(TEST_DIR)/firq.elf +tests += $(TEST_DIR)/epsw.elf pv-tests += $(TEST_DIR)/pv-diags.elf
s390x/epsw.c new file +113 -0
113 lines not on this page · raw message
s390x/unittests.cfg +4 -0
@@ -139,3 +139,7 @@ accel = tcg [sck] file = sck.elf + +[epsw] +file = epsw.elf +extra_params = -device virtio-net-ccw
Signature · 1 line
2.31.1
Quoted 1 line · On Wed, 23 Feb 2022 14:29:32 +0100 Nico Boehr <[email protected]> wrote:
This series extends the instruction interception tests for s390x.
looks good, I'll queue it, thanks
Quoted 37 lines
For most instructions, there is already coverage in existing tests, but they are not covering some failure cases, e.g. bad alignment. In this case, the existing tests were extended.
SCK was not under test anywhere yet, hence a new test file was added.
The EPSW test gets it's own file, too, because it requires a I/O device, more details in the respective commit.
Changelog from v2:
----
- Don't run the sck test under PV
- Include commit of the QEMU PMCW fix in the MSCH and STSCH commit messagesNico Boehr (8):
s390x: Add more tests for MSCH
s390x: Add test for PFMF low-address protection
s390x: Add sck tests
s390x: Add tests for STCRW
s390x: Add more tests for SSCH
s390x: Add more tests for STSCH
s390x: Add tests for TSCH
s390x: Add EPSW testlib/s390x/css.h | 17 +++ lib/s390x/css_lib.c | 60 ++++++++++ s390x/Makefile | 2 + s390x/css.c | 278 ++++++++++++++++++++++++++++++++++++++++++++ s390x/epsw.c | 113 ++++++++++++++++++ s390x/pfmf.c | 29 +++++ s390x/sck.c | 134 +++++++++++++++++++++ s390x/unittests.cfg | 7 ++ 8 files changed, 640 insertions(+) create mode 100644 s390x/epsw.c create mode 100644 s390x/sck.c