@samitouri / QOSamiQemu / commits / abefca8e7f

target/arm: Implement translate_for_debug

Implement the translate_for_debug method instead of the get_phys_addr_attrs_debug one. This allows us to pass the caller the lg_page_size from our internal GetPhysAddrResult struct. Awkwardly, translate_for_debug's "true on success" convention is the opposite of the one we use internally in ptw.c, so we have to be careful about the sense of the return values. This corresponds to the way that arm_cpu_tlb_fill_align() also has to return true when get_phys_addr() returns false. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-id: 20260417173105.1648172-17-peter.maydell@linaro.org Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-ID: <20260430093810.2762539-18-peter.maydell@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Peter Maydell committed Apr 30, 2026 at 10:38 UTC abefca8e7f957fe78ed84455ee907ef1142ed671
4 files changed +28 -20
target/arm/cpu.c
+1 -1
@@ -2498,7 +2498,7 @@ static vaddr aarch64_untagged_addr(CPUState *cs, vaddr x)
2498
2499 static const struct SysemuCPUOps arm_sysemu_ops = {
2500 .has_work = arm_cpu_has_work,
2501 - .get_phys_addr_attrs_debug = arm_cpu_get_phys_addr_attrs_debug,
2501 + .translate_for_debug = arm_cpu_translate_for_debug,
2502 .asidx_from_attrs = arm_asidx_from_attrs,
2503 .write_elf32_note = arm_cpu_write_elf32_note,
2504 .write_elf64_note = arm_cpu_write_elf64_note,
target/arm/cpu.h
-3
@@ -1260,9 +1260,6 @@ extern const VMStateDescription vmstate_arm_cpu;
1260 void arm_cpu_do_interrupt(CPUState *cpu);
1261 void arm_v7m_cpu_do_interrupt(CPUState *cpu);
1262
1263 -hwaddr arm_cpu_get_phys_addr_attrs_debug(CPUState *cpu, vaddr addr,
1264 - MemTxAttrs *attrs);
1265 -
1263 typedef struct ARMGranuleProtectionConfig {
1264 /* GPCCR_EL3 */
1265 uint64_t gpccr;
target/arm/internals.h
+4
@@ -1540,6 +1540,10 @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
1540
1541 void arm_log_exception(CPUState *cs);
1542
1543 +/* Implementation of SysemuCPUOps::translate_for_debug */
1544 +bool arm_cpu_translate_for_debug(CPUState *cs, vaddr addr,
1545 + TranslateForDebugResult *result);
1546 +
1547 #endif /* !CONFIG_USER_ONLY */
1548
1549 /*
target/arm/ptw.c
+23 -16
@@ -3942,8 +3942,9 @@ bool get_phys_addr(CPUARMState *env, vaddr address,
3942 memop, result, fi);
3943 }
3944
3945 -static hwaddr arm_cpu_get_phys_addr(CPUARMState *env, vaddr addr,
3946 - MemTxAttrs *attrs, ARMMMUIdx mmu_idx)
3945 +static bool arm_cpu_get_phys_addr(CPUARMState *env, vaddr addr,
3946 + TranslateForDebugResult *result,
3947 + ARMMMUIdx mmu_idx)
3948 {
3949 S1Translate ptw = {
3950 .in_mmu_idx = mmu_idx,
@@ -3954,26 +3955,31 @@ static hwaddr arm_cpu_get_phys_addr(CPUARMState *env, vaddr addr,
3955 };
3956 GetPhysAddrResult res = {};
3957 ARMMMUFaultInfo fi = {};
3957 - bool ret = get_phys_addr_gpc(env, &ptw, addr, MMU_DATA_LOAD, 0, &res, &fi);
3958 - *attrs = res.f.attrs;
3958 + bool fault = get_phys_addr_gpc(env, &ptw, addr, MMU_DATA_LOAD, 0, &res, &fi);
3959
3960 - if (ret) {
3961 - return -1;
3960 + if (!fault) {
3961 + /* translation succeeded */
3962 + result->physaddr = res.f.phys_addr;
3963 + result->attrs = res.f.attrs;
3964 + result->lg_page_size = res.f.lg_page_size;
3965 }
3963 - return res.f.phys_addr;
3966 + return fault;
3967 }
3968
3966 -hwaddr arm_cpu_get_phys_addr_attrs_debug(CPUState *cs, vaddr addr,
3967 - MemTxAttrs *attrs)
3969 +bool arm_cpu_translate_for_debug(CPUState *cs, vaddr addr,
3970 + TranslateForDebugResult *result)
3971 {
3972 ARMCPU *cpu = ARM_CPU(cs);
3973 CPUARMState *env = &cpu->env;
3974 ARMMMUIdx mmu_idx = arm_mmu_idx(env);
3975
3973 - hwaddr res = arm_cpu_get_phys_addr(env, addr, attrs, mmu_idx);
3974 -
3975 - if (res != -1) {
3976 - return res;
3976 + /*
3977 + * Note that this function returns true on translation success,
3978 + * but arm_cpu_get_phys_addr() and all the other get_phys_addr
3979 + * style functions in this file return true on failure.
3980 + */
3981 + if (!arm_cpu_get_phys_addr(env, addr, result, mmu_idx)) {
3982 + return true;
3983 }
3984
3985 /*
@@ -3984,11 +3990,12 @@ hwaddr arm_cpu_get_phys_addr_attrs_debug(CPUState *cs, vaddr addr,
3990 switch (mmu_idx) {
3991 case ARMMMUIdx_E10_1:
3992 case ARMMMUIdx_E10_1_PAN:
3987 - return arm_cpu_get_phys_addr(env, addr, attrs, ARMMMUIdx_E10_0);
3993 + return !arm_cpu_get_phys_addr(env, addr, result, ARMMMUIdx_E10_0);
3994 case ARMMMUIdx_E20_2:
3995 case ARMMMUIdx_E20_2_PAN:
3990 - return arm_cpu_get_phys_addr(env, addr, attrs, ARMMMUIdx_E20_0);
3996 + return !arm_cpu_get_phys_addr(env, addr, result, ARMMMUIdx_E20_0);
3997 default:
3992 - return -1;
3998 + /* translation failed */
3999 + return false;
4000 }
4001 }