aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierrick Bouvier <pierrick.bouvier@linaro.org>2025-04-14 08:30:27 -0700
committerPeter Maydell <peter.maydell@linaro.org>2025-05-06 15:01:22 +0100
commite1781b38af5e5c2e8a4b8f11e3e54de393a82eb2 (patch)
tree94069c634355c151aaa7fb13accaa90e0a85338e
parent63201878f1cab185110f4d738ca41e05689aebd7 (diff)
downloadqemu-e1781b38af5e5c2e8a4b8f11e3e54de393a82eb2.zip
qemu-e1781b38af5e5c2e8a4b8f11e3e54de393a82eb2.tar.gz
qemu-e1781b38af5e5c2e8a4b8f11e3e54de393a82eb2.tar.bz2
target/arm/ptw: fix arm_cpu_get_phys_page_attrs_debug
It was reported that QEMU monitor command gva2gpa was reporting unmapped memory for a valid access (qemu-system-aarch64), during a copy from kernel to user space (__arch_copy_to_user symbol in Linux) [1]. This was affecting cpu_memory_rw_debug also, which is used in numerous places in our codebase. After investigating, the problem was specific to arm_cpu_get_phys_page_attrs_debug. When performing user access from a privileged space, we need to do a second lookup for user mmu idx, following what get_a64_user_mem_index is doing at translation time. [1] https://lists.nongnu.org/archive/html/qemu-discuss/2025-04/msg00013.html Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> Message-id: 20250414153027.1486719-5-pierrick.bouvier@linaro.org Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--target/arm/ptw.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/target/arm/ptw.c b/target/arm/ptw.c
index 3e00e4a..d0a53d0 100644
--- a/target/arm/ptw.c
+++ b/target/arm/ptw.c
@@ -3656,5 +3656,25 @@ hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cs, vaddr addr,
CPUARMState *env = &cpu->env;
ARMMMUIdx mmu_idx = arm_mmu_idx(env);
- return arm_cpu_get_phys_page(env, addr, attrs, mmu_idx);
+ hwaddr res = arm_cpu_get_phys_page(env, addr, attrs, mmu_idx);
+
+ if (res != -1) {
+ return res;
+ }
+
+ /*
+ * Memory may be accessible for an "unprivileged load/store" variant.
+ * In this case, get_a64_user_mem_index function generates an op using an
+ * unprivileged mmu idx, so we need to try with it.
+ */
+ switch (mmu_idx) {
+ case ARMMMUIdx_E10_1:
+ case ARMMMUIdx_E10_1_PAN:
+ return arm_cpu_get_phys_page(env, addr, attrs, ARMMMUIdx_E10_0);
+ case ARMMMUIdx_E20_2:
+ case ARMMMUIdx_E20_2_PAN:
+ return arm_cpu_get_phys_page(env, addr, attrs, ARMMMUIdx_E20_0);
+ default:
+ return -1;
+ }
}