* [PATCH 0/6] accel: Restrict TCG plugin (un)registration to TCG accel
@ 2024-05-28 14:59 Philippe Mathieu-Daudé
2024-05-28 14:59 ` [PATCH 1/6] system/runstate: Remove unused 'qemu/plugin.h' header Philippe Mathieu-Daudé
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-05-28 14:59 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Pierrick Bouvier, Philippe Mathieu-Daudé,
Paolo Bonzini, Richard Henderson
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/20240209123226.32576-1-philmd@linaro.org/
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(-)
--
2.41.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/6] system/runstate: Remove unused 'qemu/plugin.h' header
2024-05-28 14:59 [PATCH 0/6] accel: Restrict TCG plugin (un)registration to TCG accel Philippe Mathieu-Daudé
@ 2024-05-28 14:59 ` Philippe Mathieu-Daudé
2024-05-28 14:59 ` [PATCH 2/6] accel/tcg: Move common declarations to 'internal-common.h' Philippe Mathieu-Daudé
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-05-28 14:59 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Pierrick Bouvier, Philippe Mathieu-Daudé,
Paolo Bonzini, Richard Henderson
system/runstate.c never required "qemu/plugin.h".
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
system/runstate.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/system/runstate.c b/system/runstate.c
index cb4905a40f..ec32e270cb 100644
--- a/system/runstate.c
+++ b/system/runstate.c
@@ -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"
--
2.41.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/6] accel/tcg: Move common declarations to 'internal-common.h'
2024-05-28 14:59 [PATCH 0/6] accel: Restrict TCG plugin (un)registration to TCG accel Philippe Mathieu-Daudé
2024-05-28 14:59 ` [PATCH 1/6] system/runstate: Remove unused 'qemu/plugin.h' header Philippe Mathieu-Daudé
@ 2024-05-28 14:59 ` Philippe Mathieu-Daudé
2024-05-28 14:59 ` [PATCH 3/6] accel: Clarify accel_cpu_common_[un]realize() use unassigned vCPU Philippe Mathieu-Daudé
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-05-28 14:59 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Pierrick Bouvier, Philippe Mathieu-Daudé,
Paolo Bonzini, Richard Henderson
'internal-target.h' is meant for target-specific declarations,
while 'internal-common.h' for common ones. Move common declarations
to it.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
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(-)
diff --git a/accel/tcg/internal-common.h b/accel/tcg/internal-common.h
index cff43d221b..a8fc3db774 100644
--- a/accel/tcg/internal-common.h
+++ b/accel/tcg/internal-common.h
@@ -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
diff --git a/accel/tcg/internal-target.h b/accel/tcg/internal-target.h
index 4e36cf858e..fe109724c6 100644
--- a/accel/tcg/internal-target.h
+++ b/accel/tcg/internal-target.h
@@ -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
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
index c6619f5b98..2090907dba 100644
--- a/accel/tcg/tcg-all.c
+++ b/accel/tcg/tcg-all.c
@@ -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;
--
2.41.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/6] accel: Clarify accel_cpu_common_[un]realize() use unassigned vCPU
2024-05-28 14:59 [PATCH 0/6] accel: Restrict TCG plugin (un)registration to TCG accel Philippe Mathieu-Daudé
2024-05-28 14:59 ` [PATCH 1/6] system/runstate: Remove unused 'qemu/plugin.h' header Philippe Mathieu-Daudé
2024-05-28 14:59 ` [PATCH 2/6] accel/tcg: Move common declarations to 'internal-common.h' Philippe Mathieu-Daudé
@ 2024-05-28 14:59 ` Philippe Mathieu-Daudé
2024-05-28 14:59 ` [PATCH 4/6] accel: Introduce accel_cpu_common_[un]realize_assigned() handlers Philippe Mathieu-Daudé
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-05-28 14:59 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Pierrick Bouvier, Philippe Mathieu-Daudé,
Paolo Bonzini, Richard Henderson
In preparation of introducing [un]realize handlers for
when vCPUs are assigned, rename current handlers using
the '_unassigned' suffix.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
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(-)
diff --git a/accel/tcg/internal-common.h b/accel/tcg/internal-common.h
index a8fc3db774..ec2c6317b7 100644
--- a/accel/tcg/internal-common.h
+++ b/accel/tcg/internal-common.h
@@ -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
diff --git a/include/qemu/accel.h b/include/qemu/accel.h
index 972a849a2b..dd18c41dc0 100644
--- a/include/qemu/accel.h
+++ b/include/qemu/accel.h
@@ -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:
diff --git a/accel/accel-target.c b/accel/accel-target.c
index 08626c00c2..e0a79c0fce 100644
--- a/accel/accel-target.c
+++ b/accel/accel-target.c
@@ -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);
}
}
diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 2972f75b96..08769cf91e 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -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);
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
index 2090907dba..c08a6acc21 100644
--- a/accel/tcg/tcg-all.c
+++ b/accel/tcg/tcg-all.c
@@ -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;
diff --git a/cpu-target.c b/cpu-target.c
index 5af120e8aa..9ab5a28cb5 100644
--- a/cpu-target.c
+++ b/cpu-target.c
@@ -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);
}
/*
--
2.41.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/6] accel: Introduce accel_cpu_common_[un]realize_assigned() handlers
2024-05-28 14:59 [PATCH 0/6] accel: Restrict TCG plugin (un)registration to TCG accel Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2024-05-28 14:59 ` [PATCH 3/6] accel: Clarify accel_cpu_common_[un]realize() use unassigned vCPU Philippe Mathieu-Daudé
@ 2024-05-28 14:59 ` Philippe Mathieu-Daudé
2024-05-28 14:59 ` [PATCH 5/6] accel: Restrict TCG plugin (un)registration to TCG accel Philippe Mathieu-Daudé
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-05-28 14:59 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Pierrick Bouvier, Philippe Mathieu-Daudé,
Paolo Bonzini, Richard Henderson
Introduce handlers called while the vCPU has an assigned
index and is still in the global %cpus_queue.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/qemu/accel.h | 20 ++++++++++++++++++++
accel/accel-target.c | 23 +++++++++++++++++++++++
cpu-target.c | 6 ++++++
3 files changed, 49 insertions(+)
diff --git a/include/qemu/accel.h b/include/qemu/accel.h
index dd18c41dc0..f828d32204 100644
--- a/include/qemu/accel.h
+++ b/include/qemu/accel.h
@@ -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.
diff --git a/accel/accel-target.c b/accel/accel-target.c
index e0a79c0fce..b2ba219a44 100644
--- a/accel/accel-target.c
+++ b/accel/accel-target.c
@@ -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();
diff --git a/cpu-target.c b/cpu-target.c
index 9ab5a28cb5..de903f30cb 100644
--- a/cpu-target.c
+++ b/cpu-target.c
@@ -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
--
2.41.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/6] accel: Restrict TCG plugin (un)registration to TCG accel
2024-05-28 14:59 [PATCH 0/6] accel: Restrict TCG plugin (un)registration to TCG accel Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2024-05-28 14:59 ` [PATCH 4/6] accel: Introduce accel_cpu_common_[un]realize_assigned() handlers Philippe Mathieu-Daudé
@ 2024-05-28 14:59 ` Philippe Mathieu-Daudé
2024-05-28 14:59 ` [PATCH 6/6] accel/tcg: Move qemu_plugin_vcpu_init__async() to plugins/ Philippe Mathieu-Daudé
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-05-28 14:59 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Pierrick Bouvier, Philippe Mathieu-Daudé,
Paolo Bonzini, Richard Henderson
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.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
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(-)
diff --git a/accel/tcg/internal-common.h b/accel/tcg/internal-common.h
index ec2c6317b7..d900897c6e 100644
--- a/accel/tcg/internal-common.h
+++ b/accel/tcg/internal-common.h
@@ -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
diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h
index bc5aef979e..d39d105795 100644
--- a/include/qemu/plugin.h
+++ b/include/qemu/plugin.h
@@ -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)
{ }
diff --git a/accel/tcg/cpu-exec-common.c b/accel/tcg/cpu-exec-common.c
index bc9b1a260e..3c4a4c9f21 100644
--- a/accel/tcg/cpu-exec-common.c
+++ b/accel/tcg/cpu-exec-common.c
@@ -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
+}
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
index c08a6acc21..a32663f507 100644
--- a/accel/tcg/tcg-all.c
+++ b/accel/tcg/tcg-all.c
@@ -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;
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 0f0a247f56..fda2c2c1d5 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -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);
}
--
2.41.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 6/6] accel/tcg: Move qemu_plugin_vcpu_init__async() to plugins/
2024-05-28 14:59 [PATCH 0/6] accel: Restrict TCG plugin (un)registration to TCG accel Philippe Mathieu-Daudé
` (4 preceding siblings ...)
2024-05-28 14:59 ` [PATCH 5/6] accel: Restrict TCG plugin (un)registration to TCG accel Philippe Mathieu-Daudé
@ 2024-05-28 14:59 ` Philippe Mathieu-Daudé
2024-05-28 18:15 ` [PATCH 0/6] accel: Restrict TCG plugin (un)registration to TCG accel Richard Henderson
2024-05-28 18:55 ` Pierrick Bouvier
7 siblings, 0 replies; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-05-28 14:59 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Bennée, Pierrick Bouvier, Philippe Mathieu-Daudé,
Paolo Bonzini, Richard Henderson
Calling qemu_plugin_vcpu_init__async() on the vCPU thread
is a detail of plugins, not relevant to TCG vCPU management.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
accel/tcg/cpu-exec-common.c | 11 ++---------
plugins/core.c | 8 +++++++-
2 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/accel/tcg/cpu-exec-common.c b/accel/tcg/cpu-exec-common.c
index 3c4a4c9f21..02499bfb1d 100644
--- a/accel/tcg/cpu-exec-common.c
+++ b/accel/tcg/cpu-exec-common.c
@@ -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;
diff --git a/plugins/core.c b/plugins/core.c
index 0726bc7f25..0eda47ba33 100644
--- a/plugins/core.c
+++ b/plugins/core.c
@@ -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;
--
2.41.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 0/6] accel: Restrict TCG plugin (un)registration to TCG accel
2024-05-28 14:59 [PATCH 0/6] accel: Restrict TCG plugin (un)registration to TCG accel Philippe Mathieu-Daudé
` (5 preceding siblings ...)
2024-05-28 14:59 ` [PATCH 6/6] accel/tcg: Move qemu_plugin_vcpu_init__async() to plugins/ Philippe Mathieu-Daudé
@ 2024-05-28 18:15 ` Richard Henderson
2024-05-28 18:55 ` Pierrick Bouvier
7 siblings, 0 replies; 9+ messages in thread
From: Richard Henderson @ 2024-05-28 18:15 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Alex Bennée, Pierrick Bouvier, Paolo Bonzini
On 5/28/24 07:59, Philippe Mathieu-Daudé wrote:
> 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/
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/6] accel: Restrict TCG plugin (un)registration to TCG accel
2024-05-28 14:59 [PATCH 0/6] accel: Restrict TCG plugin (un)registration to TCG accel Philippe Mathieu-Daudé
` (6 preceding siblings ...)
2024-05-28 18:15 ` [PATCH 0/6] accel: Restrict TCG plugin (un)registration to TCG accel Richard Henderson
@ 2024-05-28 18:55 ` Pierrick Bouvier
7 siblings, 0 replies; 9+ messages in thread
From: Pierrick Bouvier @ 2024-05-28 18:55 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Alex Bennée, Paolo Bonzini, Richard Henderson
On 5/28/24 07:59, Philippe Mathieu-Daudé wrote: > 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/
>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-05-28 18:56 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-28 14:59 [PATCH 0/6] accel: Restrict TCG plugin (un)registration to TCG accel Philippe Mathieu-Daudé
2024-05-28 14:59 ` [PATCH 1/6] system/runstate: Remove unused 'qemu/plugin.h' header Philippe Mathieu-Daudé
2024-05-28 14:59 ` [PATCH 2/6] accel/tcg: Move common declarations to 'internal-common.h' Philippe Mathieu-Daudé
2024-05-28 14:59 ` [PATCH 3/6] accel: Clarify accel_cpu_common_[un]realize() use unassigned vCPU Philippe Mathieu-Daudé
2024-05-28 14:59 ` [PATCH 4/6] accel: Introduce accel_cpu_common_[un]realize_assigned() handlers Philippe Mathieu-Daudé
2024-05-28 14:59 ` [PATCH 5/6] accel: Restrict TCG plugin (un)registration to TCG accel Philippe Mathieu-Daudé
2024-05-28 14:59 ` [PATCH 6/6] accel/tcg: Move qemu_plugin_vcpu_init__async() to plugins/ Philippe Mathieu-Daudé
2024-05-28 18:15 ` [PATCH 0/6] accel: Restrict TCG plugin (un)registration to TCG accel Richard Henderson
2024-05-28 18:55 ` Pierrick Bouvier
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).