CPUAddressSpace structures are currently allocated statically in cpu_address_space_init(). This approach is clunky to use because cpu->num_ases needs to be set immediately before the function is called.
Moreover, the static allocation is tightly coupled to the Address Space (AS) indexes, which, depending on the CPU features, can leave unused CPUAddressSpace structures. For instance, on aarch64's 'virt' machine, if secure=off but mte=on, three ASes are allocated, but only two ASes (ARMASIdx_NS and ARMASIdx_Tag) are actually used. This situation gets worse when new CPU features that require additional ASes are added, such as FEAT_MEC (which I'm working on right now). This series addresses these limitations by allocating the CPUAddressSpace dynamically. The last 4 patches in the series probably need to get squashed with the changes in the API, but I kept them separate so it's easy to see how simple the changes needed on the target side are. CI results: https://gitlab.com/gusbromero/qemu/-/pipelines/2184288007 Cheers, Gustavo Gustavo Romero (6): system/physmem: Enhance the Address Space API target/arm: Initialize AS 0 first target/arm: Add a _MAX sentinel to ARMASIdx enum target/arm: Use new CPU address space API target/i386: Add a _MAX sentinel to X86ASIdx enum target/i386: Use new CPU address space API include/exec/cpu-common.h | 16 +++++++-- include/hw/core/cpu.h | 6 +++- stubs/cpu-destroy-address-spaces.c | 2 +- system/cpus.c | 4 +-- system/physmem.c | 56 ++++++++++++++++++++++-------- target/arm/cpu.c | 20 ++++------- target/arm/cpu.h | 1 + target/i386/cpu.h | 1 + target/i386/kvm/kvm-cpu.c | 4 +-- target/i386/kvm/kvm.c | 4 +-- target/i386/tcg/system/tcg-cpu.c | 6 ++-- 11 files changed, 78 insertions(+), 42 deletions(-) -- 2.34.1
