Skip to contentSkip to conversation

cpus: Restrict SoftMMU mmu_index() to TCG

PATCH Applied Philippe Mathieu-Daudé 2 participants 31 messages Apr 1, 2025 – Apr 3, 2025 RISC-V

lore
Share & tools
lore
#0 lore raw

cover cpus: Restrict SoftMMU mmu_index() to TCG

mmu_index() is specific to TCG SoftMMU,
move CPUClass::mmu_index() to TCGCPUOps::mmu_index().

Philippe Mathieu-Daudé (24):
hw/core/cpu: Update CPUClass::mmu_index docstring accel/tcg: Introduce TCGCPUOps::mmu_index() callback target/alpha: Restrict SoftMMU mmu_index() to TCG target/arm: Restrict SoftMMU mmu_index() to TCG target/avr: Restrict SoftMMU mmu_index() to TCG target/hppa: Restrict SoftMMU mmu_index() to TCG target/i386: Remove unused cpu_(ldub,stb)_kernel macros target/i386: Restrict cpu_mmu_index_kernel() to TCG target/i386: Restrict SoftMMU mmu_index() to TCG target/loongarch: Restrict SoftMMU mmu_index() to TCG target/m68k: Restrict SoftMMU mmu_index() to TCG target/microblaze: Restrict SoftMMU mmu_index() to TCG target/mips: Restrict SoftMMU mmu_index() to TCG target/openrisc: Restrict SoftMMU mmu_index() to TCG target/ppc: Restrict SoftMMU mmu_index() to TCG target/riscv: Restrict SoftMMU mmu_index() to TCG target/rx: Restrict SoftMMU mmu_index() to TCG target/s390x: Restrict SoftMMU mmu_index() to TCG target/sh4: Restrict SoftMMU mmu_index() to TCG target/sparc: Restrict SoftMMU mmu_index() to TCG target/tricore: Restrict SoftMMU mmu_index() to TCG target/xtensa: Restrict SoftMMU mmu_index() to TCG hw/core/cpu: Remove CPUClass::mmu_index()
exec: Restrict cpu-mmu-index.h to accel/tcg/

 include/{exec => accel/tcg}/cpu-mmu-index.h |  9 +++---
 include/accel/tcg/cpu-ops.h                 |  3 ++
 include/exec/cpu_ldst.h                     |  2 +-
 include/hw/core/cpu.h                       |  3 --
 target/i386/cpu.h                           |  3 --
 target/i386/tcg/seg_helper.h                | 10 +++---
 target/i386/tcg/tcg-cpu.h                   |  2 ++
 accel/tcg/translator.c                      |  2 +-
 semihosting/uaccess.c                       |  2 +-
 target/alpha/cpu.c                          |  2 +-
 target/arm/cpu.c                            | 13 ++++----
 target/arm/gdbstub64.c                      |  2 +-
 target/avr/cpu.c                            |  2 +-
 target/hppa/cpu.c                           |  2 +-
 target/hppa/mem_helper.c                    |  2 +-
 target/i386/cpu.c                           | 34 ---------------------
 target/i386/tcg/seg_helper.c                | 17 +++++++++++
 target/i386/tcg/tcg-cpu.c                   | 18 +++++++++++
 target/i386/tcg/translate.c                 |  2 +-
 target/loongarch/cpu.c                      |  2 +-
 target/loongarch/cpu_helper.c               |  2 +-
 target/m68k/cpu.c                           |  2 +-
 target/microblaze/cpu.c                     |  2 +-
 target/microblaze/helper.c                  |  2 +-
 target/microblaze/mmu.c                     |  2 +-
 target/mips/cpu.c                           |  2 +-
 target/openrisc/cpu.c                       |  2 +-
 target/openrisc/translate.c                 |  2 +-
 target/ppc/cpu_init.c                       |  2 +-
 target/riscv/cpu.c                          |  6 ----
 target/riscv/tcg/tcg-cpu.c                  |  6 ++++
 target/rx/cpu.c                             |  2 +-
 target/s390x/cpu.c                          |  2 +-
 target/sh4/cpu.c                            |  2 +-
 target/sparc/cpu.c                          |  4 +--
 target/sparc/mmu_helper.c                   |  2 +-
 target/tricore/cpu.c                        |  2 +-
 target/tricore/helper.c                     |  2 +-
 target/xtensa/cpu.c                         |  2 +-
 target/xtensa/mmu_helper.c                  |  2 +-
 40 files changed, 91 insertions(+), 91 deletions(-)
 rename include/{exec => accel/tcg}/cpu-mmu-index.h (78%)
Signature · 1 line
2.47.1
#1 lore raw

PATCH 1/24 hw/core/cpu: Update CPUClass::mmu_index docstring

Since commits 32a8ea12fab..90b7022e698 (target: "Split out TARGET_env_mmu_index"), target's memory_rw_debug() callbacks use the target's TARGET_env_mmu_index(), not the generic CPUClass::mmu_index() callback. Update the documentation.

---
 include/hw/core/cpu.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/hw/core/cpu.h +1 -2
index 84a71d8cf17..60b7abaf49b 100644
@@ -104,8 +104,7 @@ struct SysemuCPUOps;
  *                 instantiatable CPU type.
  * @parse_features: Callback to parse command line arguments.
  * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
- * @mmu_index: Callback for choosing softmmu mmu index;
- *       may be used internally by memory_rw_debug without TCG.
+ * @mmu_index: Callback for choosing softmmu mmu index.
  * @memory_rw_debug: Callback for GDB memory access.
  * @dump_state: Callback for dumping state.
  * @query_cpu_fast:
Signature · 1 line
2.47.1
Reviewed-by on v1 1/24
#2 lore raw

Re: [PATCH-for-10.1 01/24] hw/core/cpu: Update CPUClass::mmu_index docstring

Quoted 9 lines · Philippe Mathieu-Daudé

Since commits 32a8ea12fab..90b7022e698 (target: "Split out TARGET_env_mmu_index"), target's memory_rw_debug() callbacks use the target's TARGET_env_mmu_index(), not the generic CPUClass::mmu_index() callback. Update the documentation.

---
  include/hw/core/cpu.h | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

r~

#3 lore raw

PATCH 2/24 accel/tcg: Introduce TCGCPUOps::mmu_index() callback

In reply to Philippe Mathieu-Daudé

We'll move CPUClass::mmu_index() to TCGCPUOps::mmu_index().

---
 include/accel/tcg/cpu-ops.h  | 3 +++
 include/exec/cpu-mmu-index.h | 5 ++++-
 2 files changed, 7 insertions(+), 1 deletion(-)
include/accel/tcg/cpu-ops.h +3 -0
index f60e5303f21..106a0688da8 100644
@@ -67,6 +67,9 @@ struct TCGCPUOps {
     /** @debug_excp_handler: Callback for handling debug exceptions */
     void (*debug_excp_handler)(CPUState *cpu);
 
+    /** @mmu_index: Callback for choosing softmmu mmu index */
+    int (*mmu_index)(CPUState *cpu, bool ifetch);
+
 #ifdef CONFIG_USER_ONLY
     /**
      * @fake_user_interrupt: Callback for 'fake exception' handling.
include/exec/cpu-mmu-index.h +4 -1
index cfc13d46bea..651526e9f97 100644
@@ -10,6 +10,7 @@
 #define EXEC_CPU_MMU_INDEX_H
 
 #include "hw/core/cpu.h"
+#include "accel/tcg/cpu-ops.h"
 #include "tcg/debug-assert.h"
 #ifdef COMPILING_PER_TARGET
 #include "cpu.h"
@@ -31,7 +32,9 @@ static inline int cpu_mmu_index(CPUState *cs, bool ifetch)
 # endif
 #endif
 
-    int ret = cs->cc->mmu_index(cs, ifetch);
+    const TCGCPUOps *tcg_ops = cs->cc->tcg_ops;
+    int ret = tcg_ops->mmu_index ? tcg_ops->mmu_index(cs, ifetch)
+                                 : cs->cc->mmu_index(cs, ifetch);
     tcg_debug_assert(ret >= 0 && ret < NB_MMU_MODES);
     return ret;
 }
Signature · 1 line
2.47.1
#5 lore raw

PATCH 3/24 target/alpha: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé
---
 target/alpha/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/alpha/cpu.c +1 -1
index 935ad2ee1ae..99d839a2792 100644
@@ -239,6 +239,7 @@ static const TCGCPUOps alpha_tcg_ops = {
     .translate_code = alpha_translate_code,
     .synchronize_from_tb = alpha_cpu_synchronize_from_tb,
     .restore_state_to_opc = alpha_restore_state_to_opc,
+    .mmu_index = alpha_cpu_mmu_index,
 
 #ifdef CONFIG_USER_ONLY
     .record_sigsegv = alpha_cpu_record_sigsegv,
@@ -263,7 +264,6 @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data)
                                     &acc->parent_realize);
 
     cc->class_by_name = alpha_cpu_class_by_name;
-    cc->mmu_index = alpha_cpu_mmu_index;
     cc->dump_state = alpha_cpu_dump_state;
     cc->set_pc = alpha_cpu_set_pc;
     cc->get_pc = alpha_cpu_get_pc;
Signature · 1 line
2.47.1
#6 lore raw

PATCH 4/24 target/arm: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé

Move arm_cpu_mmu_index() within CONFIG_TCG #ifdef'ry, convert CPUClass::mmu_index() to TCGCPUOps::mmu_index().

---
 target/arm/cpu.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
target/arm/cpu.c +7 -6
index f29661938c4..92909276f0f 100644
@@ -122,6 +122,12 @@ void arm_restore_state_to_opc(CPUState *cs,
         env->exception.syndrome = data[2] << ARM_INSN_START_WORD2_SHIFT;
     }
 }
+
+static int arm_cpu_mmu_index(CPUState *cs, bool ifetch)
+{
+    return arm_env_mmu_index(cpu_env(cs));
+}
+
 #endif /* CONFIG_TCG */
 
 #ifndef CONFIG_USER_ONLY
@@ -145,11 +151,6 @@ static bool arm_cpu_has_work(CPUState *cs)
 }
 #endif /* !CONFIG_USER_ONLY */
 
-static int arm_cpu_mmu_index(CPUState *cs, bool ifetch)
-{
-    return arm_env_mmu_index(cpu_env(cs));
-}
-
 void arm_register_pre_el_change_hook(ARMCPU *cpu, ARMELChangeHookFn *hook,
                                  void *opaque)
 {
@@ -2676,6 +2677,7 @@ static const TCGCPUOps arm_tcg_ops = {
     .debug_excp_handler = arm_debug_excp_handler,
     .restore_state_to_opc = arm_restore_state_to_opc,
 
+    .mmu_index = arm_cpu_mmu_index,
 #ifdef CONFIG_USER_ONLY
     .record_sigsegv = arm_cpu_record_sigsegv,
     .record_sigbus = arm_cpu_record_sigbus,
@@ -2709,7 +2711,6 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
                                        &acc->parent_phases);
 
     cc->class_by_name = arm_cpu_class_by_name;
-    cc->mmu_index = arm_cpu_mmu_index;
     cc->dump_state = arm_cpu_dump_state;
     cc->set_pc = arm_cpu_set_pc;
     cc->get_pc = arm_cpu_get_pc;
Signature · 1 line
2.47.1
#7 lore raw

PATCH 5/24 target/avr: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé
---
 target/avr/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/avr/cpu.c +1 -1
index 11218224704..feb73e722b3 100644
@@ -228,6 +228,7 @@ static const TCGCPUOps avr_tcg_ops = {
     .translate_code = avr_cpu_translate_code,
     .synchronize_from_tb = avr_cpu_synchronize_from_tb,
     .restore_state_to_opc = avr_restore_state_to_opc,
+    .mmu_index = avr_cpu_mmu_index,
     .cpu_exec_interrupt = avr_cpu_exec_interrupt,
     .cpu_exec_halt = avr_cpu_has_work,
     .tlb_fill = avr_cpu_tlb_fill,
@@ -250,7 +251,6 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data)
 
     cc->class_by_name = avr_cpu_class_by_name;
 
-    cc->mmu_index = avr_cpu_mmu_index;
     cc->dump_state = avr_cpu_dump_state;
     cc->set_pc = avr_cpu_set_pc;
     cc->get_pc = avr_cpu_get_pc;
Signature · 1 line
2.47.1
#8 lore raw

PATCH 6/24 target/hppa: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé
---
 target/hppa/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/hppa/cpu.c +1 -1
index 0da8cdf41f5..51bff0c5d62 100644
@@ -257,6 +257,7 @@ static const TCGCPUOps hppa_tcg_ops = {
     .translate_code = hppa_translate_code,
     .synchronize_from_tb = hppa_cpu_synchronize_from_tb,
     .restore_state_to_opc = hppa_restore_state_to_opc,
+    .mmu_index = hppa_cpu_mmu_index,
 
 #ifndef CONFIG_USER_ONLY
     .tlb_fill_align = hppa_cpu_tlb_fill_align,
@@ -282,7 +283,6 @@ static void hppa_cpu_class_init(ObjectClass *oc, void *data)
                                        &acc->parent_phases);
 
     cc->class_by_name = hppa_cpu_class_by_name;
-    cc->mmu_index = hppa_cpu_mmu_index;
     cc->dump_state = hppa_cpu_dump_state;
     cc->set_pc = hppa_cpu_set_pc;
     cc->get_pc = hppa_cpu_get_pc;
Signature · 1 line
2.47.1
#9 lore raw

PATCH 7/24 target/i386: Remove unused cpu_(ldub, stb)_kernel macros

In reply to Philippe Mathieu-Daudé
---
 target/i386/tcg/seg_helper.h | 6 ------
 1 file changed, 6 deletions(-)
target/i386/tcg/seg_helper.h +0 -6
index ebf10352778..6b8606cd6d8 100644
@@ -35,8 +35,6 @@
  * TODO: Convert callers to compute cpu_mmu_index_kernel once
  * and use *_mmuidx_ra directly.
  */
-#define cpu_ldub_kernel_ra(e, p, r) \
-    cpu_ldub_mmuidx_ra(e, p, cpu_mmu_index_kernel(e), r)
 #define cpu_lduw_kernel_ra(e, p, r) \
     cpu_lduw_mmuidx_ra(e, p, cpu_mmu_index_kernel(e), r)
 #define cpu_ldl_kernel_ra(e, p, r) \
@@ -44,8 +42,6 @@
 #define cpu_ldq_kernel_ra(e, p, r) \
     cpu_ldq_mmuidx_ra(e, p, cpu_mmu_index_kernel(e), r)
 
-#define cpu_stb_kernel_ra(e, p, v, r) \
-    cpu_stb_mmuidx_ra(e, p, v, cpu_mmu_index_kernel(e), r)
 #define cpu_stw_kernel_ra(e, p, v, r) \
     cpu_stw_mmuidx_ra(e, p, v, cpu_mmu_index_kernel(e), r)
 #define cpu_stl_kernel_ra(e, p, v, r) \
@@ -53,12 +49,10 @@
 #define cpu_stq_kernel_ra(e, p, v, r) \
     cpu_stq_mmuidx_ra(e, p, v, cpu_mmu_index_kernel(e), r)
 
-#define cpu_ldub_kernel(e, p)    cpu_ldub_kernel_ra(e, p, 0)
 #define cpu_lduw_kernel(e, p)    cpu_lduw_kernel_ra(e, p, 0)
 #define cpu_ldl_kernel(e, p)     cpu_ldl_kernel_ra(e, p, 0)
 #define cpu_ldq_kernel(e, p)     cpu_ldq_kernel_ra(e, p, 0)
 
-#define cpu_stb_kernel(e, p, v)  cpu_stb_kernel_ra(e, p, v, 0)
 #define cpu_stw_kernel(e, p, v)  cpu_stw_kernel_ra(e, p, v, 0)
 #define cpu_stl_kernel(e, p, v)  cpu_stl_kernel_ra(e, p, v, 0)
 #define cpu_stq_kernel(e, p, v)  cpu_stq_kernel_ra(e, p, v, 0)
Signature · 1 line
2.47.1
#10 lore raw

PATCH 8/24 target/i386: Restrict cpu_mmu_index_kernel() to TCG

In reply to Philippe Mathieu-Daudé

Move cpu_mmu_index_kernel() to seg_helper.c.

---
 target/i386/cpu.h            |  1 -
 target/i386/tcg/seg_helper.h |  4 ++++
 target/i386/cpu.c            | 16 ----------------
 target/i386/tcg/seg_helper.c | 16 ++++++++++++++++
 4 files changed, 20 insertions(+), 17 deletions(-)
target/i386/cpu.h +0 -1
index 44ee263d8f1..e23a947a7c7 100644
@@ -2598,7 +2598,6 @@ static inline bool is_mmu_index_32(int mmu_index)
 }
 
 int x86_mmu_index_pl(CPUX86State *env, unsigned pl);
-int cpu_mmu_index_kernel(CPUX86State *env);
 
 #define CC_DST  (env->cc_dst)
 #define CC_SRC  (env->cc_src)
target/i386/tcg/seg_helper.h +4 -0
index 6b8606cd6d8..ea98e1a98ed 100644
@@ -20,6 +20,8 @@
 #ifndef SEG_HELPER_H
 #define SEG_HELPER_H
 
+#include "cpu.h"
+
 //#define DEBUG_PCALL
 
 #ifdef DEBUG_PCALL
@@ -31,6 +33,8 @@
 # define LOG_PCALL_STATE(cpu) do { } while (0)
 #endif
 
+int cpu_mmu_index_kernel(CPUX86State *env);
+
 /*
  * TODO: Convert callers to compute cpu_mmu_index_kernel once
  * and use *_mmuidx_ra directly.
target/i386/cpu.c +0 -16
index af46c7a392a..0b74b9a3754 100644
@@ -8669,22 +8669,6 @@ static int x86_cpu_mmu_index(CPUState *cs, bool ifetch)
     return x86_mmu_index_pl(env, env->hflags & HF_CPL_MASK);
 }
 
-static int x86_mmu_index_kernel_pl(CPUX86State *env, unsigned pl)
-{
-    int mmu_index_32 = (env->hflags & HF_LMA_MASK) ? 0 : 1;
-    int mmu_index_base =
-        !(env->hflags & HF_SMAP_MASK) ? MMU_KNOSMAP64_IDX :
-        (pl < 3 && (env->eflags & AC_MASK)
-         ? MMU_KNOSMAP64_IDX : MMU_KSMAP64_IDX);
-
-    return mmu_index_base + mmu_index_32;
-}
-
-int cpu_mmu_index_kernel(CPUX86State *env)
-{
-    return x86_mmu_index_kernel_pl(env, env->hflags & HF_CPL_MASK);
-}
-
 static void x86_disas_set_info(CPUState *cs, disassemble_info *info)
 {
     X86CPU *cpu = X86_CPU(cs);
target/i386/tcg/seg_helper.c +16 -0
index 71962113fb8..f4370202fed 100644
@@ -128,6 +128,22 @@ int get_pg_mode(CPUX86State *env)
     return pg_mode;
 }
 
+static int x86_mmu_index_kernel_pl(CPUX86State *env, unsigned pl)
+{
+    int mmu_index_32 = (env->hflags & HF_LMA_MASK) ? 0 : 1;
+    int mmu_index_base =
+        !(env->hflags & HF_SMAP_MASK) ? MMU_KNOSMAP64_IDX :
+        (pl < 3 && (env->eflags & AC_MASK)
+         ? MMU_KNOSMAP64_IDX : MMU_KSMAP64_IDX);
+
+    return mmu_index_base + mmu_index_32;
+}
+
+int cpu_mmu_index_kernel(CPUX86State *env)
+{
+    return x86_mmu_index_kernel_pl(env, env->hflags & HF_CPL_MASK);
+}
+
 /* return non zero if error */
 static inline int load_segment_ra(CPUX86State *env, uint32_t *e1_ptr,
                                uint32_t *e2_ptr, int selector,
Signature · 1 line
2.47.1
#11 lore raw

PATCH 9/24 target/i386: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé

Move x86_cpu_mmu_index() to tcg-cpu.c, convert
CPUClass::mmu_index() to TCGCPUOps::mmu_index().

---
 target/i386/cpu.h            |  2 --
 target/i386/tcg/tcg-cpu.h    |  2 ++
 target/i386/cpu.c            | 18 ------------------
 target/i386/tcg/seg_helper.c |  1 +
 target/i386/tcg/tcg-cpu.c    | 18 ++++++++++++++++++
 5 files changed, 21 insertions(+), 20 deletions(-)
target/i386/cpu.h +0 -2
index e23a947a7c7..35c16302bdc 100644
@@ -2597,8 +2597,6 @@ static inline bool is_mmu_index_32(int mmu_index)
     return mmu_index & 1;
 }
 
-int x86_mmu_index_pl(CPUX86State *env, unsigned pl);
-
 #define CC_DST  (env->cc_dst)
 #define CC_SRC  (env->cc_src)
 #define CC_SRC2 (env->cc_src2)
target/i386/tcg/tcg-cpu.h +2 -0
index 53a84944551..7580f8afb4f 100644
@@ -78,4 +78,6 @@ QEMU_BUILD_BUG_ON(offsetof(X86XSaveArea, pkru_state) != XSAVE_PKRU_OFFSET);
 
 bool tcg_cpu_realizefn(CPUState *cs, Error **errp);
 
+int x86_mmu_index_pl(CPUX86State *env, unsigned pl);
+
 #endif /* TCG_CPU_H */
target/i386/cpu.c +0 -18
index 0b74b9a3754..d930ebd262e 100644
@@ -8652,23 +8652,6 @@ static bool x86_cpu_has_work(CPUState *cs)
 }
 #endif /* !CONFIG_USER_ONLY */
 
-int x86_mmu_index_pl(CPUX86State *env, unsigned pl)
-{
-    int mmu_index_32 = (env->hflags & HF_CS64_MASK) ? 0 : 1;
-    int mmu_index_base =
-        pl == 3 ? MMU_USER64_IDX :
-        !(env->hflags & HF_SMAP_MASK) ? MMU_KNOSMAP64_IDX :
-        (env->eflags & AC_MASK) ? MMU_KNOSMAP64_IDX : MMU_KSMAP64_IDX;
-
-    return mmu_index_base + mmu_index_32;
-}
-
-static int x86_cpu_mmu_index(CPUState *cs, bool ifetch)
-{
-    CPUX86State *env = cpu_env(cs);
-    return x86_mmu_index_pl(env, env->hflags & HF_CPL_MASK);
-}
-
 static void x86_disas_set_info(CPUState *cs, disassemble_info *info)
 {
     X86CPU *cpu = X86_CPU(cs);
@@ -8910,7 +8893,6 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
 
     cc->class_by_name = x86_cpu_class_by_name;
     cc->parse_features = x86_cpu_parse_featurestr;
-    cc->mmu_index = x86_cpu_mmu_index;
     cc->dump_state = x86_cpu_dump_state;
     cc->set_pc = x86_cpu_set_pc;
     cc->get_pc = x86_cpu_get_pc;
target/i386/tcg/seg_helper.c +1 -0
index f4370202fed..9dfbc4208cd 100644
@@ -28,6 +28,7 @@
 #include "helper-tcg.h"
 #include "seg_helper.h"
 #include "access.h"
+#include "tcg-cpu.h"
 
 #ifdef TARGET_X86_64
 #define SET_ESP(val, sp_mask)                                   \
target/i386/tcg/tcg-cpu.c +18 -0
index 36b8dc78a3e..35b17f2b183 100644
@@ -94,6 +94,23 @@ static void x86_restore_state_to_opc(CPUState *cs,
     }
 }
 
+int x86_mmu_index_pl(CPUX86State *env, unsigned pl)
+{
+    int mmu_index_32 = (env->hflags & HF_CS64_MASK) ? 0 : 1;
+    int mmu_index_base =
+        pl == 3 ? MMU_USER64_IDX :
+        !(env->hflags & HF_SMAP_MASK) ? MMU_KNOSMAP64_IDX :
+        (env->eflags & AC_MASK) ? MMU_KNOSMAP64_IDX : MMU_KSMAP64_IDX;
+
+    return mmu_index_base + mmu_index_32;
+}
+
+static int x86_cpu_mmu_index(CPUState *cs, bool ifetch)
+{
+    CPUX86State *env = cpu_env(cs);
+    return x86_mmu_index_pl(env, env->hflags & HF_CPL_MASK);
+}
+
 #ifndef CONFIG_USER_ONLY
 static bool x86_debug_check_breakpoint(CPUState *cs)
 {
@@ -112,6 +129,7 @@ static const TCGCPUOps x86_tcg_ops = {
     .translate_code = x86_translate_code,
     .synchronize_from_tb = x86_cpu_synchronize_from_tb,
     .restore_state_to_opc = x86_restore_state_to_opc,
+    .mmu_index = x86_cpu_mmu_index,
     .cpu_exec_enter = x86_cpu_exec_enter,
     .cpu_exec_exit = x86_cpu_exec_exit,
 #ifdef CONFIG_USER_ONLY
Signature · 1 line
2.47.1
#12 lore raw

PATCH 10/24 target/loongarch: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé
---
 target/loongarch/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/loongarch/cpu.c +1 -1
index ea1665e2705..cb96b17911a 100644
@@ -868,6 +868,7 @@ static const TCGCPUOps loongarch_tcg_ops = {
     .translate_code = loongarch_translate_code,
     .synchronize_from_tb = loongarch_cpu_synchronize_from_tb,
     .restore_state_to_opc = loongarch_restore_state_to_opc,
+    .mmu_index = loongarch_cpu_mmu_index,
 
 #ifndef CONFIG_USER_ONLY
     .tlb_fill = loongarch_cpu_tlb_fill,
@@ -919,7 +920,6 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data)
                                        &lacc->parent_phases);
 
     cc->class_by_name = loongarch_cpu_class_by_name;
-    cc->mmu_index = loongarch_cpu_mmu_index;
     cc->dump_state = loongarch_cpu_dump_state;
     cc->set_pc = loongarch_cpu_set_pc;
     cc->get_pc = loongarch_cpu_get_pc;
Signature · 1 line
2.47.1
#13 lore raw

PATCH 11/24 target/m68k: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé
---
 target/m68k/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/m68k/cpu.c +1 -1
index 0065e1c1ca5..4409d8941ce 100644
@@ -592,6 +592,7 @@ static const TCGCPUOps m68k_tcg_ops = {
     .initialize = m68k_tcg_init,
     .translate_code = m68k_translate_code,
     .restore_state_to_opc = m68k_restore_state_to_opc,
+    .mmu_index = m68k_cpu_mmu_index,
 
 #ifndef CONFIG_USER_ONLY
     .tlb_fill = m68k_cpu_tlb_fill,
@@ -615,7 +616,6 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data)
                                        &mcc->parent_phases);
 
     cc->class_by_name = m68k_cpu_class_by_name;
-    cc->mmu_index = m68k_cpu_mmu_index;
     cc->dump_state = m68k_cpu_dump_state;
     cc->set_pc = m68k_cpu_set_pc;
     cc->get_pc = m68k_cpu_get_pc;
Signature · 1 line
2.47.1
#14 lore raw

PATCH 12/24 target/microblaze: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé
---
 target/microblaze/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/microblaze/cpu.c +1 -1
index f3bebea856e..88baeb6807a 100644
@@ -431,6 +431,7 @@ static const TCGCPUOps mb_tcg_ops = {
     .translate_code = mb_translate_code,
     .synchronize_from_tb = mb_cpu_synchronize_from_tb,
     .restore_state_to_opc = mb_restore_state_to_opc,
+    .mmu_index = mb_cpu_mmu_index,
 
 #ifndef CONFIG_USER_ONLY
     .tlb_fill = mb_cpu_tlb_fill,
@@ -455,7 +456,6 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data)
                                        &mcc->parent_phases);
 
     cc->class_by_name = mb_cpu_class_by_name;
-    cc->mmu_index = mb_cpu_mmu_index;
     cc->dump_state = mb_cpu_dump_state;
     cc->set_pc = mb_cpu_set_pc;
     cc->get_pc = mb_cpu_get_pc;
Signature · 1 line
2.47.1
#15 lore raw

PATCH 13/24 target/mips: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé
---
 target/mips/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/mips/cpu.c +1 -1
index 47df563e123..269d3d69bd5 100644
@@ -554,6 +554,7 @@ static const TCGCPUOps mips_tcg_ops = {
     .translate_code = mips_translate_code,
     .synchronize_from_tb = mips_cpu_synchronize_from_tb,
     .restore_state_to_opc = mips_restore_state_to_opc,
+    .mmu_index = mips_cpu_mmu_index,
 
 #if !defined(CONFIG_USER_ONLY)
     .tlb_fill = mips_cpu_tlb_fill,
@@ -581,7 +582,6 @@ static void mips_cpu_class_init(ObjectClass *c, void *data)
                                        &mcc->parent_phases);
 
     cc->class_by_name = mips_cpu_class_by_name;
-    cc->mmu_index = mips_cpu_mmu_index;
     cc->dump_state = mips_cpu_dump_state;
     cc->set_pc = mips_cpu_set_pc;
     cc->get_pc = mips_cpu_get_pc;
Signature · 1 line
2.47.1
#16 lore raw

PATCH 14/24 target/openrisc: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé
---
 target/openrisc/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/openrisc/cpu.c +1 -1
index e8abf1f8b5c..dc55594a7de 100644
@@ -247,6 +247,7 @@ static const TCGCPUOps openrisc_tcg_ops = {
     .translate_code = openrisc_translate_code,
     .synchronize_from_tb = openrisc_cpu_synchronize_from_tb,
     .restore_state_to_opc = openrisc_restore_state_to_opc,
+    .mmu_index = openrisc_cpu_mmu_index,
 
 #ifndef CONFIG_USER_ONLY
     .tlb_fill = openrisc_cpu_tlb_fill,
@@ -269,7 +270,6 @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data)
                                        &occ->parent_phases);
 
     cc->class_by_name = openrisc_cpu_class_by_name;
-    cc->mmu_index = openrisc_cpu_mmu_index;
     cc->dump_state = openrisc_cpu_dump_state;
     cc->set_pc = openrisc_cpu_set_pc;
     cc->get_pc = openrisc_cpu_get_pc;
Signature · 1 line
2.47.1
#17 lore raw

PATCH 15/24 target/ppc: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé
---
 target/ppc/cpu_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/cpu_init.c +1 -1
index 3686bbc9380..30238e9a223 100644
@@ -7481,6 +7481,7 @@ static const TCGCPUOps ppc_tcg_ops = {
   .initialize = ppc_translate_init,
   .translate_code = ppc_translate_code,
   .restore_state_to_opc = ppc_restore_state_to_opc,
+  .mmu_index = ppc_cpu_mmu_index,
 
 #ifdef CONFIG_USER_ONLY
   .record_sigsegv = ppc_cpu_record_sigsegv,
@@ -7517,7 +7518,6 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)
                                        &pcc->parent_phases);
 
     cc->class_by_name = ppc_cpu_class_by_name;
-    cc->mmu_index = ppc_cpu_mmu_index;
     cc->dump_state = ppc_cpu_dump_state;
     cc->set_pc = ppc_cpu_set_pc;
     cc->get_pc = ppc_cpu_get_pc;
Signature · 1 line
2.47.1
#18 lore raw

PATCH 16/24 target/riscv: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé

Move riscv_cpu_mmu_index() to the TCG-specific file, convert CPUClass::mmu_index() to TCGCPUOps::mmu_index().

---
 target/riscv/cpu.c         | 6 ------
 target/riscv/tcg/tcg-cpu.c | 6 ++++++
 2 files changed, 6 insertions(+), 6 deletions(-)
target/riscv/cpu.c +0 -6
index 09ded6829a2..430b02d2a58 100644
@@ -1021,11 +1021,6 @@ bool riscv_cpu_has_work(CPUState *cs)
 }
 #endif /* !CONFIG_USER_ONLY */
 
-static int riscv_cpu_mmu_index(CPUState *cs, bool ifetch)
-{
-    return riscv_env_mmu_index(cpu_env(cs), ifetch);
-}
-
 static void riscv_cpu_reset_hold(Object *obj, ResetType type)
 {
 #ifndef CONFIG_USER_ONLY
@@ -3049,7 +3044,6 @@ static void riscv_cpu_common_class_init(ObjectClass *c, void *data)
                                        &mcc->parent_phases);
 
     cc->class_by_name = riscv_cpu_class_by_name;
-    cc->mmu_index = riscv_cpu_mmu_index;
     cc->dump_state = riscv_cpu_dump_state;
     cc->set_pc = riscv_cpu_set_pc;
     cc->get_pc = riscv_cpu_get_pc;
target/riscv/tcg/tcg-cpu.c +6 -0
index e539b0266f3..710449d17e8 100644
@@ -92,6 +92,11 @@ static const char *cpu_priv_ver_to_str(int priv_ver)
     return priv_spec_str;
 }
 
+static int riscv_cpu_mmu_index(CPUState *cs, bool ifetch)
+{
+    return riscv_env_mmu_index(cpu_env(cs), ifetch);
+}
+
 static void riscv_cpu_synchronize_from_tb(CPUState *cs,
                                           const TranslationBlock *tb)
 {
@@ -139,6 +144,7 @@ static const TCGCPUOps riscv_tcg_ops = {
     .translate_code = riscv_translate_code,
     .synchronize_from_tb = riscv_cpu_synchronize_from_tb,
     .restore_state_to_opc = riscv_restore_state_to_opc,
+    .mmu_index = riscv_cpu_mmu_index,
 
 #ifndef CONFIG_USER_ONLY
     .tlb_fill = riscv_cpu_tlb_fill,
Signature · 1 line
2.47.1
#19 lore raw

PATCH 17/24 target/rx: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé
---
 target/rx/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/rx/cpu.c +1 -1
index 723262f4b54..e14d9cbef93 100644
@@ -208,6 +208,7 @@ static const TCGCPUOps rx_tcg_ops = {
     .translate_code = rx_translate_code,
     .synchronize_from_tb = rx_cpu_synchronize_from_tb,
     .restore_state_to_opc = rx_restore_state_to_opc,
+    .mmu_index = rx_cpu_mmu_index,
     .tlb_fill = rx_cpu_tlb_fill,
 
     .cpu_exec_interrupt = rx_cpu_exec_interrupt,
@@ -228,7 +229,6 @@ static void rx_cpu_class_init(ObjectClass *klass, void *data)
                                        &rcc->parent_phases);
 
     cc->class_by_name = rx_cpu_class_by_name;
-    cc->mmu_index = rx_cpu_mmu_index;
     cc->dump_state = rx_cpu_dump_state;
     cc->set_pc = rx_cpu_set_pc;
     cc->get_pc = rx_cpu_get_pc;
Signature · 1 line
2.47.1
#20 lore raw

PATCH 18/24 target/s390x: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé
---
 target/s390x/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/cpu.c +1 -1
index 1f75629ddc2..320ace67198 100644
@@ -348,6 +348,7 @@ static const TCGCPUOps s390_tcg_ops = {
     .initialize = s390x_translate_init,
     .translate_code = s390x_translate_code,
     .restore_state_to_opc = s390x_restore_state_to_opc,
+    .mmu_index = s390x_cpu_mmu_index,
 
 #ifdef CONFIG_USER_ONLY
     .record_sigsegv = s390_cpu_record_sigsegv,
@@ -378,7 +379,6 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)
                                        &scc->parent_phases);
 
     cc->class_by_name = s390_cpu_class_by_name;
-    cc->mmu_index = s390x_cpu_mmu_index;
     cc->dump_state = s390_cpu_dump_state;
     cc->query_cpu_fast = s390_query_cpu_fast;
     cc->set_pc = s390_cpu_set_pc;
Signature · 1 line
2.47.1
#21 lore raw

PATCH 19/24 target/sh4: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé
---
 target/sh4/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/sh4/cpu.c +1 -1
index ce84bdf539a..df093988cb1 100644
@@ -266,6 +266,7 @@ static const TCGCPUOps superh_tcg_ops = {
     .translate_code = sh4_translate_code,
     .synchronize_from_tb = superh_cpu_synchronize_from_tb,
     .restore_state_to_opc = superh_restore_state_to_opc,
+    .mmu_index = sh4_cpu_mmu_index,
 
 #ifndef CONFIG_USER_ONLY
     .tlb_fill = superh_cpu_tlb_fill,
@@ -291,7 +292,6 @@ static void superh_cpu_class_init(ObjectClass *oc, void *data)
                                        &scc->parent_phases);
 
     cc->class_by_name = superh_cpu_class_by_name;
-    cc->mmu_index = sh4_cpu_mmu_index;
     cc->dump_state = superh_cpu_dump_state;
     cc->set_pc = superh_cpu_set_pc;
     cc->get_pc = superh_cpu_get_pc;
Signature · 1 line
2.47.1
#22 lore raw

PATCH 20/24 target/sparc: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé
---
 target/sparc/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/sparc/cpu.c +1 -1
index 1bf00407af7..072d5da5736 100644
@@ -1005,6 +1005,7 @@ static const TCGCPUOps sparc_tcg_ops = {
     .translate_code = sparc_translate_code,
     .synchronize_from_tb = sparc_cpu_synchronize_from_tb,
     .restore_state_to_opc = sparc_restore_state_to_opc,
+    .mmu_index = sparc_cpu_mmu_index,
 
 #ifndef CONFIG_USER_ONLY
     .tlb_fill = sparc_cpu_tlb_fill,
@@ -1033,7 +1034,6 @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data)
 
     cc->class_by_name = sparc_cpu_class_by_name;
     cc->parse_features = sparc_cpu_parse_features;
-    cc->mmu_index = sparc_cpu_mmu_index;
     cc->dump_state = sparc_cpu_dump_state;
 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
     cc->memory_rw_debug = sparc_cpu_memory_rw_debug;
Signature · 1 line
2.47.1
#23 lore raw

PATCH 21/24 target/tricore: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé
---
 target/tricore/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/tricore/cpu.c +1 -1
index 16acc4ecb92..833a93d37af 100644
@@ -176,6 +176,7 @@ static const TCGCPUOps tricore_tcg_ops = {
     .translate_code = tricore_translate_code,
     .synchronize_from_tb = tricore_cpu_synchronize_from_tb,
     .restore_state_to_opc = tricore_restore_state_to_opc,
+    .mmu_index = tricore_cpu_mmu_index,
     .tlb_fill = tricore_cpu_tlb_fill,
     .cpu_exec_interrupt = tricore_cpu_exec_interrupt,
     .cpu_exec_halt = tricore_cpu_has_work,
@@ -194,7 +195,6 @@ static void tricore_cpu_class_init(ObjectClass *c, void *data)
     resettable_class_set_parent_phases(rc, NULL, tricore_cpu_reset_hold, NULL,
                                        &mcc->parent_phases);
     cc->class_by_name = tricore_cpu_class_by_name;
-    cc->mmu_index = tricore_cpu_mmu_index;
 
     cc->gdb_read_register = tricore_cpu_gdb_read_register;
     cc->gdb_write_register = tricore_cpu_gdb_write_register;
Signature · 1 line
2.47.1
#24 lore raw

PATCH 22/24 target/xtensa: Restrict SoftMMU mmu_index() to TCG

In reply to Philippe Mathieu-Daudé
---
 target/xtensa/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/xtensa/cpu.c +1 -1
index ec6a0a8b662..51f9ee9e89a 100644
@@ -236,6 +236,7 @@ static const TCGCPUOps xtensa_tcg_ops = {
     .translate_code = xtensa_translate_code,
     .debug_excp_handler = xtensa_breakpoint_handler,
     .restore_state_to_opc = xtensa_restore_state_to_opc,
+    .mmu_index = xtensa_cpu_mmu_index,
 
 #ifndef CONFIG_USER_ONLY
     .tlb_fill = xtensa_cpu_tlb_fill,
@@ -262,7 +263,6 @@ static void xtensa_cpu_class_init(ObjectClass *oc, void *data)
                                        &xcc->parent_phases);
 
     cc->class_by_name = xtensa_cpu_class_by_name;
-    cc->mmu_index = xtensa_cpu_mmu_index;
     cc->dump_state = xtensa_cpu_dump_state;
     cc->set_pc = xtensa_cpu_set_pc;
     cc->get_pc = xtensa_cpu_get_pc;
Signature · 1 line
2.47.1
#25 lore raw

PATCH 23/24 hw/core/cpu: Remove CPUClass::mmu_index()

In reply to Philippe Mathieu-Daudé

All targets have been converted to TCGCPUOps::mmu_index(), remove the now unused CPUClass::mmu_index().

---
 include/exec/cpu-mmu-index.h | 4 +---
 include/hw/core/cpu.h        | 2 --
 2 files changed, 1 insertion(+), 5 deletions(-)
include/exec/cpu-mmu-index.h +1 -3
index 651526e9f97..a87b6f7c4b7 100644
@@ -32,9 +32,7 @@ static inline int cpu_mmu_index(CPUState *cs, bool ifetch)
 # endif
 #endif
 
-    const TCGCPUOps *tcg_ops = cs->cc->tcg_ops;
-    int ret = tcg_ops->mmu_index ? tcg_ops->mmu_index(cs, ifetch)
-                                 : cs->cc->mmu_index(cs, ifetch);
+    int ret = cs->cc->tcg_ops->mmu_index(cs, ifetch);
     tcg_debug_assert(ret >= 0 && ret < NB_MMU_MODES);
     return ret;
 }
include/hw/core/cpu.h +0 -2
index 60b7abaf49b..10b6b25b344 100644
@@ -104,7 +104,6 @@ struct SysemuCPUOps;
  *                 instantiatable CPU type.
  * @parse_features: Callback to parse command line arguments.
  * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
- * @mmu_index: Callback for choosing softmmu mmu index.
  * @memory_rw_debug: Callback for GDB memory access.
  * @dump_state: Callback for dumping state.
  * @query_cpu_fast:
@@ -151,7 +150,6 @@ struct CPUClass {
     ObjectClass *(*class_by_name)(const char *cpu_model);
     void (*parse_features)(const char *typename, char *str, Error **errp);
 
-    int (*mmu_index)(CPUState *cpu, bool ifetch);
     int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
                            uint8_t *buf, size_t len, bool is_write);
     void (*dump_state)(CPUState *cpu, FILE *, int flags);
Signature · 1 line
2.47.1
#26 lore raw

Re: [PATCH-for-10.1 23/24] hw/core/cpu: Remove CPUClass::mmu_index()

Quoted 37 lines · Philippe Mathieu-Daudé

All targets have been converted to TCGCPUOps::mmu_index(), remove the now unused CPUClass::mmu_index().

---
  include/exec/cpu-mmu-index.h | 4 +---
  include/hw/core/cpu.h        | 2 --
  2 files changed, 1 insertion(+), 5 deletions(-)
include/exec/cpu-mmu-index.h +1 -3
index 651526e9f97..a87b6f7c4b7 100644
@@ -32,9 +32,7 @@ static inline int cpu_mmu_index(CPUState *cs, bool ifetch)
  # endif
  #endif
 
-    const TCGCPUOps *tcg_ops = cs->cc->tcg_ops;
-    int ret = tcg_ops->mmu_index ? tcg_ops->mmu_index(cs, ifetch)
-                                 : cs->cc->mmu_index(cs, ifetch);
+    int ret = cs->cc->tcg_ops->mmu_index(cs, ifetch);
      tcg_debug_assert(ret >= 0 && ret < NB_MMU_MODES);
      return ret;
  }
include/hw/core/cpu.h +0 -1
index 60b7abaf49b..10b6b25b344 100644
@@ -104,7 +104,6 @@ struct SysemuCPUOps;
   *                 instantiatable CPU type.
   * @parse_features: Callback to parse command line arguments.
   * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
- * @mmu_index: Callback for choosing softmmu mmu index.
   * @memory_rw_debug: Callback for GDB memory access.
   * @dump_state: Callback for dumping state.
   * @query_cpu_fast:

include/hw/core/cpu.h struct CPUClass { · line 155

Quoted 7 lines
include/hw/core/cpu.h +0 -1
@@ -151,7 +150,6 @@ struct CPUClass {
      ObjectClass *(*class_by_name)(const char *cpu_model);
      void (*parse_features)(const char *typename, char *str, Error **errp);
 
-    int (*mmu_index)(CPUState *cpu, bool ifetch);
      int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
                             uint8_t *buf, size_t len, bool is_write);
      void (*dump_state)(CPUState *cpu, FILE *, int flags);

And I'll squash:

-- >8 --

accel/tcg/cpu-exec.c +1 -0
index 8057a5a0ce8..b00f046b29f 100644
@@ -1077,6 +1077,7 @@ bool tcg_exec_realizefn(CPUState *cpu, Error **errp)
         assert(tcg_ops->cpu_exec_interrupt);
 #endif /* !CONFIG_USER_ONLY */
         assert(tcg_ops->translate_code);
+        assert(tcg_ops->mmu_index);
         tcg_ops->initialize();
         tcg_target_initialized = true;
     }

---

Reviewed-by
#27 lore raw

Re: [PATCH-for-10.1 23/24] hw/core/cpu: Remove CPUClass::mmu_index()

Quoted 52 lines · Philippe Mathieu-Daudé
Quoted 36 lines · Philippe Mathieu-Daudé

All targets have been converted to TCGCPUOps::mmu_index(), remove the now unused CPUClass::mmu_index().

---
  include/exec/cpu-mmu-index.h | 4 +---
  include/hw/core/cpu.h        | 2 --

  2 files changed, 1 insertion(+), 5 deletions(-)
include/exec/cpu-mmu-index.h +1 -3
index 651526e9f97..a87b6f7c4b7 100644
@@ -32,9 +32,7 @@ static inline int cpu_mmu_index(CPUState *cs, bool ifetch)
   # endif
   #endif
-    const TCGCPUOps *tcg_ops = cs->cc->tcg_ops;
-    int ret = tcg_ops->mmu_index ? tcg_ops->mmu_index(cs, ifetch)
-                                 : cs->cc->mmu_index(cs, ifetch);
+    int ret = cs->cc->tcg_ops->mmu_index(cs, ifetch);
       tcg_debug_assert(ret >= 0 && ret < NB_MMU_MODES);
       return ret;
   }
include/hw/core/cpu.h +0 -1
index 60b7abaf49b..10b6b25b344 100644
@@ -104,7 +104,6 @@ struct SysemuCPUOps;
    *                 instantiatable CPU type.
    * @parse_features: Callback to parse command line arguments.
    * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
- * @mmu_index: Callback for choosing softmmu mmu index.
    * @memory_rw_debug: Callback for GDB memory access.
    * @dump_state: Callback for dumping state.
    * @query_cpu_fast:

include/hw/core/cpu.h struct CPUClass { · line 154

Quoted 6 lines
include/hw/core/cpu.h +0 -1
@@ -151,7 +150,6 @@ struct CPUClass {
       ObjectClass *(*class_by_name)(const char *cpu_model);
       void (*parse_features)(const char *typename, char *str, Error **errp);
-    int (*mmu_index)(CPUState *cpu, bool ifetch);
       int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
                              uint8_t *buf, size_t len, bool is_write);
       void (*dump_state)(CPUState *cpu, FILE *, int flags);

And I'll squash:

-- >8 --

accel/tcg/cpu-exec.c +0 -0
index 8057a5a0ce8..b00f046b29f 100644

accel/tcg/cpu-exec.c bool tcg_exec_realizefn(CPUState *cpu, Error **errp)

Quoted 8 lines
accel/tcg/cpu-exec.c +1 -1
@@ -1077,6 +1077,7 @@ bool tcg_exec_realizefn(CPUState *cpu, Error **errp)
          assert(tcg_ops->cpu_exec_interrupt);
  #endif /* !CONFIG_USER_ONLY */
          assert(tcg_ops->translate_code);
+        assert(tcg_ops->mmu_index);
          tcg_ops->initialize();
          tcg_target_initialized = true;
      }
---

r~

#28 lore raw

PATCH 24/24 exec: Restrict cpu-mmu-index.h to accel/tcg/

In reply to Philippe Mathieu-Daudé
---
 include/{exec => accel/tcg}/cpu-mmu-index.h | 6 +++---
 include/exec/cpu_ldst.h                     | 2 +-
 accel/tcg/translator.c                      | 2 +-
 semihosting/uaccess.c                       | 2 +-
 target/arm/gdbstub64.c                      | 2 +-
 target/hppa/mem_helper.c                    | 2 +-
 target/i386/tcg/translate.c                 | 2 +-
 target/loongarch/cpu_helper.c               | 2 +-
 target/microblaze/helper.c                  | 2 +-
 target/microblaze/mmu.c                     | 2 +-
 target/openrisc/translate.c                 | 2 +-
 target/sparc/cpu.c                          | 2 +-
 target/sparc/mmu_helper.c                   | 2 +-
 target/tricore/helper.c                     | 2 +-
 target/xtensa/mmu_helper.c                  | 2 +-
 15 files changed, 17 insertions(+), 17 deletions(-)
 rename include/{exec => accel/tcg}/cpu-mmu-index.h (87%)
include/accel/tcg/cpu-mmu-index.h renamed from include/exec/cpu-mmu-index.h +3 -3
similarity index 87%
rename from include/exec/cpu-mmu-index.h
rename to include/accel/tcg/cpu-mmu-index.h
index a87b6f7c4b7..3699c18b4cb 100644
@@ -6,8 +6,8 @@
  * SPDX-License-Identifier: LGPL-2.1-or-later
  */
 
-#ifndef EXEC_CPU_MMU_INDEX_H
-#define EXEC_CPU_MMU_INDEX_H
+#ifndef ACCEL_TCG_CPU_MMU_INDEX_H
+#define ACCEL_TCG_CPU_MMU_INDEX_H
 
 #include "hw/core/cpu.h"
 #include "accel/tcg/cpu-ops.h"
@@ -37,4 +37,4 @@ static inline int cpu_mmu_index(CPUState *cs, bool ifetch)
     return ret;
 }
 
-#endif /* EXEC_CPU_MMU_INDEX_H */
+#endif /* ACCEL_TCG_CPU_MMU_INDEX_H */
include/exec/cpu_ldst.h +1 -1
index 313100fcda1..63847f6e618 100644
@@ -68,7 +68,7 @@
 
 #include "exec/cpu-common.h"
 #include "exec/cpu-ldst-common.h"
-#include "exec/cpu-mmu-index.h"
+#include "accel/tcg/cpu-mmu-index.h"
 #include "exec/abi_ptr.h"
 
 #if defined(CONFIG_USER_ONLY)
accel/tcg/translator.c +1 -1
index 36a6a9e0408..c53bbdef99f 100644
@@ -12,7 +12,7 @@
 #include "qemu/log.h"
 #include "qemu/error-report.h"
 #include "exec/cpu-ldst-common.h"
-#include "exec/cpu-mmu-index.h"
+#include "accel/tcg/cpu-mmu-index.h"
 #include "exec/target_page.h"
 #include "exec/translator.h"
 #include "exec/plugin-gen.h"
semihosting/uaccess.c +1 -1
index 92b2421dce5..81ffecaaba4 100644
@@ -8,7 +8,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "exec/cpu-mmu-index.h"
+#include "accel/tcg/cpu-mmu-index.h"
 #include "exec/exec-all.h"
 #include "exec/target_page.h"
 #include "exec/tlb-flags.h"
target/arm/gdbstub64.c +1 -1
index 3bbca4cbb98..64ee9b3b567 100644
@@ -28,7 +28,7 @@
 #include "mte_user_helper.h"
 #endif
 #ifdef CONFIG_TCG
-#include "exec/cpu-mmu-index.h"
+#include "accel/tcg/cpu-mmu-index.h"
 #include "exec/target_page.h"
 #endif
 
target/hppa/mem_helper.c +1 -1
index df4e35f4de6..554d7bf4d14 100644
@@ -22,7 +22,7 @@
 #include "cpu.h"
 #include "exec/exec-all.h"
 #include "exec/cputlb.h"
-#include "exec/cpu-mmu-index.h"
+#include "accel/tcg/cpu-mmu-index.h"
 #include "exec/page-protection.h"
 #include "exec/target_page.h"
 #include "exec/helper-proto.h"
target/i386/tcg/translate.c +1 -1
index 7e6d1ef9379..ca49f8d6dcb 100644
@@ -20,7 +20,7 @@
 
 #include "qemu/host-utils.h"
 #include "cpu.h"
-#include "exec/cpu-mmu-index.h"
+#include "accel/tcg/cpu-mmu-index.h"
 #include "exec/exec-all.h"
 #include "exec/translation-block.h"
 #include "tcg/tcg-op.h"
target/loongarch/cpu_helper.c +1 -1
index 4597e29b153..bb343078bf7 100644
@@ -8,7 +8,7 @@
 
 #include "qemu/osdep.h"
 #include "cpu.h"
-#include "exec/cpu-mmu-index.h"
+#include "accel/tcg/cpu-mmu-index.h"
 #include "exec/target_page.h"
 #include "internals.h"
 #include "cpu-csr.h"
target/microblaze/helper.c +1 -1
index 9e6969ccc9a..92031924830 100644
@@ -21,7 +21,7 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "exec/cputlb.h"
-#include "exec/cpu-mmu-index.h"
+#include "accel/tcg/cpu-mmu-index.h"
 #include "exec/page-protection.h"
 #include "exec/target_page.h"
 #include "qemu/host-utils.h"
target/microblaze/mmu.c +1 -1
index 7f20c4e4c69..95a12e16f8e 100644
@@ -22,7 +22,7 @@
 #include "qemu/log.h"
 #include "cpu.h"
 #include "exec/cputlb.h"
-#include "exec/cpu-mmu-index.h"
+#include "accel/tcg/cpu-mmu-index.h"
 #include "exec/page-protection.h"
 #include "exec/target_page.h"
 
target/openrisc/translate.c +1 -1
index 4a8e203cf88..d4ce60188bd 100644
@@ -20,7 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "cpu.h"
-#include "exec/cpu-mmu-index.h"
+#include "accel/tcg/cpu-mmu-index.h"
 #include "exec/exec-all.h"
 #include "tcg/tcg-op.h"
 #include "qemu/log.h"
target/sparc/cpu.c +1 -1
index 072d5da5736..af3cec43e78 100644
@@ -22,7 +22,7 @@
 #include "cpu.h"
 #include "qemu/module.h"
 #include "qemu/qemu-print.h"
-#include "exec/cpu-mmu-index.h"
+#include "accel/tcg/cpu-mmu-index.h"
 #include "exec/exec-all.h"
 #include "exec/translation-block.h"
 #include "hw/qdev-properties.h"
target/sparc/mmu_helper.c +1 -1
index b3351eebd0a..217580a4d8c 100644
@@ -21,7 +21,7 @@
 #include "qemu/log.h"
 #include "cpu.h"
 #include "exec/cputlb.h"
-#include "exec/cpu-mmu-index.h"
+#include "accel/tcg/cpu-mmu-index.h"
 #include "exec/page-protection.h"
 #include "exec/target_page.h"
 #include "exec/tlb-flags.h"
target/tricore/helper.c +1 -1
index a5ae5bcb619..e4c53d453dd 100644
@@ -20,7 +20,7 @@
 #include "hw/registerfields.h"
 #include "cpu.h"
 #include "exec/cputlb.h"
-#include "exec/cpu-mmu-index.h"
+#include "accel/tcg/cpu-mmu-index.h"
 #include "exec/page-protection.h"
 #include "exec/target_page.h"
 #include "fpu/softfloat-helpers.h"
target/xtensa/mmu_helper.c +1 -1
index 45601a4b850..a7dd8100555 100644
@@ -33,7 +33,7 @@
 #include "exec/helper-proto.h"
 #include "qemu/host-utils.h"
 #include "exec/cputlb.h"
-#include "exec/cpu-mmu-index.h"
+#include "accel/tcg/cpu-mmu-index.h"
 #include "exec/exec-all.h"
 #include "exec/page-protection.h"
 #include "exec/target_page.h"
Signature · 1 line
2.47.1
Reviewed-by on the v1 series
#29 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 20 lines · Philippe Mathieu-Daudé

mmu_index() is specific to TCG SoftMMU, moveCPUClass::mmu_index() toTCGCPUOps::mmu_index().

Philippe Mathieu-Daudé (24):
hw/core/cpu: UpdateCPUClass::mmu_index docstring accel/tcg: IntroduceTCGCPUOps::mmu_index() callback target/alpha: Restrict SoftMMU mmu_index() to TCG target/arm: Restrict SoftMMU mmu_index() to TCG target/avr: Restrict SoftMMU mmu_index() to TCG target/hppa: Restrict SoftMMU mmu_index() to TCG target/i386: Remove unused cpu_(ldub,stb)_kernel macros target/i386: Restrict cpu_mmu_index_kernel() to TCG target/i386: Restrict SoftMMU mmu_index() to TCG target/loongarch: Restrict SoftMMU mmu_index() to TCG target/m68k: Restrict SoftMMU mmu_index() to TCG target/microblaze: Restrict SoftMMU mmu_index() to TCG target/mips: Restrict SoftMMU mmu_index() to TCG target/openrisc: Restrict SoftMMU mmu_index() to TCG target/ppc: Restrict SoftMMU mmu_index() to TCG target/riscv: Restrict SoftMMU mmu_index() to TCG

Quoted 8 lines

target/rx: Restrict SoftMMU mmu_index() to TCG target/s390x: Restrict SoftMMU mmu_index() to TCG target/sh4: Restrict SoftMMU mmu_index() to TCG target/sparc: Restrict SoftMMU mmu_index() to TCG target/tricore: Restrict SoftMMU mmu_index() to TCG target/xtensa: Restrict SoftMMU mmu_index() to TCG hw/core/cpu: RemoveCPUClass::mmu_index()
exec: Restrict cpu-mmu-index.h to accel/tcg/

r~

#30 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 20 lines · Philippe Mathieu-Daudé

mmu_index() is specific to TCG SoftMMU, moveCPUClass::mmu_index() toTCGCPUOps::mmu_index().

Philippe Mathieu-Daudé (24):
hw/core/cpu: UpdateCPUClass::mmu_index docstring accel/tcg: IntroduceTCGCPUOps::mmu_index() callback target/alpha: Restrict SoftMMU mmu_index() to TCG target/arm: Restrict SoftMMU mmu_index() to TCG target/avr: Restrict SoftMMU mmu_index() to TCG target/hppa: Restrict SoftMMU mmu_index() to TCG target/i386: Remove unused cpu_(ldub,stb)_kernel macros target/i386: Restrict cpu_mmu_index_kernel() to TCG target/i386: Restrict SoftMMU mmu_index() to TCG target/loongarch: Restrict SoftMMU mmu_index() to TCG target/m68k: Restrict SoftMMU mmu_index() to TCG target/microblaze: Restrict SoftMMU mmu_index() to TCG target/mips: Restrict SoftMMU mmu_index() to TCG target/openrisc: Restrict SoftMMU mmu_index() to TCG target/ppc: Restrict SoftMMU mmu_index() to TCG target/riscv: Restrict SoftMMU mmu_index() to TCG

Quoted 8 lines

target/rx: Restrict SoftMMU mmu_index() to TCG target/s390x: Restrict SoftMMU mmu_index() to TCG target/sh4: Restrict SoftMMU mmu_index() to TCG target/sparc: Restrict SoftMMU mmu_index() to TCG target/tricore: Restrict SoftMMU mmu_index() to TCG target/xtensa: Restrict SoftMMU mmu_index() to TCG hw/core/cpu: RemoveCPUClass::mmu_index()
exec: Restrict cpu-mmu-index.h to accel/tcg/

Queued to tcg-next, including the addition of the assert.

r~