s390x: SCLP Unit test
v8 cover s390x: SCLP Unit test
This patchset contains some minor cleanup, some preparatory work and then the SCLP unit test itself.
The unit test checks the following:
* Correctly ignoring instruction bits that should be ignored
* Privileged instruction check
* Check for addressing exceptions
* Specification exceptions:
- SCCB size less than 8
- SCCB unaligned
- SCCB overlaps prefix or lowcore
- SCCB address higher than 2GB
* Return codes for
- Invalid command
- SCCB too short (but at least 8)
- SCCB page boundary violation
v7 -> v8
* fixed existing stfl asm wrapper
* now using stfl asm wrapper in intercept.c
* patched the program interrupt handler to clear the sclp_busy bit
* removed now unnecessary expect_pgm_int from the unit test v6 -> v7
* renamed spx() and stpx() wrappers to set_prefix and get_prefix
* set_prefix now takes a value and get_prefix now returns a value
* put back some inline assembly for spx and stpx as a consequence
* used LC_SIZE instead of 2 * PAGE_SIZE everywhere in the unit test v5 -> v6
* fixed a bug in test_addressing
* improved comments in test_sccb_prefix
* replaced all inline assembly usages of spx and stpx with the wrappers
* added one more wrapper for test_one_sccb for read-only tests v4 -> v5
* updated usage of report()
* added SPX and STPX wrappers to the library
* improved readability
* addressed some more comments
v3 -> v4
* export sclp_setup_int instead of copying it
* add more comments
* rename some more variables to improve readability
* improve the prefix test
* improved the invalid address test
* addressed further comments received during review
v2 -> v3
* generally improved the naming of variables
* added and fixed comments
* renamed test_one_run to test_one_simple
* added some const where needed
* addresed many more small comments received during review v1 -> v2
* fix many small issues that came up during the first round of reviews
* add comments to each function
* use a static buffer for the SCCP template when used
Claudio Imbrenda (6):
s390x: export sclp_setup_int
s390x: sclp: add service call instruction wrapper
s390x: lib: fix stfl wrapper asm
s390x: lib: add SPX and STPX instruction wrapper
s390x: lib: fix program interrupt handler if sclp_busy was set
s390x: SCLP unit test
s390x/Makefile | 1 + lib/s390x/asm/arch_def.h | 26 +++ lib/s390x/asm/facility.h | 2 +- lib/s390x/sclp.h | 1 + lib/s390x/interrupt.c | 5 +- lib/s390x/sclp.c | 9 +- s390x/intercept.c | 24 +- s390x/sclp.c | 474 +++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 8 + 9 files changed, 526 insertions(+), 24 deletions(-) create mode 100644 s390x/sclp.c
Signature · 1 line
2.24.1
PATCH v8 1/6 s390x: export sclp_setup_int
Export sclp_setup_int() so that it can be used in tests.
Needed for an upcoming unit test.
--- lib/s390x/sclp.h | 1 + lib/s390x/sclp.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
lib/s390x/sclp.h +1 -0
@@ -265,6 +265,7 @@ typedef struct ReadEventData { } __attribute__((packed)) ReadEventData;extern char _sccb[]; +void sclp_setup_int (void );void sclp_handle_ext (void );void sclp_wait_busy (void );void sclp_mark_busy (void );
lib/s390x/sclp.c +1 -1
@@ -45,7 +45,7 @@ static void mem_init(phys_addr_t mem_end)page_alloc_ops_enable (); } -static void sclp_setup_int (void ) +void sclp_setup_int (void ) {uint64_t mask;
Signature · 1 line
2.24.1
PATCH v8 2/6 s390x: sclp: add service call instruction wrapper
In reply to Claudio ImbrendaAdd a wrapper for the service call instruction, and use it for SCLP interactions instead of using inline assembly everywhere.
--- lib/s390x/asm/arch_def.h | 13 +++++++++++++ lib/s390x/sclp.c | 7 +------ 2 files changed, 14 insertions(+), 6 deletions(-)
lib/s390x/asm/arch_def.h +13 -0
@@ -271,4 +271,17 @@ static inline int stsi(void *addr, int fc, int sel1, int sel2) return cc; } +static inline int servc (uint32_t command,unsigned long sccb) +{ +int cc; + + asmvolatile ( +" .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */ +" ipm %0\n" +" srl %0,28" + :"=&d" (cc) :"d" (command),"a" (sccb) + :"cc" ,"memory" ); +return cc; +} +#endif
lib/s390x/sclp.c +1 -6
@@ -116,12 +116,7 @@ int sclp_service_call(unsigned int command, void *sccb)int cc;sclp_setup_int (); - asmvolatile ( -" .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */ -" ipm %0\n" -" srl %0,28" - :"=&d" (cc) :"d" (command),"a" (__pa (sccb)) - :"cc" ,"memory" ); + cc =servc (command,__pa (sccb));sclp_wait_busy ();if (cc ==3 )return -1 ;
Signature · 1 line
2.24.1
PATCH v8 3/6 s390x: lib: fix stfl wrapper asm
In reply to Claudio Imbrendathe stfl wrapper in lib/s390x/asm/facility.h was lacking the "memory" clobber in the inline asm.
--- lib/s390x/asm/facility.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/s390x/asm/facility.h +1 -1
@@ -24,7 +24,7 @@ static inline bool test_facility(int nr)static inline void stfl (void ) { - asmvolatile (" stfl 0(0)\n" ); + asmvolatile (" stfl 0(0)\n" : : :"memory" ); }static inline void stfle (uint8_t *fac,unsigned int len)
Signature · 1 line
2.24.1
Re: [kvm-unit-tests PATCH v8 3/6] s390x: lib: fix stfl wrapper asm
Quoted 14 lines · Claudio Imbrenda
the stfl wrapper in
lib/s390x/asm/facility.hwas lacking the "memory" clobber in the inline asm.Signed-off-by Claudio Imbrenda <[email protected]>--- lib/s390x/asm/facility.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/s390x/asm/facility.h +0
-0
lib/s390x/asm/facility.h static inline bool test_facility(int nr) · line 30
Quoted 8 lines
lib/s390x/asm/facility.h +1
-1@@ -24,7 +24,7 @@ static inline bool test_facility(int nr)static inline void stfl (void ) { - asmvolatile (" stfl 0(0)\n" ); + asmvolatile (" stfl 0(0)\n" : : :"memory" ); }static inline void stfle (uint8_t *fac,unsigned int len)
Re: [kvm-unit-tests PATCH v8 3/6] s390x: lib: fix stfl wrapper asm
In reply to Claudio ImbrendaQuoted 14 lines · Claudio Imbrenda
the stfl wrapper in
lib/s390x/asm/facility.hwas lacking the "memory" clobber in the inline asm.Signed-off-by Claudio Imbrenda <[email protected]>--- lib/s390x/asm/facility.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/s390x/asm/facility.h +0
-0
lib/s390x/asm/facility.h static inline bool test_facility(int nr) · line 30
Quoted 8 lines
lib/s390x/asm/facility.h +1
-1@@ -24,7 +24,7 @@ static inline bool test_facility(int nr)static inline void stfl (void ) { - asmvolatile (" stfl 0(0)\n" ); + asmvolatile (" stfl 0(0)\n" : : :"memory" ); }static inline void stfle (uint8_t *fac,unsigned int len)
Signature · 3 lines
Thanks, David / dhildenb
Re: [kvm-unit-tests PATCH v8 3/6] s390x: lib: fix stfl wrapper asm
In reply to Claudio ImbrendaQuoted 14 lines · Claudio Imbrenda
the stfl wrapper in
lib/s390x/asm/facility.hwas lacking the "memory" clobber in the inline asm.Signed-off-by Claudio Imbrenda <[email protected]>--- lib/s390x/asm/facility.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/s390x/asm/facility.h +0
-0
lib/s390x/asm/facility.h static inline bool test_facility(int nr) · line 30
Quoted 8 lines
lib/s390x/asm/facility.h +1
-1@@ -24,7 +24,7 @@ static inline bool test_facility(int nr)static inline void stfl (void ) { - asmvolatile (" stfl 0(0)\n" ); + asmvolatile (" stfl 0(0)\n" : : :"memory" ); }static inline void stfle (uint8_t *fac,unsigned int len)
PATCH v8 4/6 s390x: lib: add SPX and STPX instruction wrapper
In reply to Claudio ImbrendaAdd a wrapper for the SET PREFIX and STORE PREFIX instructions, and use it instead of using inline assembly.
--- lib/s390x/asm/arch_def.h | 13 +++++++++++++ s390x/intercept.c | 24 +++++++++--------------- 2 files changed, 22 insertions(+), 15 deletions(-)
lib/s390x/asm/arch_def.h +13 -0
@@ -284,4 +284,17 @@ static inline int servc(uint32_t command, unsigned long sccb) return cc; } +static inline void set_prefix (uint32_t new_prefix) +{ + asmvolatile (" spx %0" : :"Q" (new_prefix) :"memory" ); +} + +static inline uint32_t get_prefix (void ) +{ +uint32_t current_prefix; + + asmvolatile (" stpx %0" :"=Q" (current_prefix)); +return current_prefix; +} +#endif
s390x/intercept.c +9 -15
@@ -13,6 +13,7 @@#include <asm/asm-offsets.h> #include <asm/interrupt.h> #include <asm/page.h> +#include <asm/facility.h> static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE * 2)));
@@ -26,13 +27,10 @@ static void test_stpx(void)uint32_t new_prefix = (uint32_t )(intptr_t )pagebuf;/* Can we successfully change the prefix? */ - asmvolatile ( -" stpx %0\n" -" spx %2\n" -" stpx %1\n" -" spx %0\n" - :"+Q" (old_prefix),"+Q" (tst_prefix) - :"Q" (new_prefix)); + old_prefix =get_prefix (); +set_prefix (new_prefix); + tst_prefix =get_prefix (); +set_prefix (old_prefix);report (old_prefix ==0 && tst_prefix == new_prefix,"store prefix" );expect_pgm_int ();
@@ -63,14 +61,10 @@ static void test_spx(void)* some facility bits there ... at least some of them should be * set in our buffer afterwards. */ - asmvolatile ( -" stpx %0\n" -" spx %1\n" -" stfl 0\n" -" spx %0\n" - :"+Q" (old_prefix) - :"Q" (new_prefix) - :"memory" ); + old_prefix =get_prefix (); +set_prefix (new_prefix); +stfl (); +set_prefix (old_prefix);report (pagebuf[GEN_LC_STFL ] !=0 ,"stfl to new prefix" );expect_pgm_int ();
Signature · 1 line
2.24.1
PATCH v8 5/6 s390x: lib: fix program interrupt handler if sclp_busy was set
In reply to Claudio ImbrendaFix the program interrupt handler for the case where sclp_busy is set.
The interrupt handler will attempt to write an error message on the console using the SCLP, and will wait for sclp_busy to become false before doing so. If an exception happenes between setting the flag and the SCLP call, or if the call itself raises an exception, we need to clear the flag so we can successfully print the error message.
--- lib/s390x/interrupt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
lib/s390x/interrupt.c +4 -1
@@ -106,10 +106,13 @@ static void fixup_pgm_int(void)void handle_pgm_int (void ) { -if (!pgm_int_expected) +if (!pgm_int_expected) { +/* Force sclp_busy to false, otherwise we will loop forever */ +sclp_handle_ext ();report_abort ("Unexpected program interrupt: %d at %#lx, ilen %d\n" , lc->pgm_int_code, lc->pgm_old_psw.addr, lc->pgm_int_id); + } pgm_int_expected = false;fixup_pgm_int ();
Signature · 1 line
2.24.1
Re: [kvm-unit-tests PATCH v8 5/6] s390x: lib: fix program interrupt handler if sclp_busy was set
Quoted 23 lines · Claudio Imbrenda
Fix the program interrupt handler for the case where
sclp_busyis set.The interrupt handler will attempt to write an error message on the console using the SCLP, and will wait for
sclp_busyto become false before doing so. If an exception happenes between setting the flag and the SCLP call, or if the call itself raises an exception, we need to clear the flag so we can successfully print the error message.Signed-off-by Claudio Imbrenda <[email protected]>--- lib/s390x/interrupt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)lib/s390x/interrupt.c +0
-1@@ -106,10 +106,13 @@ static void fixup_pgm_int(void)void handle_pgm_int (void ) { -if (!pgm_int_expected)
lib/s390x/interrupt.c static void fixup_pgm_int(void) · line 118
Quoted 10 lines
lib/s390x/interrupt.c +4
-0+if (!pgm_int_expected) { +/* Force sclp_busy to false, otherwise we will loop forever */ +sclp_handle_ext ();report_abort ("Unexpected program interrupt: %d at %#lx, ilen %d\n" , lc->pgm_int_code, lc->pgm_old_psw.addr, lc->pgm_int_id); + } pgm_int_expected = false;fixup_pgm_int ();
Re: [kvm-unit-tests PATCH v8 5/6] s390x: lib: fix program interrupt handler if sclp_busy was set
In reply to Claudio ImbrendaQuoted 23 lines · Claudio Imbrenda
Fix the program interrupt handler for the case where
sclp_busyis set.The interrupt handler will attempt to write an error message on the console using the SCLP, and will wait for
sclp_busyto become false before doing so. If an exception happenes between setting the flag and the SCLP call, or if the call itself raises an exception, we need to clear the flag so we can successfully print the error message.Signed-off-by Claudio Imbrenda <[email protected]>--- lib/s390x/interrupt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)lib/s390x/interrupt.c +0
-1@@ -106,10 +106,13 @@ static void fixup_pgm_int(void)void handle_pgm_int (void ) { -if (!pgm_int_expected)
lib/s390x/interrupt.c static void fixup_pgm_int(void) · line 118
Quoted 10 lines
lib/s390x/interrupt.c +4
-0+if (!pgm_int_expected) { +/* Force sclp_busy to false, otherwise we will loop forever */ +sclp_handle_ext ();report_abort ("Unexpected program interrupt: %d at %#lx, ilen %d\n" , lc->pgm_int_code, lc->pgm_old_psw.addr, lc->pgm_int_id); + } pgm_int_expected = false;fixup_pgm_int ();
Signature · 3 lines
Thanks, David / dhildenb
PATCH v8 6/6 s390x: SCLP unit test
In reply to Claudio ImbrendaSCLP unit test. Testing the following:
* Correctly ignoring instruction bits that should be ignored
* Privileged instruction check
* Check for addressing exceptions
* Specification exceptions:
- SCCB size less than 8
- SCCB unaligned
- SCCB overlaps prefix or lowcore
- SCCB address higher than 2GB
* Return codes for
- Invalid command
- SCCB too short (but at least 8)
- SCCB page boundary violation
--- s390x/Makefile | 1 + s390x/sclp.c | 474 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 8 + 3 files changed, 483 insertions(+) create mode 100644 s390x/sclp.c
s390x/Makefile +1 -0
@@ -16,6 +16,7 @@ tests += $(TEST_DIR)/diag288.elf tests += $(TEST_DIR)/stsi.elf tests += $(TEST_DIR)/skrf.elf tests += $(TEST_DIR)/smp.elf +tests += $(TEST_DIR)/sclp.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binary
s390x/sclp.c new file +474 -0
474 lines not on this page · raw message
s390x/unittests.cfg +8 -0
@@ -75,3 +75,11 @@ file = stsi.elf [smp] file = smp.elf extra_params =-smp 2 + +[sclp-1g] +file = sclp.elf +extra_params = -m 1G + +[sclp-3g] +file = sclp.elf +extra_params = -m 3G
Signature · 1 line
2.24.1
Re: [kvm-unit-tests PATCH v8 6/6] s390x: SCLP unit test
[...]
s390x/sclp.c line 4
Quoted 11 lines
all: directories
test_casestest_cases_binarys390x/sclp.c new file +4
-0@@ -0,0 +1,474 @@ +/* +* Service Call tests +* +* Copyright (c) 2019 IBM Corp
Should be 2020 now. Will fix that up.
[...]
Quoted 13 lines
s390x/sclp.c new file +13
-0+/** +* Perform one test at the given address, optionally using the SCCB template, +* checking for the expected program interrupts and return codes. +* +* The parameter buf_len indicates the number of bytes of the template that +* should be copied to the test address, and should be 0 when the test +* address is invalid, in which case nothing is copied. +* +* The template is used to simplify tests where the same buffer content is +* used many times in a row, at different addresses. +* +* Returns true in case of success or false in case of failure +*/
s390x/sclp.c line 74
Quoted 10 lines
s390x/sclp.c new file +10
-0+static bool test_one_sccb (uint32_t cmd,uint8_t *addr,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) +{ +SCCBHeader *h = (SCCBHeader *)addr; +int res, pgm; + +/* Copy the template to the test address if needed */ +if (buf_len) +memcpy (addr, sccb_template, buf_len); +if (exp_pgm !=PGM_NONE ) +expect_pgm_int ();
I still dislike the handling here. Any caller can simply do a
expect_pgm_int();test_one_sccb(...)check_pgm_int_code(PGM_);
Same thing goes for exp_rc. We really should drop exp_rc and exp_pgm handling from the function completely and handle it in the caller. That makes the tests actually readable.
But I feel like I am repeating myself. I'll queue this patch with the 2020 fixed up and might send a fixup myself (if I find some spare minutes).
Signature · 3 lines
Thanks, David / dhildenb
Re: [kvm-unit-tests PATCH v8 6/6] s390x: SCLP unit test
In reply to Claudio ImbrendaQuoted 155 lines · Claudio Imbrenda
SCLP unit test. Testing the following:
* Correctly ignoring instruction bits that should be ignored
* Privileged instruction check
* Check for addressing exceptions
* Specification exceptions:
- SCCB size less than 8
- SCCB unaligned
- SCCB overlaps prefix or lowcore
- SCCB address higher than 2GB
* Return codes for
- Invalid command
- SCCB too short (but at least 8)
- SCCB page boundary violationSigned-off-by Claudio Imbrenda <[email protected]>Reviewed-by Thomas Huth <[email protected]>Acked-by Janosch Frank <[email protected]>--- s390x/Makefile | 1 + s390x/sclp.c | 474 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 8 + 3 files changed, 483 insertions(+) create mode 100644 s390x/sclp.cs390x/Makefile +1
-0@@ -16,6 +16,7 @@ tests += $(TEST_DIR)/diag288.elf tests += $(TEST_DIR)/stsi.elf tests += $(TEST_DIR)/skrf.elf tests += $(TEST_DIR)/smp.elf +tests += $(TEST_DIR)/sclp.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binarys390x/sclp.c new file +112
-0@@ -0,0 +1,474 @@ +/* +* Service Call tests +* +* Copyright (c) 2019 IBM Corp +* +* Authors: +* Claudio Imbrenda <[email protected]> +* +* This code is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2. +*/ + +#include <libcflat.h> +#include <asm/page.h> +#include <asm/asm-offsets.h> +#include <asm/interrupt.h> +#include <sclp.h> + +#define PGM_NONE 1 +#define PGM_BIT_SPEC (1ULL << PGM_INT_CODE_SPECIFICATION) +#define PGM_BIT_ADDR (1ULL << PGM_INT_CODE_ADDRESSING) +#define PGM_BIT_PRIV (1ULL << PGM_INT_CODE_PRIVILEGED_OPERATION) +#define MKPTR (x) ((void *)(uint64_t)(x)) + +#define LC_SIZE (2 * PAGE_SIZE) + +static uint8_t pagebuf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* scratch pages used for some tests */ +static uint8_t prefix_buf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* temporary lowcore for test_sccb_prefix */ +static uint8_t sccb_template[PAGE_SIZE ];/* SCCB template to be used */ +static uint32_t valid_code;/* valid command code for READ SCP INFO */ +static struct lowcore *lc; + +/** +* Perform one service call, handling exceptions and interrupts. +*/ +static int sclp_service_call_test (unsigned int command,void *sccb) +{ +int cc; + +sclp_mark_busy (); +sclp_setup_int (); + cc =servc (command,__pa (sccb)); +if (lc->pgm_int_code) { +sclp_handle_ext (); +return 0 ; + } +if (!cc) +sclp_wait_busy (); +return cc; +} + +/** +* Perform one test at the given address, optionally using the SCCB template, +* checking for the expected program interrupts and return codes. +* +* The parameter buf_len indicates the number of bytes of the template that +* should be copied to the test address, and should be 0 when the test +* address is invalid, in which case nothing is copied. +* +* The template is used to simplify tests where the same buffer content is +* used many times in a row, at different addresses. +* +* Returns true in case of success or false in case of failure +*/ +static bool test_one_sccb (uint32_t cmd,uint8_t *addr,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) +{ +SCCBHeader *h = (SCCBHeader *)addr; +int res, pgm; + +/* Copy the template to the test address if needed */ +if (buf_len) +memcpy (addr, sccb_template, buf_len); +if (exp_pgm !=PGM_NONE ) +expect_pgm_int (); +/* perform the actual call */ + res =sclp_service_call_test (cmd, h); +if (res) { +report_info ("SCLP not ready (command %#x, address %p, cc %d)" , cmd, addr, res); +return false; + } + pgm =clear_pgm_int (); +/* Check if the program exception was one of the expected ones */ +if (!((1ULL << pgm) & exp_pgm)) { +report_info ("First failure at addr %p, buf_len %d, cmd %#x, pgm code %d" , + addr, buf_len, cmd, pgm); +return false; + } +/* Check if the response code is the one expected */ +if (exp_rc && exp_rc != h->response_code) { +report_info ("First failure at addr %p, buf_len %d, cmd %#x, resp code %#x" , + addr, buf_len, cmd, h->response_code); +return false; + } +return true; +} + +/** +* Wrapper for test_one_sccb to be used when the template should not be +* copied and the memory address should not be touched. +*/ +static bool test_one_ro (uint32_t cmd,uint8_t *addr,uint64_t exp_pgm,uint16_t exp_rc) +{ +return test_one_sccb (cmd, addr,0 , exp_pgm, exp_rc); +} + +/** +* Wrapper for test_one_sccb to set up a simple SCCB template. +* +* The parameter sccb_len indicates the value that will be saved in the SCCB +* length field of the SCCB, buf_len indicates the number of bytes of +* template that need to be copied to the actual test address. In many cases +* it's enough to clear/copy the first 8 bytes of the buffer, while the SCCB
s390x/sclp.c line 122
Quoted 10 lines
s390x/sclp.c new file +10
-0+* itself can be larger. +* +* Returns true in case of success or false in case of failure +*/ +static bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len, +uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) +{ +memset (sccb_template,0 ,sizeof (sccb_template)); + ((SCCBHeader *)sccb_template)->length = sccb_len; +return test_one_sccb (cmd, addr, buf_len, exp_pgm, exp_rc);
Doing a fresh ./configure + make on RHEL7 gives me
[linux1@rhkvm01 kvm-unit-tests]$ make
gcc -std=gnu99 -ffreestanding -I /home/linux1/git/kvm-unit-tests/lib -I /home/linux1/git/kvm-unit-tests/lib/s390x -I lib -O2 -march=zEC12 -fno-delete-null-pointer-checks -g -MMD -MF s390x/.sclp.d -Wall -Wwrite-strings -Wempty-body -Wuninitialized -Wignored-qualifiers -Werror -fomit-frame-pointer -Wno-frame-address -fno-pic -Wclobbered -Wunused-but-set-parameter -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -Wmissing-prototypes -Wstrict-prototypes -c -o s390x/sclp.o s390x/sclp.cs390x/sclp.c: In function 'test_one_simple':s390x/sclp.c:121:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
((SCCBHeader *)sccb_template)->length = sccb_len;
^s390x/sclp.c: At top level:
cc1: error: unrecognized command line option "-Wno-frame-address" [-Werror]
cc1: all warnings being treated as errors
make: *** [s390x/sclp.o] Error 1
Signature · 3 lines
Thanks, David / dhildenb
Re: [kvm-unit-tests PATCH v8 6/6] s390x: SCLP unit test
Quoted 169 lines · David Hildenbrand
Quoted 155 lines · Claudio Imbrenda
SCLP unit test. Testing the following:
* Correctly ignoring instruction bits that should be ignored
* Privileged instruction check
* Check for addressing exceptions
* Specification exceptions:
- SCCB size less than 8
- SCCB unaligned
- SCCB overlaps prefix or lowcore
- SCCB address higher than 2GB
* Return codes for
- Invalid command
- SCCB too short (but at least 8)
- SCCB page boundary violationSigned-off-by Claudio Imbrenda <[email protected]>Reviewed-by Thomas Huth <[email protected]>Acked-by Janosch Frank <[email protected]>--- s390x/Makefile | 1 + s390x/sclp.c | 474 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 8 + 3 files changed, 483 insertions(+) create mode 100644 s390x/sclp.cs390x/Makefile +1
-0@@ -16,6 +16,7 @@ tests += $(TEST_DIR)/diag288.elf tests += $(TEST_DIR)/stsi.elf tests += $(TEST_DIR)/skrf.elf tests += $(TEST_DIR)/smp.elf +tests += $(TEST_DIR)/sclp.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binarys390x/sclp.c new file +112
-0@@ -0,0 +1,474 @@ +/* +* Service Call tests +* +* Copyright (c) 2019 IBM Corp +* +* Authors: +* Claudio Imbrenda <[email protected]> +* +* This code is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2. +*/ + +#include <libcflat.h> +#include <asm/page.h> +#include <asm/asm-offsets.h> +#include <asm/interrupt.h> +#include <sclp.h> + +#define PGM_NONE 1 +#define PGM_BIT_SPEC (1ULL << PGM_INT_CODE_SPECIFICATION) +#define PGM_BIT_ADDR (1ULL << PGM_INT_CODE_ADDRESSING) +#define PGM_BIT_PRIV (1ULL << PGM_INT_CODE_PRIVILEGED_OPERATION) +#define MKPTR (x) ((void *)(uint64_t)(x)) + +#define LC_SIZE (2 * PAGE_SIZE) + +static uint8_t pagebuf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* scratch pages used for some tests */ +static uint8_t prefix_buf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* temporary lowcore for test_sccb_prefix */ +static uint8_t sccb_template[PAGE_SIZE ];/* SCCB template to be used */ +static uint32_t valid_code;/* valid command code for READ SCP INFO */ +static struct lowcore *lc; + +/** +* Perform one service call, handling exceptions and interrupts. +*/ +static int sclp_service_call_test (unsigned int command,void *sccb) +{ +int cc; + +sclp_mark_busy (); +sclp_setup_int (); + cc =servc (command,__pa (sccb)); +if (lc->pgm_int_code) { +sclp_handle_ext (); +return 0 ; + } +if (!cc) +sclp_wait_busy (); +return cc; +} + +/** +* Perform one test at the given address, optionally using the SCCB template, +* checking for the expected program interrupts and return codes. +* +* The parameter buf_len indicates the number of bytes of the template that +* should be copied to the test address, and should be 0 when the test +* address is invalid, in which case nothing is copied. +* +* The template is used to simplify tests where the same buffer content is +* used many times in a row, at different addresses. +* +* Returns true in case of success or false in case of failure +*/ +static bool test_one_sccb (uint32_t cmd,uint8_t *addr,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) +{ +SCCBHeader *h = (SCCBHeader *)addr; +int res, pgm; + +/* Copy the template to the test address if needed */ +if (buf_len) +memcpy (addr, sccb_template, buf_len); +if (exp_pgm !=PGM_NONE ) +expect_pgm_int (); +/* perform the actual call */ + res =sclp_service_call_test (cmd, h); +if (res) { +report_info ("SCLP not ready (command %#x, address %p, cc %d)" , cmd, addr, res); +return false; + } + pgm =clear_pgm_int (); +/* Check if the program exception was one of the expected ones */ +if (!((1ULL << pgm) & exp_pgm)) { +report_info ("First failure at addr %p, buf_len %d, cmd %#x, pgm code %d" , + addr, buf_len, cmd, pgm); +return false; + } +/* Check if the response code is the one expected */ +if (exp_rc && exp_rc != h->response_code) { +report_info ("First failure at addr %p, buf_len %d, cmd %#x, resp code %#x" , + addr, buf_len, cmd, h->response_code); +return false; + } +return true; +} + +/** +* Wrapper for test_one_sccb to be used when the template should not be +* copied and the memory address should not be touched. +*/ +static bool test_one_ro (uint32_t cmd,uint8_t *addr,uint64_t exp_pgm,uint16_t exp_rc) +{ +return test_one_sccb (cmd, addr,0 , exp_pgm, exp_rc); +} + +/** +* Wrapper for test_one_sccb to set up a simple SCCB template. +* +* The parameter sccb_len indicates the value that will be saved in the SCCB +* length field of the SCCB, buf_len indicates the number of bytes of +* template that need to be copied to the actual test address. In many cases +* it's enough to clear/copy the first 8 bytes of the buffer, while the SCCB s390x/sclp.c line 122
Quoted 10 lines
s390x/sclp.c new file +10
-0+* itself can be larger. +* +* Returns true in case of success or false in case of failure +*/ +static bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len, +uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) +{ +memset (sccb_template,0 ,sizeof (sccb_template)); + ((SCCBHeader *)sccb_template)->length = sccb_len; +return test_one_sccb (cmd, addr, buf_len, exp_pgm, exp_rc);Doing a fresh ./configure + make on RHEL7 gives me
Quoted 10 lines
[linux1@rhkvm01 kvm-unit-tests]$ make
gcc -std=gnu99 -ffreestanding -I/home/linux1/git/kvm-unit-tests/lib-I/home/linux1/git/kvm-unit-tests/lib/s390x-I lib -O2 -march=zEC12 -fno-delete-null-pointer-checks -g -MMD -MF s390x/.sclp.d -Wall -Wwrite-strings -Wempty-body -Wuninitialized -Wignored-qualifiers -Werror -fomit-frame-pointer -Wno-frame-address -fno-pic -Wclobbered -Wunused-but-set-parameter -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -Wmissing-prototypes -Wstrict-prototypes -c -os390x/sclp.os390x/sclp.cs390x/sclp.c: In function 'test_one_simple':s390x/sclp.c:121:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
((SCCBHeader *)sccb_template)->length =sccb_len;
^s390x/sclp.c: At top level:
cc1: error: unrecognized command line option "-Wno-frame-address" [-Werror]
cc1: all warnings being treated as errors
make: *** [s390x/sclp.o] Error 1
The following makes it work:
s390x/sclp.c +3 -1
@@ -117,8 +117,10 @@ static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_tstatic bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) { +SCCBHeader *header = (void *)sccb_template; +memset (sccb_template,0 ,sizeof (sccb_template)); - ((SCCBHeader *)sccb_template)->length = sccb_len; + header->length = sccb_len;return test_one_sccb (cmd, addr, buf_len, exp_pgm, exp_rc); }
Signature · 3 lines
Thanks, David / dhildenb
Re: [kvm-unit-tests PATCH v8 6/6] s390x: SCLP unit test
Quoted 189 lines · David Hildenbrand
Quoted 169 lines · David Hildenbrand
Quoted 155 lines · Claudio Imbrenda
SCLP unit test. Testing the following:
* Correctly ignoring instruction bits that should be ignored
* Privileged instruction check
* Check for addressing exceptions
* Specification exceptions:
- SCCB size less than 8
- SCCB unaligned
- SCCB overlaps prefix or lowcore
- SCCB address higher than 2GB
* Return codes for
- Invalid command
- SCCB too short (but at least 8)
- SCCB page boundary violationSigned-off-by Claudio Imbrenda <[email protected]>Reviewed-by Thomas Huth <[email protected]>Acked-by Janosch Frank <[email protected]>--- s390x/Makefile | 1 + s390x/sclp.c | 474 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 8 + 3 files changed, 483 insertions(+) create mode 100644 s390x/sclp.cs390x/Makefile +1
-0@@ -16,6 +16,7 @@ tests += $(TEST_DIR)/diag288.elf tests += $(TEST_DIR)/stsi.elf tests += $(TEST_DIR)/skrf.elf tests += $(TEST_DIR)/smp.elf +tests += $(TEST_DIR)/sclp.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binarys390x/sclp.c new file +112
-0@@ -0,0 +1,474 @@ +/* +* Service Call tests +* +* Copyright (c) 2019 IBM Corp +* +* Authors: +* Claudio Imbrenda <[email protected]> +* +* This code is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2. +*/ + +#include <libcflat.h> +#include <asm/page.h> +#include <asm/asm-offsets.h> +#include <asm/interrupt.h> +#include <sclp.h> + +#define PGM_NONE 1 +#define PGM_BIT_SPEC (1ULL << PGM_INT_CODE_SPECIFICATION) +#define PGM_BIT_ADDR (1ULL << PGM_INT_CODE_ADDRESSING) +#define PGM_BIT_PRIV (1ULL << PGM_INT_CODE_PRIVILEGED_OPERATION) +#define MKPTR (x) ((void *)(uint64_t)(x)) + +#define LC_SIZE (2 * PAGE_SIZE) + +static uint8_t pagebuf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* scratch pages used for some tests */ +static uint8_t prefix_buf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* temporary lowcore for test_sccb_prefix */ +static uint8_t sccb_template[PAGE_SIZE ];/* SCCB template to be used */ +static uint32_t valid_code;/* valid command code for READ SCP INFO */ +static struct lowcore *lc; + +/** +* Perform one service call, handling exceptions and interrupts. +*/ +static int sclp_service_call_test (unsigned int command,void *sccb) +{ +int cc; + +sclp_mark_busy (); +sclp_setup_int (); + cc =servc (command,__pa (sccb)); +if (lc->pgm_int_code) { +sclp_handle_ext (); +return 0 ; + } +if (!cc) +sclp_wait_busy (); +return cc; +} + +/** +* Perform one test at the given address, optionally using the SCCB template, +* checking for the expected program interrupts and return codes. +* +* The parameter buf_len indicates the number of bytes of the template that +* should be copied to the test address, and should be 0 when the test +* address is invalid, in which case nothing is copied. +* +* The template is used to simplify tests where the same buffer content is +* used many times in a row, at different addresses. +* +* Returns true in case of success or false in case of failure +*/ +static bool test_one_sccb (uint32_t cmd,uint8_t *addr,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) +{ +SCCBHeader *h = (SCCBHeader *)addr; +int res, pgm; + +/* Copy the template to the test address if needed */ +if (buf_len) +memcpy (addr, sccb_template, buf_len); +if (exp_pgm !=PGM_NONE ) +expect_pgm_int (); +/* perform the actual call */ + res =sclp_service_call_test (cmd, h); +if (res) { +report_info ("SCLP not ready (command %#x, address %p, cc %d)" , cmd, addr, res); +return false; + } + pgm =clear_pgm_int (); +/* Check if the program exception was one of the expected ones */ +if (!((1ULL << pgm) & exp_pgm)) { +report_info ("First failure at addr %p, buf_len %d, cmd %#x, pgm code %d" , + addr, buf_len, cmd, pgm); +return false; + } +/* Check if the response code is the one expected */ +if (exp_rc && exp_rc != h->response_code) { +report_info ("First failure at addr %p, buf_len %d, cmd %#x, resp code %#x" , + addr, buf_len, cmd, h->response_code); +return false; + } +return true; +} + +/** +* Wrapper for test_one_sccb to be used when the template should not be +* copied and the memory address should not be touched. +*/ +static bool test_one_ro (uint32_t cmd,uint8_t *addr,uint64_t exp_pgm,uint16_t exp_rc) +{ +return test_one_sccb (cmd, addr,0 , exp_pgm, exp_rc); +} + +/** +* Wrapper for test_one_sccb to set up a simple SCCB template. +* +* The parameter sccb_len indicates the value that will be saved in the SCCB +* length field of the SCCB, buf_len indicates the number of bytes of +* template that need to be copied to the actual test address. In many cases +* it's enough to clear/copy the first 8 bytes of the buffer, while the SCCB s390x/sclp.c line 122
Quoted 10 lines
s390x/sclp.c new file +10
-0+* itself can be larger. +* +* Returns true in case of success or false in case of failure +*/ +static bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len, +uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) +{ +memset (sccb_template,0 ,sizeof (sccb_template)); + ((SCCBHeader *)sccb_template)->length = sccb_len; +return test_one_sccb (cmd, addr, buf_len, exp_pgm, exp_rc);Doing a fresh ./configure + make on RHEL7 gives me
Quoted 10 lines
[linux1@rhkvm01 kvm-unit-tests]$ make
gcc -std=gnu99 -ffreestanding -I/home/linux1/git/kvm-unit-tests/lib-I/home/linux1/git/kvm-unit-tests/lib/s390x-I lib -O2 -march=zEC12 -fno-delete-null-pointer-checks -g -MMD -MF s390x/.sclp.d -Wall -Wwrite-strings -Wempty-body -Wuninitialized -Wignored-qualifiers -Werror -fomit-frame-pointer -Wno-frame-address -fno-pic -Wclobbered -Wunused-but-set-parameter -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -Wmissing-prototypes -Wstrict-prototypes -c -os390x/sclp.os390x/sclp.cs390x/sclp.c: In function 'test_one_simple':s390x/sclp.c:121:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
((SCCBHeader *)sccb_template)->length =sccb_len;
^s390x/sclp.c: At top level:
cc1: error: unrecognized command line option "-Wno-frame-address" [-Werror]
cc1: all warnings being treated as errors
make: *** [s390x/sclp.o] Error 1The following makes it work:
s390x/sclp.c +0
-0
s390x/sclp.c static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_t · line 123
Quoted 8 lines
s390x/sclp.c +3
-1@@ -117,8 +117,10 @@ static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_tstatic bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) { +SCCBHeader *header = (void *)sccb_template; +memset (sccb_template,0 ,sizeof (sccb_template)); - ((SCCBHeader *)sccb_template)->length = sccb_len; + header->length = sccb_len;
While that might silence the compiler warning, we still might get aliasing problems here, I think.
The right way to solve this problem is to turn sccb_template into a union of the various structs/arrays that you want to use and then access the fields through the union instead ("type-punning through union").
Thomas
Re: [kvm-unit-tests PATCH v8 6/6] s390x: SCLP unit test
Quoted 196 lines · Thomas Huth
Quoted 195 lines · David Hildenbrand
Quoted 169 lines · David Hildenbrand
Quoted 155 lines · Claudio Imbrenda
SCLP unit test. Testing the following:
* Correctly ignoring instruction bits that should be ignored
* Privileged instruction check
* Check for addressing exceptions
* Specification exceptions:
- SCCB size less than 8
- SCCB unaligned
- SCCB overlaps prefix or lowcore
- SCCB address higher than 2GB
* Return codes for
- Invalid command
- SCCB too short (but at least 8)
- SCCB page boundary violationSigned-off-by Claudio Imbrenda <[email protected]>Reviewed-by Thomas Huth <[email protected]>Acked-by Janosch Frank <[email protected]>--- s390x/Makefile | 1 + s390x/sclp.c | 474 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 8 + 3 files changed, 483 insertions(+) create mode 100644 s390x/sclp.cs390x/Makefile +1
-0@@ -16,6 +16,7 @@ tests += $(TEST_DIR)/diag288.elf tests += $(TEST_DIR)/stsi.elf tests += $(TEST_DIR)/skrf.elf tests += $(TEST_DIR)/smp.elf +tests += $(TEST_DIR)/sclp.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binarys390x/sclp.c new file +112
-0@@ -0,0 +1,474 @@ +/* +* Service Call tests +* +* Copyright (c) 2019 IBM Corp +* +* Authors: +* Claudio Imbrenda <[email protected]> +* +* This code is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2. +*/ + +#include <libcflat.h> +#include <asm/page.h> +#include <asm/asm-offsets.h> +#include <asm/interrupt.h> +#include <sclp.h> + +#define PGM_NONE 1 +#define PGM_BIT_SPEC (1ULL << PGM_INT_CODE_SPECIFICATION) +#define PGM_BIT_ADDR (1ULL << PGM_INT_CODE_ADDRESSING) +#define PGM_BIT_PRIV (1ULL << PGM_INT_CODE_PRIVILEGED_OPERATION) +#define MKPTR (x) ((void *)(uint64_t)(x)) + +#define LC_SIZE (2 * PAGE_SIZE) + +static uint8_t pagebuf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* scratch pages used for some tests */ +static uint8_t prefix_buf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* temporary lowcore for test_sccb_prefix */ +static uint8_t sccb_template[PAGE_SIZE ];/* SCCB template to be used */ +static uint32_t valid_code;/* valid command code for READ SCP INFO */ +static struct lowcore *lc; + +/** +* Perform one service call, handling exceptions and interrupts. +*/ +static int sclp_service_call_test (unsigned int command,void *sccb) +{ +int cc; + +sclp_mark_busy (); +sclp_setup_int (); + cc =servc (command,__pa (sccb)); +if (lc->pgm_int_code) { +sclp_handle_ext (); +return 0 ; + } +if (!cc) +sclp_wait_busy (); +return cc; +} + +/** +* Perform one test at the given address, optionally using the SCCB template, +* checking for the expected program interrupts and return codes. +* +* The parameter buf_len indicates the number of bytes of the template that +* should be copied to the test address, and should be 0 when the test +* address is invalid, in which case nothing is copied. +* +* The template is used to simplify tests where the same buffer content is +* used many times in a row, at different addresses. +* +* Returns true in case of success or false in case of failure +*/ +static bool test_one_sccb (uint32_t cmd,uint8_t *addr,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) +{ +SCCBHeader *h = (SCCBHeader *)addr; +int res, pgm; + +/* Copy the template to the test address if needed */ +if (buf_len) +memcpy (addr, sccb_template, buf_len); +if (exp_pgm !=PGM_NONE ) +expect_pgm_int (); +/* perform the actual call */ + res =sclp_service_call_test (cmd, h); +if (res) { +report_info ("SCLP not ready (command %#x, address %p, cc %d)" , cmd, addr, res); +return false; + } + pgm =clear_pgm_int (); +/* Check if the program exception was one of the expected ones */ +if (!((1ULL << pgm) & exp_pgm)) { +report_info ("First failure at addr %p, buf_len %d, cmd %#x, pgm code %d" , + addr, buf_len, cmd, pgm); +return false; + } +/* Check if the response code is the one expected */ +if (exp_rc && exp_rc != h->response_code) { +report_info ("First failure at addr %p, buf_len %d, cmd %#x, resp code %#x" , + addr, buf_len, cmd, h->response_code); +return false; + } +return true; +} + +/** +* Wrapper for test_one_sccb to be used when the template should not be +* copied and the memory address should not be touched. +*/ +static bool test_one_ro (uint32_t cmd,uint8_t *addr,uint64_t exp_pgm,uint16_t exp_rc) +{ +return test_one_sccb (cmd, addr,0 , exp_pgm, exp_rc); +} + +/** +* Wrapper for test_one_sccb to set up a simple SCCB template. +* +* The parameter sccb_len indicates the value that will be saved in the SCCB +* length field of the SCCB, buf_len indicates the number of bytes of +* template that need to be copied to the actual test address. In many cases +* it's enough to clear/copy the first 8 bytes of the buffer, while the SCCB s390x/sclp.c line 122
Quoted 10 lines
s390x/sclp.c new file +10
-0+* itself can be larger. +* +* Returns true in case of success or false in case of failure +*/ +static bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len, +uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) +{ +memset (sccb_template,0 ,sizeof (sccb_template)); + ((SCCBHeader *)sccb_template)->length = sccb_len; +return test_one_sccb (cmd, addr, buf_len, exp_pgm, exp_rc);Doing a fresh ./configure + make on RHEL7 gives me
Quoted 10 lines
[linux1@rhkvm01 kvm-unit-tests]$ make
gcc -std=gnu99 -ffreestanding -I/home/linux1/git/kvm-unit-tests/lib-I/home/linux1/git/kvm-unit-tests/lib/s390x-I lib -O2 -march=zEC12 -fno-delete-null-pointer-checks -g -MMD -MF s390x/.sclp.d -Wall -Wwrite-strings -Wempty-body -Wuninitialized -Wignored-qualifiers -Werror -fomit-frame-pointer -Wno-frame-address -fno-pic -Wclobbered -Wunused-but-set-parameter -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -Wmissing-prototypes -Wstrict-prototypes -c -os390x/sclp.os390x/sclp.cs390x/sclp.c: In function 'test_one_simple':s390x/sclp.c:121:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
((SCCBHeader *)sccb_template)->length =sccb_len;
^s390x/sclp.c: At top level:
cc1: error: unrecognized command line option "-Wno-frame-address" [-Werror]
cc1: all warnings being treated as errors
make: *** [s390x/sclp.o] Error 1The following makes it work:
s390x/sclp.c +2
-0@@ -117,8 +117,10 @@ static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_tstatic bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) { +SCCBHeader *header = (void *)sccb_template; +memset (sccb_template,0 ,sizeof (sccb_template));
Quoted 8 lines
s390x/sclp.c static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_t · line 123
Quoted 2 lines
s390x/sclp.c +1
-1- ((SCCBHeader *)sccb_template)->length = sccb_len; + header->length = sccb_len;While that might silence the compiler warning, we still might get aliasing problems here, I think.
The right way to solve this problem is to turnsccb_templateinto a union of the various structs/arrays that you want to use and then access the fields through the union instead ("type-punning through union").
We do have the exact same thing in lib/s390x/sclp.c already, no?
Especially, new compilers don't seem to care?
Signature · 3 lines
Thanks, David / dhildenb
Re: [kvm-unit-tests PATCH v8 6/6] s390x: SCLP unit test
Quoted 206 lines · David Hildenbrand
Quoted 196 lines · Thomas Huth
Quoted 195 lines · David Hildenbrand
Quoted 169 lines · David Hildenbrand
Quoted 155 lines · Claudio Imbrenda
SCLP unit test. Testing the following:
* Correctly ignoring instruction bits that should be ignored
* Privileged instruction check
* Check for addressing exceptions
* Specification exceptions:
- SCCB size less than 8
- SCCB unaligned
- SCCB overlaps prefix or lowcore
- SCCB address higher than 2GB
* Return codes for
- Invalid command
- SCCB too short (but at least 8)
- SCCB page boundary violationSigned-off-by Claudio Imbrenda <[email protected]>Reviewed-by Thomas Huth <[email protected]>Acked-by Janosch Frank <[email protected]>--- s390x/Makefile | 1 + s390x/sclp.c | 474 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 8 + 3 files changed, 483 insertions(+) create mode 100644 s390x/sclp.cs390x/Makefile +1
-0@@ -16,6 +16,7 @@ tests += $(TEST_DIR)/diag288.elf tests += $(TEST_DIR)/stsi.elf tests += $(TEST_DIR)/skrf.elf tests += $(TEST_DIR)/smp.elf +tests += $(TEST_DIR)/sclp.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binarys390x/sclp.c new file +112
-0@@ -0,0 +1,474 @@ +/* +* Service Call tests +* +* Copyright (c) 2019 IBM Corp +* +* Authors: +* Claudio Imbrenda <[email protected]> +* +* This code is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2. +*/ + +#include <libcflat.h> +#include <asm/page.h> +#include <asm/asm-offsets.h> +#include <asm/interrupt.h> +#include <sclp.h> + +#define PGM_NONE 1 +#define PGM_BIT_SPEC (1ULL << PGM_INT_CODE_SPECIFICATION) +#define PGM_BIT_ADDR (1ULL << PGM_INT_CODE_ADDRESSING) +#define PGM_BIT_PRIV (1ULL << PGM_INT_CODE_PRIVILEGED_OPERATION) +#define MKPTR (x) ((void *)(uint64_t)(x)) + +#define LC_SIZE (2 * PAGE_SIZE) + +static uint8_t pagebuf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* scratch pages used for some tests */ +static uint8_t prefix_buf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* temporary lowcore for test_sccb_prefix */ +static uint8_t sccb_template[PAGE_SIZE ];/* SCCB template to be used */ +static uint32_t valid_code;/* valid command code for READ SCP INFO */ +static struct lowcore *lc; + +/** +* Perform one service call, handling exceptions and interrupts. +*/ +static int sclp_service_call_test (unsigned int command,void *sccb) +{ +int cc; + +sclp_mark_busy (); +sclp_setup_int (); + cc =servc (command,__pa (sccb)); +if (lc->pgm_int_code) { +sclp_handle_ext (); +return 0 ; + } +if (!cc) +sclp_wait_busy (); +return cc; +} + +/** +* Perform one test at the given address, optionally using the SCCB template, +* checking for the expected program interrupts and return codes. +* +* The parameter buf_len indicates the number of bytes of the template that +* should be copied to the test address, and should be 0 when the test +* address is invalid, in which case nothing is copied. +* +* The template is used to simplify tests where the same buffer content is +* used many times in a row, at different addresses. +* +* Returns true in case of success or false in case of failure +*/ +static bool test_one_sccb (uint32_t cmd,uint8_t *addr,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) +{ +SCCBHeader *h = (SCCBHeader *)addr; +int res, pgm; + +/* Copy the template to the test address if needed */ +if (buf_len) +memcpy (addr, sccb_template, buf_len); +if (exp_pgm !=PGM_NONE ) +expect_pgm_int (); +/* perform the actual call */ + res =sclp_service_call_test (cmd, h); +if (res) { +report_info ("SCLP not ready (command %#x, address %p, cc %d)" , cmd, addr, res); +return false; + } + pgm =clear_pgm_int (); +/* Check if the program exception was one of the expected ones */ +if (!((1ULL << pgm) & exp_pgm)) { +report_info ("First failure at addr %p, buf_len %d, cmd %#x, pgm code %d" , + addr, buf_len, cmd, pgm); +return false; + } +/* Check if the response code is the one expected */ +if (exp_rc && exp_rc != h->response_code) { +report_info ("First failure at addr %p, buf_len %d, cmd %#x, resp code %#x" , + addr, buf_len, cmd, h->response_code); +return false; + } +return true; +} + +/** +* Wrapper for test_one_sccb to be used when the template should not be +* copied and the memory address should not be touched. +*/ +static bool test_one_ro (uint32_t cmd,uint8_t *addr,uint64_t exp_pgm,uint16_t exp_rc) +{ +return test_one_sccb (cmd, addr,0 , exp_pgm, exp_rc); +} + +/** +* Wrapper for test_one_sccb to set up a simple SCCB template. +* +* The parameter sccb_len indicates the value that will be saved in the SCCB +* length field of the SCCB, buf_len indicates the number of bytes of +* template that need to be copied to the actual test address. In many cases +* it's enough to clear/copy the first 8 bytes of the buffer, while the SCCB s390x/sclp.c line 122
Quoted 10 lines
s390x/sclp.c new file +10
-0+* itself can be larger. +* +* Returns true in case of success or false in case of failure +*/ +static bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len, +uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) +{ +memset (sccb_template,0 ,sizeof (sccb_template)); + ((SCCBHeader *)sccb_template)->length = sccb_len; +return test_one_sccb (cmd, addr, buf_len, exp_pgm, exp_rc);Doing a fresh ./configure + make on RHEL7 gives me
Quoted 10 lines
[linux1@rhkvm01 kvm-unit-tests]$ make
gcc -std=gnu99 -ffreestanding -I/home/linux1/git/kvm-unit-tests/lib-I/home/linux1/git/kvm-unit-tests/lib/s390x-I lib -O2 -march=zEC12 -fno-delete-null-pointer-checks -g -MMD -MF s390x/.sclp.d -Wall -Wwrite-strings -Wempty-body -Wuninitialized -Wignored-qualifiers -Werror -fomit-frame-pointer -Wno-frame-address -fno-pic -Wclobbered -Wunused-but-set-parameter -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -Wmissing-prototypes -Wstrict-prototypes -c -os390x/sclp.os390x/sclp.cs390x/sclp.c: In function 'test_one_simple':s390x/sclp.c:121:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
((SCCBHeader *)sccb_template)->length =sccb_len;
^s390x/sclp.c: At top level:
cc1: error: unrecognized command line option "-Wno-frame-address" [-Werror]
cc1: all warnings being treated as errors
make: *** [s390x/sclp.o] Error 1The following makes it work:
s390x/sclp.c +2
-0@@ -117,8 +117,10 @@ static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_tstatic bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) { +SCCBHeader *header = (void *)sccb_template; +memset (sccb_template,0 ,sizeof (sccb_template));Quoted 8 lines
s390x/sclp.c static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_t · line 123
Quoted 2 lines
s390x/sclp.c +1
-1- ((SCCBHeader *)sccb_template)->length = sccb_len; + header->length = sccb_len;While that might silence the compiler warning, we still might get aliasing problems here, I think.
The right way to solve this problem is to turnsccb_templateinto a union of the various structs/arrays that you want to use and then access the fields through the union instead ("type-punning through union").
Quoted 1 line
We do have the exact same thing in
lib/s390x/sclp.calready, no?
Maybe we should carefully check that code, too...
Quoted 1 line
Especially, new compilers don't seem to care?
I've seen horrible bugs due to these aliasing problems in the past - without compiler warnings showing up! Certain versions of GCC assume that they can re-order code with pointers that point to types of different sizes, i.e. in the above example, I think they could assume that they could re-order the memset() and the header->length = ... line. I'd feel better if we play safe and use a union here.
Thomas
Re: [kvm-unit-tests PATCH v8 6/6] s390x: SCLP unit test
Quoted 211 lines · Thomas Huth
Quoted 206 lines · David Hildenbrand
Quoted 196 lines · Thomas Huth
Quoted 195 lines · David Hildenbrand
Quoted 169 lines · David Hildenbrand
Quoted 155 lines · Claudio Imbrenda
SCLP unit test. Testing the following:
* Correctly ignoring instruction bits that should be ignored
* Privileged instruction check
* Check for addressing exceptions
* Specification exceptions:
- SCCB size less than 8
- SCCB unaligned
- SCCB overlaps prefix or lowcore
- SCCB address higher than 2GB
* Return codes for
- Invalid command
- SCCB too short (but at least 8)
- SCCB page boundary violationSigned-off-by Claudio Imbrenda <[email protected]>Reviewed-by Thomas Huth <[email protected]>Acked-by Janosch Frank <[email protected]>--- s390x/Makefile | 1 + s390x/sclp.c | 474 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 8 + 3 files changed, 483 insertions(+) create mode 100644 s390x/sclp.cs390x/Makefile +1
-0@@ -16,6 +16,7 @@ tests += $(TEST_DIR)/diag288.elf tests += $(TEST_DIR)/stsi.elf tests += $(TEST_DIR)/skrf.elf tests += $(TEST_DIR)/smp.elf +tests += $(TEST_DIR)/sclp.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binarys390x/sclp.c new file +112
-0@@ -0,0 +1,474 @@ +/* +* Service Call tests +* +* Copyright (c) 2019 IBM Corp +* +* Authors: +* Claudio Imbrenda <[email protected]> +* +* This code is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2. +*/ + +#include <libcflat.h> +#include <asm/page.h> +#include <asm/asm-offsets.h> +#include <asm/interrupt.h> +#include <sclp.h> + +#define PGM_NONE 1 +#define PGM_BIT_SPEC (1ULL << PGM_INT_CODE_SPECIFICATION) +#define PGM_BIT_ADDR (1ULL << PGM_INT_CODE_ADDRESSING) +#define PGM_BIT_PRIV (1ULL << PGM_INT_CODE_PRIVILEGED_OPERATION) +#define MKPTR (x) ((void *)(uint64_t)(x)) + +#define LC_SIZE (2 * PAGE_SIZE) + +static uint8_t pagebuf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* scratch pages used for some tests */ +static uint8_t prefix_buf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* temporary lowcore for test_sccb_prefix */ +static uint8_t sccb_template[PAGE_SIZE ];/* SCCB template to be used */ +static uint32_t valid_code;/* valid command code for READ SCP INFO */ +static struct lowcore *lc; + +/** +* Perform one service call, handling exceptions and interrupts. +*/ +static int sclp_service_call_test (unsigned int command,void *sccb) +{ +int cc; + +sclp_mark_busy (); +sclp_setup_int (); + cc =servc (command,__pa (sccb)); +if (lc->pgm_int_code) { +sclp_handle_ext (); +return 0 ; + } +if (!cc) +sclp_wait_busy (); +return cc; +} + +/** +* Perform one test at the given address, optionally using the SCCB template, +* checking for the expected program interrupts and return codes. +* +* The parameter buf_len indicates the number of bytes of the template that +* should be copied to the test address, and should be 0 when the test +* address is invalid, in which case nothing is copied. +* +* The template is used to simplify tests where the same buffer content is +* used many times in a row, at different addresses. +* +* Returns true in case of success or false in case of failure +*/ +static bool test_one_sccb (uint32_t cmd,uint8_t *addr,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) +{ +SCCBHeader *h = (SCCBHeader *)addr; +int res, pgm; + +/* Copy the template to the test address if needed */ +if (buf_len) +memcpy (addr, sccb_template, buf_len); +if (exp_pgm !=PGM_NONE ) +expect_pgm_int (); +/* perform the actual call */ + res =sclp_service_call_test (cmd, h); +if (res) { +report_info ("SCLP not ready (command %#x, address %p, cc %d)" , cmd, addr, res); +return false; + } + pgm =clear_pgm_int (); +/* Check if the program exception was one of the expected ones */ +if (!((1ULL << pgm) & exp_pgm)) { +report_info ("First failure at addr %p, buf_len %d, cmd %#x, pgm code %d" , + addr, buf_len, cmd, pgm); +return false; + } +/* Check if the response code is the one expected */ +if (exp_rc && exp_rc != h->response_code) { +report_info ("First failure at addr %p, buf_len %d, cmd %#x, resp code %#x" , + addr, buf_len, cmd, h->response_code); +return false; + } +return true; +} + +/** +* Wrapper for test_one_sccb to be used when the template should not be +* copied and the memory address should not be touched. +*/ +static bool test_one_ro (uint32_t cmd,uint8_t *addr,uint64_t exp_pgm,uint16_t exp_rc) +{ +return test_one_sccb (cmd, addr,0 , exp_pgm, exp_rc); +} + +/** +* Wrapper for test_one_sccb to set up a simple SCCB template. +* +* The parameter sccb_len indicates the value that will be saved in the SCCB +* length field of the SCCB, buf_len indicates the number of bytes of +* template that need to be copied to the actual test address. In many cases +* it's enough to clear/copy the first 8 bytes of the buffer, while the SCCB s390x/sclp.c line 122
Quoted 10 lines
s390x/sclp.c new file +10
-0+* itself can be larger. +* +* Returns true in case of success or false in case of failure +*/ +static bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len, +uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) +{ +memset (sccb_template,0 ,sizeof (sccb_template)); + ((SCCBHeader *)sccb_template)->length = sccb_len; +return test_one_sccb (cmd, addr, buf_len, exp_pgm, exp_rc);Doing a fresh ./configure + make on RHEL7 gives me
Quoted 10 lines
[linux1@rhkvm01 kvm-unit-tests]$ make
gcc -std=gnu99 -ffreestanding -I/home/linux1/git/kvm-unit-tests/lib-I/home/linux1/git/kvm-unit-tests/lib/s390x-I lib -O2 -march=zEC12 -fno-delete-null-pointer-checks -g -MMD -MF s390x/.sclp.d -Wall -Wwrite-strings -Wempty-body -Wuninitialized -Wignored-qualifiers -Werror -fomit-frame-pointer -Wno-frame-address -fno-pic -Wclobbered -Wunused-but-set-parameter -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -Wmissing-prototypes -Wstrict-prototypes -c -os390x/sclp.os390x/sclp.cs390x/sclp.c: In function 'test_one_simple':s390x/sclp.c:121:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
((SCCBHeader *)sccb_template)->length =sccb_len;
^s390x/sclp.c: At top level:
cc1: error: unrecognized command line option "-Wno-frame-address" [-Werror]
cc1: all warnings being treated as errors
make: *** [s390x/sclp.o] Error 1The following makes it work:
s390x/sclp.c +2
-0@@ -117,8 +117,10 @@ static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_tstatic bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) { +SCCBHeader *header = (void *)sccb_template; +memset (sccb_template,0 ,sizeof (sccb_template));Quoted 8 lines
s390x/sclp.c static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_t · line 123
Quoted 2 lines
s390x/sclp.c +1
-1- ((SCCBHeader *)sccb_template)->length = sccb_len; + header->length = sccb_len;While that might silence the compiler warning, we still might get aliasing problems here, I think.
The right way to solve this problem is to turnsccb_templateinto a union of the various structs/arrays that you want to use and then access the fields through the union instead ("type-punning through union").Quoted 1 line
We do have the exact same thing in
lib/s390x/sclp.calready, no?Maybe we should carefully check that code, too...
Quoted 8 lines
Quoted 1 line
Especially, new compilers don't seem to care?
I've seen horrible bugs due to these aliasing problems in the past - without compiler warnings showing up! Certain versions of GCC assume that they can re-order code with pointers that point to types of different sizes, i.e. in the above example, I think they could assume that they could re-order the
memset()and theheader->length= ... line. I'd feel better if we play safe and use a union here.
Should we simply allow type-punning?
Signature · 3 lines
Thanks, David / dhildenb
Re: [kvm-unit-tests PATCH v8 6/6] s390x: SCLP unit test
Quoted 214 lines · David Hildenbrand
Quoted 213 lines · Thomas Huth
Quoted 206 lines · David Hildenbrand
Quoted 196 lines · Thomas Huth
Quoted 195 lines · David Hildenbrand
Quoted 169 lines · David Hildenbrand
Quoted 155 lines · Claudio Imbrenda
SCLP unit test. Testing the following:
* Correctly ignoring instruction bits that should be ignored
* Privileged instruction check
* Check for addressing exceptions
* Specification exceptions:
- SCCB size less than 8
- SCCB unaligned
- SCCB overlaps prefix or lowcore
- SCCB address higher than 2GB
* Return codes for
- Invalid command
- SCCB too short (but at least 8)
- SCCB page boundary violationSigned-off-by Claudio Imbrenda <[email protected]>Reviewed-by Thomas Huth <[email protected]>Acked-by Janosch Frank <[email protected]>--- s390x/Makefile | 1 + s390x/sclp.c | 474 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 8 + 3 files changed, 483 insertions(+) create mode 100644 s390x/sclp.cs390x/Makefile +1
-0@@ -16,6 +16,7 @@ tests += $(TEST_DIR)/diag288.elf tests += $(TEST_DIR)/stsi.elf tests += $(TEST_DIR)/skrf.elf tests += $(TEST_DIR)/smp.elf +tests += $(TEST_DIR)/sclp.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binarys390x/sclp.c new file +112
-0@@ -0,0 +1,474 @@ +/* +* Service Call tests +* +* Copyright (c) 2019 IBM Corp +* +* Authors: +* Claudio Imbrenda <[email protected]> +* +* This code is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2. +*/ + +#include <libcflat.h> +#include <asm/page.h> +#include <asm/asm-offsets.h> +#include <asm/interrupt.h> +#include <sclp.h> + +#define PGM_NONE 1 +#define PGM_BIT_SPEC (1ULL << PGM_INT_CODE_SPECIFICATION) +#define PGM_BIT_ADDR (1ULL << PGM_INT_CODE_ADDRESSING) +#define PGM_BIT_PRIV (1ULL << PGM_INT_CODE_PRIVILEGED_OPERATION) +#define MKPTR (x) ((void *)(uint64_t)(x)) + +#define LC_SIZE (2 * PAGE_SIZE) + +static uint8_t pagebuf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* scratch pages used for some tests */ +static uint8_t prefix_buf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* temporary lowcore for test_sccb_prefix */ +static uint8_t sccb_template[PAGE_SIZE ];/* SCCB template to be used */ +static uint32_t valid_code;/* valid command code for READ SCP INFO */ +static struct lowcore *lc; + +/** +* Perform one service call, handling exceptions and interrupts. +*/ +static int sclp_service_call_test (unsigned int command,void *sccb) +{ +int cc; + +sclp_mark_busy (); +sclp_setup_int (); + cc =servc (command,__pa (sccb)); +if (lc->pgm_int_code) { +sclp_handle_ext (); +return 0 ; + } +if (!cc) +sclp_wait_busy (); +return cc; +} + +/** +* Perform one test at the given address, optionally using the SCCB template, +* checking for the expected program interrupts and return codes. +* +* The parameter buf_len indicates the number of bytes of the template that +* should be copied to the test address, and should be 0 when the test +* address is invalid, in which case nothing is copied. +* +* The template is used to simplify tests where the same buffer content is +* used many times in a row, at different addresses. +* +* Returns true in case of success or false in case of failure +*/ +static bool test_one_sccb (uint32_t cmd,uint8_t *addr,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) +{ +SCCBHeader *h = (SCCBHeader *)addr; +int res, pgm; + +/* Copy the template to the test address if needed */ +if (buf_len) +memcpy (addr, sccb_template, buf_len); +if (exp_pgm !=PGM_NONE ) +expect_pgm_int (); +/* perform the actual call */ + res =sclp_service_call_test (cmd, h); +if (res) { +report_info ("SCLP not ready (command %#x, address %p, cc %d)" , cmd, addr, res); +return false; + } + pgm =clear_pgm_int (); +/* Check if the program exception was one of the expected ones */ +if (!((1ULL << pgm) & exp_pgm)) { +report_info ("First failure at addr %p, buf_len %d, cmd %#x, pgm code %d" , + addr, buf_len, cmd, pgm); +return false; + } +/* Check if the response code is the one expected */ +if (exp_rc && exp_rc != h->response_code) { +report_info ("First failure at addr %p, buf_len %d, cmd %#x, resp code %#x" , + addr, buf_len, cmd, h->response_code); +return false; + } +return true; +} + +/** +* Wrapper for test_one_sccb to be used when the template should not be +* copied and the memory address should not be touched. +*/ +static bool test_one_ro (uint32_t cmd,uint8_t *addr,uint64_t exp_pgm,uint16_t exp_rc) +{ +return test_one_sccb (cmd, addr,0 , exp_pgm, exp_rc); +} + +/** +* Wrapper for test_one_sccb to set up a simple SCCB template. +* +* The parameter sccb_len indicates the value that will be saved in the SCCB +* length field of the SCCB, buf_len indicates the number of bytes of +* template that need to be copied to the actual test address. In many cases +* it's enough to clear/copy the first 8 bytes of the buffer, while the SCCB s390x/sclp.c line 122
Quoted 10 lines
s390x/sclp.c new file +10
-0+* itself can be larger. +* +* Returns true in case of success or false in case of failure +*/ +static bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len, +uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) +{ +memset (sccb_template,0 ,sizeof (sccb_template)); + ((SCCBHeader *)sccb_template)->length = sccb_len; +return test_one_sccb (cmd, addr, buf_len, exp_pgm, exp_rc);Doing a fresh ./configure + make on RHEL7 gives me
Quoted 10 lines
[linux1@rhkvm01 kvm-unit-tests]$ make
gcc -std=gnu99 -ffreestanding -I/home/linux1/git/kvm-unit-tests/lib-I/home/linux1/git/kvm-unit-tests/lib/s390x-I lib -O2 -march=zEC12 -fno-delete-null-pointer-checks -g -MMD -MF s390x/.sclp.d -Wall -Wwrite-strings -Wempty-body -Wuninitialized -Wignored-qualifiers -Werror -fomit-frame-pointer -Wno-frame-address -fno-pic -Wclobbered -Wunused-but-set-parameter -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -Wmissing-prototypes -Wstrict-prototypes -c -os390x/sclp.os390x/sclp.cs390x/sclp.c: In function 'test_one_simple':s390x/sclp.c:121:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
((SCCBHeader *)sccb_template)->length =sccb_len;
^s390x/sclp.c: At top level:
cc1: error: unrecognized command line option "-Wno-frame-address" [-Werror]
cc1: all warnings being treated as errors
make: *** [s390x/sclp.o] Error 1The following makes it work:
s390x/sclp.c +2
-0@@ -117,8 +117,10 @@ static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_tstatic bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) { +SCCBHeader *header = (void *)sccb_template; +memset (sccb_template,0 ,sizeof (sccb_template));Quoted 8 lines
s390x/sclp.c static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_t · line 123
Quoted 2 lines
s390x/sclp.c +1
-1- ((SCCBHeader *)sccb_template)->length = sccb_len; + header->length = sccb_len;While that might silence the compiler warning, we still might get aliasing problems here, I think.
The right way to solve this problem is to turnsccb_templateinto a union of the various structs/arrays that you want to use and then access the fields through the union instead ("type-punning through union").Quoted 1 line
We do have the exact same thing in
lib/s390x/sclp.calready, no?Maybe we should carefully check that code, too...
Quoted 1 line
Especially, new compilers don't seem to care?
Quoted 8 lines
Quoted 6 lines
I've seen horrible bugs due to these aliasing problems in the past - without compiler warnings showing up! Certain versions of GCC assume that they can re-order code with pointers that point to types of different sizes, i.e. in the above example, I think they could assume that they could re-order the
memset()and theheader->length= ... line. I'd feel better if we play safe and use a union here.Should we simply allow type-punning?
For now I squashed
s390x/sclp.c +0 -0
@@ -26,7 +26,12 @@ static uint8_t pagebuf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /*
scratch pages used for some tests */
static uint8_t prefix_buf[LC_SIZE] __attribute__((aligned(LC_SIZE)));
/* temporary lowcore for test_sccb_prefix */
-static uint8_t sccb_template[PAGE_SIZE]; /* SCCB template to be used */
+/* SCCB template to be used */
+static union {
+ uint8_t raw[PAGE_SIZE];
+ SCCBHeader header;
+ WriteEventData data;
+} sccb_template;
static uint32_t valid_code; /* valid command code for READ SCP INFO */
static struct lowcore *lc;
@@ -69,7 +74,7 @@ static bool test_one_sccb(uint32_t cmd, uint8_t *addr, uint16_t buf_len, uint64_
/* Copy the template to the test address if needed */
if (buf_len)
- memcpy(addr, sccb_template, buf_len);
+ memcpy(addr, sccb_template.raw, buf_len);
if (exp_pgm != PGM_NONE)
expect_pgm_int();
/* perform the actual call */
@@ -117,8 +122,8 @@ static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_t
static bool test_one_simple(uint32_t cmd, uint8_t *addr, uint16_t sccb_len,
uint16_t buf_len, uint64_t exp_pgm, uint16_t exp_rc)
{
- memset(sccb_template, 0, sizeof(sccb_template));
- ((SCCBHeader *)sccb_template)->length = sccb_len;
+ memset(sccb_template.raw, 0, sizeof(sccb_template.raw));
+ sccb_template.header.length = sccb_len;
return test_one_sccb(cmd, addr, buf_len, exp_pgm, exp_rc);
}
@@ -299,10 +304,10 @@ static void test_boundary(void)
{
const uint32_t cmd = SCLP_CMD_WRITE_EVENT_DATA; const uint16_t res = SCLP_RC_SCCB_BOUNDARY_VIOLATION;
- WriteEventData *sccb = (WriteEventData *)sccb_template;
+ WriteEventData *sccb = &sccb_template.data;
int len, offset;
- memset(sccb_template, 0, sizeof(sccb_template));
+ memset(sccb_template.raw, 0, sizeof(sccb_template.raw));
sccb->h.function_code = SCLP_FC_NORMAL_WRITE; for (len = 32; len <= 4096; len++) {
offset = len & 7 ? len & ~7 : len - 8;
@@ -323,10 +328,10 @@ static void test_toolong(void)
{
const uint32_t cmd = SCLP_CMD_WRITE_EVENT_DATA; const uint16_t res = SCLP_RC_SCCB_BOUNDARY_VIOLATION;
- WriteEventData *sccb = (WriteEventData *)sccb_template;
+ WriteEventData *sccb = &sccb_template.data;
int len;
- memset(sccb_template, 0, sizeof(sccb_template));
+ memset(sccb_template.raw, 0, sizeof(sccb_template.raw));
sccb->h.function_code = SCLP_FC_NORMAL_WRITE; for (len = 4097; len < 8192; len++) {
sccb->h.length = len;
Signature · 9 lines
2.24.1 -- Thanks, David / dhildenb
Re: [kvm-unit-tests PATCH v8 6/6] s390x: SCLP unit test
Quoted 284 lines · David Hildenbrand
Quoted 214 lines · David Hildenbrand
Quoted 213 lines · Thomas Huth
Quoted 206 lines · David Hildenbrand
Quoted 196 lines · Thomas Huth
Quoted 195 lines · David Hildenbrand
Quoted 169 lines · David Hildenbrand
Quoted 155 lines · Claudio Imbrenda
SCLP unit test. Testing the following:
* Correctly ignoring instruction bits that should be ignored
* Privileged instruction check
* Check for addressing exceptions
* Specification exceptions:
- SCCB size less than 8
- SCCB unaligned
- SCCB overlaps prefix or lowcore
- SCCB address higher than 2GB
* Return codes for
- Invalid command
- SCCB too short (but at least 8)
- SCCB page boundary violationSigned-off-by Claudio Imbrenda <[email protected]>Reviewed-by Thomas Huth <[email protected]>Acked-by Janosch Frank <[email protected]>--- s390x/Makefile | 1 + s390x/sclp.c | 474 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 8 + 3 files changed, 483 insertions(+) create mode 100644 s390x/sclp.cs390x/Makefile +1
-0@@ -16,6 +16,7 @@ tests += $(TEST_DIR)/diag288.elf tests += $(TEST_DIR)/stsi.elf tests += $(TEST_DIR)/skrf.elf tests += $(TEST_DIR)/smp.elf +tests += $(TEST_DIR)/sclp.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binarys390x/sclp.c new file +112
-0@@ -0,0 +1,474 @@ +/* +* Service Call tests +* +* Copyright (c) 2019 IBM Corp +* +* Authors: +* Claudio Imbrenda <[email protected]> +* +* This code is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2. +*/ + +#include <libcflat.h> +#include <asm/page.h> +#include <asm/asm-offsets.h> +#include <asm/interrupt.h> +#include <sclp.h> + +#define PGM_NONE 1 +#define PGM_BIT_SPEC (1ULL << PGM_INT_CODE_SPECIFICATION) +#define PGM_BIT_ADDR (1ULL << PGM_INT_CODE_ADDRESSING) +#define PGM_BIT_PRIV (1ULL << PGM_INT_CODE_PRIVILEGED_OPERATION) +#define MKPTR (x) ((void *)(uint64_t)(x)) + +#define LC_SIZE (2 * PAGE_SIZE) + +static uint8_t pagebuf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* scratch pages used for some tests */ +static uint8_t prefix_buf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* temporary lowcore for test_sccb_prefix */ +static uint8_t sccb_template[PAGE_SIZE ];/* SCCB template to be used */ +static uint32_t valid_code;/* valid command code for READ SCP INFO */ +static struct lowcore *lc; + +/** +* Perform one service call, handling exceptions and interrupts. +*/ +static int sclp_service_call_test (unsigned int command,void *sccb) +{ +int cc; + +sclp_mark_busy (); +sclp_setup_int (); + cc =servc (command,__pa (sccb)); +if (lc->pgm_int_code) { +sclp_handle_ext (); +return 0 ; + } +if (!cc) +sclp_wait_busy (); +return cc; +} + +/** +* Perform one test at the given address, optionally using the SCCB template, +* checking for the expected program interrupts and return codes. +* +* The parameter buf_len indicates the number of bytes of the template that +* should be copied to the test address, and should be 0 when the test +* address is invalid, in which case nothing is copied. +* +* The template is used to simplify tests where the same buffer content is +* used many times in a row, at different addresses. +* +* Returns true in case of success or false in case of failure +*/ +static bool test_one_sccb (uint32_t cmd,uint8_t *addr,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) +{ +SCCBHeader *h = (SCCBHeader *)addr; +int res, pgm; + +/* Copy the template to the test address if needed */ +if (buf_len) +memcpy (addr, sccb_template, buf_len); +if (exp_pgm !=PGM_NONE ) +expect_pgm_int (); +/* perform the actual call */ + res =sclp_service_call_test (cmd, h); +if (res) { +report_info ("SCLP not ready (command %#x, address %p, cc %d)" , cmd, addr, res); +return false; + } + pgm =clear_pgm_int (); +/* Check if the program exception was one of the expected ones */ +if (!((1ULL << pgm) & exp_pgm)) { +report_info ("First failure at addr %p, buf_len %d, cmd %#x, pgm code %d" , + addr, buf_len, cmd, pgm); +return false; + } +/* Check if the response code is the one expected */ +if (exp_rc && exp_rc != h->response_code) { +report_info ("First failure at addr %p, buf_len %d, cmd %#x, resp code %#x" , + addr, buf_len, cmd, h->response_code); +return false; + } +return true; +} + +/** +* Wrapper for test_one_sccb to be used when the template should not be +* copied and the memory address should not be touched. +*/ +static bool test_one_ro (uint32_t cmd,uint8_t *addr,uint64_t exp_pgm,uint16_t exp_rc) +{ +return test_one_sccb (cmd, addr,0 , exp_pgm, exp_rc); +} + +/** +* Wrapper for test_one_sccb to set up a simple SCCB template. +* +* The parameter sccb_len indicates the value that will be saved in the SCCB +* length field of the SCCB, buf_len indicates the number of bytes of +* template that need to be copied to the actual test address. In many cases +* it's enough to clear/copy the first 8 bytes of the buffer, while the SCCB s390x/sclp.c line 122
Quoted 10 lines
s390x/sclp.c new file +10
-0+* itself can be larger. +* +* Returns true in case of success or false in case of failure +*/ +static bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len, +uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) +{ +memset (sccb_template,0 ,sizeof (sccb_template)); + ((SCCBHeader *)sccb_template)->length = sccb_len; +return test_one_sccb (cmd, addr, buf_len, exp_pgm, exp_rc);Doing a fresh ./configure + make on RHEL7 gives me
Quoted 10 lines
[linux1@rhkvm01 kvm-unit-tests]$ make
gcc -std=gnu99 -ffreestanding -I/home/linux1/git/kvm-unit-tests/lib-I/home/linux1/git/kvm-unit-tests/lib/s390x-I lib -O2 -march=zEC12 -fno-delete-null-pointer-checks -g -MMD -MF s390x/.sclp.d -Wall -Wwrite-strings -Wempty-body -Wuninitialized -Wignored-qualifiers -Werror -fomit-frame-pointer -Wno-frame-address -fno-pic -Wclobbered -Wunused-but-set-parameter -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -Wmissing-prototypes -Wstrict-prototypes -c -os390x/sclp.os390x/sclp.cs390x/sclp.c: In function 'test_one_simple':s390x/sclp.c:121:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
((SCCBHeader *)sccb_template)->length =sccb_len;
^s390x/sclp.c: At top level:
cc1: error: unrecognized command line option "-Wno-frame-address" [-Werror]
cc1: all warnings being treated as errors
make: *** [s390x/sclp.o] Error 1The following makes it work:
s390x/sclp.c +2
-0@@ -117,8 +117,10 @@ static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_tstatic bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) { +SCCBHeader *header = (void *)sccb_template; +memset (sccb_template,0 ,sizeof (sccb_template));Quoted 8 lines
s390x/sclp.c static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_t · line 123
Quoted 2 lines
s390x/sclp.c +1
-1- ((SCCBHeader *)sccb_template)->length = sccb_len; + header->length = sccb_len;While that might silence the compiler warning, we still might get aliasing problems here, I think.
The right way to solve this problem is to turnsccb_templateinto a union of the various structs/arrays that you want to use and then access the fields through the union instead ("type-punning through union").Quoted 1 line
We do have the exact same thing in
lib/s390x/sclp.calready, no?Maybe we should carefully check that code, too...
Quoted 1 line
Especially, new compilers don't seem to care?
Quoted 8 lines
Quoted 6 lines
I've seen horrible bugs due to these aliasing problems in the past - without compiler warnings showing up! Certain versions of GCC assume that they can re-order code with pointers that point to types of different sizes, i.e. in the above example, I think they could assume that they could re-order the
memset()and theheader->length= ... line. I'd feel better if we play safe and use a union here.Should we simply allow type-punning?
For now I squashed
s390x/sclp.c +0
-0@@ -26,7 +26,12 @@ static uint8_t pagebuf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /*scratch pages used for some tests */
staticuint8_tprefix_buf[LC_SIZE] __attribute__((aligned(LC_SIZE)));
/* temporary lowcore fortest_sccb_prefix*/s390x/sclp.c +6
-1-static uint8_t sccb_template[PAGE_SIZE ];/* SCCB template to be used */ +/* SCCB template to be used */ +static union { +uint8_t raw[PAGE_SIZE ]; +SCCBHeader header; +WriteEventData data; +} sccb_template;static uint32_t valid_code;/* valid command code for READ SCP INFO */ static struct lowcore *lc;@@ -69,7 +74,7 @@ static bool test_one_sccb(uint32_t cmd, uint8_t *addr,
uint16_tbuf_len,uint64_s390x/sclp.c +1
-1/* Copy the template to the test address if needed */ if (buf_len) -memcpy (addr, sccb_template, buf_len); +memcpy (addr, sccb_template.raw, buf_len);if (exp_pgm !=PGM_NONE )expect_pgm_int ();/* perform the actual call */ @@ -117,8 +122,8 @@ static bool test_one_ro(uint32_t cmd, uint8_t *addr,
uint64_texp_pgm,uint16_t
static bool test_one_simple(uint32_t cmd,uint8_t*addr,uint16_tsccb_len,s390x/sclp.c +4
-4uint16_t buf_len, uint64_t exp_pgm, uint16_t exp_rc) { - memset(sccb_template, 0, sizeof(sccb_template)); - ((SCCBHeader *)sccb_template)->length = sccb_len; + memset(sccb_template.raw, 0, sizeof(sccb_template.raw)); + sccb_template.header.length = sccb_len;return test_one_sccb (cmd, addr, buf_len, exp_pgm, exp_rc); }@@ -299,10 +304,10 @@ static void test_boundary(void) {const uint32_t cmd =SCLP_CMD_WRITE_EVENT_DATA ;const uint16_t res =SCLP_RC_SCCB_BOUNDARY_VIOLATION ; -WriteEventData *sccb = (WriteEventData *)sccb_template; +WriteEventData *sccb = &sccb_template.data;int len, offset; -memset (sccb_template,0 ,sizeof (sccb_template)); +memset (sccb_template.raw,0 ,sizeof (sccb_template.raw)); sccb->h.function_code =SCLP_FC_NORMAL_WRITE ;for (len =32 ; len <=4096 ; len++) { offset = len &7 ? len & ~7 : len -8 ;@@ -323,10 +328,10 @@ static void test_toolong(void) {const uint32_t cmd =SCLP_CMD_WRITE_EVENT_DATA ;
s390x/sclp.c static void test_toolong(void) · line 337
Quoted 10 lines
s390x/sclp.c +2
-2const uint16_t res =SCLP_RC_SCCB_BOUNDARY_VIOLATION ; -WriteEventData *sccb = (WriteEventData *)sccb_template; +WriteEventData *sccb = &sccb_template.data;int len; -memset (sccb_template,0 ,sizeof (sccb_template)); +memset (sccb_template.raw,0 ,sizeof (sccb_template.raw)); sccb->h.function_code =SCLP_FC_NORMAL_WRITE ;for (len =4097 ; len <8192 ; len++) { sccb->h.length = len;
Thanks, that looks better now!
Thomas
Re: [kvm-unit-tests PATCH v8 6/6] s390x: SCLP unit test
In reply to David HildenbrandQuoted 5 lines · David Hildenbrand
Quoted 4 lines · Thomas Huth
Quoted 3 lines · David Hildenbrand
Quoted 2 lines · Thomas Huth
Quoted 1 line · David Hildenbrand
On 22.01.20 11:10, David Hildenbrand wrote:
[...]
Quoted 42 lines
Quoted 42 lines
Quoted 36 lines
Quoted 27 lines
Quoted 27 lines
Quoted 12 lines
Doing a fresh ./configure + make on RHEL7 gives me
[linux1@rhkvm01 kvm-unit-tests]$ make
gcc -std=gnu99 -ffreestanding -I/home/linux1/git/kvm-unit-tests/lib-I/home/linux1/git/kvm-unit-tests/lib/s390x-I lib -O2 -march=zEC12 -fno-delete-null-pointer-checks -g -MMD -MF s390x/.sclp.d -Wall -Wwrite-strings -Wempty-body -Wuninitialized -Wignored-qualifiers -Werror -fomit-frame-pointer -Wno-frame-address -fno-pic -Wclobbered -Wunused-but-set-parameter -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -Wmissing-prototypes -Wstrict-prototypes -c -os390x/sclp.os390x/sclp.cs390x/sclp.c: In function 'test_one_simple':s390x/sclp.c:121:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
((SCCBHeader *)sccb_template)->length =sccb_len;
^s390x/sclp.c: At top level:
cc1: error: unrecognized command line option "-Wno-frame-address" [-Werror]
cc1: all warnings being treated as errors
make: *** [s390x/sclp.o] Error 1The following makes it work:
s390x/sclp.c +2
-0@@ -117,8 +117,10 @@ static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_tstatic bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) { +SCCBHeader *header = (void *)sccb_template; +memset (sccb_template,0 ,sizeof (sccb_template));Quoted 8 lines
s390x/sclp.c static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_t · line 123
Quoted 2 lines
s390x/sclp.c +1
-1- ((SCCBHeader *)sccb_template)->length = sccb_len; + header->length = sccb_len;While that might silence the compiler warning, we still might get aliasing problems here, I think.
The right way to solve this problem is to turnsccb_templateinto a union of the various structs/arrays that you want to use and then access the fields through the union instead ("type-punning through union").Quoted 1 line
We do have the exact same thing in
lib/s390x/sclp.calready, no?Maybe we should carefully check that code, too...
Quoted 1 line
Especially, new compilers don't seem to care?
Quoted 8 lines
Quoted 6 lines
I've seen horrible bugs due to these aliasing problems in the past - without compiler warnings showing up! Certain versions of GCC assume that they can re-order code with pointers that point to types of different sizes, i.e. in the above example, I think they could assume that they could re-order the
memset()and theheader->length= ... line. I'd feel better if we play safe and use a union here.Should we simply allow type-punning?
Maybe yes. The kernel also compiles with "-fno-strict-aliasing", and since kvm-unit-tests is mainly a "playground" for people who do kernel development, too, we should maybe also compile the unit tests with "-fno-strict-aliasing".
Paolo, Andrew, Laurent, what do you think?
Thomas
strict aliasing in kvm-unit-tests (was: Re: [kvm-unit-tests PATCH v8 6/6] s390x: SCLP unit test)
Quoted 56 lines · Thomas Huth
Quoted 5 lines · David Hildenbrand
Quoted 4 lines · Thomas Huth
Quoted 3 lines · David Hildenbrand
Quoted 2 lines · Thomas Huth
Quoted 1 line · David Hildenbrand
On 22.01.20 11:10, David Hildenbrand wrote:
[...]
Quoted 49 lines
Quoted 48 lines
Quoted 36 lines
Quoted 27 lines
Quoted 27 lines
Quoted 12 lines
Doing a fresh ./configure + make on RHEL7 gives me
[linux1@rhkvm01 kvm-unit-tests]$ make
gcc -std=gnu99 -ffreestanding -I/home/linux1/git/kvm-unit-tests/lib-I/home/linux1/git/kvm-unit-tests/lib/s390x-I lib -O2 -march=zEC12 -fno-delete-null-pointer-checks -g -MMD -MF s390x/.sclp.d -Wall -Wwrite-strings -Wempty-body -Wuninitialized -Wignored-qualifiers -Werror -fomit-frame-pointer -Wno-frame-address -fno-pic -Wclobbered -Wunused-but-set-parameter -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -Wmissing-prototypes -Wstrict-prototypes -c -os390x/sclp.os390x/sclp.cs390x/sclp.c: In function 'test_one_simple':s390x/sclp.c:121:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
((SCCBHeader *)sccb_template)->length =sccb_len;
^s390x/sclp.c: At top level:
cc1: error: unrecognized command line option "-Wno-frame-address" [-Werror]
cc1: all warnings being treated as errors
make: *** [s390x/sclp.o] Error 1The following makes it work:
s390x/sclp.c +2
-0@@ -117,8 +117,10 @@ static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_tstatic bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) { +SCCBHeader *header = (void *)sccb_template; +memset (sccb_template,0 ,sizeof (sccb_template));Quoted 8 lines
s390x/sclp.c static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_t · line 123
Quoted 2 lines
s390x/sclp.c +1
-1- ((SCCBHeader *)sccb_template)->length = sccb_len; + header->length = sccb_len;While that might silence the compiler warning, we still might get aliasing problems here, I think.
The right way to solve this problem is to turnsccb_templateinto a union of the various structs/arrays that you want to use and then access the fields through the union instead ("type-punning through union").Quoted 1 line
We do have the exact same thing in
lib/s390x/sclp.calready, no?Maybe we should carefully check that code, too...
Quoted 1 line
Especially, new compilers don't seem to care?
I've seen horrible bugs due to these aliasing problems in the past - without compiler warnings showing up! Certain versions of GCC assume that they can re-order code with pointers that point to types of different sizes, i.e. in the above example, I think they could assume that they could re-order the
memset()and theheader->length= ... line. I'd feel better if we play safe and use a union here.
Quoted 8 lines
Quoted 1 line
Should we simply allow type-punning?
Maybe yes. The kernel also compiles with "-fno-strict-aliasing", and since kvm-unit-tests is mainly a "playground" for people who do kernel development, too, we should maybe also compile the unit tests with "-fno-strict-aliasing".
Paolo, Andrew, Laurent, what do you think?
By the way, when compiling the x86 code with -O2 instead of -O1, I also get:
lib/x86/intel-iommu.c: In function ‘vtd_setup_msi’:lib/x86/intel-iommu.c:324:4: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
*(uint64_t *)&msi_addr, *(uint32_t *)&msi_data);
^~~~~~~~~~~~~~~~~~~~~
lib/x86/intel-iommu.c:324:28: error: dereferencing type-punned pointer
will break strict-aliasing rules [-Werror=strict-aliasing]
*(uint64_t *)&msi_addr, *(uint32_t *)&msi_data);
^~~~~~~~~~~~~~~~~~~~~
lib/x86/intel-iommu.c:326:29: error: dereferencing type-punned pointer
will break strict-aliasing rules [-Werror=strict-aliasing]
return pci_setup_msi(dev, *(uint64_t *)&msi_addr,
^~~~~~~~~~~~~~~~~~~~~
lib/x86/intel-iommu.c:327:10: error: dereferencing type-punned pointer
will break strict-aliasing rules [-Werror=strict-aliasing]
*(uint32_t *)&msi_data);
^~~~~~~~~~~~~~~~~~~~~cc1: all warnings being treated as errors
... so maybe -fno-strict-aliasing would be a good idea for that, too?
Thomas
Paolo Bonzini
maintainerRe: strict aliasing in kvm-unit-tests (was: Re: [kvm-unit-tests PATCH v8 6/6] s390x: SCLP unit test)
Quoted 57 lines · Thomas Huth
Quoted 56 lines · Thomas Huth
Quoted 5 lines · David Hildenbrand
Quoted 4 lines · Thomas Huth
Quoted 3 lines · David Hildenbrand
Quoted 2 lines · Thomas Huth
Quoted 1 line · David Hildenbrand
On 22.01.20 11:10, David Hildenbrand wrote:
[...]
Quoted 49 lines
Quoted 48 lines
Quoted 36 lines
Quoted 27 lines
Quoted 27 lines
Quoted 12 lines
Doing a fresh ./configure + make on RHEL7 gives me
[linux1@rhkvm01 kvm-unit-tests]$ make
gcc -std=gnu99 -ffreestanding -I/home/linux1/git/kvm-unit-tests/lib-I/home/linux1/git/kvm-unit-tests/lib/s390x-I lib -O2 -march=zEC12 -fno-delete-null-pointer-checks -g -MMD -MF s390x/.sclp.d -Wall -Wwrite-strings -Wempty-body -Wuninitialized -Wignored-qualifiers -Werror -fomit-frame-pointer -Wno-frame-address -fno-pic -Wclobbered -Wunused-but-set-parameter -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -Wmissing-prototypes -Wstrict-prototypes -c -os390x/sclp.os390x/sclp.cs390x/sclp.c: In function 'test_one_simple':s390x/sclp.c:121:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
((SCCBHeader *)sccb_template)->length =sccb_len;
^s390x/sclp.c: At top level:
cc1: error: unrecognized command line option "-Wno-frame-address" [-Werror]
cc1: all warnings being treated as errors
make: *** [s390x/sclp.o] Error 1The following makes it work:
s390x/sclp.c +2
-0@@ -117,8 +117,10 @@ static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_tstatic bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) { +SCCBHeader *header = (void *)sccb_template; +memset (sccb_template,0 ,sizeof (sccb_template));Quoted 8 lines
s390x/sclp.c static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_t · line 123
Quoted 2 lines
s390x/sclp.c +1
-1- ((SCCBHeader *)sccb_template)->length = sccb_len; + header->length = sccb_len;While that might silence the compiler warning, we still might get aliasing problems here, I think.
The right way to solve this problem is to turnsccb_templateinto a union of the various structs/arrays that you want to use and then access the fields through the union instead ("type-punning through union").Quoted 1 line
We do have the exact same thing in
lib/s390x/sclp.calready, no?Maybe we should carefully check that code, too...
Quoted 1 line
Especially, new compilers don't seem to care?
I've seen horrible bugs due to these aliasing problems in the past - without compiler warnings showing up! Certain versions of GCC assume that they can re-order code with pointers that point to types of different sizes, i.e. in the above example, I think they could assume that they could re-order the
memset()and theheader->length= ... line. I'd feel better if we play safe and use a union here.
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Should we simply allow type-punning?
Maybe yes. The kernel also compiles with "-fno-strict-aliasing", and since kvm-unit-tests is mainly a "playground" for people who do kernel development, too, we should maybe also compile the unit tests with "-fno-strict-aliasing".
Paolo, Andrew, Laurent, what do you think?
I think enabling -fno-strict-aliasing is a good idea.
Paolo
Re: strict aliasing in kvm-unit-tests (was: Re: [kvm-unit-tests PATCH v8 6/6] s390x: SCLP unit test)
Quoted 60 lines · Paolo Bonzini
Quoted 59 lines · Thomas Huth
Quoted 58 lines · Thomas Huth
Quoted 5 lines · David Hildenbrand
Quoted 4 lines · Thomas Huth
Quoted 3 lines · David Hildenbrand
Quoted 2 lines · Thomas Huth
Quoted 1 line · David Hildenbrand
On 22.01.20 11:10, David Hildenbrand wrote:
[...]
Quoted 50 lines
Quoted 40 lines
Quoted 36 lines
Quoted 27 lines
Quoted 27 lines
Quoted 12 lines
Doing a fresh ./configure + make on RHEL7 gives me
[linux1@rhkvm01 kvm-unit-tests]$ make
gcc -std=gnu99 -ffreestanding -I/home/linux1/git/kvm-unit-tests/lib-I/home/linux1/git/kvm-unit-tests/lib/s390x-I lib -O2 -march=zEC12 -fno-delete-null-pointer-checks -g -MMD -MF s390x/.sclp.d -Wall -Wwrite-strings -Wempty-body -Wuninitialized -Wignored-qualifiers -Werror -fomit-frame-pointer -Wno-frame-address -fno-pic -Wclobbered -Wunused-but-set-parameter -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -Wmissing-prototypes -Wstrict-prototypes -c -os390x/sclp.os390x/sclp.cs390x/sclp.c: In function 'test_one_simple':s390x/sclp.c:121:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
((SCCBHeader *)sccb_template)->length =sccb_len;
^s390x/sclp.c: At top level:
cc1: error: unrecognized command line option "-Wno-frame-address" [-Werror]
cc1: all warnings being treated as errors
make: *** [s390x/sclp.o] Error 1The following makes it work:
s390x/sclp.c +2
-0@@ -117,8 +117,10 @@ static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_tstatic bool test_one_simple (uint32_t cmd,uint8_t *addr,uint16_t sccb_len,uint16_t buf_len,uint64_t exp_pgm,uint16_t exp_rc) { +SCCBHeader *header = (void *)sccb_template; +memset (sccb_template,0 ,sizeof (sccb_template));Quoted 8 lines
s390x/sclp.c static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_t · line 123
Quoted 2 lines
s390x/sclp.c +1
-1- ((SCCBHeader *)sccb_template)->length = sccb_len; + header->length = sccb_len;While that might silence the compiler warning, we still might get aliasing problems here, I think.
The right way to solve this problem is to turnsccb_templateinto a union of the various structs/arrays that you want to use and then access the fields through the union instead ("type-punning through union").Quoted 1 line
We do have the exact same thing in
lib/s390x/sclp.calready, no?Maybe we should carefully check that code, too...
Quoted 8 lines
Quoted 1 line
Especially, new compilers don't seem to care?
I've seen horrible bugs due to these aliasing problems in the past - without compiler warnings showing up! Certain versions of GCC assume that they can re-order code with pointers that point to types of different sizes, i.e. in the above example, I think they could assume that they could re-order the
memset()and theheader->length= ... line. I'd feel better if we play safe and use a union here.Should we simply allow type-punning?
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Maybe yes. The kernel also compiles with "-fno-strict-aliasing", and since kvm-unit-tests is mainly a "playground" for people who do kernel development, too, we should maybe also compile the unit tests with "-fno-strict-aliasing".
Paolo, Andrew, Laurent, what do you think?
I think enabling -fno-strict-aliasing is a good idea.
I agree too
Laurent
Quoted 64 lines · Claudio Imbrenda
This patchset contains some minor cleanup, some preparatory work and then the SCLP unit test itself.
The unit test checks the following:
* Correctly ignoring instruction bits that should be ignored
* Privileged instruction check
* Check for addressing exceptions
* Specification exceptions:
- SCCB size less than 8
- SCCB unaligned
- SCCB overlaps prefix or lowcore
- SCCB address higher than 2GB
* Return codes for
- Invalid command
- SCCB too short (but at least 8)
- SCCB page boundary violationv7 -> v8
* fixed existing stfl asm wrapper
* now using stfl asm wrapper inintercept.c
* patched the program interrupt handler to clear thesclp_busybit
* removed now unnecessaryexpect_pgm_intfrom the unit test v6 -> v7
* renamedspx()andstpx()wrappers toset_prefixandget_prefix
*set_prefixnow takes a value andget_prefixnow returns a value
* put back some inline assembly for spx and stpx as a consequence
* usedLC_SIZEinstead of 2 *PAGE_SIZEeverywhere in the unit test v5 -> v6
* fixed a bug intest_addressing
* improved comments intest_sccb_prefix
* replaced all inline assembly usages of spx and stpx with the wrappers
* added one more wrapper fortest_one_sccbfor read-only tests v4 -> v5
* updated usage ofreport()
* added SPX and STPX wrappers to the library
* improved readability
* addressed some more comments
v3 -> v4
* exportsclp_setup_intinstead of copying it
* add more comments
* rename some more variables to improve readability
* improve the prefix test
* improved the invalid address test
* addressed further comments received during review
v2 -> v3
* generally improved the naming of variables
* added and fixed comments
* renamedtest_one_runtotest_one_simple
* added some const where needed
* addresed many more small comments received during review v1 -> v2
* fix many small issues that came up during the first round of reviews
* add comments to each function
* use a static buffer for the SCCP template when usedClaudio Imbrenda (6):
s390x: exportsclp_setup_int
s390x: sclp: add service call instruction wrapper
s390x: lib: fix stfl wrapper asm
s390x: lib: add SPX and STPX instruction wrapper
s390x: lib: fix program interrupt handler ifsclp_busywas set
s390x: SCLP unit test
Quoted 12 lines
s390x/Makefile | 1 + lib/s390x/asm/arch_def.h | 26 +++ lib/s390x/asm/facility.h | 2 +- lib/s390x/sclp.h | 1 + lib/s390x/interrupt.c | 5 +- lib/s390x/sclp.c | 9 +- s390x/intercept.c | 24 +- s390x/sclp.c | 474 +++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 8 + 9 files changed, 526 insertions(+), 24 deletions(-) create mode 100644 s390x/sclp.c
Queued to
https://github.com/davidhildenbrand/qemu.git s390-tcg-next
Thanks!
Signature · 3 lines
Thanks, David / dhildenb
Quoted 78 lines · David Hildenbrand
Quoted 64 lines · Claudio Imbrenda
This patchset contains some minor cleanup, some preparatory work and then the SCLP unit test itself.
The unit test checks the following:
* Correctly ignoring instruction bits that should be ignored
* Privileged instruction check
* Check for addressing exceptions
* Specification exceptions:
- SCCB size less than 8
- SCCB unaligned
- SCCB overlaps prefix or lowcore
- SCCB address higher than 2GB
* Return codes for
- Invalid command
- SCCB too short (but at least 8)
- SCCB page boundary violationv7 -> v8
* fixed existing stfl asm wrapper
* now using stfl asm wrapper inintercept.c
* patched the program interrupt handler to clear thesclp_busybit
* removed now unnecessaryexpect_pgm_intfrom the unit test v6 -> v7
* renamedspx()andstpx()wrappers toset_prefixandget_prefix
*set_prefixnow takes a value andget_prefixnow returns a value
* put back some inline assembly for spx and stpx as a consequence
* usedLC_SIZEinstead of 2 *PAGE_SIZEeverywhere in the unit test v5 -> v6
* fixed a bug intest_addressing
* improved comments intest_sccb_prefix
* replaced all inline assembly usages of spx and stpx with the wrappers
* added one more wrapper fortest_one_sccbfor read-only tests v4 -> v5
* updated usage ofreport()
* added SPX and STPX wrappers to the library
* improved readability
* addressed some more comments
v3 -> v4
* exportsclp_setup_intinstead of copying it
* add more comments
* rename some more variables to improve readability
* improve the prefix test
* improved the invalid address test
* addressed further comments received during review
v2 -> v3
* generally improved the naming of variables
* added and fixed comments
* renamedtest_one_runtotest_one_simple
* added some const where needed
* addresed many more small comments received during review v1 -> v2
* fix many small issues that came up during the first round of reviews
* add comments to each function
* use a static buffer for the SCCP template when usedClaudio Imbrenda (6):
s390x: exportsclp_setup_int
s390x: sclp: add service call instruction wrapper
s390x: lib: fix stfl wrapper asm
s390x: lib: add SPX and STPX instruction wrapper
s390x: lib: fix program interrupt handler ifsclp_busywas set
s390x: SCLP unit testQuoted 12 lines
s390x/Makefile | 1 + lib/s390x/asm/arch_def.h | 26 +++ lib/s390x/asm/facility.h | 2 +- lib/s390x/sclp.h | 1 + lib/s390x/interrupt.c | 5 +- lib/s390x/sclp.c | 9 +- s390x/intercept.c | 24 +- s390x/sclp.c | 474 +++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 8 + 9 files changed, 526 insertions(+), 24 deletions(-) create mode 100644 s390x/sclp.c
Quoted 3 lines
Queued to
https://github.com/davidhildenbrand/qemu.git s390-tcg-next
Lol, wrong shortcut (thanks Thomas :) )
Queued to
https://github.com/davidhildenbrand/kvm-unit-tests.git s390x-next
Signature · 3 lines
Thanks, David / dhildenb