You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
qemu/stubs
Peter Maydell 300a87c502 physmem: Destroy all CPU AddressSpaces on unrealize
When we unrealize a CPU object (which happens on vCPU hot-unplug), we
should destroy all the AddressSpace objects we created via calls to
cpu_address_space_init() when the CPU was realized.

Commit 24bec42f3d added a function to do this for a specific
AddressSpace, but did not add any places where the function was
called.

Since we always want to destroy all the AddressSpaces on unrealize,
regardless of the target architecture, we don't need to try to keep
track of how many are still undestroyed, or make the target
architecture code manually call a destroy function for each AS it
created.  Instead we can adjust the function to always completely
destroy the whole cpu->ases array, and arrange for it to be called
during CPU unrealize as part of the common code.

Without this fix, AddressSanitizer will report a leak like this
from a run where we hot-plugged and then hot-unplugged an x86 KVM
vCPU:

Direct leak of 416 byte(s) in 1 object(s) allocated from:
    #0 0x5b638565053d in calloc (/data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/qemu-system-x86_64+0x1ee153d) (BuildId: c1cd6022b195142106e1bffeca23498c2b752bca)
    #1 0x7c28083f77b1 in g_malloc0 (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x637b1) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75)
    #2 0x5b6386999c7c in cpu_address_space_init /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../system/physmem.c:797:25
    #3 0x5b638727f049 in kvm_cpu_realizefn /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../target/i386/kvm/kvm-cpu.c:102:5
    #4 0x5b6385745f40 in accel_cpu_common_realize /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../accel/accel-common.c:101:13
    #5 0x5b638568fe3c in cpu_exec_realizefn /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../hw/core/cpu-common.c:232:10
    #6 0x5b63874a2cd5 in x86_cpu_realizefn /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../target/i386/cpu.c:9321:5
    #7 0x5b6387a0469a in device_set_realized /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../hw/core/qdev.c:494:13
    #8 0x5b6387a27d9e in property_set_bool /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../qom/object.c:2375:5
    #9 0x5b6387a2090b in object_property_set /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../qom/object.c:1450:5
    #10 0x5b6387a35b05 in object_property_set_qobject /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../qom/qom-qobject.c:28:10
    #11 0x5b6387a21739 in object_property_set_bool /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../qom/object.c:1520:15
    #12 0x5b63879fe510 in qdev_realize /data_nvme1n1/linaro/qemu-from-laptop/qemu/build/x86-tgts-asan/../../hw/core/qdev.c:276:12

Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2517
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
Link: https://lore.kernel.org/r/20250929144228.1994037-4-peter.maydell@linaro.org
Signed-off-by: Peter Xu <peterx@redhat.com>
3 weeks ago
..
bdrv-next-monitor-owned.c
blk-commit-all.c include: Rename sysemu/ -> system/ 10 months ago
blk-exp-close-all.c meson: Drop the .fa library suffix 1 year ago
blockdev-close-all-bdrv-states.c
change-state-handler.c include: Rename sysemu/ -> system/ 10 months ago
cmos.c
cpu-destroy-address-spaces.c physmem: Destroy all CPU AddressSpaces on unrealize 3 weeks ago
cpu-get-clock.c include: Rename sysemu/ -> system/ 10 months ago
cpu-synchronize-state.c include: Rename sysemu/ -> system/ 10 months ago
cpus-virtual-clock.c include: Rename sysemu/ -> system/ 10 months ago
dump.c include: Rename sysemu/ -> system/ 10 months ago
error-printf.c Move error_printf_unless_qmp() with monitor unit 4 years ago
fdset.c monitor: Report errors from monitor_fdset_dup_fd_add 1 year ago
fw_cfg.c
gdbstub.c gdbstub: Introduce GDBFeature structure 2 years ago
get-vm-name.c include: Rename sysemu/ -> system/ 10 months ago
graph-lock.c async: Register/unregister aiocontext in graph lock list 3 years ago
hotplug-stubs.c hw/core: Move system emulation files to system_ss 2 years ago
icount.c include/exec: Split out icount.h 6 months ago
io_uring.c
iothread-lock-block.c main-loop.h: introduce qemu_in_main_thread() 4 years ago
iothread-lock.c bql: add a "mock" BQL for Rust unit tests 10 months ago
is-daemonized.c
linux-aio.c
meson.build physmem: Destroy all CPU AddressSpaces on unrealize 3 weeks ago
migr-blocker.c migration: per-mode blockers 2 years ago
monitor-arm-gic.c qapi: expose query-gic-capability command unconditionally 5 months ago
monitor-core.c stubs: remove obsolete stubs 2 years ago
monitor-cpu-s390x-kvm.c qapi: make s390x specific CPU commands unconditionally available 5 months ago
monitor-cpu-s390x.c qapi: make most CPU commands unconditionally available 5 months ago
monitor-cpu.c qapi: make most CPU commands unconditionally available 5 months ago
monitor-i386-rtc.c qapi: expose rtc-reset-reinjection command unconditionally 5 months ago
monitor-i386-sev.c qapi: make SEV commands unconditionally available 5 months ago
monitor-i386-sgx.c qapi: make SGX commands unconditionally available 5 months ago
monitor-i386-xen.c qapi: make Xen event commands unconditionally available 5 months ago
monitor-internal.c stubs: move monitor_fdsets_cleanup with other fdset stubs 2 years ago
physmem.c stubs: add qemu_ram_block_from_host() and qemu_ram_get_fd() 3 years ago
qdev.c stubs: remove obsolete stubs 2 years ago
qemu-timer-notify-cb.c include: Rename sysemu/ -> system/ 10 months ago
qmp-command-available.c qapi: Move and rename qapi/qmp/dispatch.h to qapi/qmp-registry.h 8 months ago
qmp-quit.c qapi: Move and rename qapi/qmp/dispatch.h to qapi/qmp-registry.h 8 months ago
qtest.c include: Rename sysemu/ -> system/ 10 months ago
ram-block.c include/system: Move exec/memory.h to system/memory.h 6 months ago
replay-mode.c include: Rename sysemu/ -> system/ 10 months ago
replay-tools.c include: Rename sysemu/ -> system/ 10 months ago
replay.c stubs: split record/replay stubs further 2 years ago
runstate-check.c include: Rename sysemu/ -> system/ 10 months ago
sysbus.c
target-get-monitor-def.c
target-monitor-defs.c monitor: remove MonitorDef from typedefs.h 1 year ago
trace-control.c trace: remove code that depends on setting vcpu 2 years ago
uuid.c
vm-stop.c include: Rename sysemu/ -> system/ 10 months ago
vmstate.c migration: cpr-transfer mode 9 months ago
win32-kbd-hook.c
xen-hw-stub.c hw/xen: Remove unnecessary xen_hvm_inject_msi() stub 2 years ago