[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 19/32] core/cpu-common: initialise plugin state before thread crea
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 19/32] core/cpu-common: initialise plugin state before thread creation |
Date: |
Tue, 4 Jun 2024 11:55:55 +0200 |
From: Alex Bennée <alex.bennee@linaro.org>
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>
---
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();
+ async_run_on_cpu(cpu, qemu_plugin_vcpu_init__async, RUN_ON_CPU_NULL);
+ }
+#endif
}
static void cpu_common_finalize(Object *obj)
--
2.41.0
- [PULL 09/32] util/hexdump: Remove b parameter from qemu_hexdump_line, (continued)
- [PULL 09/32] util/hexdump: Remove b parameter from qemu_hexdump_line, Philippe Mathieu-Daudé, 2024/06/04
- [PULL 10/32] util/hexdump: Remove ascii parameter from qemu_hexdump_line, Philippe Mathieu-Daudé, 2024/06/04
- [PULL 11/32] MAINTAINERS: drop usb maintainership, Philippe Mathieu-Daudé, 2024/06/04
- [PULL 12/32] system/runstate: Remove unused 'qemu/plugin.h' header, Philippe Mathieu-Daudé, 2024/06/04
- [PULL 13/32] accel/tcg: Move common declarations to 'internal-common.h', Philippe Mathieu-Daudé, 2024/06/04
- [PULL 14/32] accel/kvm: Fix two lines with hard-coded tabs, Philippe Mathieu-Daudé, 2024/06/04
- [PULL 15/32] hw/core: expand on the alignment of CPUState, Philippe Mathieu-Daudé, 2024/06/04
- [PULL 16/32] cpu: move Qemu[Thread|Cond] setup into common code, Philippe Mathieu-Daudé, 2024/06/04
- [PULL 17/32] cpu-target: don't set cpu->thread_id to bogus value, Philippe Mathieu-Daudé, 2024/06/04
- [PULL 18/32] plugins: remove special casing for cpu->realized, Philippe Mathieu-Daudé, 2024/06/04
- [PULL 19/32] core/cpu-common: initialise plugin state before thread creation,
Philippe Mathieu-Daudé <=
- [PULL 21/32] physmem: Always pass offset + addr to xen_map_cache, Philippe Mathieu-Daudé, 2024/06/04
- [PULL 20/32] xen: Add xen_mr_is_memory(), Philippe Mathieu-Daudé, 2024/06/04
- [PULL 22/32] physmem: Replace check for RAMBlock offset 0 with xen_mr_is_memory, Philippe Mathieu-Daudé, 2024/06/04
- [PULL 23/32] hw/xen: Constify XenLegacyDevice::XenDevOps, Philippe Mathieu-Daudé, 2024/06/04
- [PULL 24/32] hw/xen: Constify xenstore_be::XenDevOps, Philippe Mathieu-Daudé, 2024/06/04
- [PULL 25/32] hw/xen: Make XenDevOps structures const, Philippe Mathieu-Daudé, 2024/06/04
- [PULL 26/32] hw/xen: Register framebuffer backend via xen_backend_init(), Philippe Mathieu-Daudé, 2024/06/04
- [PULL 27/32] hw/misc/debugexit: use runstate API instead of plain exit(), Philippe Mathieu-Daudé, 2024/06/04
- [PULL 28/32] hw/dma/xlnx_dpdma: Read descriptor into buffer, not into pointer-to-buffer, Philippe Mathieu-Daudé, 2024/06/04
- [PULL 29/32] hw/acpi: Remove the deprecated QAPI MEM_UNPLUG_ERROR event, Philippe Mathieu-Daudé, 2024/06/04