target/mips: Use probe_access_full() in Atomic Load/Store helpers
v6 cover target/mips: Use probe_access_full() in Atomic Load/Store helpers
Since v5:
- Remove dead code (rth)
- Reword commit desc (rth)
- Inline translator_ld*
Since v4:
- Moved MO_ALIGN change
Following Richard suggestion in [*], use probe_access_full() and replace legacy cpu_ld*_mmuidx_ra() by cpu_ld*_mmu() in Atomic Load/Store helpers.
[*] https://lore.kernel.org/qemu-devel/[email protected]/
Philippe Mathieu-Daudé (4):
target/mips: Pass MemOpIdx argument to Linked Load/Store helpers target/mips: Inline cpu_ld/st_mmuidx_ra() calls in Atomic LD/ST
helpers
target/mips: Inline translator_ld[uw,l,q]() calls target/mips: Remove last MO_TE use
target/mips/helper.h | 4 ++-- target/mips/tcg/ldst_helper.c | 27 ++++++++++++++--------- target/mips/tcg/translate.c | 19 ++++++++++------ target/mips/tcg/micromips_translate.c.inc | 2 +- target/mips/tcg/mips16e_translate.c.inc | 8 ++++--- target/mips/tcg/nanomips_translate.c.inc | 5 +++-- 6 files changed, 40 insertions(+), 25 deletions(-)
Signature · 1 line
2.53.0
PATCH v6 1/4 target/mips: Pass MemOpIdx argument to Linked Load/Store helpers
In preparation of using the MemOp content in the next commit (thus stopping ignoring it), pass it as MemOpIdx.
The helper prototype declaration always took a TCGv_i32 as last argument, correct that.
Rename the ignored 'mem_idx' argument on user emulation.
--- target/mips/helper.h | 4 ++-- target/mips/tcg/ldst_helper.c | 5 ++++- target/mips/tcg/translate.c | 7 ++++--- 3 files changed, 10 insertions(+), 6 deletions(-)
target/mips/helper.h +2 -2
@@ -10,9 +10,9 @@ DEF_HELPER_4(swl, void, env, tl, tl, int) DEF_HELPER_4(swr, void, env, tl, tl, int)#ifndef CONFIG_USER_ONLY -DEF_HELPER_3(ll, tl, env, tl, int) +DEF_HELPER_3(ll, tl, env, tl, i32)#ifdef TARGET_MIPS64 -DEF_HELPER_3(lld, tl, env, tl, int) +DEF_HELPER_3(lld, tl, env, tl, i32)#endif #endif
target/mips/tcg/ldst_helper.c +4 -1
@@ -30,8 +30,11 @@#ifndef CONFIG_USER_ONLY #define HELPER_LD_ATOMIC (name, insn, almask, do_cast) \ -target_ulong helper_##name(CPUMIPSState *env, target_ulong arg, int mem_idx) \ +target_ulong helper_##name(CPUMIPSState *env, target_ulong arg, \ + uint32_t memop_idx) \ { \ + MemOpIdx oi = memop_idx; \ + unsigned mem_idx = get_mmuidx(oi); \ if (arg & almask) { \ if (!(env->hflags & MIPS_HFLAG_DM)) { \ env->CP0_BadVAddr = arg; \
target/mips/tcg/translate.c +4 -3
@@ -1922,7 +1922,7 @@ FOP_CONDNS(s, FMT_S, 32, gen_store_fpr32(ctx, fp0, fd))/* load/store instructions. */ #ifdef CONFIG_USER_ONLY #define OP_LD_ATOMIC (insn, memop) \ -static inline void op_ld_##insn(TCGv ret, TCGv arg1, int mem_idx, \ +static inline void op_ld_##insn(TCGv ret, TCGv arg1, int mem_idx_ignored, \ DisasContext *ctx) \ { \ TCGv t0 = tcg_temp_new(); \
@@ -1932,11 +1932,12 @@ static inline void op_ld_##insn(TCGv ret, TCGv arg1, int mem_idx, \ tcg_gen_st_tl(ret, tcg_env, offsetof(CPUMIPSState, llval)); \ }#else -#define OP_LD_ATOMIC (insn, ignored_memop) \ +#define OP_LD_ATOMIC (insn, memop) \ static inline void op_ld_##insn(TCGv ret, TCGv arg1, int mem_idx, \ DisasContext *ctx) \ { \ - gen_helper_##insn(ret, tcg_env, arg1, tcg_constant_i32(mem_idx)); \ + MemOpIdx oi = make_memop_idx(memop, mem_idx); \ + gen_helper_##insn(ret, tcg_env, arg1, tcg_constant_i32(oi)); \ }#endif OP_LD_ATOMIC (ll,mo_endian (ctx) |MO_SL );
Signature · 1 line
2.53.0
Re: [PATCH v6 1/4] target/mips: Pass MemOpIdx argument to Linked Load/Store helpers
Quoted 6 lines · Philippe Mathieu-Daudé
In preparation of using the MemOp content in the next commit (thus stopping ignoring it), pass it as MemOpIdx.
The helper prototype declaration always took a
TCGv_i32as last argument, correct that.
Quoted 8 lines
Rename the ignored '
mem_idx' argument on user emulation.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/mips/helper.h | 4 ++-- target/mips/tcg/ldst_helper.c | 5 ++++- target/mips/tcg/translate.c | 7 ++++--- 3 files changed, 10 insertions(+), 6 deletions(-)
r~
PATCH v6 2/4 target/mips: Inline cpu_ld/st_mmuidx_ra() calls in Atomic LD/ST helpers
In reply to Philippe Mathieu-DaudéHave callers set MO_ALIGN in the MemOp bits.
Perform the access first, filling the TLB in the process. If the tlb cannot be filled, access is not permitted, and an exception is raised. Thus remove the now unnecessary do_raise_exception() call.
Since the TLB is filled, use probe_access() to get CP0_LLAddr.
Move env->CP0_LLAddr and env->lladdr assignments so we don't update them when an alignment fault occurs.
Since we have a handy MemOpIdx, replace the legacy cpu_ld*_mmuidx_ra() calls by cpu_ld*_mmu() equivalent.
--- target/mips/tcg/ldst_helper.c | 26 +++++++++++++++----------- target/mips/tcg/translate.c | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-)
target/mips/tcg/ldst_helper.c +15 -11
@@ -28,23 +28,27 @@#include "internal.h" #ifndef CONFIG_USER_ONLY +#include "accel/tcg/probe.h" +#include "exec/tlb-flags.h" #define HELPER_LD_ATOMIC (name, insn, almask, do_cast) \ target_ulong helper_##name(CPUMIPSState *env, target_ulong arg, \ uint32_t memop_idx) \ { \ - MemOpIdx oi = memop_idx; \ - unsigned mem_idx = get_mmuidx(oi); \ - if (arg & almask) { \ - if (!(env->hflags & MIPS_HFLAG_DM)) { \ - env->CP0_BadVAddr = arg; \ - } \ - do_raise_exception(env, EXCP_AdEL, GETPC()); \ - } \ - env->CP0_LLAddr = cpu_mips_translate_address(env, arg, MMU_DATA_LOAD, \ - GETPC()); \ + MemOpIdx oi = memop_idx; \ + unsigned mem_idx = get_mmuidx(oi); \ + unsigned size = memop_size(get_memop(oi)); \ + uintptr_t ra = GETPC(); \ + CPUTLBEntryFull *full; \ + void *host_unused; \ + int flags; \ + \ + env->llval = do_cast cpu_##insn##_mmu(env, arg, oi, ra); \ + flags = probe_access_full(env, arg, size, MMU_DATA_LOAD, mem_idx, \ + true, &host_unused, &full, ra); \ + assert(!(flags & TLB_INVALID_MASK)); \ + env->CP0_LLAddr = full->phys_addr; \ env->lladdr = arg; \ - env->llval = do_cast cpu_##insn##_mmuidx_ra(env, arg, mem_idx, GETPC()); \ return env->llval; \ }HELPER_LD_ATOMIC (ll, ldl,0x3 , (target_long)(int32_t))
target/mips/tcg/translate.c +1 -1
@@ -1936,7 +1936,7 @@ static inline void op_ld_##insn(TCGv ret, TCGv arg1, int mem_idx_ignored, \ static inline void op_ld_##insn(TCGv ret, TCGv arg1, int mem_idx, \ DisasContext *ctx) \ { \ - MemOpIdx oi = make_memop_idx(memop, mem_idx); \ + MemOpIdx oi = make_memop_idx(memop | MO_ALIGN, mem_idx); \ gen_helper_##insn(ret, tcg_env, arg1, tcg_constant_i32(oi)); \ }#endif
Signature · 1 line
2.53.0
Re: [PATCH v6 2/4] target/mips: Inline cpu_ld/st_mmuidx_ra() calls in Atomic LD/ST helpers
Quoted 15 lines · Philippe Mathieu-Daudé
Have callers set
MO_ALIGNin the MemOp bits.Perform the access first, filling the TLB in the process. If the tlb cannot be filled, access is not permitted, and an exception is raised. Thus remove the now unnecessary
do_raise_exception()call.Since the TLB is filled, use
probe_access()to getCP0_LLAddr.Move
env->CP0_LLAddrandenv->lladdrassignments so we don't update them when an alignment fault occurs.Since we have a handy MemOpIdx, replace the legacy cpu_ld*_mmuidx_ra() calls by cpu_ld*_mmu() equivalent.
Quoted 6 lines
Suggested-by Richard Henderson<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/mips/tcg/ldst_helper.c | 26 +++++++++++++++----------- target/mips/tcg/translate.c | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-)
r~
PATCH v6 3/4 target/mips: Inline translator_ld[uw,l,q]() calls
In reply to Philippe Mathieu-DaudéIn preparation of removing the translator_ld[uw,l,q]() methods, inline them for the MIPS target, expanding MO_TE by a runtime check on mo_endian(ctx).
Mechanical change using the following Coccinelle 'spatch' script:
@@
expression env, db, pc;
@@
(
- translator_lduw(env, db, pc)
+ translator_lduw_end(env, db, pc, mo_endian(ctx)) |
- translator_ldl(env, db, pc)
+ translator_ldl_end(env, db, pc, mo_endian(ctx)) |
- translator_ldq(env, db, pc)
+ translator_ldq_end(env, db, pc, mo_endian(ctx)) )
--- target/mips/tcg/translate.c | 12 ++++++++---- target/mips/tcg/micromips_translate.c.inc | 2 +- target/mips/tcg/mips16e_translate.c.inc | 6 ++++-- target/mips/tcg/nanomips_translate.c.inc | 5 +++-- 4 files changed, 16 insertions(+), 9 deletions(-)
target/mips/tcg/translate.c +8 -4
@@ -15147,17 +15147,21 @@ static void mips_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) is_slot = ctx->hflags &MIPS_HFLAG_BMASK ;if (ctx->insn_flags &ISA_NANOMIPS32 ) { - ctx->opcode =translator_lduw (env, &ctx->base, ctx->base.pc_next); + ctx->opcode =translator_lduw_end (env, &ctx->base, ctx->base.pc_next, +mo_endian (ctx)); insn_bytes =decode_isa_nanomips (env, ctx); }else if (!(ctx->hflags &MIPS_HFLAG_M16 )) { - ctx->opcode =translator_ldl (env, &ctx->base, ctx->base.pc_next); + ctx->opcode =translator_ldl_end (env, &ctx->base, ctx->base.pc_next, +mo_endian (ctx)); insn_bytes =4 ;decode_opc (env, ctx); }else if (ctx->insn_flags &ASE_MICROMIPS ) { - ctx->opcode =translator_lduw (env, &ctx->base, ctx->base.pc_next); + ctx->opcode =translator_lduw_end (env, &ctx->base, ctx->base.pc_next, +mo_endian (ctx)); insn_bytes =decode_isa_micromips (env, ctx); }else if (ctx->insn_flags &ASE_MIPS16 ) { - ctx->opcode =translator_lduw (env, &ctx->base, ctx->base.pc_next); + ctx->opcode =translator_lduw_end (env, &ctx->base, ctx->base.pc_next, +mo_endian (ctx)); insn_bytes =decode_ase_mips16e (env, ctx); }else {gen_reserved_instruction (ctx);
target/mips/tcg/micromips_translate.c.inc +1 -1
@@ -1623,7 +1623,7 @@ static void decode_micromips32_opc(CPUMIPSState *env, DisasContext *ctx) uint32_t op, minor, minor2, mips32_op; uint32_t cond, fmt, cc; - insn = translator_lduw(env, &ctx->base, ctx->base.pc_next + 2); + insn = translator_lduw_end(env, &ctx->base, ctx->base.pc_next + 2, mo_endian(ctx)); ctx->opcode = (ctx->opcode << 16) | insn; rt = (ctx->opcode >> 21) & 0x1f;
target/mips/tcg/mips16e_translate.c.inc +4 -2
@@ -453,7 +453,8 @@ static void decode_i64_mips16(DisasContext *ctx, static int decode_extended_mips16_opc(CPUMIPSState *env, DisasContext *ctx) { - int extend = translator_lduw(env, &ctx->base, ctx->base.pc_next + 2); + int extend = translator_lduw_end(env, &ctx->base, ctx->base.pc_next + 2, + mo_endian(ctx)); int op, rx, ry, funct, sa; int16_t imm, offset;
@@ -686,7 +687,8 @@ static int decode_ase_mips16e(CPUMIPSState *env, DisasContext *ctx) /* No delay slot, so just process as a normal instruction */ break; case M16_OPC_JAL: - offset = translator_lduw(env, &ctx->base, ctx->base.pc_next + 2); + offset = translator_lduw_end(env, &ctx->base, ctx->base.pc_next + 2, + mo_endian(ctx)); offset = (((ctx->opcode & 0x1f) << 21) | ((ctx->opcode >> 5) & 0x1f) << 16 | offset) << 2;
target/mips/tcg/nanomips_translate.c.inc +3 -2
@@ -3551,7 +3551,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) int offset; int imm; - insn = translator_lduw(env, &ctx->base, ctx->base.pc_next + 2); + insn = translator_lduw_end(env, &ctx->base, ctx->base.pc_next + 2, mo_endian(ctx)); ctx->opcode = (ctx->opcode << 16) | insn; rt = extract32(ctx->opcode, 21, 5);
@@ -3665,7 +3665,8 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) break; case NM_P48I: { - insn = translator_lduw(env, &ctx->base, ctx->base.pc_next + 4); + insn = translator_lduw_end(env, &ctx->base, ctx->base.pc_next + 4, + mo_endian(ctx)); target_long addr_off = extract32(ctx->opcode, 0, 16) | insn << 16; switch (extract32(ctx->opcode, 16, 5)) { case NM_LI48:
Signature · 1 line
2.53.0
Re: [PATCH v6 3/4] target/mips: Inline translator_ld[uw,l,q]() calls
Quoted 20 lines · Philippe Mathieu-Daudé
In preparation of removing the translator_ld[uw,l,q]() methods, inline them for the MIPS target, expanding
MO_TEby a runtime check onmo_endian(ctx).Mechanical change using the following Coccinelle 'spatch' script:
@@ expression env, db, pc; @@ ( - translator_lduw(env, db, pc) + translator_lduw_end(env, db, pc, mo_endian(ctx)) | - translator_ldl(env, db, pc) + translator_ldl_end(env, db, pc, mo_endian(ctx)) | - translator_ldq(env, db, pc) + translator_ldq_end(env, db, pc, mo_endian(ctx)) )
Quoted 7 lines
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/mips/tcg/translate.c | 12 ++++++++---- target/mips/tcg/micromips_translate.c.inc | 2 +- target/mips/tcg/mips16e_translate.c.inc | 6 ++++-- target/mips/tcg/nanomips_translate.c.inc | 5 +++-- 4 files changed, 16 insertions(+), 9 deletions(-)
r~
PATCH v6 4/4 target/mips: Remove last MO_TE use
In reply to Philippe Mathieu-DaudéUnfortunately commit 54821ff6e90 ("target/mips: Convert mips16e decr_and_load/store() macros to functions") got rebased on top of commit 2803e24694c ("target/mips: Replace MO_TE by mo_endian") and we missed the replacement. Fix that.
--- target/mips/tcg/mips16e_translate.c.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/mips/tcg/mips16e_translate.c.inc +1 -1
@@ -293,7 +293,7 @@ static void decr_and_load(DisasContext *ctx, unsigned regidx, TCGv t0) tcg_gen_movi_tl(t2, -4); gen_op_addr_add(ctx, t0, t0, t2); - tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx, MO_TE | MO_SL | + tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx, mo_endian(ctx) | MO_SL | ctx->default_tcg_memop_mask); gen_store_gpr(t1, regidx); }
Signature · 1 line
2.53.0
Re: [PATCH v6 4/4] target/mips: Remove last MO_TE use
Quoted 15 lines · Philippe Mathieu-Daudé
Unfortunately commit
54821ff6e90("target/mips: Convert mips16e decr_and_load/store() macros to functions") got rebased on top of commit2803e24694c("target/mips: ReplaceMO_TEbymo_endian") and we missed the replacement. Fix that.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/tcg/mips16e_translate.c.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/mips/tcg/mips16e_translate.c.inc +0
-0
target/mips/tcg/mips16e_translate.c.inc static void decr_and_load(DisasContext *ctx, unsigned regidx, TCGv t0) · line 299
Quoted 8 lines
target/mips/tcg/mips16e_translate.c.inc +1
-1@@ -293,7 +293,7 @@ static void decr_and_load(DisasContext *ctx, unsigned regidx, TCGv t0) tcg_gen_movi_tl(t2, -4); gen_op_addr_add(ctx, t0, t0, t2); - tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx, MO_TE | MO_SL | + tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx, mo_endian(ctx) | MO_SL | ctx->default_tcg_memop_mask); gen_store_gpr(t1, regidx); }
r~
Quoted 6 lines · Philippe Mathieu-Daudé
Philippe Mathieu-Daudé (4):
target/mips: Pass MemOpIdx argument to Linked Load/Store helpers target/mips: Inline cpu_ld/st_mmuidx_ra() calls in Atomic LD/ST
helpers
target/mips: Inline translator_ld[uw,l,q]() calls target/mips: Remove lastMO_TEuse
Series queued, thanks.