From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Pierrick Bouvier <pierrick.bouvier@linaro.org>, qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
"Alexandre Iooss" <erdnaxe@crans.org>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Yanan Wang" <wangyanan55@huawei.com>,
"Mahmoud Mandour" <ma.mandourr@gmail.com>
Subject: Re: [PATCH 2/3] plugins: Free CPUPluginState before destroying vCPU state
Date: Fri, 7 Jun 2024 06:53:36 +0200 [thread overview]
Message-ID: <cc029923-bd07-4b48-ad8a-b68501a0e54d@linaro.org> (raw)
In-Reply-To: <26cb32be-d5a6-48b9-98c9-ca94ac6ceafd@linaro.org>
On 6/6/24 23:14, Pierrick Bouvier wrote:
> On 6/6/24 05:40, Philippe Mathieu-Daudé wrote:
>> cpu::plugin_state is allocated in cpu_common_initfn() when
>> the vCPU state is created. Release it in cpu_common_finalize()
>> when we are done.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>> include/qemu/plugin.h | 3 +++
>> hw/core/cpu-common.c | 5 +++++
>> 2 files changed, 8 insertions(+)
>>
>> diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h
>> index bc5aef979e..af5f9db469 100644
>> --- a/include/qemu/plugin.h
>> +++ b/include/qemu/plugin.h
>> @@ -149,6 +149,9 @@ struct CPUPluginState {
>> /**
>> * qemu_plugin_create_vcpu_state: allocate plugin state
>> + *
>> + * The returned data must be released with g_free()
>> + * when no longer required.
>> */
>> CPUPluginState *qemu_plugin_create_vcpu_state(void);
>> diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
>> index bf1a7b8892..cd15402552 100644
>> --- a/hw/core/cpu-common.c
>> +++ b/hw/core/cpu-common.c
>> @@ -283,6 +283,11 @@ static void cpu_common_finalize(Object *obj)
>> {
>> CPUState *cpu = CPU(obj);
>> +#ifdef CONFIG_PLUGIN
>> + if (tcg_enabled()) {
>> + g_free(cpu->plugin_state);
>> + }
>> +#endif
>> g_array_free(cpu->gdb_regs, TRUE);
>> qemu_lockcnt_destroy(&cpu->in_ioctl_lock);
>> qemu_mutex_destroy(&cpu->work_mutex);
>
> To ensure I get it right, order of cpu init/deinit is:
> - init
> - realize
> - unrealize
> - finalize
> Is that correct?
Yes, this is valid for all QDev (CPU is based on it).
+ init: allocate state, expose configurable properties
. user configure properties
+ realize: consume properties to tune the object
+ reset: set default values
. object is used
+ unrealize: undo stuff from realize because the object
might be realized again (unplug - plug)
+ finalize: release resources
See
https://lore.kernel.org/qemu-devel/20240209123226.32576-1-philmd@linaro.org/
> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Thanks!
next prev parent reply other threads:[~2024-06-07 4:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-06 12:40 [PATCH 0/3] plugins: Few debugging cleanups Philippe Mathieu-Daudé
2024-06-06 12:40 ` [PATCH 1/3] plugins: Ensure vCPU index is assigned in init/exit hooks Philippe Mathieu-Daudé
2024-06-06 21:13 ` Pierrick Bouvier
2024-06-06 12:40 ` [PATCH 2/3] plugins: Free CPUPluginState before destroying vCPU state Philippe Mathieu-Daudé
2024-06-06 21:14 ` Pierrick Bouvier
2024-06-07 4:53 ` Philippe Mathieu-Daudé [this message]
2024-06-07 16:13 ` Pierrick Bouvier
2024-06-06 12:40 ` [PATCH 3/3] accel/tcg: Move qemu_plugin_vcpu_init__async() to plugins/ Philippe Mathieu-Daudé
2024-06-13 10:52 ` [PATCH 0/3] plugins: Few debugging cleanups Philippe Mathieu-Daudé
2024-07-04 10:13 ` Alex Bennée
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=cc029923-bd07-4b48-ad8a-b68501a0e54d@linaro.org \
--to=philmd@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=eduardo@habkost.net \
--cc=erdnaxe@crans.org \
--cc=ma.mandourr@gmail.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-devel@nongnu.org \
--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).