target/s390x/tcg: Compile various files once
cover target/s390x/tcg: Compile various files once
When a file doesn't use any target-specific knowledge, it can be compiled once as common object. By moving the file to a meson 'common' source set, we ensure no target-specific API will be ever used [*]. This series move early few s390x TCG files to common because in the current state it is cheap enough to do so, no need to procrastinate.
[*] https://lore.kernel.org/qemu-devel/[email protected]/
Philippe Mathieu-Daudé (9):
tcg: Include missing 'tcg/tcg-op-common.h' header in 'tcg-op-mem.h' target/s390x: Do not compile KVM stubs for linux-user binary target/s390x: Introduce common system/user meson source set target/s390x: Compile few files as common unit target/s390x: Compile translate.c as common unit target/s390x: Compile vec_helper.c as common unit target/s390x: Have MSA helper pass a mmu_idx argument target/s390x: Compile crypto_helper.c as common unit target/s390x: Replace cpu_stb_data_ra -> cpu_stb_mmu in STFLE opcode
include/tcg/tcg-op-mem.h | 2 + target/s390x/tcg/crypto_helper.c | 80 +++++++++++++++++--------------- target/s390x/tcg/misc_helper.c | 7 ++- target/s390x/tcg/translate.c | 6 ++- target/s390x/tcg/vec_helper.c | 34 +++++++++----- target/s390x/kvm/meson.build | 2 +- target/s390x/meson.build | 25 +++++----- target/s390x/tcg/meson.build | 8 ++-- 8 files changed, 96 insertions(+), 68 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/9 tcg: Include missing 'tcg/tcg-op-common.h' header in 'tcg-op-mem.h'
"tcg-op-mem.h" uses methods declared in "tcg/tcg-op-common.h". Include the latter to avoid when including the former:
include/tcg/tcg-op-mem.h:34:5: error: call to undeclared function 'tcg_gen_qemu_ld_i32_chk'
34 | tcg_gen_qemu_ld_i32_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
| ^$ git grep -w tcg_gen_qemu_ld_i32_chk include/tcg/tcg-op-common.h:328:void tcg_gen_qemu_ld_i32_chk(TCGv_i32, TCGTemp *, TCGArg, MemOp, TCGType); include/tcg/tcg-op-mem.h:35: tcg_gen_qemu_ld_i32_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA); tcg/tcg-op-ldst.c:286:void tcg_gen_qemu_ld_i32_chk(TCGv_i32 val, TCGTemp *addr, TCGArg idx,
--- include/tcg/tcg-op-mem.h | 2 ++ 1 file changed, 2 insertions(+)
include/tcg/tcg-op-mem.h +2 -0
@@ -12,6 +12,8 @@#error TCG_ADDRESS_BITS must be defined#endif +#include "tcg/tcg-op-common.h" +#if TCG_ADDRESS_BITS ==32 typedef TCGv_i32 TCGv_va ;#define TCG_TYPE_VA TCG_TYPE_I32
Signature · 1 line
2.53.0
Re: [PATCH 1/9] tcg: Include missing 'tcg/tcg-op-common.h' header in 'tcg-op-mem.h'
Quoted 12 lines · Philippe Mathieu-Daudé
"
tcg-op-mem.h" uses methods declared in "tcg/tcg-op-common.h". Include the latter to avoid when including the former:include/tcg/tcg-op-mem.h:34:5: error: call to undeclared function 'tcg_gen_qemu_ld_i32_chk' 34 | tcg_gen_qemu_ld_i32_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA); | ^ $ git grep -w tcg_gen_qemu_ld_i32_chk include/tcg/tcg-op-common.h:328:void tcg_gen_qemu_ld_i32_chk(TCGv_i32, TCGTemp *, TCGArg, MemOp, TCGType); include/tcg/tcg-op-mem.h:35: tcg_gen_qemu_ld_i32_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA); tcg/tcg-op-ldst.c:286:void tcg_gen_qemu_ld_i32_chk(TCGv_i32 val, TCGTemp *addr, TCGArg idx,
Quoted 6 lines
Fixes a8af0fb24da ("include/tcg/tcg-op: extract memory operations to tcg-op-mem.h")Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/tcg/tcg-op-mem.h | 2 ++ 1 file changed, 2 insertions(+)
Re: [PATCH 1/9] tcg: Include missing 'tcg/tcg-op-common.h' header in 'tcg-op-mem.h'
In reply to Philippe Mathieu-DaudéQuoted 12 lines · Philippe Mathieu-Daudé
"
tcg-op-mem.h" uses methods declared in "tcg/tcg-op-common.h". Include the latter to avoid when including the former:include/tcg/tcg-op-mem.h:34:5: error: call to undeclared function 'tcg_gen_qemu_ld_i32_chk' 34 | tcg_gen_qemu_ld_i32_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA); | ^ $ git grep -w tcg_gen_qemu_ld_i32_chk include/tcg/tcg-op-common.h:328:void tcg_gen_qemu_ld_i32_chk(TCGv_i32, TCGTemp *, TCGArg, MemOp, TCGType); include/tcg/tcg-op-mem.h:35: tcg_gen_qemu_ld_i32_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA); tcg/tcg-op-ldst.c:286:void tcg_gen_qemu_ld_i32_chk(TCGv_i32 val, TCGTemp *addr, TCGArg idx,
Quoted 2 lines
Fixes a8af0fb24da ("include/tcg/tcg-op: extract memory operations to tcg-op-mem.h")
Just to clarify: this patch has been Cc'd qemu-stable by mistake, right? Because the mentioned Fixes: commit is not in any qemu release, it is applied to the master branch after 11.0.0 version.
Thanks,
/mjt
Re: [PATCH 1/9] tcg: Include missing 'tcg/tcg-op-common.h' header in 'tcg-op-mem.h'
Quoted 13 lines · Michael Tokarev
Quoted 12 lines · Philippe Mathieu-Daudé
"
tcg-op-mem.h" uses methods declared in "tcg/tcg-op-common.h". Include the latter to avoid when including the former:
include/tcg/tcg-op-mem.h:34:5: error: call to undeclared function 'tcg_gen_qemu_ld_i32_chk' 34 |tcg_gen_qemu_ld_i32_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
| ^$ git grep -w tcg_gen_qemu_ld_i32_chk include/tcg/tcg-op-common.h:328:void tcg_gen_qemu_ld_i32_chk(TCGv_i32, TCGTemp *, TCGArg, MemOp, TCGType); include/tcg/tcg-op-mem.h:35: tcg_gen_qemu_ld_i32_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA); tcg/tcg-op-ldst.c:286:void tcg_gen_qemu_ld_i32_chk(TCGv_i32 val, TCGTemp *addr, TCGArg idx,
Quoted 6 lines
Quoted 2 lines
Fixes a8af0fb24da ("include/tcg/tcg-op: extract memory operations to tcg-op-mem.h")Just to clarify: this patch has been Cc'd qemu-stable by mistake, right? Because the mentioned Fixes: commit is not in any qemu release, it is applied to the master branch after 11.0.0 version.
Oops, likely... Sorry!
PATCH 2/9 target/s390x: Do not compile KVM stubs for linux-user binary
In reply to Philippe Mathieu-DaudéNone of these KVM symbols should be used in the qemu-s390x linux-user binary. Do not build the stub there, prefer a real linker failure.
--- target/s390x/kvm/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/kvm/meson.build +1 -1
@@ -1,5 +1,5 @@ -s390x_ss.add(when: 'CONFIG_KVM', if_true: files( +s390x_system_ss.add(when: 'CONFIG_KVM', if_true: files( 'pv.c', 'kvm.c', 'stsi-topology.c'
Signature · 1 line
2.53.0
Re: [PATCH 2/9] target/s390x: Do not compile KVM stubs for linux-user binary
Quoted 8 lines · Philippe Mathieu-Daudé
None of these KVM symbols should be used in the qemu-s390x linux-user binary. Do not build the stub there, prefer a real linker failure.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/s390x/kvm/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH 3/9 target/s390x: Introduce common system/user meson source set
In reply to Philippe Mathieu-DaudéIntroduce a source set common to system / user. Start it with the files built in both sets: 'cpu_models_user.c' and 'gdbstub.c' No logical change intended.
--- target/s390x/meson.build | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
target/s390x/meson.build +13 -12
@@ -1,4 +1,9 @@ s390x_ss = ss.source_set() +s390x_common_ss = ss.source_set() +s390x_common_system_ss = ss.source_set() +s390x_system_ss = ss.source_set() +s390x_user_ss = ss.source_set() + s390x_ss.add(files( 'cpu.c', 'cpu_features.c',
@@ -15,15 +20,16 @@ gen_features_h = custom_target('gen-features.h', capture: true, command: gen_features) -s390x_ss.add(gen_features_h) +s390x_common_ss.add(gen_features_h) +s390x_common_ss.add(files( + 'cpu_models_user.c', + 'gdbstub.c', +)) -s390x_system_ss = ss.source_set() s390x_system_ss.add(files( 'ioinst.c', )) -s390x_common_system_ss = ss.source_set() -s390x_common_system_ss.add(gen_features_h) s390x_common_system_ss.add(files( 'helper.c', 'arch_dump.c',
@@ -32,19 +38,14 @@ s390x_common_system_ss.add(files( 'mmu_helper.c', 'sigp.c', 'cpu-system.c', - 'cpu_models_system.c', - 'gdbstub.c', -)) - -s390x_user_ss = ss.source_set() -s390x_user_ss.add(files( - 'cpu_models_user.c', - 'gdbstub.c', )) subdir('tcg') subdir('kvm') +s390x_common_system_ss.add_all(s390x_common_ss) +s390x_user_ss.add_all(s390x_common_ss) + target_arch += {'s390x': s390x_ss} target_system_arch += {'s390x': s390x_system_ss} target_common_system_arch += {'s390x': s390x_common_system_ss}
Signature · 1 line
2.53.0
Re: [PATCH 3/9] target/s390x: Introduce common system/user meson source set
Quoted 8 lines · Philippe Mathieu-Daudé
Introduce a source set common to system / user. Start it with the files built in both sets: '
cpu_models_user.c' and 'gdbstub.c' No logical change intended.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/s390x/meson.build | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
PATCH 4/9 target/s390x: Compile few files as common unit
In reply to Philippe Mathieu-DaudéNothing in these files prevents it to be built as common unit:
- cc_helper.c
- excp_helper.c
- fpu_helper.c
- vec_fpu_helper.c
- vec_int_helper.c
- vec_string_helper.c
--- target/s390x/tcg/meson.build | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
target/s390x/tcg/meson.build +6 -4
@@ -1,14 +1,16 @@ s390x_ss.add(when: 'CONFIG_TCG', if_true: files( - 'cc_helper.c', 'crypto_helper.c', - 'excp_helper.c', - 'fpu_helper.c', 'int_helper.c', 'mem_helper.c', 'misc_helper.c', 'translate.c', - 'vec_fpu_helper.c', 'vec_helper.c', +)) +s390x_common_ss.add(when: 'CONFIG_TCG', if_true: files( + 'cc_helper.c', + 'excp_helper.c', + 'fpu_helper.c', + 'vec_fpu_helper.c', 'vec_int_helper.c', 'vec_string_helper.c', ))
Signature · 1 line
2.53.0
Re: [PATCH 4/9] target/s390x: Compile few files as common unit
Quoted 9 lines · Philippe Mathieu-Daudé
Nothing in these files prevents it to be built as common unit:
-
cc_helper.c
-excp_helper.c
-fpu_helper.c
-vec_fpu_helper.c
-vec_int_helper.c
-vec_string_helper.c
Quoted 4 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/s390x/tcg/meson.build | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
PATCH 5/9 target/s390x: Compile translate.c as common unit
In reply to Philippe Mathieu-DaudéIn order do build translate.c as a common unit we need to replace:
#include "tcg/tcg-op.h" -> #include "tcg/tcg-op-common.h"
-> #include "tcg/tcg-op-mem.h"and:
"accel/tcg/tcg-op-gvec.h" -> "accel/tcg/tcg-op-gvec-common.h"
taking care to define TCG_ADDRESS_BITS, which is fixed for this 64-bit target.
--- target/s390x/tcg/translate.c | 6 ++++-- target/s390x/tcg/meson.build | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-)
target/s390x/tcg/translate.c +4 -2
@@ -31,8 +31,10 @@#include "qemu/osdep.h" #include "cpu.h" #include "s390x-internal.h" -#include "tcg/tcg-op.h" -#include "tcg/tcg-op-gvec.h" +#define TCG_ADDRESS_BITS 64 +#include "tcg/tcg-op-common.h" +#include "tcg/tcg-op-mem.h" +#include "tcg/tcg-op-gvec-common.h" #include "qemu/log.h" #include "qemu/host-utils.h" #include "exec/helper-proto.h"
target/s390x/tcg/meson.build +1 -1
@@ -3,13 +3,13 @@ s390x_ss.add(when: 'CONFIG_TCG', if_true: files( 'int_helper.c', 'mem_helper.c', 'misc_helper.c', - 'translate.c', 'vec_helper.c', )) s390x_common_ss.add(when: 'CONFIG_TCG', if_true: files( 'cc_helper.c', 'excp_helper.c', 'fpu_helper.c', + 'translate.c', 'vec_fpu_helper.c', 'vec_int_helper.c', 'vec_string_helper.c',
Signature · 1 line
2.53.0
Re: [PATCH 5/9] target/s390x: Compile translate.c as common unit
Quoted 10 lines · Philippe Mathieu-Daudé
In order do build
translate.cas a common unit we need to replace:#include "tcg/tcg-op.h" -> #include "tcg/tcg-op-common.h" -> #include "tcg/tcg-op-mem.h"and:
"accel/tcg/tcg-op-gvec.h" -> "accel/tcg/tcg-op-gvec-common.h"
Quoted 8 lines
taking care to define
TCG_ADDRESS_BITS, which is fixed for this 64-bit target.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/s390x/tcg/translate.c | 6 ++++-- target/s390x/tcg/meson.build | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-)
PATCH 6/9 target/s390x: Compile vec_helper.c as common unit
In reply to Philippe Mathieu-DaudéIn order do build vec_helper.c as a common unit we need to replace:
"accel/tcg/cpu-ldst.h" -> "accel/tcg/cpu-ldst-common.h"
and update the cpu_ld/st_be_data_ra() API by cpu_ld/st_mmu() one.
---
Unrelated but could VLL / VSTL leverage the Int128 type?
--- target/s390x/tcg/vec_helper.c | 34 +++++++++++++++++++++++----------- target/s390x/tcg/meson.build | 2 +- 2 files changed, 24 insertions(+), 12 deletions(-)
target/s390x/tcg/vec_helper.c +23 -11
@@ -16,7 +16,8 @@#include "tcg/tcg.h" #include "tcg/tcg-gvec-desc.h" #include "exec/helper-proto.h" -#include "accel/tcg/cpu-ldst.h" +#include "accel/tcg/cpu-ldst-common.h" +#include "accel/tcg/cpu-mmu-index.h" void HELPER (gvec_vbperm )(void *v1,const void *v2,const void *v3,uint32_t desc)
@@ -42,20 +43,26 @@ void HELPER(gvec_vbperm)(void *v1, const void *v2, const void *v3,void HELPER (vll )(CPUS390XState *env,void *v1,uint64_t addr,uint64_t bytes) { +const int mmu_idx =cpu_mmu_index (env_cpu (env), false); +const uintptr_t ra =GETPC (); +MemOpIdx oi; +if (likely (bytes >=16 )) {uint64_t t0, t1; - t0 =cpu_ldq_be_data_ra (env, addr,GETPC ()); + oi =make_memop_idx (MO_BE |MO_64 |MO_UNALN , mmu_idx); + t0 =cpu_ldq_mmu (env, addr, oi, ra); addr =wrap_address (env, addr +8 ); - t1 =cpu_ldq_be_data_ra (env, addr,GETPC ()); + t1 =cpu_ldq_mmu (env, addr, oi, ra);s390_vec_write_element64 (v1,0 , t0);s390_vec_write_element64 (v1,1 , t1); }else {S390Vector tmp = {}; -int i; -for (i =0 ; i < bytes; i++) { -uint8_t byte =cpu_ldub_data_ra (env, addr,GETPC ()); + oi =make_memop_idx (MO_8 , mmu_idx); +for (int i =0 ; i < bytes; i++) { +uint8_t byte =cpu_ldb_mmu (env, addr, oi, ra); +s390_vec_write_element8 (&tmp, i, byte); addr =wrap_address (env, addr +1 );
@@ -191,20 +198,25 @@ void HELPER(gvec_vperm)(void *v1, const void *v2, const void *v3,void HELPER (vstl )(CPUS390XState *env,const void *v1,uint64_t addr,uint64_t bytes) { +const int mmu_idx =cpu_mmu_index (env_cpu (env), false); +const uintptr_t ra =GETPC (); +MemOpIdx oi; +/* Probe write access before actually modifying memory */ probe_write_access (env, addr,MIN (bytes,16 ),GETPC ());if (likely (bytes >=16 )) { -cpu_stq_be_data_ra (env, addr,s390_vec_read_element64 (v1,0 ),GETPC ()); + oi =make_memop_idx (MO_BE |MO_64 |MO_UNALN , mmu_idx); +cpu_stq_mmu (env, addr,s390_vec_read_element64 (v1,0 ), oi, ra); addr =wrap_address (env, addr +8 ); -cpu_stq_be_data_ra (env, addr,s390_vec_read_element64 (v1,1 ),GETPC ()); +cpu_stq_mmu (env, addr,s390_vec_read_element64 (v1,1 ), oi, ra); }else { -int i; + oi =make_memop_idx (MO_8 , mmu_idx); -for (i =0 ; i < bytes; i++) { +for (int i =0 ; i < bytes; i++) {uint8_t byte =s390_vec_read_element8 (v1, i); -cpu_stb_data_ra (env, addr, byte,GETPC ()); +cpu_stb_mmu (env, addr, byte, oi, ra); addr =wrap_address (env, addr +1 ); } }
target/s390x/tcg/meson.build +1 -1
@@ -3,7 +3,6 @@ s390x_ss.add(when: 'CONFIG_TCG', if_true: files( 'int_helper.c', 'mem_helper.c', 'misc_helper.c', - 'vec_helper.c', )) s390x_common_ss.add(when: 'CONFIG_TCG', if_true: files( 'cc_helper.c',
@@ -11,6 +10,7 @@ s390x_common_ss.add(when: 'CONFIG_TCG', if_true: files( 'fpu_helper.c', 'translate.c', 'vec_fpu_helper.c', + 'vec_helper.c', 'vec_int_helper.c', 'vec_string_helper.c', ))
Signature · 1 line
2.53.0
Re: [PATCH 6/9] target/s390x: Compile vec_helper.c as common unit
Quoted 10 lines · Philippe Mathieu-Daudé
In order do build
vec_helper.cas a common unit we need to replace:"accel/tcg/cpu-ldst.h" -> "accel/tcg/cpu-ldst-common.h"and update the cpu_ld/st_be_data_ra() API by cpu_ld/st_mmu() one.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Unrelated but could VLL / VSTL leverage the Int128 type?
Self-answered:
https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 4 lines
--- target/s390x/tcg/vec_helper.c | 34 +++++++++++++++++++++++----------- target/s390x/tcg/meson.build | 2 +- 2 files changed, 24 insertions(+), 12 deletions(-)
Re: [PATCH 6/9] target/s390x: Compile vec_helper.c as common unit
In reply to Philippe Mathieu-DaudéQuoted 7 lines · Philippe Mathieu-Daudé
In order do build
vec_helper.cas a common unit we need to replace:"accel/tcg/cpu-ldst.h" -> "accel/tcg/cpu-ldst-common.h"and update the cpu_ld/st_be_data_ra() API by cpu_ld/st_mmu() one.
Quoted 7 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Unrelated but could VLL / VSTL leverage the Int128 type?--- target/s390x/tcg/vec_helper.c | 34 +++++++++++++++++++++++----------- target/s390x/tcg/meson.build | 2 +- 2 files changed, 24 insertions(+), 12 deletions(-)
IIUC, we are open-coding these functions because the wrappers refer to target-specific abi_ptr and are therefore effectively deprecated.
Does docs/devel/loads-stores.rst need to be updated to reflect this? Currently it states:
``cpu_{ld,st}*_data_ra``
~~~~~~~~~~~~~~~~~~~~~~~~
[...]
These are generally the preferred way to do accesses by guest virtual address from helper functions, unless the access should be performed with a context other than the default, or alignment should be enforced for the access.
And it's a pleasant surprise to learn that for (int i is in fact allowed by docs/devel/style.rst.
PATCH 7/9 target/s390x: Have MSA helper pass a mmu_idx argument
In reply to Philippe Mathieu-DaudéNext commit will use the cpu_ld/st_mmu() API and thus will also use a @mmu_idx. In order to keep it simple to review, propate @mmu_idx in a preliminary step.
--- target/s390x/tcg/crypto_helper.c | 41 +++++++++++++++++--------------- 1 file changed, 22 insertions(+), 19 deletions(-)
target/s390x/tcg/crypto_helper.c +22 -19
@@ -18,6 +18,7 @@#include "tcg_s390x.h" #include "exec/helper-proto.h" #include "accel/tcg/cpu-ldst.h" +#include "accel/tcg/cpu-mmu-index.h" static uint64_t R (uint64_t x,int c) {
@@ -119,8 +120,8 @@ static void sha512_bda_be64(uint64_t a[8], uint64_t w[16])sha512_bda (a, t); } -static void sha512_read_icv (CPUS390XState *env,uint64_t addr, -uint64_t a[8 ],uintptr_t ra) +static void sha512_read_icv (CPUS390XState *env,const int mmu_idx, +uint64_t addr,uint64_t a[8 ],uintptr_t ra) {int i;
@@ -130,8 +131,8 @@ static void sha512_read_icv(CPUS390XState *env, uint64_t addr, } } -static void sha512_write_ocv (CPUS390XState *env,uint64_t addr, -uint64_t a[8 ],uintptr_t ra) +static void sha512_write_ocv (CPUS390XState *env,const int mmu_idx, +uint64_t addr,uint64_t a[8 ],uintptr_t ra) {int i;
@@ -141,8 +142,8 @@ static void sha512_write_ocv(CPUS390XState *env, uint64_t addr, } } -static void sha512_read_block (CPUS390XState *env,uint64_t addr, -uint64_t a[16 ],uintptr_t ra) +static void sha512_read_block (CPUS390XState *env,const int mmu_idx, +uint64_t addr,uint64_t a[16 ],uintptr_t ra) {int i;
@@ -152,8 +153,8 @@ static void sha512_read_block(CPUS390XState *env, uint64_t addr, } } -static void sha512_read_mbl_be64 (CPUS390XState *env,uint64_t addr, -uint8_t a[16 ],uintptr_t ra) +static void sha512_read_mbl_be64 (CPUS390XState *env,const int mmu_idx, +uint64_t addr,uint8_t a[16 ],uintptr_t ra) {int i;
@@ -163,8 +164,9 @@ static void sha512_read_mbl_be64(CPUS390XState *env, uint64_t addr, } } -static int cpacf_sha512 (CPUS390XState *env,uintptr_t ra,uint64_t param_addr, -uint64_t *message_reg,uint64_t *len_reg,uint32_t type) +static int cpacf_sha512 (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint64_t param_addr,uint64_t *message_reg, +uint64_t *len_reg,uint32_t type) {enum {MAX_BLOCKS_PER_RUN =64 };/* Arbitrary: keep interactivity. */ uint64_t len = *len_reg, a[8 ], processed =0 ;
@@ -182,7 +184,7 @@ static int cpacf_sha512(CPUS390XState *env, uintptr_t ra, uint64_t param_addr,tcg_s390_program_interrupt (env,PGM_SPECIFICATION , ra); } -sha512_read_icv (env, param_addr, a, ra); +sha512_read_icv (env, mmu_idx, param_addr, a, ra);/* Process full blocks first. */ for (; len >=128 ; len -=128 , processed +=128 ) {
@@ -192,7 +194,7 @@ static int cpacf_sha512(CPUS390XState *env, uintptr_t ra, uint64_t param_addr,break ; } -sha512_read_block (env, *message_reg + processed, w, ra); +sha512_read_block (env, mmu_idx, *message_reg + processed, w, ra);sha512_bda (a, w); }
@@ -215,13 +217,13 @@ static int cpacf_sha512(CPUS390XState *env, uintptr_t ra, uint64_t param_addr,* or use an additional one. */ if (len <112 ) { -sha512_read_mbl_be64 (env, param_addr +64 , x +112 , ra); +sha512_read_mbl_be64 (env, mmu_idx, param_addr +64 , x +112 , ra); }sha512_bda_be64 (a, (uint64_t *)x);if (len >=112 ) {memset (x,0 ,112 ); -sha512_read_mbl_be64 (env, param_addr +64 , x +112 , ra); +sha512_read_mbl_be64 (env, mmu_idx, param_addr +64 , x +112 , ra);sha512_bda_be64 (a, (uint64_t *)x); }
@@ -236,14 +238,14 @@ static int cpacf_sha512(CPUS390XState *env, uintptr_t ra, uint64_t param_addr,* TODO: if writing fails halfway through (e.g., when crossing page * boundaries), we're in trouble. We'd need something like access_prepare(). */ -sha512_write_ocv (env, param_addr, a, ra); +sha512_write_ocv (env, mmu_idx, param_addr, a, ra); *message_reg =deposit64 (*message_reg,0 , message_reg_len, *message_reg + processed); *len_reg -= processed;return !len ?0 :3 ; } -static void fill_buf_random (CPUS390XState *env,uintptr_t ra, +static void fill_buf_random (CPUS390XState *env,const int mmu_idx,uintptr_t ra,uint64_t *buf_reg,uint64_t *len_reg) {uint8_t tmp[256 ];
@@ -271,6 +273,7 @@ static void fill_buf_random(CPUS390XState *env, uintptr_t ra,uint32_t HELPER (msa )(CPUS390XState *env,uint32_t r1,uint32_t r2,uint32_t r3,uint32_t type) { +const int mmu_idx =cpu_mmu_index (env_cpu (env), false);const uintptr_t ra =GETPC ();const uint8_t mod = env->regs[0 ] &0x80ULL ;const uint8_t fc = env->regs[0 ] &0x7fULL ;
@@ -303,11 +306,11 @@ uint32_t HELPER(msa)(CPUS390XState *env, uint32_t r1, uint32_t r2, uint32_t r3, }break ;case 3 :/* CPACF_*_SHA_512 */ -return cpacf_sha512 (env, ra, env->regs[1 ], &env->regs[r2], +return cpacf_sha512 (env, mmu_idx, ra, env->regs[1 ], &env->regs[r2], &env->regs[r2 +1 ], type);case 114 :/* CPACF_PRNO_TRNG */ -fill_buf_random (env, ra, &env->regs[r1], &env->regs[r1 +1 ]); -fill_buf_random (env, ra, &env->regs[r2], &env->regs[r2 +1 ]); +fill_buf_random (env, mmu_idx, ra, &env->regs[r1], &env->regs[r1 +1 ]); +fill_buf_random (env, mmu_idx, ra, &env->regs[r2], &env->regs[r2 +1 ]);break ;default :/* we don't implement any other subfunction yet */
Signature · 1 line
2.53.0
Re: [PATCH 7/9] target/s390x: Have MSA helper pass a mmu_idx argument
Quoted 8 lines · Philippe Mathieu-Daudé
Next commit will use the cpu_ld/st_mmu() API and thus will also use a @mmu_idx. In order to keep it simple to review, propate @mmu_idx in a preliminary step.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/s390x/tcg/crypto_helper.c | 41 +++++++++++++++++--------------- 1 file changed, 22 insertions(+), 19 deletions(-)
I was worrying that this might break bisectability with -Werror by causing unused function argument warnings, but for some reason this does not happen.
PATCH 8/9 target/s390x: Compile crypto_helper.c as common unit
In reply to Philippe Mathieu-DaudéIn order do build crypto_helper.c as a common unit we need to replace:
"accel/tcg/cpu-ldst.h" -> "accel/tcg/cpu-ldst-common.h"
and update the cpu_ld/st_be_data_ra() API by cpu_ld/st_mmu() one.
--- target/s390x/tcg/crypto_helper.c | 39 +++++++++++++++++--------------- target/s390x/tcg/meson.build | 2 +- 2 files changed, 22 insertions(+), 19 deletions(-)
target/s390x/tcg/crypto_helper.c +21 -18
@@ -17,7 +17,7 @@#include "s390x-internal.h" #include "tcg_s390x.h" #include "exec/helper-proto.h" -#include "accel/tcg/cpu-ldst.h" +#include "accel/tcg/cpu-ldst-common.h" #include "accel/tcg/cpu-mmu-index.h" static uint64_t R (uint64_t x,int c)
@@ -123,44 +123,44 @@ static void sha512_bda_be64(uint64_t a[8], uint64_t w[16])static void sha512_read_icv (CPUS390XState *env,const int mmu_idx,uint64_t addr,uint64_t a[8 ],uintptr_t ra) { -int i; +const MemOpIdx oi =make_memop_idx (MO_BE |MO_64 |MO_UNALN , mmu_idx); -for (i =0 ; i <8 ; i++, addr +=8 ) { +for (int i =0 ; i <8 ; i++, addr +=8 ) { addr =wrap_address (env, addr); - a[i] =cpu_ldq_be_data_ra (env, addr, ra); + a[i] =cpu_ldq_mmu (env, addr, oi, ra); } }static void sha512_write_ocv (CPUS390XState *env,const int mmu_idx,uint64_t addr,uint64_t a[8 ],uintptr_t ra) { -int i; +const MemOpIdx oi =make_memop_idx (MO_BE |MO_64 |MO_UNALN , mmu_idx); -for (i =0 ; i <8 ; i++, addr +=8 ) { +for (int i =0 ; i <8 ; i++, addr +=8 ) { addr =wrap_address (env, addr); -cpu_stq_be_data_ra (env, addr, a[i], ra); +cpu_stq_mmu (env, addr, a[i], oi, ra); } }static void sha512_read_block (CPUS390XState *env,const int mmu_idx,uint64_t addr,uint64_t a[16 ],uintptr_t ra) { -int i; +const MemOpIdx oi =make_memop_idx (MO_BE |MO_64 |MO_UNALN , mmu_idx); -for (i =0 ; i <16 ; i++, addr +=8 ) { +for (int i =0 ; i <16 ; i++, addr +=8 ) { addr =wrap_address (env, addr); - a[i] =cpu_ldq_be_data_ra (env, addr, ra); + a[i] =cpu_ldq_mmu (env, addr, oi, ra); } }static void sha512_read_mbl_be64 (CPUS390XState *env,const int mmu_idx,uint64_t addr,uint8_t a[16 ],uintptr_t ra) { -int i; +const MemOpIdx oi =make_memop_idx (MO_8 , mmu_idx); -for (i =0 ; i <16 ; i++, addr +=1 ) { +for (int i =0 ; i <16 ; i++, addr +=1 ) { addr =wrap_address (env, addr); - a[i] =cpu_ldub_data_ra (env, addr, ra); + a[i] =cpu_ldb_mmu (env, addr, oi, ra); } }
@@ -200,13 +200,14 @@ static int cpacf_sha512(CPUS390XState *env, const int mmu_idx, uintptr_t ra,/* KLMD: Process partial/empty block last. */ if (type ==S390_FEAT_TYPE_KLMD && len <128 ) { +const MemOpIdx oi =make_memop_idx (MO_8 , mmu_idx);uint8_t x[128 ];/* Read the remainder of the message byte-per-byte. */ for (i =0 ; i < len; i++) {uint64_t addr =wrap_address (env, *message_reg + processed + i); - x[i] =cpu_ldub_data_ra (env, addr, ra); + x[i] =cpu_ldb_mmu (env, addr, oi, ra); }/* Pad the remainder with zero and set the top bit. */ memset (x + len,0 ,128 - len);
@@ -248,6 +249,7 @@ static int cpacf_sha512(CPUS390XState *env, const int mmu_idx, uintptr_t ra,static void fill_buf_random (CPUS390XState *env,const int mmu_idx,uintptr_t ra,uint64_t *buf_reg,uint64_t *len_reg) { +const MemOpIdx oi =make_memop_idx (MO_8 , mmu_idx);uint8_t tmp[256 ];uint64_t len = *len_reg;int buf_reg_len =64 ;
@@ -262,7 +264,7 @@ static void fill_buf_random(CPUS390XState *env, const int mmu_idx, uintptr_t ra,qemu_guest_getrandom_nofail (tmp, block);for (size_t i =0 ; i < block; ++i) { -cpu_stb_data_ra (env,wrap_address (env, *buf_reg), tmp[i], ra); +cpu_stb_mmu (env,wrap_address (env, *buf_reg), tmp[i], oi, ra); *buf_reg =deposit64 (*buf_reg,0 , buf_reg_len, *buf_reg +1 ); --*len_reg; }
@@ -279,7 +281,7 @@ uint32_t HELPER(msa)(CPUS390XState *env, uint32_t r1, uint32_t r2, uint32_t r3,const uint8_t fc = env->regs[0 ] &0x7fULL ;uint8_t subfunc[16 ] = {0 };uint64_t param_addr; -int i; +MemOpIdx oi;switch (type) {case S390_FEAT_TYPE_KMAC :
@@ -300,9 +302,10 @@ uint32_t HELPER(msa)(CPUS390XState *env, uint32_t r1, uint32_t r2, uint32_t r3,switch (fc) {case 0 :/* query subfunction */ -for (i =0 ; i <16 ; i++) { + oi =make_memop_idx (MO_8 , mmu_idx); +for (int i =0 ; i <16 ; i++) { param_addr =wrap_address (env, env->regs[1 ] + i); -cpu_stb_data_ra (env, param_addr, subfunc[i], ra); +cpu_stb_mmu (env, param_addr, subfunc[i], oi, ra); }break ;case 3 :/* CPACF_*_SHA_512 */
target/s390x/tcg/meson.build +1 -1
@@ -1,11 +1,11 @@ s390x_ss.add(when: 'CONFIG_TCG', if_true: files( - 'crypto_helper.c', 'int_helper.c', 'mem_helper.c', 'misc_helper.c', )) s390x_common_ss.add(when: 'CONFIG_TCG', if_true: files( 'cc_helper.c', + 'crypto_helper.c', 'excp_helper.c', 'fpu_helper.c', 'translate.c',
Signature · 1 line
2.53.0
Re: [PATCH 8/9] target/s390x: Compile crypto_helper.c as common unit
Quoted 5 lines · Philippe Mathieu-Daudé
In order do build
crypto_helper.cas a common unit we need to replace:"accel/tcg/cpu-ldst.h" -> "accel/tcg/cpu-ldst-common.h"
Quoted 7 lines
and update the cpu_ld/st_be_data_ra() API by cpu_ld/st_mmu() one.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/s390x/tcg/crypto_helper.c | 39 +++++++++++++++++--------------- target/s390x/tcg/meson.build | 2 +- 2 files changed, 22 insertions(+), 19 deletions(-)
PATCH 9/9 target/s390x: Replace cpu_stb_data_ra -> cpu_stb_mmu in STFLE opcode
In reply to Philippe Mathieu-DaudéIn preparation of building misc_helper.c as a common unit, update the cpu_ld/st_be_data_ra() API by cpu_ld/st_mmu() one and replace "accel/tcg/cpu-ldst.h" by "accel/tcg/cpu-ldst-common.h".
For now we are blocked by the CONFIG_DEVICES use so keep the file in s390x_ss[].
--- target/s390x/tcg/misc_helper.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
target/s390x/tcg/misc_helper.c +5 -2
@@ -27,7 +27,8 @@#include "exec/helper-proto.h" #include "qemu/timer.h" #include "exec/cputlb.h" -#include "accel/tcg/cpu-ldst.h" +#include "accel/tcg/cpu-ldst-common.h" +#include "accel/tcg/cpu-mmu-index.h" #include "exec/target_page.h" #include "qapi/error.h" #include "tcg_s390x.h"
@@ -710,6 +711,8 @@ void HELPER(stfl)(CPUS390XState *env)uint32_t HELPER (stfle )(CPUS390XState *env,uint64_t addr) { +const int mmu_idx =cpu_mmu_index (env_cpu (env), false); +const MemOpIdx oi =make_memop_idx (MO_8 , mmu_idx);const uintptr_t ra =GETPC ();const int count_bytes = ((env->regs[0 ] &0xff ) +1 ) *8 ;int max_bytes;
@@ -728,7 +731,7 @@ uint32_t HELPER(stfle)(CPUS390XState *env, uint64_t addr)* not store the words, and existing software depend on that. */ for (i =0 ; i <MIN (count_bytes, max_bytes); ++i) { -cpu_stb_data_ra (env, addr + i, stfl_bytes[i], ra); +cpu_stb_mmu (env, addr + i, stfl_bytes[i], oi, ra); } env->regs[0 ] =deposit64 (env->regs[0 ],0 ,8 , (max_bytes /8 ) -1 );
Signature · 1 line
2.53.0
Re: [PATCH 9/9] target/s390x: Replace cpu_stb_data_ra -> cpu_stb_mmu in STFLE opcode
Quoted 11 lines · Philippe Mathieu-Daudé
In preparation of building
misc_helper.cas a common unit, update the cpu_ld/st_be_data_ra() API by cpu_ld/st_mmu() one and replace "accel/tcg/cpu-ldst.h" by "accel/tcg/cpu-ldst-common.h".For now we are blocked by the
CONFIG_DEVICESuse so keep the file in s390x_ss[].Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/s390x/tcg/misc_helper.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 20 lines · Philippe Mathieu-Daudé
When a file doesn't use any target-specific knowledge, it can be compiled once as common object. By moving the file to a meson 'common' source set, we ensure no target-specific API will be ever used [*]. This series move early few s390x TCG files to common because in the current state it is cheap enough to do so, no need to procrastinate.
[*] https://lore.kernel.org/qemu-devel/[email protected]/
Philippe Mathieu-Daudé (9):
tcg: Include missing 'tcg/tcg-op-common.h' header in 'tcg-op-mem.h' target/s390x: Do not compile KVM stubs for linux-user binary target/s390x: Introduce common system/user meson source set target/s390x: Compile few files as common unit target/s390x: Compiletranslate.cas common unit target/s390x: Compilevec_helper.cas common unit target/s390x: Have MSA helper pass ammu_idxargument target/s390x: Compilecrypto_helper.cas common unit target/s390x: Replacecpu_stb_data_ra->cpu_stb_mmuin STFLE opcode
Quoted 9 lines
include/tcg/tcg-op-mem.h | 2 + target/s390x/tcg/crypto_helper.c | 80 +++++++++++++++++--------------- target/s390x/tcg/misc_helper.c | 7 ++- target/s390x/tcg/translate.c | 6 ++- target/s390x/tcg/vec_helper.c | 34 +++++++++----- target/s390x/kvm/meson.build | 2 +- target/s390x/meson.build | 25 +++++----- target/s390x/tcg/meson.build | 8 ++-- 8 files changed, 96 insertions(+), 68 deletions(-)
I assume this series is Based-on: <[email protected]>?
Quoted 22 lines · Ilya Leoshkevich
Quoted 9 lines · Philippe Mathieu-Daudé
When a file doesn't use any target-specific knowledge, it can be compiled once as common object. By moving the file to a meson 'common' source set, we ensure no target-specific API will be ever used [*]. This series move early few s390x TCG files to common because in the current state it is cheap enough to do so, no need to procrastinate.
[*] https://lore.kernel.org/qemu-devel/beefeef5-96ba-4645- [email protected]/
Quoted 10 lines
Philippe Mathieu-Daudé (9):
tcg: Include missing 'tcg/tcg-op-common.h' header in 'tcg-op-mem.h' target/s390x: Do not compile KVM stubs for linux-user binary target/s390x: Introduce common system/user meson source set target/s390x: Compile few files as common unit target/s390x: Compiletranslate.cas common unit target/s390x: Compilevec_helper.cas common unit target/s390x: Have MSA helper pass ammu_idxargument target/s390x: Compilecrypto_helper.cas common unit target/s390x: Replacecpu_stb_data_ra->cpu_stb_mmuin STFLE opcode
Quoted 1 line
I assume this series is Based-on: <20260423100229.2941820-1- [email protected]>?
Oops yes, sorry!