target/mips: Use probe_access_full() in Atomic Load/Store helpers
v4 cover target/mips: Use probe_access_full() in Atomic Load/Store helpers
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é (2):
target/mips: Pass MemOpIdx argument to Linked Load/Store helpers target/mips: Use probe_access_full() in Atomic Load/Store helpers
target/mips/helper.h | 4 ++-- target/mips/tcg/ldst_helper.c | 22 +++++++++++++++++----- target/mips/tcg/translate.c | 7 ++++--- 3 files changed, 23 insertions(+), 10 deletions(-)
Signature · 1 line
2.53.0
PATCH v4 1/2 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 | MO_ALIGN, 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 v4 1/2] target/mips: Pass MemOpIdx argument to Linked Load/Store helpers
Quoted 16 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.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(-)
target/mips/tcg/translate.c static inline void op_ld_##insn(TCGv ret, TCGv arg1, int mem_idx, \ · line 1939
Quoted 7 lines
target/mips/tcg/translate.c +2
-2-#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 | MO_ALIGN, mem_idx); \
Oops, MO_ALIGN is part of the following patch.
Quoted 4 lines
+ gen_helper_##insn(ret,
tcg_env, arg1,tcg_constant_i32(oi)); \
}
#endif
OP_LD_ATOMIC(ll, mo_endian(ctx) | MO_SL);
PATCH v4 2/2 target/mips: Use probe_access_full() in Atomic Load/Store helpers
In reply to Philippe Mathieu-DaudéLet the probe_access() API check the address alignment.
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 | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
target/mips/tcg/ldst_helper.c +15 -6
@@ -28,23 +28,32 @@#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) { \ + 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); \ + if (unlikely(flags & TLB_INVALID_MASK)) { \ 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()); \ + 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))
Signature · 1 line
2.53.0
Quoted 1 line · Philippe Mathieu-Daudé
Let the
probe_access()API check the address alignment.
The probe_access will not check the alignment.
The use of the memory access before the probe checks the alignment.
Quoted 30 lines
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.
Suggested-by Richard Henderson <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/tcg/ldst_helper.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)target/mips/tcg/ldst_helper.c +2
-2@@ -28,23 +28,32 @@#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); \
target/mips/tcg/ldst_helper.c line 46
Quoted 10 lines
target/mips/tcg/ldst_helper.c +9
-1-if (arg & almask) { \ +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); \
This performs the access, filling the tlb in the process.
If the tlb cannot be filled, access is not permitted an an exception is raised.
target/mips/tcg/ldst_helper.c line 48
Quoted 2 lines
target/mips/tcg/ldst_helper.c +2
-0+ flags =probe_access_full (env, arg, size,MMU_DATA_LOAD , mem_idx, \ + true, &host_unused, &full, ra); \
Which means this probe for the tlb entry *must* succeed, because we can't reach here unless it was confirmed present by the access above.
target/mips/tcg/ldst_helper.c line 49
Quoted 1 line
target/mips/tcg/ldst_helper.c +1
-0+if (unlikely (flags &TLB_INVALID_MASK )) {
Which means this must be
assert(!(flags & TLB_INVALID_MASK));
\target/mips/tcg/ldst_helper.c line 58
Quoted 5 lines
target/mips/tcg/ldst_helper.c +0
-0if (!(env->hflags &MIPS_HFLAG_DM )) { \ env->CP0_BadVAddr = arg; \ } \do_raise_exception (env, EXCP_AdEL,GETPC ()); \ }
... and the rest of the IF is dead code.
r~