core/cpu-common: initialise plugin state before thread creation

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.

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>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Message-ID: <20240530194250.1801701-6-alex.bennee@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
Alex Bennée 2024-05-30 20:42:50 +01:00 committed by Philippe Mathieu-Daudé
parent 2fa16246dd
commit 638181a180

View File

@ -222,14 +222,6 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)
cpu_resume(cpu); 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 */ /* 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); QTAILQ_INIT(&cpu->watchpoints);
cpu_exec_initfn(cpu); 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();
async_run_on_cpu(cpu, qemu_plugin_vcpu_init__async, RUN_ON_CPU_NULL);
}
#endif
} }
static void cpu_common_finalize(Object *obj) static void cpu_common_finalize(Object *obj)