target/s390x: Miscellaneous TCG fixes
cover target/s390x: Miscellaneous TCG fixes
Hi,
Randomized testing found a number of issues in the s390x emulation. This series fixes 6 of them (patches 2-7) and adds tests (patches 8-12); patch 1 is a cosmetic improvement needed for the EPSW test.
There are more issues, but I thought it would be better to send this batch now.
Best regards,
Ilya
Ilya Leoshkevich (12):
linux-user: elfload: Add more initial s390x PSW bits target/s390x: Fix EPSW CC reporting
target/s390x: Fix MDEB and MDEBR
target/s390x: Fix MVCRL with a large value in R0 target/s390x: Fix LRA overwriting the top 32 bits on DAT error target/s390x: Fix LRA when DAT is off
target/s390x: Fix relative long instructions with large offsets tests/tcg/s390x: Test EPSW
tests/tcg/s390x: Test LARL with a large offset tests/tcg/s390x: Test LRA
tests/tcg/s390x: Test MDEB and MDEBR
tests/tcg/s390x: Test MVCRL with a large value in R0
linux-user/elfload.c | 4 ++- target/s390x/helper.h | 2 +- target/s390x/mmu_helper.c | 2 +- target/s390x/tcg/fpu_helper.c | 3 +- target/s390x/tcg/insn-data.h.inc | 4 +-- target/s390x/tcg/mem_helper.c | 5 +-- target/s390x/tcg/translate.c | 8 +++-- tests/tcg/s390x/Makefile.softmmu-target | 1 + tests/tcg/s390x/Makefile.target | 3 ++ tests/tcg/s390x/epsw.c | 23 +++++++++++++ tests/tcg/s390x/larl.c | 17 +++++++++ tests/tcg/s390x/lra.S | 19 ++++++++++ tests/tcg/s390x/mdeb.c | 30 ++++++++++++++++ tests/tcg/s390x/mie3-mvcrl.c | 46 +++++++++++++++++++------ 14 files changed, 147 insertions(+), 20 deletions(-) create mode 100644 tests/tcg/s390x/epsw.c create mode 100644 tests/tcg/s390x/larl.c create mode 100644 tests/tcg/s390x/lra.S create mode 100644 tests/tcg/s390x/mdeb.c
Signature · 1 line
2.41.0
PATCH 1/12 linux-user: elfload: Add more initial s390x PSW bits
Make the PSW look more similar to the real s390x userspace PSW. Except for being there, the newly added bits should not affect the userspace code execution.
--- linux-user/elfload.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
linux-user/elfload.c +3 -1
@@ -1635,7 +1635,9 @@ const char *elf_hwcap_str(uint32_t bit)static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) { regs->psw.addr = infop->entry; - regs->psw.mask =PSW_MASK_64 |PSW_MASK_32 ; + regs->psw.mask =PSW_MASK_DAT |PSW_MASK_IO |PSW_MASK_EXT | \ +PSW_MASK_MCHECK |PSW_MASK_PSTATE |PSW_MASK_64 | \ +PSW_MASK_32 ; regs->gprs[15 ] = infop->start_stack; }
Signature · 1 line
2.41.0
Re: [PATCH 01/12] linux-user: elfload: Add more initial s390x PSW bits
Quoted 3 lines · Ilya Leoshkevich
Make the PSW look more similar to the real s390x userspace PSW. Except for being there, the newly added bits should not affect the userspace code execution.
What's the purpose of this then? Required for follow-up patches?
Quoted 21 lines
Signed-off-by Ilya Leoshkevich <[email protected]>--- linux-user/elfload.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)linux-user/elfload.c +3
-1@@ -1635,7 +1635,9 @@ const char *elf_hwcap_str(uint32_t bit)static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) { regs->psw.addr = infop->entry; - regs->psw.mask =PSW_MASK_64 |PSW_MASK_32 ; + regs->psw.mask =PSW_MASK_DAT |PSW_MASK_IO |PSW_MASK_EXT | \ +PSW_MASK_MCHECK |PSW_MASK_PSTATE |PSW_MASK_64 | \ +PSW_MASK_32 ; regs->gprs[15 ] = infop->start_stack; }
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 01/12] linux-user: elfload: Add more initial s390x PSW bits
Quoted 6 lines · David Hildenbrand
Quoted 3 lines · Ilya Leoshkevich
Make the PSW look more similar to the real s390x userspace PSW. Except for being there, the newly added bits should not affect the userspace code execution.
What's the purpose of this then? Required for follow-up patches?
That's required for the EPSW test.
I could, of course, mask out the bits that are not emulated in the test, but I thought it was better to make the emulation closer to reality, if only for cosmetic purposes.
[...]
David Hildenbrand
Reviewed-byRe: [PATCH 01/12] linux-user: elfload: Add more initial s390x PSW bits
Quoted 6 lines · Ilya Leoshkevich
Quoted 5 lines · David Hildenbrand
Quoted 3 lines · Ilya Leoshkevich
Make the PSW look more similar to the real s390x userspace PSW. Except for being there, the newly added bits should not affect the userspace code execution.
Quoted 6 lines
Quoted 1 line
What's the purpose of this then? Required for follow-up patches?
That's required for the EPSW test.
I could, of course, mask out the bits that are not emulated in the test, but I thought it was better to make the emulation closer to reality, if only for cosmetic purposes.
Thanks
Signature · 3 lines
Cheers, David / dhildenb
PATCH 2/12 target/s390x: Fix EPSW CC reporting
In reply to Ilya LeoshkevichEPSW should explicitly calculate and insert CC, like IPM does.
--- target/s390x/tcg/translate.c | 4 ++++ 1 file changed, 4 insertions(+)
target/s390x/tcg/translate.c +4 -0
@@ -2383,10 +2383,14 @@ static DisasJumpType op_epsw(DisasContext *s, DisasOps *o)int r1 =get_field (s, r1);int r2 =get_field (s, r2);TCGv_i64 t =tcg_temp_new_i64 (); +TCGv_i64 t_cc =tcg_temp_new_i64 ();/* Note the "subsequently" in the PoO, which implies a defined result if r1 == r2. Thus we cannot defer these writes to an output hook. */ +gen_op_calc_cc (s); +tcg_gen_extu_i32_i64 (t_cc, cc_op);tcg_gen_shri_i64 (t, psw_mask,32 ); +tcg_gen_deposit_i64 (t, t, t_cc,12 ,2 );store_reg32_i64 (r1, t);if (r2 !=0 ) {store_reg32_i64 (r2, psw_mask);
Signature · 1 line
2.41.0
Re: [PATCH 02/12] target/s390x: Fix EPSW CC reporting
Quoted 6 lines · Ilya Leoshkevich
EPSW should explicitly calculate and insert CC, like IPM does.
Fixes e30a9d3fea58 ("target-s390: Implement EPSW")Signed-off-by Ilya Leoshkevich <[email protected]>---
Signature · 3 lines
Cheers, David / dhildenb
PATCH 3/12 target/s390x: Fix MDEB and MDEBR
In reply to Ilya LeoshkevichThese instructions multiply 32 bits by 32 bits, not 32 bits by 64 bits.
--- target/s390x/tcg/fpu_helper.c | 3 ++- target/s390x/tcg/insn-data.h.inc | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-)
target/s390x/tcg/fpu_helper.c +2 -1
@@ -306,8 +306,9 @@ uint64_t HELPER(mdb)(CPUS390XState *env, uint64_t f1, uint64_t f2)/* 64/32-bit FP multiplication */ uint64_t HELPER (mdeb )(CPUS390XState *env,uint64_t f1,uint64_t f2) { +float64 f1_64 =float32_to_float64 (f1, &env->fpu_status);float64 ret =float32_to_float64 (f2, &env->fpu_status); - ret =float64_mul (f1, ret, &env->fpu_status); + ret =float64_mul (f1_64, ret, &env->fpu_status);handle_exceptions (env, false,GETPC ());return ret; }
target/s390x/tcg/insn-data.h.inc +2 -2
@@ -667,11 +667,11 @@ F(0xb317, MEEBR, RRE, Z, e1, e2, new, e1, meeb, 0, IF_BFP) F(0xb31c, MDBR, RRE, Z, f1, f2, new, f1, mdb, 0, IF_BFP) F(0xb34c, MXBR, RRE, Z, x1, x2, new_x, x1, mxb, 0, IF_BFP) - F(0xb30c, MDEBR, RRE, Z, f1, e2, new, f1, mdeb, 0, IF_BFP) + F(0xb30c, MDEBR, RRE, Z, e1, e2, new, f1, mdeb, 0, IF_BFP) F(0xb307, MXDBR, RRE, Z, f1, f2, new_x, x1, mxdb, 0, IF_BFP) F(0xed17, MEEB, RXE, Z, e1, m2_32u, new, e1, meeb, 0, IF_BFP) F(0xed1c, MDB, RXE, Z, f1, m2_64, new, f1, mdb, 0, IF_BFP) - F(0xed0c, MDEB, RXE, Z, f1, m2_32u, new, f1, mdeb, 0, IF_BFP) + F(0xed0c, MDEB, RXE, Z, e1, m2_32u, new, f1, mdeb, 0, IF_BFP) F(0xed07, MXDB, RXE, Z, f1, m2_64, new_x, x1, mxdb, 0, IF_BFP) /* MULTIPLY HALFWORD */ C(0x4c00, MH, RX_a, Z, r1_o, m2_16s, new, r1_32, mul, 0)
Signature · 1 line
2.41.0
Re: [PATCH 03/12] target/s390x: Fix MDEB and MDEBR
Quoted 6 lines · Ilya Leoshkevich
These instructions multiply 32 bits by 32 bits, not 32 bits by 64 bits.
Fixes 83b00736f3d8 ("target-s390: Convert FP MULTIPLY")Signed-off-by Ilya Leoshkevich <[email protected]>---
Signature · 3 lines
Cheers, David / dhildenb
PATCH 4/12 target/s390x: Fix MVCRL with a large value in R0
In reply to Ilya LeoshkevichUsing a large R0 causes an assertion error:
qemu-s390x: target/s390x/tcg/mem_helper.c:183: access_prepare_nf: Assertion `size > 0 && size <= 4096' failed.
Even though PoP explicitly advises against using more than 8 bits for the size, an emulator crash is never a good thing.
Fix by truncating the size to 8 bits.
--- target/s390x/tcg/mem_helper.c | 1 + 1 file changed, 1 insertion(+)
target/s390x/tcg/mem_helper.c +1 -0
@@ -514,6 +514,7 @@ void HELPER(mvcrl)(CPUS390XState *env, uint64_t l, uint64_t dest, uint64_t src)int32_t i;/* MVCRL always copies one more byte than specified - maximum is 256 */ + l &=0xff ; l++;access_prepare (&srca, env, src, l,MMU_DATA_LOAD , mmu_idx, ra);
Signature · 1 line
2.41.0
Re: [PATCH 04/12] target/s390x: Fix MVCRL with a large value in R0
Quoted 4 lines · Ilya Leoshkevich
Using a large R0 causes an assertion error:
qemu-s390x: target/s390x/tcg/mem_helper.c:183: access_prepare_nf: Assertion `size > 0 && size <= 4096' failed.
Quoted 8 lines
Even though PoP explicitly advises against using more than 8 bits for the size, an emulator crash is never a good thing.
Fix by truncating the size to 8 bits.
Fixes ea0a1053e276 ("s390x/tcg: Implement Miscellaneous-Instruction-Extensions Facility 3 for the s390x")Signed-off-by Ilya Leoshkevich <[email protected]>
Signature · 3 lines
Cheers, David / dhildenb
PATCH 5/12 target/s390x: Fix LRA overwriting the top 32 bits on DAT error
In reply to Ilya LeoshkevichWhen a DAT error occurs, LRA is supposed to write the error information to the bottom 32 bits of R1, and leave the top 32 bits of R1 alone.
Fix by passing the original value of R1 into helper and copying the top 32 bits to the return value.
--- target/s390x/helper.h | 2 +- target/s390x/tcg/mem_helper.c | 4 ++-- target/s390x/tcg/translate.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
target/s390x/helper.h +1 -1
@@ -355,7 +355,7 @@ DEF_HELPER_FLAGS_4(idte, TCG_CALL_NO_RWG, void, env, i64, i64, i32) DEF_HELPER_FLAGS_4(ipte, TCG_CALL_NO_RWG, void, env, i64, i64, i32) DEF_HELPER_FLAGS_1(ptlb, TCG_CALL_NO_RWG, void, env) DEF_HELPER_FLAGS_1(purge, TCG_CALL_NO_RWG, void, env) -DEF_HELPER_2(lra, i64, env, i64) +DEF_HELPER_3(lra, i64, env, i64, i64) DEF_HELPER_1(per_check_exception, void, env) DEF_HELPER_FLAGS_3(per_branch, TCG_CALL_NO_RWG, void, env, i64, i64)DEF_HELPER_FLAGS_2 (per_ifetch,TCG_CALL_NO_RWG , void, env, i64)
target/s390x/tcg/mem_helper.c +2 -2
@@ -2356,7 +2356,7 @@ void HELPER(purge)(CPUS390XState *env) }/* load real address */ -uint64_t HELPER (lra )(CPUS390XState *env,uint64_t addr) +uint64_t HELPER (lra )(CPUS390XState *env,uint64_t r1,uint64_t addr) {uint64_t asc = env->psw.mask &PSW_MASK_ASC ;uint64_t ret, tec;
@@ -2370,7 +2370,7 @@ uint64_t HELPER(lra)(CPUS390XState *env, uint64_t addr) exc =mmu_translate (env, addr,MMU_S390_LRA , asc, &ret, &flags, &tec);if (exc) { cc =3 ; - ret = exc |0x80000000 ; + ret = (r1 &0xFFFFFFFF00000000 ) | exc |0x80000000 ; }else { cc =0 ; ret |= addr & ~TARGET_PAGE_MASK ;
target/s390x/tcg/translate.c +1 -1
@@ -2932,7 +2932,7 @@ static DisasJumpType op_lctlg(DisasContext *s, DisasOps *o)static DisasJumpType op_lra (DisasContext *s,DisasOps *o) { -gen_helper_lra (o->out, cpu_env, o->in2); +gen_helper_lra (o->out, cpu_env, o->out, o->in2);set_cc_static (s);return DISAS_NEXT ; }
Signature · 1 line
2.41.0
Re: [PATCH 05/12] target/s390x: Fix LRA overwriting the top 32 bits on DAT error
Quoted 42 lines · Ilya Leoshkevich
When a DAT error occurs, LRA is supposed to write the error information to the bottom 32 bits of R1, and leave the top 32 bits of R1 alone.
Fix by passing the original value of R1 into helper and copying the top 32 bits to the return value.
Fixes d8fe4a9c284f ("target-s390: Convert LRA")Signed-off-by Ilya Leoshkevich <[email protected]>--- target/s390x/helper.h | 2 +- target/s390x/tcg/mem_helper.c | 4 ++-- target/s390x/tcg/translate.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)target/s390x/helper.h +1
-1@@ -355,7 +355,7 @@ DEF_HELPER_FLAGS_4(idte, TCG_CALL_NO_RWG, void, env, i64, i64, i32) DEF_HELPER_FLAGS_4(ipte, TCG_CALL_NO_RWG, void, env, i64, i64, i32) DEF_HELPER_FLAGS_1(ptlb, TCG_CALL_NO_RWG, void, env) DEF_HELPER_FLAGS_1(purge, TCG_CALL_NO_RWG, void, env) -DEF_HELPER_2(lra, i64, env, i64) +DEF_HELPER_3(lra, i64, env, i64, i64) DEF_HELPER_1(per_check_exception, void, env) DEF_HELPER_FLAGS_3(per_branch, TCG_CALL_NO_RWG, void, env, i64, i64)DEF_HELPER_FLAGS_2 (per_ifetch,TCG_CALL_NO_RWG , void, env, i64)target/s390x/tcg/mem_helper.c +1
-1@@ -2356,7 +2356,7 @@ void HELPER(purge)(CPUS390XState *env) }/* load real address */ -uint64_t HELPER (lra )(CPUS390XState *env,uint64_t addr) +uint64_t HELPER (lra )(CPUS390XState *env,uint64_t r1,uint64_t addr) {uint64_t asc = env->psw.mask &PSW_MASK_ASC ;uint64_t ret, tec;
target/s390x/tcg/mem_helper.c uint64_t HELPER(lra)(CPUS390XState *env, uint64_t addr) · line 2373
Quoted 5 lines
target/s390x/tcg/mem_helper.c +1
-1@@ -2370,7 +2370,7 @@ uint64_t HELPER(lra)(CPUS390XState *env, uint64_t addr) exc =mmu_translate (env, addr,MMU_S390_LRA , asc, &ret, &flags, &tec);if (exc) { cc =3 ; - ret = exc |0x80000000 ; + ret = (r1 &0xFFFFFFFF00000000 ) | exc |0x80000000 ;
ull missing for large constant?
Quoted 8 lines
target/s390x/tcg/mem_helper.c +0
-0}else { cc =0 ; ret |= addr & ~TARGET_PAGE_MASK ;target/s390x/tcg/translate.c +0
-0
target/s390x/tcg/translate.c static DisasJumpType op_lctlg(DisasContext *s, DisasOps *o) · line 2938
Quoted 8 lines
target/s390x/tcg/translate.c +1
-1@@ -2932,7 +2932,7 @@ static DisasJumpType op_lctlg(DisasContext *s, DisasOps *o)static DisasJumpType op_lra (DisasContext *s,DisasOps *o) { -gen_helper_lra (o->out, cpu_env, o->in2); +gen_helper_lra (o->out, cpu_env, o->out, o->in2);set_cc_static (s);return DISAS_NEXT ; }
Can't we use something like in1_r1 + wout_r1_32 instead ? *maybe* cleaner :)
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 05/12] target/s390x: Fix LRA overwriting the top 32 bits on DAT error
Quoted 50 lines · David Hildenbrand
Quoted 49 lines · Ilya Leoshkevich
When a DAT error occurs, LRA is supposed to write the error information
to the bottom 32 bits of R1, and leave the top 32 bits of R1 alone.Fix by passing the original value of R1 into helper and copying the top 32 bits to the return value.
Fixes d8fe4a9c284f ("target-s390: Convert LRA")Signed-off-by Ilya Leoshkevich <[email protected]>---
target/s390x/helper.h | 2 +-
target/s390x/tcg/mem_helper.c| 4 ++--
target/s390x/tcg/translate.c | 2 +-3 files changed, 4 insertions(+), 4 deletions(-)target/s390x/helper.h +1
-1@@ -355,7 +355,7 @@ DEF_HELPER_FLAGS_4(idte, TCG_CALL_NO_RWG, void, env, i64, i64, i32) DEF_HELPER_FLAGS_4(ipte, TCG_CALL_NO_RWG, void, env, i64, i64, i32) DEF_HELPER_FLAGS_1(ptlb, TCG_CALL_NO_RWG, void, env) DEF_HELPER_FLAGS_1(purge, TCG_CALL_NO_RWG, void, env) -DEF_HELPER_2(lra, i64, env, i64) +DEF_HELPER_3(lra, i64, env, i64, i64) DEF_HELPER_1(per_check_exception, void, env)
DEF_HELPER_FLAGS_3(per_branch, TCG_CALL_NO_RWG, void, env, i64, i64)
DEF_HELPER_FLAGS_2(per_ifetch, TCG_CALL_NO_RWG, void, env, i64)target/s390x/tcg/mem_helper.c +0
-0@@ -2356,7 +2356,7 @@ void HELPER(purge)(CPUS390XState *env) }
/* load real address */target/s390x/tcg/mem_helper.c +1
-1-uint64_t HELPER (lra )(CPUS390XState *env,uint64_t addr) +uint64_t HELPER(lra)(CPUS390XState *env, uint64_t r1, uint64_taddr)
{
uint64_tasc =env->psw.mask&PSW_MASK_ASC;uint64_tret, tec;target/s390x/tcg/mem_helper.c +0
-0@@ -2370,7 +2370,7 @@ uint64_t HELPER(lra)(CPUS390XState *env, uint64_t addr)
Quoted 8 lines
target/s390x/tcg/mem_helper.c uint64_t HELPER(lra)(CPUS390XState *env, uint64_t addr) · line 2373
Quoted 6 lines
target/s390x/tcg/mem_helper.c +1
-1exc = mmu_translate(env, addr, MMU_S390_LRA, asc, &ret, &flags, &tec); if (exc) { cc = 3; - ret = exc | 0x80000000; + ret = (r1 & 0xFFFFFFFF00000000) | exc | 0x80000000;ull missing for large constant?
Will do.
Just for my understanding, why is this necessary?
The current code base tends towards using ULL, but it's a little bit inconsistent:
$ git grep -i 0xfffffffff | wc -l 2338 $ git grep -i 0xfffffffff | grep -i -v ul | wc -l 95
Quoted 14 lines
Quoted 14 lines
target/s390x/tcg/mem_helper.c +0
-0} else {cc = 0;
ret |= addr & ~TARGET_PAGE_MASK;target/s390x/tcg/translate.c +0
-0@@ -2932,7 +2932,7 @@ static DisasJumpType op_lctlg(DisasContext *s, DisasOps *o)
static DisasJumpTypeop_lra(DisasContext *s, DisasOps *o){
Quoted 9 lines
Quoted 5 lines
-
gen_helper_lra(o->out, cpu_env, o->in2); +gen_helper_lra(o->out, cpu_env, o->out, o->in2);set_cc_static(s);
returnDISAS_NEXT;
}Can't we use something like
in1_r1+wout_r1_32instead ? *maybe* cleaner :)
The problem is that we want all 64 bits for the non-error case.
Re: [PATCH 05/12] target/s390x: Fix LRA overwriting the top 32 bits on DAT error
Quoted 7 lines · Ilya Leoshkevich
Quoted 3 lines
Quoted 1 line
+ ret = (r1 &
0xFFFFFFFF00000000) | exc |0x80000000;ull missing for large constant?
Will do.
Just for my understanding, why is this necessary?
32-bit host; you'll get a warning for the large constant.
r~
Re: [PATCH 05/12] target/s390x: Fix LRA overwriting the top 32 bits on DAT error
In reply to Ilya LeoshkevichQuoted 24 lines
Quoted 12 lines
Quoted 12 lines
} else {
cc = 0;
ret |= addr & ~TARGET_PAGE_MASK;target/s390x/tcg/translate.c +0
-0@@ -2932,7 +2932,7 @@ static DisasJumpType op_lctlg(DisasContext *s, DisasOps *o)Quoted 11 lines
Quoted 7 lines
target/s390x/tcg/translate.c +1
-1static DisasJumpType op_lra(DisasContext *s, DisasOps *o) { - gen_helper_lra(o->out, cpu_env, o->in2); + gen_helper_lra(o->out, cpu_env, o->out, o->in2); set_cc_static(s); return DISAS_NEXT;}
Can't we use something like
in1_r1+wout_r1_32instead ? *maybe* cleaner :)
Quoted 2 lines
The problem is that we want all 64 bits for the non-error case.
Ah, I missed that detail, thanks.
Signature · 3 lines
Cheers, David / dhildenb
PATCH 6/12 target/s390x: Fix LRA when DAT is off
In reply to Ilya LeoshkevichLRA should perform DAT regardless of whether it's on or off. Disable DAT check for MMU_S390_LRA.
--- target/s390x/mmu_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/mmu_helper.c +1 -1
@@ -417,7 +417,7 @@ int mmu_translate(CPUS390XState *env, target_ulong vaddr, int rw, uint64_t asc, vaddr &=TARGET_PAGE_MASK ; -if (!(env->psw.mask &PSW_MASK_DAT )) { +if (rw !=MMU_S390_LRA && !(env->psw.mask &PSW_MASK_DAT )) { *raddr = vaddr; goto nodat; }
Signature · 1 line
2.41.0
Re: [PATCH 06/12] target/s390x: Fix LRA when DAT is off
Quoted 15 lines · Ilya Leoshkevich
LRA should perform DAT regardless of whether it's on or off. Disable DAT check for
MMU_S390_LRA.Fixes defb0e3157af ("s390x: Implement opcode helpers")Signed-off-by Ilya Leoshkevich <[email protected]>--- target/s390x/mmu_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/s390x/mmu_helper.c +0
-0
target/s390x/mmu_helper.c int mmu_translate(CPUS390XState *env, target_ulong vaddr, int rw, uint64_t asc, · line 423
Quoted 8 lines
target/s390x/mmu_helper.c +1
-1@@ -417,7 +417,7 @@ int mmu_translate(CPUS390XState *env, target_ulong vaddr, int rw, uint64_t asc, vaddr &=TARGET_PAGE_MASK ; -if (!(env->psw.mask &PSW_MASK_DAT )) { +if (rw !=MMU_S390_LRA && !(env->psw.mask &PSW_MASK_DAT )) { *raddr = vaddr; goto nodat; }
Interesting
Signature · 3 lines
Cheers, David / dhildenb
PATCH 7/12 target/s390x: Fix relative long instructions with large offsets
In reply to Ilya LeoshkevichThe expression "imm * 2" in gen_ri2() can wrap around if imm is large enough.
Fix by casting imm to int64_t, like it's done in disas_jdest().
--- target/s390x/tcg/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/tcg/translate.c +1 -1
@@ -5794,7 +5794,7 @@ static TCGv gen_ri2(DisasContext *s)disas_jdest (s, i2, is_imm, imm, ri2);if (is_imm) { - ri2 =tcg_constant_i64 (s->base.pc_next + imm *2 ); + ri2 =tcg_constant_i64 (s->base.pc_next + (int64_t )imm *2 ); }return ri2;
Signature · 1 line
2.41.0
Re: [PATCH 07/12] target/s390x: Fix relative long instructions with large offsets
Quoted 16 lines · Ilya Leoshkevich
The expression "imm * 2" in
gen_ri2()can wrap around if imm is large enough.Fix by casting imm to
int64_t, like it's done indisas_jdest().Fixes e8ecdfeb30f0 ("Fix EXECUTE of relative branches")Signed-off-by Ilya Leoshkevich <[email protected]>--- target/s390x/tcg/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/s390x/tcg/translate.c +0
-0
target/s390x/tcg/translate.c static TCGv gen_ri2(DisasContext *s) · line 5800
Quoted 8 lines
target/s390x/tcg/translate.c +1
-1@@ -5794,7 +5794,7 @@ static TCGv gen_ri2(DisasContext *s)disas_jdest (s, i2, is_imm, imm, ri2);if (is_imm) { - ri2 =tcg_constant_i64 (s->base.pc_next + imm *2 ); + ri2 =tcg_constant_i64 (s->base.pc_next + (int64_t )imm *2 ); }return ri2;
Signature · 3 lines
Cheers, David / dhildenb
PATCH 8/12 tests/tcg/s390x: Test EPSW
In reply to Ilya LeoshkevichAdd a small test to prevent regressions.
--- tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/epsw.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/tcg/s390x/epsw.c
tests/tcg/s390x/Makefile.target +1 -0
@@ -36,6 +36,7 @@ TESTS+=rxsbg TESTS+=ex-relative-long TESTS+=ex-branch TESTS+=mxdb +TESTS+=epsw cdsg: CFLAGS+=-pthread cdsg: LDFLAGS+=-pthread
tests/tcg/s390x/epsw.c new file +23 -0
@@ -0,0 +1,23 @@ +/* +* Test the EPSW instruction. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#include <assert.h> +#include <stdlib.h> + +int main (void ) +{ +unsigned long r1 =0x1234567887654321UL , r2 =0x8765432112345678UL ; + + asm("cr %[r1],%[r2]\n" /* cc = 1 */ +"epsw %[r1],%[r2]" + : [r1]"+r" (r1), [r2]"+r" (r2) : :"cc" ); + +/* Do not check the R and RI bits. */ + r1 &= ~0x40000008UL ; +assert (r1 ==0x1234567807051001UL ); +assert (r2 ==0x8765432180000000UL ); + +return EXIT_SUCCESS ; +}
Signature · 1 line
2.41.0
Re: [PATCH 08/12] tests/tcg/s390x: Test EPSW
Quoted 40 lines · Ilya Leoshkevich
Add a small test to prevent regressions.
Signed-off-by Ilya Leoshkevich <[email protected]>--- tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/epsw.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+)create mode 100644
tests/tcg/s390x/epsw.ctests/tcg/s390x/Makefile.target +1
-0@@ -36,6 +36,7 @@ TESTS+=rxsbg TESTS+=ex-relative-long TESTS+=ex-branch TESTS+=mxdb +TESTS+=epsw cdsg: CFLAGS+=-pthread cdsg: LDFLAGS+=-pthreadtests/tcg/s390x/epsw.c new file +13
-0@@ -0,0 +1,23 @@ +/* +* Test the EPSW instruction. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#include <assert.h> +#include <stdlib.h> + +int main (void ) +{ +unsigned long r1 =0x1234567887654321UL , r2 =0x8765432112345678UL ; + + asm("cr %[r1],%[r2]\n" /* cc = 1 */
tests/tcg/s390x/epsw.c line 23
Quoted 10 lines
tests/tcg/s390x/epsw.c new file +10
-0+"epsw %[r1],%[r2]" + : [r1] "+r" (r1), [r2] "+r" (r2) : : "cc"); + + /* Do not check the R and RI bits. */ + r1 &= ~0x40000008UL; +assert (r1 ==0x1234567807051001UL ); +assert (r2 ==0x8765432180000000UL ); + +return EXIT_SUCCESS ; +}
Signature · 3 lines
Cheers, David / dhildenb
PATCH 9/12 tests/tcg/s390x: Test LARL with a large offset
In reply to Ilya LeoshkevichAdd a small test to prevent regressions.
--- tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/larl.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 tests/tcg/s390x/larl.c
tests/tcg/s390x/Makefile.target +1 -0
@@ -37,6 +37,7 @@ TESTS+=ex-relative-long TESTS+=ex-branch TESTS+=mxdb TESTS+=epsw +TESTS+=larl cdsg: CFLAGS+=-pthread cdsg: LDFLAGS+=-pthread
tests/tcg/s390x/larl.c new file +17 -0
@@ -0,0 +1,17 @@ +/* +* Test the LARL instruction. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#include <stdlib.h> + +int main (void ) +{ +long algfi = (long )main; +long larl; + + asm("algfi %[r],0xd0000000" : [r]"+r" (algfi) : :"cc" ); + asm("larl %[r],main+0xd0000000" : [r]"=r" (larl)); + +return algfi == larl ?EXIT_SUCCESS :EXIT_FAILURE ; +}
Signature · 1 line
2.41.0
Re: [PATCH 09/12] tests/tcg/s390x: Test LARL with a large offset
Quoted 31 lines · Ilya Leoshkevich
Add a small test to prevent regressions.
Signed-off-by Ilya Leoshkevich <[email protected]>--- tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/larl.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)create mode 100644
tests/tcg/s390x/larl.ctests/tcg/s390x/Makefile.target +1
-0@@ -37,6 +37,7 @@ TESTS+=ex-relative-long TESTS+=ex-branch TESTS+=mxdb TESTS+=epsw +TESTS+=larl cdsg: CFLAGS+=-pthread cdsg: LDFLAGS+=-pthreadtests/tcg/s390x/larl.c new file +4
-0@@ -0,0 +1,17 @@ +/* +* Test the LARL instruction. +* +* SPDX-License-Identifier: GPL-2.0-or-later
tests/tcg/s390x/larl.c line 14
Quoted 10 lines
tests/tcg/s390x/larl.c new file +10
-0+*/ +#include <stdlib.h> + +int main (void ) +{ +long algfi = (long )main; +long larl; + + asm("algfi %[r],0xd0000000" : [r]"+r" (algfi) : :"cc" ); + asm("larl %[r],main+0xd0000000" : [r]"=r" (larl));
Not sure if worth combining both statements.
tests/tcg/s390x/larl.c line 17
Quoted 3 lines
tests/tcg/s390x/larl.c new file +3
-0+ +return algfi == larl ?EXIT_SUCCESS :EXIT_FAILURE ; +}
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 09/12] tests/tcg/s390x: Test LARL with a large offset
Quoted 37 lines · David Hildenbrand
Quoted 36 lines · Ilya Leoshkevich
Add a small test to prevent regressions.
Signed-off-by Ilya Leoshkevich <[email protected]>---
tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/larl.c | 17 +++++++++++++++++2 files changed, 18 insertions(+)create mode 100644
tests/tcg/s390x/larl.ctests/tcg/s390x/Makefile.target +0
-0@@ -37,6 +37,7 @@ TESTS+=ex-relative-longTESTS+=ex-branch
TESTS+=mxdb
TESTS+=epsw
+TESTS+=larl
cdsg: CFLAGS+=-pthread
cdsg: LDFLAGS+=-pthreadtests/tcg/s390x/larl.c new file +8
-0@@ -0,0 +1,17 @@ +/* +* Test the LARL instruction. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#include <stdlib.h> + +int main (void )
Quoted 8 lines
tests/tcg/s390x/larl.c line 14
Quoted 6 lines
tests/tcg/s390x/larl.c new file +6
-0+{ + long algfi = (long)main; + long larl; + + asm("algfi %[r],0xd0000000" : [r] "+r" (algfi) : : "cc"); + asm("larl %[r],main+0xd0000000" : [r] "=r" (larl));Not sure if worth combining both statements.
I thought it would be easier on the eyes; this way one immediately sees that they are independent.
And maybe I should've added a comment about this, but the reason I used algfi instead of C addition was that I feared that the compiler might generate larl, making the test useless.
Quoted 7 lines
tests/tcg/s390x/larl.c line 17
Quoted 4 lines
tests/tcg/s390x/larl.c new file +3
-0+ + return algfi == larl ? EXIT_SUCCESS : EXIT_FAILURE; +}
PATCH 10/12 tests/tcg/s390x: Test LRA
In reply to Ilya LeoshkevichAdd a small test to prevent regressions.
--- tests/tcg/s390x/Makefile.softmmu-target | 1 + tests/tcg/s390x/lra.S | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/tcg/s390x/lra.S
tests/tcg/s390x/Makefile.softmmu-target +1 -0
@@ -20,6 +20,7 @@ ASM_TESTS = \ sam \ lpsw \ lpswe-early \ + lra \ ssm-early \ stosm-early \ unaligned-lowcore
tests/tcg/s390x/lra.S new file +19 -0
@@ -0,0 +1,19 @@ + .org 0x200 /* lowcore padding */ + .globl _start +_start: + lgrl %r1,initial_r1 + lra %r1,0(%r1) + cgrl %r1,expected_r1 + jne 1f + lpswe success_psw +1: + lpswe failure_psw + .align 8 +initial_r1: + .quad 0x8765432112345678 +expected_r1: + .quad 0x8765432180000038 /* ASCE type exception */ +success_psw: + .quad 0x2000000000000,0xfff /* see is_special_wait_psw() */ +failure_psw: + .quad 0x2000000000000,0 /* disabled wait */
Signature · 1 line
2.41.0
PATCH 11/12 tests/tcg/s390x: Test MDEB and MDEBR
In reply to Ilya LeoshkevichAdd a small test to prevent regressions.
--- tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/mdeb.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/tcg/s390x/mdeb.c
tests/tcg/s390x/Makefile.target +1 -0
@@ -38,6 +38,7 @@ TESTS+=ex-branch TESTS+=mxdb TESTS+=epsw TESTS+=larl +TESTS+=mdeb cdsg: CFLAGS+=-pthread cdsg: LDFLAGS+=-pthread
tests/tcg/s390x/mdeb.c new file +30 -0
@@ -0,0 +1,30 @@ +/* +* Test the MDEB and MDEBR instructions. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#include <assert.h> +#include <stdlib.h> + +int main (void ) +{ +union { +float f[2 ]; +double d; + } a; +float b; + + a.f[0 ] =1.2345 ; + a.f[1 ] =999 ; + b =6.789 ; + asm("mdeb %[a],%[b]" : [a]"+f" (a.d) : [b]"R" (b)); +assert (a.d >8.38 && a.d <8.39 ); + + a.f[0 ] =1.2345 ; + a.f[1 ] =999 ; + b =6.789 ; + asm("mdebr %[a],%[b]" : [a]"+f" (a.d) : [b]"f" (b)); +assert (a.d >8.38 && a.d <8.39 ); + +return EXIT_SUCCESS ; +}
Signature · 1 line
2.41.0
Re: [PATCH 11/12] tests/tcg/s390x: Test MDEB and MDEBR
Quoted 47 lines · Ilya Leoshkevich
Add a small test to prevent regressions.
Signed-off-by Ilya Leoshkevich <[email protected]>--- tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/mdeb.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+)create mode 100644
tests/tcg/s390x/mdeb.ctests/tcg/s390x/Makefile.target +1
-0@@ -38,6 +38,7 @@ TESTS+=ex-branch TESTS+=mxdb TESTS+=epsw TESTS+=larl +TESTS+=mdeb cdsg: CFLAGS+=-pthread cdsg: LDFLAGS+=-pthreadtests/tcg/s390x/mdeb.c new file +20
-0@@ -0,0 +1,30 @@ +/* +* Test the MDEB and MDEBR instructions. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#include <assert.h> +#include <stdlib.h> + +int main (void ) +{ +union { +float f[2 ]; +double d; + } a; +float b; + + a.f[0 ] =1.2345 ; + a.f[1 ] =999 ; + b =6.789 ; + asm("mdeb %[a],%[b]" : [a]"+f" (a.d) : [b]"R" (b));
tests/tcg/s390x/mdeb.c line 30
Quoted 10 lines
tests/tcg/s390x/mdeb.c new file +10
-0+assert (a.d >8.38 && a.d <8.39 ); + + a.f[0 ] =1.2345 ; + a.f[1 ] =999 ; + b =6.789 ; + asm("mdebr %[a],%[b]" : [a]"+f" (a.d) : [b]"f" (b)); +assert (a.d >8.38 && a.d <8.39 ); + +return EXIT_SUCCESS ; +}
Signature · 3 lines
Cheers, David / dhildenb
PATCH 12/12 tests/tcg/s390x: Test MVCRL with a large value in R0
In reply to Ilya LeoshkevichAdd a small test to prevent regressions.
--- tests/tcg/s390x/mie3-mvcrl.c | 46 ++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 10 deletions(-)
tests/tcg/s390x/mie3-mvcrl.c +36 -10
@@ -1,29 +1,55 @@ +#include <stdbool.h> #include <stdint.h> +#include <stdlib.h> #include <string.h> - -static inline void mvcrl_8 (const char *dst,const char *src) +static void mvcrl (const char *dst,const char *src,size_t len) { + register long r0 asm("r0") = len; + asmvolatile ( -"llill %%r0, 8\n" ".insn sse, 0xE50A00000000, 0(%[dst]), 0(%[src])" - : : [dst]"d" (dst), [src]"d" (src) - :"r0" ,"memory" ); + : : [dst]"d" (dst), [src]"d" (src),"r" (r0) + :"memory" ); } - -int main (int argc,char *argv[]) +static bool test (void ) {const char *alpha ="abcdefghijklmnop" ;/* array missing 'i' */ -char tstr[17 ] ="abcdefghjklmnop\0" ; +char tstr[17 ] ="abcdefghjklmnop\0" ;/* mvcrl reference use: 'open a hole in an array' */ -mvcrl_8 (tstr +9 , tstr +8 ); +mvcrl (tstr +9 , tstr +8 ,8 );/* place missing 'i' */ tstr[8 ] ='i' ; -return strncmp (alpha, tstr,16ul ); +return strncmp (alpha, tstr,16ul ) ==0 ; +} + +static bool test_bad_r0 (void ) +{ +char src[256 ]; + +/* +* PoP says: Bits 32-55 of general register 0 should contain zeros; +* otherwise, the program may not operate compatibly in the future. +* +* Try it anyway in order to check whether this would crash QEMU itself. +*/ +mvcrl (src, src, (size_t )-1 ); + +return true; +} + +int main (void ) +{ +bool ok = true; + + ok &=test (); + ok &=test_bad_r0 (); + +return ok ?EXIT_SUCCESS :EXIT_FAILURE ; }
Signature · 1 line
2.41.0
Re: [PATCH 12/12] tests/tcg/s390x: Test MVCRL with a large value in R0
Quoted 67 lines · Ilya Leoshkevich
Add a small test to prevent regressions.
Signed-off-by Ilya Leoshkevich <[email protected]>--- tests/tcg/s390x/mie3-mvcrl.c | 46 ++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 10 deletions(-)tests/tcg/s390x/mie3-mvcrl.c +27
-10@@ -1,29 +1,55 @@ +#include <stdbool.h> #include <stdint.h> +#include <stdlib.h> #include <string.h> - -static inline void mvcrl_8 (const char *dst,const char *src) +static void mvcrl (const char *dst,const char *src,size_t len) { + register long r0 asm("r0") = len; + asmvolatile ( -"llill %%r0, 8\n" ".insn sse, 0xE50A00000000, 0(%[dst]), 0(%[src])" - : : [dst]"d" (dst), [src]"d" (src) - :"r0" ,"memory" ); + : : [dst]"d" (dst), [src]"d" (src),"r" (r0) + :"memory" ); } - -int main (int argc,char *argv[]) +static bool test (void ) {const char *alpha ="abcdefghijklmnop" ;/* array missing 'i' */ -char tstr[17 ] ="abcdefghjklmnop\0" ; +char tstr[17 ] ="abcdefghjklmnop\0" ;/* mvcrl reference use: 'open a hole in an array' */ -mvcrl_8 (tstr +9 , tstr +8 ); +mvcrl (tstr +9 , tstr +8 ,8 );/* place missing 'i' */ tstr[8 ] ='i' ; -return strncmp (alpha, tstr,16ul ); +return strncmp (alpha, tstr,16ul ) ==0 ; +} + +static bool test_bad_r0 (void ) +{ +char src[256 ]; + +/* +* PoP says: Bits 32-55 of general register 0 should contain zeros; +* otherwise, the program may not operate compatibly in the future. +* +* Try it anyway in order to check whether this would crash QEMU itself. +*/ +mvcrl (src, src, (size_t )-1 ); + +return true; +}
tests/tcg/s390x/mie3-mvcrl.c line 55
Quoted 10 lines
tests/tcg/s390x/mie3-mvcrl.c +9
-0+ +int main (void ) +{ +bool ok = true; + + ok &=test (); + ok &=test_bad_r0 (); + +return ok ?EXIT_SUCCESS :EXIT_FAILURE ; }
Signature · 3 lines
Cheers, David / dhildenb