From: "Alex Bennée" <alex.bennee@linaro.org>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org,
Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
Cameron Esfahani <dirty@apple.com>,
Alexandre Iooss <erdnaxe@crans.org>,
Yanan Wang <wangyanan55@huawei.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Eduardo Habkost <eduardo@habkost.net>,
Sunil Muthuswamy <sunilmut@microsoft.com>,
Richard Henderson <richard.henderson@linaro.org>,
Pierrick Bouvier <pierrick.bouvier@linaro.org>,
Mahmoud Mandour <ma.mandourr@gmail.com>,
Reinoud Zandijk <reinoud@netbsd.org>,
kvm@vger.kernel.org, Roman Bolshakov <rbolshakov@ddn.com>
Subject: Re: [PATCH 5/5] core/cpu-common: initialise plugin state before thread creation
Date: Fri, 31 May 2024 09:47:59 +0100 [thread overview]
Message-ID: <87a5k6cqps.fsf@draig.linaro.org> (raw)
In-Reply-To: <1c950cd6-9ee0-4b40-b9d6-3cc422046d65@linaro.org> ("Philippe Mathieu-Daudé"'s message of "Fri, 31 May 2024 09:26:55 +0200")
Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> On 30/5/24 21:42, Alex Bennée wrote:
>> Originally I tried to move where vCPU thread initialisation to later
>> in realize. However pulling that thread (sic) got gnarly really
>> quickly. It turns out some steps of CPU realization need values that
>> can only be determined from the running vCPU thread.
>
> FYI:
> https://lore.kernel.org/qemu-devel/20240528145953.65398-6-philmd@linaro.org/
But this still has it in realize which would still race as the threads
are started before we call the common realize functions.
>
>> However having moved enough out of the thread creation we can now
>> queue work before the thread starts (at least for TCG guests) and
>> avoid the race between vcpu_init and other vcpu states a plugin might
>> subscribe to.
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> ---
>> hw/core/cpu-common.c | 20 ++++++++++++--------
>> 1 file changed, 12 insertions(+), 8 deletions(-)
>> diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
>> index 6cfc01593a..bf1a7b8892 100644
>> --- a/hw/core/cpu-common.c
>> +++ b/hw/core/cpu-common.c
>> @@ -222,14 +222,6 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)
>> cpu_resume(cpu);
>> }
>> - /* Plugin initialization must wait until the cpu start
>> executing code */
>> -#ifdef CONFIG_PLUGIN
>> - if (tcg_enabled()) {
>> - cpu->plugin_state = qemu_plugin_create_vcpu_state();
>> - async_run_on_cpu(cpu, qemu_plugin_vcpu_init__async, RUN_ON_CPU_NULL);
>> - }
>> -#endif
>> -
>> /* NOTE: latest generic point where the cpu is fully realized */
>> }
>> @@ -273,6 +265,18 @@ static void cpu_common_initfn(Object *obj)
>> QTAILQ_INIT(&cpu->watchpoints);
>> cpu_exec_initfn(cpu);
>> +
>> + /*
>> + * Plugin initialization must wait until the cpu start executing
>> + * code, but we must queue this work before the threads are
>> + * created to ensure we don't race.
>> + */
>> +#ifdef CONFIG_PLUGIN
>> + if (tcg_enabled()) {
>> + cpu->plugin_state = qemu_plugin_create_vcpu_state();
>
> Per https://etherpad.opendev.org/p/QEMU_vCPU_life, plugin_state could
> be initialized in AccelCPUClass::cpu_instance_init (although this
> callback is called at CPUClass::instance_post_init which I haven't
> yet figured why).
Why are x86 and RiscV special in terms of calling this function?
>
>> + async_run_on_cpu(cpu, qemu_plugin_vcpu_init__async, RUN_ON_CPU_NULL);
>> + }
>> +#endif
>> }
>> static void cpu_common_finalize(Object *obj)
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
next prev parent reply other threads:[~2024-05-31 8:48 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-30 19:42 [PATCH 0/5] cpus: a few tweaks to CPU realization Alex Bennée
2024-05-30 19:42 ` [PATCH 1/5] hw/core: expand on the alignment of CPUState Alex Bennée
2024-05-30 22:28 ` Pierrick Bouvier
2024-06-03 11:32 ` Philippe Mathieu-Daudé
2024-05-30 19:42 ` [PATCH 2/5] cpu: move Qemu[Thread|Cond] setup into common code Alex Bennée
2024-05-30 22:29 ` Pierrick Bouvier
2024-05-31 13:46 ` Reinoud Zandijk
2024-06-03 11:28 ` Philippe Mathieu-Daudé
2024-05-30 19:42 ` [PATCH 3/5] cpu-target: don't set cpu->thread_id to bogus value Alex Bennée
2024-05-30 22:29 ` Pierrick Bouvier
2024-06-03 11:29 ` Philippe Mathieu-Daudé
2024-05-30 19:42 ` [PATCH 4/5] plugins: remove special casing for cpu->realized Alex Bennée
2024-05-30 22:30 ` Pierrick Bouvier
2024-06-03 11:31 ` Philippe Mathieu-Daudé
2024-06-03 14:11 ` Philippe Mathieu-Daudé
2024-06-03 14:19 ` Alex Bennée
2024-05-30 19:42 ` [PATCH 5/5] core/cpu-common: initialise plugin state before thread creation Alex Bennée
2024-05-30 22:31 ` Pierrick Bouvier
2024-05-31 8:59 ` Alex Bennée
2024-05-31 7:26 ` Philippe Mathieu-Daudé
2024-05-31 8:47 ` Alex Bennée [this message]
2024-06-03 14:10 ` Philippe Mathieu-Daudé
2024-06-03 12:47 ` [PATCH 0/5] cpus: a few tweaks to CPU realization Philippe Mathieu-Daudé
2024-06-03 14:11 ` Philippe Mathieu-Daudé
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=87a5k6cqps.fsf@draig.linaro.org \
--to=alex.bennee@linaro.org \
--cc=dirty@apple.com \
--cc=eduardo@habkost.net \
--cc=erdnaxe@crans.org \
--cc=kvm@vger.kernel.org \
--cc=ma.mandourr@gmail.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=rbolshakov@ddn.com \
--cc=reinoud@netbsd.org \
--cc=richard.henderson@linaro.org \
--cc=sunilmut@microsoft.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