The proposal in v2 was to allocate all defined address spaces (CPUAddressSpace structs) statically, modifying the Address Space (AS) API by renaming cpu_address_space_init() to cpu_address_space_add() and by introducing a new cpu_address_space_init() meant to be used to set the total number of address spaces in a CPU (instead of setting the cpu->num_ases invariant directly, as we currently do).
However, Phil said that what he actually had in mind was to set cpu->num_ases automatically in the CPUClass, hence without the need to set cpu->num_ases using any AS API function, burying the details of initializing cpu->num_ases within the CPUClass. This way, the initialization of the ASes is reduced to the simple and unique use of cpu_address_space_init(). v3 is essentially based on what Phil proposed in the v2 review, but I removed the re-setting of cs->num_ases to 1 in x86_cpu_realizefn(), avoiding changes to num_ases beyond the CPUClass instantiation. First, because it will become inconsistent as new ASes are added. Second, it risks causing confusion about the new AS API semantics, which require using cpu_address_space_init on demand, as ASes are required by the target, without modifying num_ases elsewhere in the code beyond CPUClass instantiation. This version, v4, a) addresses Richard's comments on using CPUClass 'max_as' field instead of CPUState (CPUClass instance) 'num_ases' field and use enum _MAX definitions, removing the _COUNT definitions; and b) removes math for setting cs->num_ases in arm_cpu_realizefn(), which I forgot to remove in v3 and is now moot with the changes. CI results: https://gitlab.com/gusbromero/qemu/-/pipelines/2265804059 v1: https://mail.gnu.org/archive/html/qemu-devel/2025-11/msg04406.html v2: https://mail.gnu.org/archive/html/qemu-devel/2025-12/msg02298.html v3: https://mail.gnu.org/archive/html/qemu-devel/2025-12/msg02917.html Cheers, Gustavo Gustavo Romero (3): target/arm: Initialize AS 0 first target/i386: Add a _MAX sentinel to X86ASIdx enum target/arm: Add a _MAX sentinel to ARMASIdx enum Philippe Mathieu-Daudé (1): cpus: Allocate maximum number of ASes supported by the arch hw/core/cpu-common.c | 1 - hw/core/cpu-system.c | 2 +- include/exec/cpu-common.h | 4 ---- include/hw/core/cpu.h | 7 +++++-- system/cpus.c | 1 - system/physmem.c | 8 ++++---- target/arm/cpu.c | 13 ++----------- target/arm/cpu.h | 1 + target/i386/cpu.c | 1 + target/i386/cpu.h | 1 + target/i386/kvm/kvm-cpu.c | 1 - target/i386/tcg/system/tcg-cpu.c | 1 - 12 files changed, 15 insertions(+), 26 deletions(-) -- 2.34.1
