Skip to contentSkip to conversation

accel: Restrict TCG plugin (un)registration to TCG accel

PATCH In review Philippe Mathieu-Daudé 3 participants 9 messages May 28, 2024

lore
Share & tools
lore
#0 lore raw

cover accel: Restrict TCG plugin (un)registration to TCG accel

Hi,

TL;DR; this series remove TCG plugin code from generic accel code.

Since the introduction of the scoreboard in plugins, the INIT hook use the vCPU index, which is only available somewhere during the vCPU REALIZE() step (see below for call tree).

In order to clarify that, we split accel_cpu_common_[un]realize as *unassigned and *assigned steps. This allow to remove the plugin [un]registration code from common accel code.

Another approach suggested by rth is to add a PostRealize() handler in DeviceClass. This was already experimented here:
https://lore.kernel.org/qemu-devel/[email protected]/
Since it is a change harder to sell, I took this simplified path which just make the vCPU REALIZE a bit more complex, but not really an concern since the current call tree is
https://etherpad.opendev.org/p/QEMU_vCPU_life.

Philippe Mathieu-Daudé (6):
system/runstate: Remove unused 'qemu/plugin.h' header accel/tcg: Move common declarations to 'internal-common.h'
accel: Clarify accel_cpu_common_[un]realize() use unassigned vCPU
accel: Introduce accel_cpu_common_[un]realize_assigned() handlers
accel: Restrict TCG plugin (un)registration to TCG accel accel/tcg: Move qemu_plugin_vcpu_init__async() to plugins/

 accel/tcg/internal-common.h | 17 ++++++++++++++++
 accel/tcg/internal-target.h | 14 -------------
 include/qemu/accel.h        | 39 ++++++++++++++++++++++++++++++-------
 include/qemu/plugin.h       |  6 ------
 accel/accel-target.c        | 34 +++++++++++++++++++++++++++-----
 accel/tcg/cpu-exec-common.c | 20 +++++++++++++++++++
 accel/tcg/cpu-exec.c        |  4 ++--
 accel/tcg/tcg-all.c         |  8 +++++---
 cpu-target.c                | 10 ++++++++--
 hw/core/cpu-common.c        | 25 ------------------------
 plugins/core.c              |  8 +++++++-
 system/runstate.c           |  1 -
 12 files changed, 120 insertions(+), 66 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/6 system/runstate: Remove unused 'qemu/plugin.h' header

system/runstate.c never required "qemu/plugin.h".

---
 system/runstate.c | 1 -
 1 file changed, 1 deletion(-)
system/runstate.c +0 -1
index cb4905a40f..ec32e270cb 100644
@@ -45,7 +45,6 @@
 #include "qemu/job.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
-#include "qemu/plugin.h"
 #include "qemu/sockets.h"
 #include "qemu/timer.h"
 #include "qemu/thread.h"
Signature · 1 line
2.41.0
#2 lore raw

PATCH 2/6 accel/tcg: Move common declarations to 'internal-common.h'

In reply to Philippe Mathieu-Daudé

'internal-target.h' is meant for target-specific declarations, while 'internal-common.h' for common ones. Move common declarations to it.

---
 accel/tcg/internal-common.h | 15 +++++++++++++++
 accel/tcg/internal-target.h | 14 --------------
 accel/tcg/tcg-all.c         |  2 +-
 3 files changed, 16 insertions(+), 15 deletions(-)
accel/tcg/internal-common.h +15 -0
index cff43d221b..a8fc3db774 100644
@@ -15,6 +15,8 @@
 extern int64_t max_delay;
 extern int64_t max_advance;
 
+extern bool one_insn_per_tb;
+
 /*
  * Return true if CS is not running in parallel with other cpus, either
  * because there are no other cpus or we are within an exclusive context.
@@ -41,4 +43,17 @@ static inline bool cpu_plugin_mem_cbs_enabled(const CPUState *cpu)
 #endif
 }
 
+TranslationBlock *tb_gen_code(CPUState *cpu, vaddr pc,
+                              uint64_t cs_base, uint32_t flags,
+                              int cflags);
+void page_init(void);
+void tb_htable_init(void);
+void tb_reset_jump(TranslationBlock *tb, int n);
+TranslationBlock *tb_link_page(TranslationBlock *tb);
+void cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,
+                               uintptr_t host_pc);
+
+bool tcg_exec_realizefn(CPUState *cpu, Error **errp);
+void tcg_exec_unrealizefn(CPUState *cpu);
+
 #endif
accel/tcg/internal-target.h +0 -14
index 4e36cf858e..fe109724c6 100644
@@ -69,19 +69,7 @@ void tb_invalidate_phys_range_fast(ram_addr_t ram_addr,
 G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
 #endif /* CONFIG_SOFTMMU */
 
-TranslationBlock *tb_gen_code(CPUState *cpu, vaddr pc,
-                              uint64_t cs_base, uint32_t flags,
-                              int cflags);
-void page_init(void);
-void tb_htable_init(void);
-void tb_reset_jump(TranslationBlock *tb, int n);
-TranslationBlock *tb_link_page(TranslationBlock *tb);
 bool tb_invalidate_phys_page_unwind(tb_page_addr_t addr, uintptr_t pc);
-void cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,
-                               uintptr_t host_pc);
-
-bool tcg_exec_realizefn(CPUState *cpu, Error **errp);
-void tcg_exec_unrealizefn(CPUState *cpu);
 
 /* Return the current PC from CPU, which may be cached in TB. */
 static inline vaddr log_pc(CPUState *cpu, const TranslationBlock *tb)
@@ -93,8 +81,6 @@ static inline vaddr log_pc(CPUState *cpu, const TranslationBlock *tb)
     }
 }
 
-extern bool one_insn_per_tb;
-
 /**
  * tcg_req_mo:
  * @type: TCGBar
accel/tcg/tcg-all.c +1 -1
index c6619f5b98..2090907dba 100644
@@ -38,7 +38,7 @@
 #if !defined(CONFIG_USER_ONLY)
 #include "hw/boards.h"
 #endif
-#include "internal-target.h"
+#include "internal-common.h"
 
 struct TCGState {
     AccelState parent_obj;
Signature · 1 line
2.41.0
#3 lore raw

PATCH 3/6 accel: Clarify accel_cpu_common_[un]realize() use unassigned vCPU

In reply to Philippe Mathieu-Daudé

In preparation of introducing [un]realize handlers for when vCPUs are assigned, rename current handlers using the '_unassigned' suffix.

---
 accel/tcg/internal-common.h |  4 ++--
 include/qemu/accel.h        | 17 +++++++++++------
 accel/accel-target.c        | 11 ++++++-----
 accel/tcg/cpu-exec.c        |  4 ++--
 accel/tcg/tcg-all.c         |  4 ++--
 cpu-target.c                |  4 ++--
 6 files changed, 25 insertions(+), 19 deletions(-)
accel/tcg/internal-common.h +2 -2
index a8fc3db774..ec2c6317b7 100644
@@ -53,7 +53,7 @@ TranslationBlock *tb_link_page(TranslationBlock *tb);
 void cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,
                                uintptr_t host_pc);
 
-bool tcg_exec_realizefn(CPUState *cpu, Error **errp);
-void tcg_exec_unrealizefn(CPUState *cpu);
+bool tcg_exec_realize_unassigned(CPUState *cpu, Error **errp);
+void tcg_exec_unrealize_unassigned(CPUState *cpu);
 
 #endif
include/qemu/accel.h +11 -6
index 972a849a2b..dd18c41dc0 100644
@@ -43,8 +43,8 @@ typedef struct AccelClass {
     bool (*has_memory)(MachineState *ms, AddressSpace *as,
                        hwaddr start_addr, hwaddr size);
 #endif
-    bool (*cpu_common_realize)(CPUState *cpu, Error **errp);
-    void (*cpu_common_unrealize)(CPUState *cpu);
+    bool (*cpu_common_realize_unassigned)(CPUState *cpu, Error **errp);
+    void (*cpu_common_unrealize_unassigned)(CPUState *cpu);
 
     /* gdbstub related hooks */
     int (*gdbstub_supported_sstep_flags)(void);
@@ -92,17 +92,22 @@ void accel_setup_post(MachineState *ms);
 void accel_cpu_instance_init(CPUState *cpu);
 
 /**
- * accel_cpu_common_realize:
+ * accel_cpu_common_realize_unassigned:
  * @cpu: The CPU that needs to call accel-specific cpu realization.
  * @errp: currently unused.
+ *
+ * The @cpu index is not yet assigned.
  */
-bool accel_cpu_common_realize(CPUState *cpu, Error **errp);
+bool accel_cpu_common_realize_unassigned(CPUState *cpu, Error **errp);
 
 /**
- * accel_cpu_common_unrealize:
+ * accel_cpu_common_unrealize_unassigned:
  * @cpu: The CPU that needs to call accel-specific cpu unrealization.
+ *
+ * The @cpu index is no more assigned, @cpu has been removed from the global
+ * #cpus_queue.
  */
-void accel_cpu_common_unrealize(CPUState *cpu);
+void accel_cpu_common_unrealize_unassigned(CPUState *cpu);
 
 /**
  * accel_supported_gdbstub_sstep_flags:
accel/accel-target.c +6 -5
index 08626c00c2..e0a79c0fce 100644
@@ -119,7 +119,7 @@ void accel_cpu_instance_init(CPUState *cpu)
     }
 }
 
-bool accel_cpu_common_realize(CPUState *cpu, Error **errp)
+bool accel_cpu_common_realize_unassigned(CPUState *cpu, Error **errp)
 {
     CPUClass *cc = CPU_GET_CLASS(cpu);
     AccelState *accel = current_accel();
@@ -132,21 +132,22 @@ bool accel_cpu_common_realize(CPUState *cpu, Error **errp)
     }
 
     /* generic realization */
-    if (acc->cpu_common_realize && !acc->cpu_common_realize(cpu, errp)) {
+    if (acc->cpu_common_realize_unassigned
+            && !acc->cpu_common_realize_unassigned(cpu, errp)) {
         return false;
     }
 
     return true;
 }
 
-void accel_cpu_common_unrealize(CPUState *cpu)
+void accel_cpu_common_unrealize_unassigned(CPUState *cpu)
 {
     AccelState *accel = current_accel();
     AccelClass *acc = ACCEL_GET_CLASS(accel);
 
     /* generic unrealization */
-    if (acc->cpu_common_unrealize) {
-        acc->cpu_common_unrealize(cpu);
+    if (acc->cpu_common_unrealize_unassigned) {
+        acc->cpu_common_unrealize_unassigned(cpu);
     }
 }
 
accel/tcg/cpu-exec.c +2 -2
index 2972f75b96..08769cf91e 100644
@@ -1074,7 +1074,7 @@ int cpu_exec(CPUState *cpu)
     return ret;
 }
 
-bool tcg_exec_realizefn(CPUState *cpu, Error **errp)
+bool tcg_exec_realize_unassigned(CPUState *cpu, Error **errp)
 {
     static bool tcg_target_initialized;
 
@@ -1094,7 +1094,7 @@ bool tcg_exec_realizefn(CPUState *cpu, Error **errp)
 }
 
 /* undo the initializations in reverse order */
-void tcg_exec_unrealizefn(CPUState *cpu)
+void tcg_exec_unrealize_unassigned(CPUState *cpu)
 {
 #ifndef CONFIG_USER_ONLY
     tcg_iommu_free_notifier_list(cpu);
accel/tcg/tcg-all.c +2 -2
index 2090907dba..c08a6acc21 100644
@@ -227,8 +227,8 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data)
     AccelClass *ac = ACCEL_CLASS(oc);
     ac->name = "tcg";
     ac->init_machine = tcg_init_machine;
-    ac->cpu_common_realize = tcg_exec_realizefn;
-    ac->cpu_common_unrealize = tcg_exec_unrealizefn;
+    ac->cpu_common_realize_unassigned = tcg_exec_realize_unassigned;
+    ac->cpu_common_unrealize_unassigned = tcg_exec_unrealize_unassigned;
     ac->allowed = &tcg_allowed;
     ac->gdbstub_supported_sstep_flags = tcg_gdbstub_supported_sstep_flags;
 
cpu-target.c +2 -2
index 5af120e8aa..9ab5a28cb5 100644
@@ -136,7 +136,7 @@ bool cpu_exec_realizefn(CPUState *cpu, Error **errp)
     /* cache the cpu class for the hotpath */
     cpu->cc = CPU_GET_CLASS(cpu);
 
-    if (!accel_cpu_common_realize(cpu, errp)) {
+    if (!accel_cpu_common_realize_unassigned(cpu, errp)) {
         return false;
     }
 
@@ -176,7 +176,7 @@ void cpu_exec_unrealizefn(CPUState *cpu)
      * Now that the vCPU has been removed from the RCU list, we can call
      * accel_cpu_common_unrealize, which may free fields using call_rcu.
      */
-    accel_cpu_common_unrealize(cpu);
+    accel_cpu_common_unrealize_unassigned(cpu);
 }
 
 /*
Signature · 1 line
2.41.0
#4 lore raw

PATCH 4/6 accel: Introduce accel_cpu_common_[un]realize_assigned() handlers

In reply to Philippe Mathieu-Daudé

Introduce handlers called while the vCPU has an assigned index and is still in the global %cpus_queue.

---
 include/qemu/accel.h | 20 ++++++++++++++++++++
 accel/accel-target.c | 23 +++++++++++++++++++++++
 cpu-target.c         |  6 ++++++
 3 files changed, 49 insertions(+)
include/qemu/accel.h +20 -0
index dd18c41dc0..f828d32204 100644
@@ -44,6 +44,8 @@ typedef struct AccelClass {
                        hwaddr start_addr, hwaddr size);
 #endif
     bool (*cpu_common_realize_unassigned)(CPUState *cpu, Error **errp);
+    bool (*cpu_common_realize_assigned)(CPUState *cpu, Error **errp);
+    void (*cpu_common_unrealize_assigned)(CPUState *cpu);
     void (*cpu_common_unrealize_unassigned)(CPUState *cpu);
 
     /* gdbstub related hooks */
@@ -100,6 +102,24 @@ void accel_cpu_instance_init(CPUState *cpu);
  */
 bool accel_cpu_common_realize_unassigned(CPUState *cpu, Error **errp);
 
+/**
+ * accel_cpu_common_realize_assigned:
+ * @cpu: The CPU that needs to call accel-specific cpu realization.
+ * @errp: currently unused.
+ *
+ * The @cpu index is assigned, @cpu is added to the global #cpus_queue.
+ */
+bool accel_cpu_common_realize_assigned(CPUState *cpu, Error **errp);
+
+/**
+ * accel_cpu_common_unrealize_unassigned:
+ * @cpu: The CPU that needs to call accel-specific cpu unrealization.
+ *
+ * The @cpu index is still assigned, @cpu is still part of the global
+ * #cpus_queue.
+ */
+void accel_cpu_common_unrealize_assigned(CPUState *cpu);
+
 /**
  * accel_cpu_common_unrealize_unassigned:
  * @cpu: The CPU that needs to call accel-specific cpu unrealization.
accel/accel-target.c +23 -0
index e0a79c0fce..b2ba219a44 100644
@@ -140,6 +140,29 @@ bool accel_cpu_common_realize_unassigned(CPUState *cpu, Error **errp)
     return true;
 }
 
+bool accel_cpu_common_realize_assigned(CPUState *cpu, Error **errp)
+{
+    AccelState *accel = current_accel();
+    AccelClass *acc = ACCEL_GET_CLASS(accel);
+
+    if (acc->cpu_common_realize_assigned
+            && !acc->cpu_common_realize_assigned(cpu, errp)) {
+        return false;
+    }
+
+    return true;
+}
+
+void accel_cpu_common_unrealize_assigned(CPUState *cpu)
+{
+    AccelState *accel = current_accel();
+    AccelClass *acc = ACCEL_GET_CLASS(accel);
+
+    if (acc->cpu_common_unrealize_assigned) {
+        acc->cpu_common_unrealize_assigned(cpu);
+    }
+}
+
 void accel_cpu_common_unrealize_unassigned(CPUState *cpu)
 {
     AccelState *accel = current_accel();
cpu-target.c +6 -0
index 9ab5a28cb5..de903f30cb 100644
@@ -143,6 +143,10 @@ bool cpu_exec_realizefn(CPUState *cpu, Error **errp)
     /* Wait until cpu initialization complete before exposing cpu. */
     cpu_list_add(cpu);
 
+    if (!accel_cpu_common_realize_assigned(cpu, errp)) {
+        return false;
+    }
+
 #ifdef CONFIG_USER_ONLY
     assert(qdev_get_vmsd(DEVICE(cpu)) == NULL ||
            qdev_get_vmsd(DEVICE(cpu))->unmigratable);
@@ -171,6 +175,8 @@ void cpu_exec_unrealizefn(CPUState *cpu)
     }
 #endif
 
+    accel_cpu_common_unrealize_assigned(cpu);
+
     cpu_list_remove(cpu);
     /*
      * Now that the vCPU has been removed from the RCU list, we can call
Signature · 1 line
2.41.0
#5 lore raw

PATCH 5/6 accel: Restrict TCG plugin (un)registration to TCG accel

In reply to Philippe Mathieu-Daudé

Use the AccelClass::cpu_common_[un]realize_assigned() handlers to [un]register the TCG plugin handlers, allowing to remove accel specific code from the common hw/core/cpu-common.c file.

Remove the now unnecessary qemu_plugin_vcpu_init_hook() and qemu_plugin_vcpu_exit_hook() stub.

---
 accel/tcg/internal-common.h |  2 ++
 include/qemu/plugin.h       |  6 ------
 accel/tcg/cpu-exec-common.c | 27 +++++++++++++++++++++++++++
 accel/tcg/tcg-all.c         |  2 ++
 hw/core/cpu-common.c        | 25 -------------------------
 5 files changed, 31 insertions(+), 31 deletions(-)
accel/tcg/internal-common.h +2 -0
index ec2c6317b7..d900897c6e 100644
@@ -54,6 +54,8 @@ void cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,
                                uintptr_t host_pc);
 
 bool tcg_exec_realize_unassigned(CPUState *cpu, Error **errp);
+bool tcg_exec_realize_assigned(CPUState *cpu, Error **errp);
+void tcg_exec_unrealize_assigned(CPUState *cpu);
 void tcg_exec_unrealize_unassigned(CPUState *cpu);
 
 #endif
include/qemu/plugin.h +0 -6
index bc5aef979e..d39d105795 100644
@@ -221,12 +221,6 @@ static inline int qemu_plugin_load_list(QemuPluginList *head, Error **errp)
     return 0;
 }
 
-static inline void qemu_plugin_vcpu_init_hook(CPUState *cpu)
-{ }
-
-static inline void qemu_plugin_vcpu_exit_hook(CPUState *cpu)
-{ }
-
 static inline void qemu_plugin_tb_trans_cb(CPUState *cpu,
                                            struct qemu_plugin_tb *tb)
 { }
accel/tcg/cpu-exec-common.c +27 -0
index bc9b1a260e..3c4a4c9f21 100644
@@ -56,3 +56,30 @@ void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc)
     cpu->exception_index = EXCP_ATOMIC;
     cpu_loop_exit_restore(cpu, pc);
 }
+
+#ifdef CONFIG_PLUGIN
+static void qemu_plugin_vcpu_init__async(CPUState *cpu, run_on_cpu_data unused)
+{
+    qemu_plugin_vcpu_init_hook(cpu);
+}
+#endif
+
+bool tcg_exec_realize_assigned(CPUState *cpu, Error **errp)
+{
+#ifdef CONFIG_PLUGIN
+    cpu->plugin_state = qemu_plugin_create_vcpu_state();
+    /* Plugin initialization must wait until the cpu start executing code */
+    async_run_on_cpu(cpu, qemu_plugin_vcpu_init__async, RUN_ON_CPU_NULL);
+#endif
+
+    return true;
+}
+
+/* undo the initializations in reverse order */
+void tcg_exec_unrealize_assigned(CPUState *cpu)
+{
+#ifdef CONFIG_PLUGIN
+    /* Call the plugin hook before clearing the cpu is fully unrealized */
+    qemu_plugin_vcpu_exit_hook(cpu);
+#endif
+}
accel/tcg/tcg-all.c +2 -0
index c08a6acc21..a32663f507 100644
@@ -228,6 +228,8 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data)
     ac->name = "tcg";
     ac->init_machine = tcg_init_machine;
     ac->cpu_common_realize_unassigned = tcg_exec_realize_unassigned;
+    ac->cpu_common_realize_assigned = tcg_exec_realize_assigned;
+    ac->cpu_common_unrealize_assigned = tcg_exec_unrealize_assigned;
     ac->cpu_common_unrealize_unassigned = tcg_exec_unrealize_unassigned;
     ac->allowed = &tcg_allowed;
     ac->gdbstub_supported_sstep_flags = tcg_gdbstub_supported_sstep_flags;
hw/core/cpu-common.c +0 -25
index 0f0a247f56..fda2c2c1d5 100644
@@ -30,9 +30,6 @@
 #include "hw/boards.h"
 #include "hw/qdev-properties.h"
 #include "trace.h"
-#ifdef CONFIG_PLUGIN
-#include "qemu/plugin.h"
-#endif
 
 CPUState *cpu_by_arch_id(int64_t id)
 {
@@ -192,13 +189,6 @@ static void cpu_common_parse_features(const char *typename, char *features,
     }
 }
 
-#ifdef CONFIG_PLUGIN
-static void qemu_plugin_vcpu_init__async(CPUState *cpu, run_on_cpu_data unused)
-{
-    qemu_plugin_vcpu_init_hook(cpu);
-}
-#endif
-
 static void cpu_common_realizefn(DeviceState *dev, Error **errp)
 {
     CPUState *cpu = CPU(dev);
@@ -222,14 +212,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 */
 }
 
@@ -237,13 +219,6 @@ static void cpu_common_unrealizefn(DeviceState *dev)
 {
     CPUState *cpu = CPU(dev);
 
-    /* Call the plugin hook before clearing the cpu is fully unrealized */
-#ifdef CONFIG_PLUGIN
-    if (tcg_enabled()) {
-        qemu_plugin_vcpu_exit_hook(cpu);
-    }
-#endif
-
     /* NOTE: latest generic point before the cpu is fully unrealized */
     cpu_exec_unrealizefn(cpu);
 }
Signature · 1 line
2.41.0
#6 lore raw

PATCH 6/6 accel/tcg: Move qemu_plugin_vcpu_init__async() to plugins/

In reply to Philippe Mathieu-Daudé

Calling qemu_plugin_vcpu_init__async() on the vCPU thread is a detail of plugins, not relevant to TCG vCPU management.

---
 accel/tcg/cpu-exec-common.c | 11 ++---------
 plugins/core.c              |  8 +++++++-
 2 files changed, 9 insertions(+), 10 deletions(-)
accel/tcg/cpu-exec-common.c +2 -9
index 3c4a4c9f21..02499bfb1d 100644
@@ -57,19 +57,12 @@ void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc)
     cpu_loop_exit_restore(cpu, pc);
 }
 
-#ifdef CONFIG_PLUGIN
-static void qemu_plugin_vcpu_init__async(CPUState *cpu, run_on_cpu_data unused)
-{
-    qemu_plugin_vcpu_init_hook(cpu);
-}
-#endif
-
 bool tcg_exec_realize_assigned(CPUState *cpu, Error **errp)
 {
 #ifdef CONFIG_PLUGIN
     cpu->plugin_state = qemu_plugin_create_vcpu_state();
-    /* Plugin initialization must wait until the cpu start executing code */
-    async_run_on_cpu(cpu, qemu_plugin_vcpu_init__async, RUN_ON_CPU_NULL);
+
+    qemu_plugin_vcpu_init_hook(cpu);
 #endif
 
     return true;
plugins/core.c +7 -1
index 0726bc7f25..0eda47ba33 100644
@@ -245,7 +245,7 @@ static void plugin_grow_scoreboards__locked(CPUState *cpu)
     end_exclusive();
 }
 
-void qemu_plugin_vcpu_init_hook(CPUState *cpu)
+static void qemu_plugin_vcpu_init__async(CPUState *cpu, run_on_cpu_data unused)
 {
     bool success;
 
@@ -261,6 +261,12 @@ void qemu_plugin_vcpu_init_hook(CPUState *cpu)
     plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_INIT);
 }
 
+void qemu_plugin_vcpu_init_hook(CPUState *cpu)
+{
+    /* Plugin initialization must wait until the cpu start executing code */
+    async_run_on_cpu(cpu, qemu_plugin_vcpu_init__async, RUN_ON_CPU_NULL);
+}
+
 void qemu_plugin_vcpu_exit_hook(CPUState *cpu)
 {
     bool success;
Signature · 1 line
2.41.0
Reviewed-by on the v1 series
#7 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Philippe Mathieu-Daudé (6):
system/runstate: Remove unused 'qemu/plugin.h' header accel/tcg: Move common declarations to 'internal-common.h'
accel: Clarify accel_cpu_common_[un]realize() use unassigned vCPU
accel: Introduce accel_cpu_common_[un]realize_assigned() handlers
accel: Restrict TCG plugin (un)registration to TCG accel accel/tcg: Move qemu_plugin_vcpu_init__async() to plugins/

r~

Reviewed-by on the v1 series
#8 lore raw
In reply to Philippe Mathieu-Daudé

On 5/28/24 07:59, Philippe Mathieu-Daudé wrote: > Philippe Mathieu-Daudé (6):

Quoted 7 lines

system/runstate: Remove unused 'qemu/plugin.h' header accel/tcg: Move common declarations to 'internal-common.h'
accel: Clarify accel_cpu_common_[un]realize() use unassigned vCPU
accel: Introduce accel_cpu_common_[un]realize_assigned() handlers
accel: Restrict TCG plugin (un)registration to TCG accel accel/tcg: Move qemu_plugin_vcpu_init__async() to plugins/