When a vCPU is created, it typically calls cpu_address_space_init() one or more times to set up its address spaces. We don't currently do anything to destroy these address spaces, which means that we will leak them on a vcpu hot-plug -> hot-unplug cycle.
This patchset fixes the leak by replacing the current cpu_address_space_destroy() (which has an awkward API, includes a bug, and is never called from anywhere) with a new cpu_destroy_address_spaces() which cleans up all the ASes a CPU has and is called from generic unrealize code. Patch 1 is just a comment improvement to clarify that address_space_destroy() defers most of its work to RCU and you can't free the memory for the AS struct itself until it's done. Patch 2 is from Peter Xu; we need to be able to do "destroy and free an AS" via RCU, and at the moment you can't do that. Patch 3 is the bugfix proper. thanks -- PMM Peter Maydell (2): include/system/memory.h: Clarify address_space_destroy() behaviour physmem: Destroy all CPU AddressSpaces on unrealize Peter Xu (1): memory: New AS helper to serialize destroy+free include/exec/cpu-common.h | 10 ++++----- include/hw/core/cpu.h | 1 - include/system/memory.h | 24 ++++++++++++++++++--- hw/core/cpu-common.c | 1 + stubs/cpu-destroy-address-spaces.c | 15 +++++++++++++ system/memory.c | 20 +++++++++++++++++- system/physmem.c | 34 ++++++++++++++---------------- stubs/meson.build | 1 + 8 files changed, 78 insertions(+), 28 deletions(-) create mode 100644 stubs/cpu-destroy-address-spaces.c -- 2.43.0
