All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/25] Handle sub-page granularity in cpu_memory_rw_debug()
@ 2026-04-30  9:37 Peter Maydell
  2026-04-30  9:37 ` [PATCH v2 01/25] hw/i386/vapic: Cope with non-page-aligned return from cpu_get_phys_page_debug() Peter Maydell
                   ` (25 more replies)
  0 siblings, 26 replies; 50+ messages in thread
From: Peter Maydell @ 2026-04-30  9:37 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, qemu-ppc, qemu-riscv, qemu-s390x,
	Philippe Mathieu-Daudé, Marcel Apfelbaum, Yanan Wang,
	Zhao Liu, Paolo Bonzini, Richard Henderson,
	Dr. David Alan Gilbert, Alex Bennée, Alexandre Iooss,
	Mahmoud Mandour, Peter Xu, Edgar E. Iglesias, Jiaxun Yang,
	Nicholas Piggin, Chinmay Rath, Glenn Miles, Palmer Dabbelt,
	Alistair Francis, Weiwei Li, Daniel Henrique Barboza, Liu Zhiwei,
	Chao Liu, Ilya Leoshkevich, David Hildenbrand, Mark Cave-Ayland,
	Artyom Tarasenko, Max Filippov


A while back we added support for targets having memory protection at
a sub-page granularity in TCG: the target returns a CPUTLBEntryFull
with a lg_page_size field that tells TCG how big a block of memory the
translation covers. At the moment we only use this in Arm, for the
M-profile and R-profile MPU which can set protections on small regions
of memory.

However, we forgot about cpu_memory_rw_debug(), which still assumes
that translations cover target-page sized regions. It rounds the input
virtual address down to a page boundary, translates that, and then
puts the offset within the page back in again. This causes problems
for the Arm MPU case, because if the MPU is set up so that the memory
at the rounded-down address isn't within a valid region then we
incorrectly conclude that we can't read the memory at the address we
were actually asked about.
https://gitlab.com/qemu-project/qemu/-/work_items/3292 is a report of
this for the semihosting case, but it applies also to general debug
accesses.

This series fixes this by providing and using a new
cpu_translate_for_debug() function which takes a non-page-aligned
virtual address and returns all of:
 - the exact physical address for that virtual address
 - the memory attributes
 - the lg_page_size the translation is valid for

Changes in v2:
 - I noticed that I'd missed that a vapic.c callsite currently relies
   on the i386 "always return a page-aligned result" behaviour;
   patch 1 is new and makes it work with both "returns the page
   address" and "returns the exact adress"
 - fixed a TARGET_PAGE_BITS/TARGET_PAGE_SIZE mixup pointed out
   in code review
 - in the arm translate_for_debug patch, name a (preexisting) bool
   variable 'fault' rather than 'ret' to help clarify that it is
   true-on-failure
 - the last 7 patches are new, and update callers of
   cpu_get_phys_addr_debug() to use the new cpu_translate_for_debug();
   this means we can remove cpu_get_phys_addr_debug() and
   cpu_get_phys_addr_attrs_debug(), so there is only one API
   now for doing debug virt-to-phys translations

Further cleanup for once this series is accepted:
 - we could convert the 15 targets using get_phys_addr_debug and the
   two using get_phys_addr_attrs_debug to translate_for_debug, so we
   only have one CPU method for phys-to-virt translations instead of
   three

Patches 1, 18, and 19-25 need review.

thanks
-- PMM

Peter Maydell (25):
  hw/i386/vapic: Cope with non-page-aligned return from
    cpu_get_phys_page_debug()
  target/riscv: Make get_phys_page_debug handle non-page-aligned addrs
  target/alpha: Make get_phys_page_debug handle non-page-aligned addrs
  target/microblaze: Make get_phys_page_attrs_debug handle
    non-page-aligned addrs
  target/sparc: Make get_phys_page_debug handle non-page-aligned addrs
  target/x86: Make get_phys_page_attrs_debug handle non-page-aligned
    addrs
  target/s390x: Make get_phys_page_debug handle non-page-aligned addrs
  target/ppc: Make get_phys_page_debug handle non-page-aligned addrs
  target: Rename get_phys_page_debug to get_phys_addr_debug
  target: Rename cpu_get_phys_page_{,attrs_}debug
  hw/core: Update docs for get_phys_addr_{attrs_,}debug
  target/arm: Rename arm_cpu_get_phys_page()
  monitor: hmp_gva2gpa: Don't page-align cpu_get_phys_addr_debug() arg
    and return
  plugins/api.c: Trust cpu_get_phys_addr_debug() return address
  hw/core: Implement new cpu_translate_for_debug()
  hw/core: Implement cpu_get_phys_addr_attrs_debug() with
    cpu_translate_for_debug()
  target/arm: Implement translate_for_debug
  system/physmem: Use translate_for_debug() in cpu_memory_rw_debug()
  hw/i386/vapic.c: Use cpu_translate_for_debug()
  target/sparc: Use cpu_translate_for_debug()
  hw/xtensa: Use cpu_translate_for_debug()
  target/xtensa/xtensa-semi: Use cpu_translate_for_debug()
  monitor/hmp-cmds: Use cpu_translate_for_debug()
  plugins/api.c: Use cpu_translate_for_debug()
  Remove cpu_get_phys_addr_debug() and cpu_get_phys_addr_attrs_debug()

 hw/core/cpu-system.c             | 47 ++++++++++++++++++--------------
 hw/i386/vapic.c                  | 13 +++++----
 hw/xtensa/sim.c                  |  6 +++-
 hw/xtensa/xtfpga.c               |  6 +++-
 include/hw/core/cpu.h            | 40 +++++++++++++++------------
 include/hw/core/sysemu-cpu-ops.h | 39 ++++++++++++++++++++++----
 monitor/hmp-cmds.c               |  8 ++----
 plugins/api.c                    |  8 +++---
 system/physmem.c                 | 38 ++++++++++++++++----------
 target/alpha/cpu.c               |  2 +-
 target/alpha/cpu.h               |  2 +-
 target/alpha/helper.c            |  3 +-
 target/arm/cpu.c                 |  2 +-
 target/arm/cpu.h                 |  3 --
 target/arm/internals.h           |  4 +++
 target/arm/ptw.c                 | 39 +++++++++++++++-----------
 target/avr/cpu.c                 |  2 +-
 target/avr/cpu.h                 |  2 +-
 target/avr/helper.c              |  2 +-
 target/hppa/cpu.c                |  2 +-
 target/hppa/cpu.h                |  2 +-
 target/hppa/mem_helper.c         |  2 +-
 target/i386/cpu.c                |  2 +-
 target/i386/cpu.h                |  2 +-
 target/i386/helper.c             |  4 +--
 target/i386/whpx/whpx-all.c      |  2 +-
 target/loongarch/cpu-mmu.h       |  2 +-
 target/loongarch/cpu.c           |  2 +-
 target/loongarch/cpu_helper.c    |  2 +-
 target/m68k/cpu.c                |  2 +-
 target/m68k/cpu.h                |  2 +-
 target/m68k/helper.c             |  2 +-
 target/microblaze/cpu.c          |  2 +-
 target/microblaze/cpu.h          |  2 +-
 target/microblaze/helper.c       | 11 ++++----
 target/mips/cpu.c                |  2 +-
 target/mips/internal.h           |  2 +-
 target/mips/system/physaddr.c    |  2 +-
 target/or1k/cpu.c                |  2 +-
 target/or1k/cpu.h                |  2 +-
 target/or1k/mmu.c                |  2 +-
 target/ppc/cpu.h                 |  2 +-
 target/ppc/cpu_init.c            |  2 +-
 target/ppc/mmu-hash32.c          |  2 +-
 target/ppc/mmu_common.c          |  4 +--
 target/riscv/cpu.c               |  2 +-
 target/riscv/cpu.h               |  2 +-
 target/riscv/cpu_helper.c        |  4 +--
 target/rx/cpu.c                  |  2 +-
 target/rx/cpu.h                  |  2 +-
 target/rx/helper.c               |  2 +-
 target/s390x/cpu-system.c        |  2 +-
 target/s390x/helper.c            | 20 ++++----------
 target/s390x/s390x-internal.h    |  1 -
 target/sh4/cpu.c                 |  2 +-
 target/sh4/cpu.h                 |  2 +-
 target/sh4/helper.c              |  2 +-
 target/sparc/cpu.c               |  2 +-
 target/sparc/cpu.h               |  2 +-
 target/sparc/mmu_helper.c        | 23 ++++++++++++----
 target/tricore/cpu.c             |  2 +-
 target/tricore/cpu.h             |  2 +-
 target/tricore/helper.c          |  2 +-
 target/xtensa/cpu.c              |  2 +-
 target/xtensa/cpu.h              |  2 +-
 target/xtensa/mmu_helper.c       |  2 +-
 target/xtensa/xtensa-semi.c      |  9 ++++--
 67 files changed, 246 insertions(+), 176 deletions(-)

-- 
2.43.0



^ permalink raw reply	[flat|nested] 50+ messages in thread

end of thread, other threads:[~2026-05-07 17:09 UTC | newest]

Thread overview: 50+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30  9:37 [PATCH v2 00/25] Handle sub-page granularity in cpu_memory_rw_debug() Peter Maydell
2026-04-30  9:37 ` [PATCH v2 01/25] hw/i386/vapic: Cope with non-page-aligned return from cpu_get_phys_page_debug() Peter Maydell
2026-04-30 13:33   ` Philippe Mathieu-Daudé
2026-05-01  9:53   ` Richard Henderson
2026-05-07 16:44   ` Alex Bennée
2026-04-30  9:37 ` [PATCH v2 02/25] target/riscv: Make get_phys_page_debug handle non-page-aligned addrs Peter Maydell
2026-04-30  9:37 ` [PATCH v2 03/25] target/alpha: " Peter Maydell
2026-04-30  9:37 ` [PATCH v2 04/25] target/microblaze: Make get_phys_page_attrs_debug " Peter Maydell
2026-05-07 16:49   ` Alex Bennée
2026-04-30  9:37 ` [PATCH v2 05/25] target/sparc: Make get_phys_page_debug " Peter Maydell
2026-04-30  9:37 ` [PATCH v2 06/25] target/x86: Make get_phys_page_attrs_debug " Peter Maydell
2026-04-30  9:37 ` [PATCH v2 07/25] target/s390x: Make get_phys_page_debug " Peter Maydell
2026-05-07  9:59   ` Philippe Mathieu-Daudé
2026-04-30  9:37 ` [PATCH v2 08/25] target/ppc: " Peter Maydell
2026-04-30 15:02   ` Miles Glenn
2026-04-30  9:37 ` [PATCH v2 09/25] target: Rename get_phys_page_debug to get_phys_addr_debug Peter Maydell
2026-04-30  9:37 ` [PATCH v2 10/25] target: Rename cpu_get_phys_page_{,attrs_}debug Peter Maydell
2026-04-30  9:37 ` [PATCH v2 11/25] hw/core: Update docs for get_phys_addr_{attrs_, }debug Peter Maydell
2026-04-30  9:37 ` [PATCH v2 12/25] target/arm: Rename arm_cpu_get_phys_page() Peter Maydell
2026-04-30  9:37 ` [PATCH v2 13/25] monitor: hmp_gva2gpa: Don't page-align cpu_get_phys_addr_debug() arg and return Peter Maydell
2026-04-30  9:37 ` [PATCH v2 14/25] plugins/api.c: Trust cpu_get_phys_addr_debug() return address Peter Maydell
2026-04-30  9:38 ` [PATCH v2 15/25] hw/core: Implement new cpu_translate_for_debug() Peter Maydell
2026-05-01  9:56   ` Richard Henderson
2026-04-30  9:38 ` [PATCH v2 16/25] hw/core: Implement cpu_get_phys_addr_attrs_debug() with cpu_translate_for_debug() Peter Maydell
2026-05-07 13:28   ` Philippe Mathieu-Daudé
2026-04-30  9:38 ` [PATCH v2 17/25] target/arm: Implement translate_for_debug Peter Maydell
2026-05-01  9:57   ` Richard Henderson
2026-04-30  9:38 ` [PATCH v2 18/25] system/physmem: Use translate_for_debug() in cpu_memory_rw_debug() Peter Maydell
2026-05-01  9:58   ` Richard Henderson
2026-05-06 15:27   ` Peter Xu
2026-04-30  9:38 ` [PATCH v2 19/25] hw/i386/vapic.c: Use cpu_translate_for_debug() Peter Maydell
2026-04-30 14:31   ` Philippe Mathieu-Daudé
2026-04-30  9:38 ` [PATCH v2 20/25] target/sparc: " Peter Maydell
2026-05-01 10:00   ` Richard Henderson
2026-04-30  9:38 ` [PATCH v2 21/25] hw/xtensa: " Peter Maydell
2026-04-30 14:37   ` Philippe Mathieu-Daudé
2026-05-01 10:00   ` Richard Henderson
2026-04-30  9:38 ` [PATCH v2 22/25] target/xtensa/xtensa-semi: " Peter Maydell
2026-04-30 14:38   ` Philippe Mathieu-Daudé
2026-05-01 10:01   ` Richard Henderson
2026-04-30  9:38 ` [PATCH v2 23/25] monitor/hmp-cmds: " Peter Maydell
2026-04-30 14:39   ` Philippe Mathieu-Daudé
2026-05-01 10:01   ` Richard Henderson
2026-04-30  9:38 ` [PATCH v2 24/25] plugins/api.c: " Peter Maydell
2026-04-30 14:39   ` Philippe Mathieu-Daudé
2026-05-01 10:02   ` Richard Henderson
2026-04-30  9:38 ` [PATCH v2 25/25] Remove cpu_get_phys_addr_debug() and cpu_get_phys_addr_attrs_debug() Peter Maydell
2026-04-30 14:39   ` Philippe Mathieu-Daudé
2026-05-01 10:03   ` Richard Henderson
2026-05-07 17:08 ` [PATCH v2 00/25] Handle sub-page granularity in cpu_memory_rw_debug() Philippe Mathieu-Daudé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.