From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: qemu-stable@nongnu.org, "Eduardo Habkost" <eduardo@habkost.net>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Yanan Wang" <wangyanan55@huawei.com>,
"Zhao Liu" <zhao1.liu@intel.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Peter Xu" <peterx@redhat.com>,
"David Hildenbrand" <david@redhat.com>
Subject: [PATCH 0/3] system: Don't leak CPU AddressSpaces
Date: Mon, 29 Sep 2025 15:42:25 +0100 [thread overview]
Message-ID: <20250929144228.1994037-1-peter.maydell@linaro.org> (raw)
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
next reply other threads:[~2025-09-29 14:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-29 14:42 Peter Maydell [this message]
2025-09-29 14:42 ` [PATCH 1/3] include/system/memory.h: Clarify address_space_destroy() behaviour Peter Maydell
2025-09-29 16:14 ` David Hildenbrand
2025-09-29 14:42 ` [PATCH 2/3] memory: New AS helper to serialize destroy+free Peter Maydell
2025-09-29 16:15 ` David Hildenbrand
2025-09-29 14:42 ` [PATCH 3/3] physmem: Destroy all CPU AddressSpaces on unrealize Peter Maydell
2025-09-29 15:04 ` Philippe Mathieu-Daudé
2025-09-29 16:17 ` David Hildenbrand
2025-09-29 15:02 ` [PATCH 0/3] system: Don't leak CPU AddressSpaces Philippe Mathieu-Daudé
2025-09-29 19:03 ` Peter Xu
2025-10-01 20:36 ` Richard Henderson
2025-10-01 21:37 ` Peter Xu
2025-10-01 21:59 ` Richard Henderson
2025-10-02 8:30 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250929144228.1994037-1-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=david@redhat.com \
--cc=eduardo@habkost.net \
--cc=marcel.apfelbaum@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=wangyanan55@huawei.com \
--cc=zhao1.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).