Skip to contentSkip to conversation

target/mips: Use probe_access_full() in Atomic Load/Store helpers

PATCH In review Philippe Mathieu-Daudé 2 participants 4 messages Apr 16

lore
Share & tools
lore
#0 lore raw

v5 cover target/mips: Use probe_access_full() in Atomic Load/Store helpers

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é (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
#1 lore raw

PATCH v5 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
index e70a3942fac..10c6470514d 100644
@@ -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
index 10319bf03a6..b725c6d0333 100644
@@ -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
index 6d4b6412d70..839bfe18bab 100644
@@ -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
#2 lore raw

PATCH v5 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 (request MO_ALIGN in the MemOp bits).

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 +++++++++++++++------
 target/mips/tcg/translate.c   |  2 +-
 2 files changed, 16 insertions(+), 7 deletions(-)
target/mips/tcg/ldst_helper.c +15 -6
index b725c6d0333..4ebf72d610e 100644
@@ -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))
target/mips/tcg/translate.c +1 -1
index 839bfe18bab..4889bd1e518 100644
@@ -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