@samitouri / QOSamiQemu / commits / dfdf349889

target/s390x: Make get_phys_page_debug handle non-page-aligned addrs

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 <peter.maydell@linaro.org> Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20260417173105.1648172-7-peter.maydell@linaro.org Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20260430093810.2762539-8-peter.maydell@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Peter Maydell committed Apr 30, 2026 at 10:37 UTC dfdf349889a4a6af41fad1e4ee401004753597c3
3 files changed +6 -17
target/s390x/cpu-system.c
+1 -1
@@ -176,7 +176,7 @@ void s390_cpu_finalize(Object *obj)
176
177 static const struct SysemuCPUOps s390_sysemu_ops = {
178 .has_work = s390_cpu_has_work,
179 - .get_phys_page_debug = s390_cpu_get_phys_page_debug,
179 + .get_phys_page_debug = s390_cpu_get_phys_addr_debug,
180 .get_crash_info = s390_cpu_get_crash_info,
181 .write_elf64_note = s390_cpu_write_elf64_note,
182 .legacy_vmsd = &vmstate_s390_cpu,
target/s390x/helper.c
+5 -15
@@ -39,7 +39,7 @@ void s390x_cpu_timer(void *opaque)
39 cpu_inject_cpu_timer((S390CPU *) opaque);
40 }
41
42 -hwaddr s390_cpu_get_phys_page_debug(CPUState *cs, vaddr vaddr)
42 +hwaddr s390_cpu_get_phys_addr_debug(CPUState *cs, vaddr addr)
43 {
44 S390CPU *cpu = S390_CPU(cs);
45 CPUS390XState *env = &cpu->env;
@@ -47,10 +47,11 @@ hwaddr s390_cpu_get_phys_page_debug(CPUState *cs, vaddr vaddr)
47 int prot;
48 uint64_t asc = env->psw.mask & PSW_MASK_ASC;
49 uint64_t tec;
50 + vaddr page = addr & TARGET_PAGE_MASK;
51
52 /* 31-Bit mode */
53 if (!(env->psw.mask & PSW_MASK_64)) {
53 - vaddr &= 0x7fffffff;
54 + page &= 0x7fffffff;
55 }
56
57 /* 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)
63 * We want to read code even if IEP is active. Use MMU_DATA_LOAD instead
64 * of MMU_INST_FETCH.
65 */
65 - if (mmu_translate(env, vaddr, MMU_DATA_LOAD, asc, &raddr, &prot, &tec)) {
66 + if (mmu_translate(env, page, MMU_DATA_LOAD, asc, &raddr, &prot, &tec)) {
67 return -1;
68 }
69 + raddr += (addr & ~TARGET_PAGE_MASK);
70 return raddr;
71 }
72
71 -hwaddr s390_cpu_get_phys_addr_debug(CPUState *cs, vaddr v_addr)
72 -{
73 - hwaddr phys_addr;
74 - vaddr page;
75 -
76 - page = v_addr & TARGET_PAGE_MASK;
77 - phys_addr = cpu_get_phys_page_debug(cs, page);
78 - phys_addr += (v_addr & ~TARGET_PAGE_MASK);
79 -
80 - return phys_addr;
81 -}
82 -
73 static inline bool is_special_wait_psw(uint64_t psw_addr)
74 {
75 /* signal quiesce */
target/s390x/s390x-internal.h
-1
@@ -321,7 +321,6 @@ void do_restart_interrupt(CPUS390XState *env);
321 void s390x_tod_timer(void *opaque);
322 void s390x_cpu_timer(void *opaque);
323 void s390_handle_wait(S390CPU *cpu);
324 -hwaddr s390_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
324 hwaddr s390_cpu_get_phys_addr_debug(CPUState *cpu, vaddr addr);
325 LowCore *cpu_map_lowcore(CPUS390XState *env);
326 void cpu_unmap_lowcore(CPUS390XState *env, LowCore *lowcore);