The proposal in v1 was to allocate all CPUAddressSpace structures
dynamically as the address spaces were added. However, after private
discussions with Richard, Peter, and Phil, I agreed to take the opposite
approach: allocating all defined address spaces (CPUAddressSpace struct)
for a target statically.

This different approach simplifies the current AS API too for the
definition of new address spaces for a target, while also simplifying
the changes necessary to achieve it.

CPUAddressSpace is a tiny structure, so allocating it statically has
negligible impact. Meanwhile, the AddressSpace struct (inside the
CPUAddressSpace struct), although larger, is already allocated
dynamically and allocated only when an address space is required.

The AS API simplification proposed here simply requires calling
cpu_address_space_init() once to set the total number of ASes supported
by a given target, and then adding the required address spaces using
cpu_address_space_add(). Consequently, there is no longer a need to
precompute the total number of ASes beforehand, which becomes clumsy for
targets that require different combinations of ASes.

Finally, the problem of mapping a sparse sequence of AS indexes to a
dense sequence of CPU AS indexes (array indexes) disappears, since a
CPUAddressSpace struct is statically allocated for all defined ASes
supported by the target.

CI results:
https://gitlab.com/gusbromero/qemu/-/pipelines/2220115152

v1:
https://mail.gnu.org/archive/html/qemu-devel/2025-11/msg04406.html


Cheers,
Gustavo

Gustavo Romero (6):
  target/arm: Initialize AS 0 first
  target/arm: Add a _MAX sentinel to ARMASIdx enum
  target/i386: Add a _MAX sentinel to X86ASIdx enum
  system/physmem: Rename cpu_address_space_init
  system/physmem: Add cpu_address_space_init
  system/physmem: Use cpu_address_space_init to set cpu->num_ases

 include/exec/cpu-common.h          | 23 ++++++++++++++++++-----
 stubs/cpu-destroy-address-spaces.c |  2 +-
 system/cpus.c                      |  4 ++--
 system/physmem.c                   | 12 ++++++++++--
 target/arm/cpu.c                   | 28 ++++++++++------------------
 target/arm/cpu.h                   |  3 ++-
 target/i386/cpu.h                  |  1 +
 target/i386/kvm/kvm-cpu.c          |  5 +++--
 target/i386/kvm/kvm.c              |  4 ++--
 target/i386/tcg/system/tcg-cpu.c   |  6 +++---
 10 files changed, 52 insertions(+), 36 deletions(-)

-- 
2.34.1


Reply via email to