From: Peter Maydell <[email protected]> Currently our implementations of SysemuCPUOps::get_phys_page_debug and SysemuCPUOps::get_phys_page_attrs_debug are a mix of "accepts a non-page-aligned virtual address and returns the corresponding non-page-aligned physical address" and "only returns a page-aligned physical address". This is awkward for callsites, which in practice all want the physical address for an arbitrary virtual address and have to work around the possibility of getting a page-aligned address, and it doesn't account for protection being possibly on a sub-page-sized granularity. We want to standardize on the implementation having to handle non-page-aligned addresses.
s390x already has an implementation of "give me the actual physical address, not rounded down", in s390_get_phys_addr_debug(), so we can use this for the SysemuCPUOps::get_phys_page_debug method, and merge the s390_cpu_get_phys_page_debug() function into s390_get_phys_addr_debug() which is now its only caller. This leaves the function implementing the method with a name that doesn't match the method name, but we will fix that shortly by renaming the method to *_addr_* for all targets. Signed-off-by: Peter Maydell <[email protected]> Reviewed-by: Ilya Leoshkevich <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Message-id: [email protected] Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Message-ID: <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> --- target/s390x/s390x-internal.h | 1 - target/s390x/cpu-system.c | 2 +- target/s390x/helper.c | 20 +++++--------------- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/target/s390x/s390x-internal.h b/target/s390x/s390x-internal.h index 40850bcdc45..e7e4f2b45d4 100644 --- a/target/s390x/s390x-internal.h +++ b/target/s390x/s390x-internal.h @@ -321,7 +321,6 @@ void do_restart_interrupt(CPUS390XState *env); void s390x_tod_timer(void *opaque); void s390x_cpu_timer(void *opaque); void s390_handle_wait(S390CPU *cpu); -hwaddr s390_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); hwaddr s390_cpu_get_phys_addr_debug(CPUState *cpu, vaddr addr); LowCore *cpu_map_lowcore(CPUS390XState *env); void cpu_unmap_lowcore(CPUS390XState *env, LowCore *lowcore); diff --git a/target/s390x/cpu-system.c b/target/s390x/cpu-system.c index 285f5999661..c9daa633c14 100644 --- a/target/s390x/cpu-system.c +++ b/target/s390x/cpu-system.c @@ -176,7 +176,7 @@ void s390_cpu_finalize(Object *obj) static const struct SysemuCPUOps s390_sysemu_ops = { .has_work = s390_cpu_has_work, - .get_phys_page_debug = s390_cpu_get_phys_page_debug, + .get_phys_page_debug = s390_cpu_get_phys_addr_debug, .get_crash_info = s390_cpu_get_crash_info, .write_elf64_note = s390_cpu_write_elf64_note, .legacy_vmsd = &vmstate_s390_cpu, diff --git a/target/s390x/helper.c b/target/s390x/helper.c index 667d4a0da75..1a2658eaf93 100644 --- a/target/s390x/helper.c +++ b/target/s390x/helper.c @@ -39,7 +39,7 @@ void s390x_cpu_timer(void *opaque) cpu_inject_cpu_timer((S390CPU *) opaque); } -hwaddr s390_cpu_get_phys_page_debug(CPUState *cs, vaddr vaddr) +hwaddr s390_cpu_get_phys_addr_debug(CPUState *cs, vaddr addr) { S390CPU *cpu = S390_CPU(cs); CPUS390XState *env = &cpu->env; @@ -47,10 +47,11 @@ hwaddr s390_cpu_get_phys_page_debug(CPUState *cs, vaddr vaddr) int prot; uint64_t asc = env->psw.mask & PSW_MASK_ASC; uint64_t tec; + vaddr page = addr & TARGET_PAGE_MASK; /* 31-Bit mode */ if (!(env->psw.mask & PSW_MASK_64)) { - vaddr &= 0x7fffffff; + page &= 0x7fffffff; } /* We want to read the code (e.g., see what we are single-stepping).*/ @@ -62,24 +63,13 @@ hwaddr s390_cpu_get_phys_page_debug(CPUState *cs, vaddr vaddr) * We want to read code even if IEP is active. Use MMU_DATA_LOAD instead * of MMU_INST_FETCH. */ - if (mmu_translate(env, vaddr, MMU_DATA_LOAD, asc, &raddr, &prot, &tec)) { + if (mmu_translate(env, page, MMU_DATA_LOAD, asc, &raddr, &prot, &tec)) { return -1; } + raddr += (addr & ~TARGET_PAGE_MASK); return raddr; } -hwaddr s390_cpu_get_phys_addr_debug(CPUState *cs, vaddr v_addr) -{ - hwaddr phys_addr; - vaddr page; - - page = v_addr & TARGET_PAGE_MASK; - phys_addr = cpu_get_phys_page_debug(cs, page); - phys_addr += (v_addr & ~TARGET_PAGE_MASK); - - return phys_addr; -} - static inline bool is_special_wait_psw(uint64_t psw_addr) { /* signal quiesce */ -- 2.53.0
