From: Thomas Huth <thuth@redhat.com>
To: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, qemu-devel@nongnu.org
Cc: "Alex Williamson" <alex.williamson@redhat.com>,
"Cédric Le Goater" <clg@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Peter Xu" <peterx@redhat.com>,
"David Hildenbrand" <david@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"John Snow" <jsnow@redhat.com>, "Keith Busch" <kbusch@kernel.org>,
"Klaus Jensen" <its@irrelevant.dk>,
"Jesper Devantier" <foss@defmacro.it>,
"Nicholas Piggin" <npiggin@gmail.com>,
"John Levon" <john.levon@nutanix.com>,
"Thanos Makatos" <thanos.makatos@nutanix.com>,
"Yanan Wang" <wangyanan55@huawei.com>,
"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
"Harsh Prateek Bora" <harshpb@linux.ibm.com>,
"Alexey Kardashevskiy" <aik@ozlabs.ru>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Fabiano Rosas" <farosas@suse.de>,
"Laurent Vivier" <lvivier@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Aleksandar Rikalo" <arikalo@gmail.com>,
"Max Filippov" <jcmvbkbc@gmail.com>,
"Hervé Poussineau" <hpoussin@reactos.org>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
"Artyom Tarasenko" <atar4qemu@gmail.com>
Subject: Re: [PATCH 05/22] target/xtensa: Fix AddressSpace exposure timing
Date: Tue, 9 Sep 2025 11:42:50 +0200 [thread overview]
Message-ID: <c24112e8-dc1a-4f52-b2ec-6f9e35ec1b0b@redhat.com> (raw)
In-Reply-To: <20250906-use-v1-5-c51caafd1eb7@rsg.ci.i.u-tokyo.ac.jp>
On 06/09/2025 04.11, Akihiko Odaki wrote:
> xtensa-cpu is not hotpluggable but its instance can still be created and
> finalized when processing the device-list-properties QMP command.
> Exposing such a temporary instance to AddressSpace should be
> avoided because it leaks the instance.
>
> Expose instances to the AddressSpace at their realization time so that
> it won't happen for the temporary instances.
>
> Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
> ---
> target/xtensa/cpu.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c
> index ea9b6df3aa24178c8e6a88b02afda5db659199da..63edc3a5b2778c8379a30125481f65361655fe1c 100644
> --- a/target/xtensa/cpu.c
> +++ b/target/xtensa/cpu.c
> @@ -243,7 +243,11 @@ static void xtensa_cpu_realizefn(DeviceState *dev, Error **errp)
> Error *local_err = NULL;
>
> #ifndef CONFIG_USER_ONLY
> - xtensa_irq_init(&XTENSA_CPU(dev)->env);
> + CPUXtensaState *env = &XTENSA_CPU(dev)->env;
> +
> + env->address_space_er = g_malloc(sizeof(*env->address_space_er));
> + address_space_init(env->address_space_er, env->system_er, "ER");
> + xtensa_irq_init(env);
> #endif
>
> cpu_exec_realizefn(cs, &local_err);
> @@ -268,11 +272,9 @@ static void xtensa_cpu_initfn(Object *obj)
> env->config = xcc->config;
>
> #ifndef CONFIG_USER_ONLY
> - env->address_space_er = g_malloc(sizeof(*env->address_space_er));
> env->system_er = g_malloc(sizeof(*env->system_er));
> memory_region_init_io(env->system_er, obj, NULL, env, "er",
> UINT64_C(0x100000000));
> - address_space_init(env->address_space_er, env->system_er, "ER");
>
> cpu->clock = qdev_init_clock_in(DEVICE(obj), "clk-in", NULL, cpu, 0);
> clock_set_hz(cpu->clock, env->config->clock_freq_khz * 1000);
>
Reviewed-by: Thomas Huth <thuth@redhat.com>
next prev parent reply other threads:[~2025-09-09 9:43 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-06 2:11 [PATCH 00/22] Fix memory region leaks and use-after-finalization Akihiko Odaki
2025-09-06 2:11 ` [PATCH 01/22] docs/devel: Do not unparent in instance_finalize() Akihiko Odaki
2025-09-06 2:11 ` [PATCH 02/22] vfio/pci: " Akihiko Odaki
2025-09-10 20:41 ` Peter Xu
2025-09-11 3:47 ` Akihiko Odaki
2025-09-11 21:37 ` Peter Xu
2025-09-12 2:09 ` Akihiko Odaki
2025-09-12 21:26 ` Peter Xu
2025-09-14 9:06 ` Akihiko Odaki
2025-09-15 20:30 ` Peter Xu
2025-09-16 11:45 ` Akihiko Odaki
2025-09-06 2:11 ` [PATCH 03/22] hw/pci-bridge: Do not assume immediate MemoryRegion finalization Akihiko Odaki
2025-09-06 2:11 ` [PATCH 04/22] target/mips: Fix AddressSpace exposure timing Akihiko Odaki
2025-09-09 9:39 ` Thomas Huth
2025-09-06 2:11 ` [PATCH 05/22] target/xtensa: " Akihiko Odaki
2025-09-09 9:42 ` Thomas Huth [this message]
2025-09-06 2:11 ` [PATCH 06/22] auxbus: " Akihiko Odaki
2025-09-09 9:43 ` Thomas Huth
2025-09-06 2:11 ` [PATCH 07/22] hw/pci-host/raven: " Akihiko Odaki
2025-09-06 9:03 ` BALATON Zoltan
2025-09-08 15:20 ` Akihiko Odaki
2025-09-08 15:31 ` Peter Maydell
2025-09-06 2:11 ` [PATCH 08/22] sun4m: " Akihiko Odaki
2025-09-09 9:48 ` Thomas Huth
2025-09-09 20:25 ` Mark Cave-Ayland
2025-09-06 2:11 ` [PATCH 09/22] sun4u: " Akihiko Odaki
2025-09-09 9:54 ` Thomas Huth
2025-09-09 20:26 ` Mark Cave-Ayland
2025-09-06 2:11 ` [PATCH 10/22] qdev: Automatically delete memory subregions Akihiko Odaki
2025-09-10 21:10 ` Peter Xu
2025-09-11 3:55 ` Akihiko Odaki
2025-09-06 2:11 ` [PATCH 11/22] vfio-user: Do not delete the subregion Akihiko Odaki
2025-09-06 2:11 ` [PATCH 12/22] hw/char/diva-gsp: " Akihiko Odaki
2025-09-06 2:11 ` [PATCH 13/22] hw/char/serial-pci-multi: " Akihiko Odaki
2025-09-06 2:11 ` [PATCH 14/22] secondary-vga: Do not delete the subregions Akihiko Odaki
2025-09-06 2:11 ` [PATCH 15/22] cmd646: " Akihiko Odaki
2025-09-06 2:11 ` [PATCH 16/22] hw/ide/piix: " Akihiko Odaki
2025-09-06 2:11 ` [PATCH 17/22] hw/ide/via: " Akihiko Odaki
2025-09-06 2:11 ` [PATCH 18/22] hw/nvme: Do not delete the subregion Akihiko Odaki
2025-09-06 2:11 ` [PATCH 19/22] pci: Do not delete the subregions Akihiko Odaki
2025-09-06 2:11 ` [PATCH 20/22] hw/ppc/spapr_pci: " Akihiko Odaki
2025-09-06 2:11 ` [PATCH 21/22] hw/usb/hcd-ehci: " Akihiko Odaki
2025-09-06 2:11 ` [PATCH 22/22] hw/usb/hcd-xhci: " Akihiko Odaki
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=c24112e8-dc1a-4f52-b2ec-6f9e35ec1b0b@redhat.com \
--to=thuth@redhat.com \
--cc=aik@ozlabs.ru \
--cc=alex.bennee@linaro.org \
--cc=alex.williamson@redhat.com \
--cc=arikalo@gmail.com \
--cc=atar4qemu@gmail.com \
--cc=berrange@redhat.com \
--cc=clg@redhat.com \
--cc=danielhb413@gmail.com \
--cc=david@redhat.com \
--cc=eduardo@habkost.net \
--cc=farosas@suse.de \
--cc=foss@defmacro.it \
--cc=harshpb@linux.ibm.com \
--cc=hpoussin@reactos.org \
--cc=its@irrelevant.dk \
--cc=jcmvbkbc@gmail.com \
--cc=jiaxun.yang@flygoat.com \
--cc=john.levon@nutanix.com \
--cc=jsnow@redhat.com \
--cc=kbusch@kernel.org \
--cc=kraxel@redhat.com \
--cc=lvivier@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=mst@redhat.com \
--cc=npiggin@gmail.com \
--cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=thanos.makatos@nutanix.com \
--cc=wangyanan55@huawei.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).