From aff56de576c949880d674d37b82bdc97841107fb Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Thu, 14 Mar 2024 14:09:33 -1000 Subject: plugins: Move function pointer in qemu_plugin_dyn_cb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The out-of-line function pointer is mutually exclusive with inline expansion, so move it into the union. Wrap the pointer in a structure named 'regular' to match PLUGIN_CB_REGULAR. Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- include/qemu/plugin.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include/qemu') diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 41db748..5676ab5 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -85,7 +85,6 @@ enum plugin_dyn_cb_subtype { * instance of a callback to be called upon the execution of a particular TB. */ struct qemu_plugin_dyn_cb { - union qemu_plugin_cb_sig f; void *userp; enum plugin_dyn_cb_subtype type; /* @rw applies to mem callbacks only (both regular and inline) */ @@ -93,6 +92,9 @@ struct qemu_plugin_dyn_cb { /* fields specific to each dyn_cb type go here */ union { struct { + union qemu_plugin_cb_sig f; + } regular; + struct { qemu_plugin_u64 entry; enum qemu_plugin_op op; uint64_t imm; -- cgit v1.1 From c7ba94836aa0665a931250e8f03f4aabce3c31f6 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Thu, 14 Mar 2024 09:09:11 -1000 Subject: plugins: Create TCGHelperInfo for all out-of-line callbacks TCGHelperInfo includes the ABI for every function call. Reviewed-by: Pierrick Bouvier Signed-off-by: Richard Henderson --- include/qemu/plugin.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/qemu') diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 5676ab5..d0d830b 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -93,6 +93,7 @@ struct qemu_plugin_dyn_cb { union { struct { union qemu_plugin_cb_sig f; + TCGHelperInfo *info; } regular; struct { qemu_plugin_u64 entry; -- cgit v1.1 From ac977170bf1e89fce25197ad54f04d9ec1f6a2b6 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Thu, 14 Mar 2024 11:27:35 -1000 Subject: plugins: Use emit_before_op for PLUGIN_GEN_FROM_INSN Reviewed-by: Pierrick Bouvier Signed-off-by: Richard Henderson --- include/qemu/plugin.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include/qemu') diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index d0d830b..0d00624 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -74,7 +74,6 @@ enum plugin_dyn_cb_type { enum plugin_dyn_cb_subtype { PLUGIN_CB_REGULAR, - PLUGIN_CB_REGULAR_R, PLUGIN_CB_INLINE, PLUGIN_N_CB_SUBTYPES, }; -- cgit v1.1 From db409c01fde5be31ef34c69aa1d91880975e93c5 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Thu, 14 Mar 2024 16:02:19 -1000 Subject: plugins: Simplify callback queues We have qemu_plugin_dyn_cb.type to differentiate the various callback types, so we do not need to keep them in separate queues. Reviewed-by: Pierrick Bouvier Signed-off-by: Richard Henderson --- include/qemu/plugin.h | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 0d00624..b679a22 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -67,15 +67,8 @@ union qemu_plugin_cb_sig { }; enum plugin_dyn_cb_type { - PLUGIN_CB_INSN, - PLUGIN_CB_MEM, - PLUGIN_N_CB_TYPES, -}; - -enum plugin_dyn_cb_subtype { PLUGIN_CB_REGULAR, PLUGIN_CB_INLINE, - PLUGIN_N_CB_SUBTYPES, }; /* @@ -85,7 +78,7 @@ enum plugin_dyn_cb_subtype { */ struct qemu_plugin_dyn_cb { void *userp; - enum plugin_dyn_cb_subtype type; + enum plugin_dyn_cb_type type; /* @rw applies to mem callbacks only (both regular and inline) */ enum qemu_plugin_mem_rw rw; /* fields specific to each dyn_cb type go here */ @@ -107,7 +100,8 @@ struct qemu_plugin_insn { GByteArray *data; uint64_t vaddr; void *haddr; - GArray *cbs[PLUGIN_N_CB_TYPES][PLUGIN_N_CB_SUBTYPES]; + GArray *insn_cbs; + GArray *mem_cbs; bool calls_helpers; /* if set, the instruction calls helpers that might access guest memory */ @@ -136,16 +130,9 @@ static inline void qemu_plugin_insn_cleanup_fn(gpointer data) static inline struct qemu_plugin_insn *qemu_plugin_insn_alloc(void) { - int i, j; struct qemu_plugin_insn *insn = g_new0(struct qemu_plugin_insn, 1); - insn->data = g_byte_array_sized_new(4); - for (i = 0; i < PLUGIN_N_CB_TYPES; i++) { - for (j = 0; j < PLUGIN_N_CB_SUBTYPES; j++) { - insn->cbs[i][j] = g_array_new(false, false, - sizeof(struct qemu_plugin_dyn_cb)); - } - } + insn->data = g_byte_array_sized_new(4); return insn; } @@ -162,7 +149,7 @@ struct qemu_plugin_tb { /* if set, the TB calls helpers that might access guest memory */ bool mem_helper; - GArray *cbs[PLUGIN_N_CB_SUBTYPES]; + GArray *cbs; }; /** @@ -175,22 +162,22 @@ struct qemu_plugin_insn *qemu_plugin_tb_insn_get(struct qemu_plugin_tb *tb, uint64_t pc) { struct qemu_plugin_insn *insn; - int i, j; if (unlikely(tb->n == tb->insns->len)) { struct qemu_plugin_insn *new_insn = qemu_plugin_insn_alloc(); g_ptr_array_add(tb->insns, new_insn); } + insn = g_ptr_array_index(tb->insns, tb->n++); g_byte_array_set_size(insn->data, 0); insn->calls_helpers = false; insn->mem_helper = false; insn->vaddr = pc; - - for (i = 0; i < PLUGIN_N_CB_TYPES; i++) { - for (j = 0; j < PLUGIN_N_CB_SUBTYPES; j++) { - g_array_set_size(insn->cbs[i][j], 0); - } + if (insn->insn_cbs) { + g_array_set_size(insn->insn_cbs, 0); + } + if (insn->mem_cbs) { + g_array_set_size(insn->mem_cbs, 0); } return insn; -- cgit v1.1 From ccd8f17e02d70c4e9e1d7f3b8ee0f80dd58dc979 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Fri, 15 Mar 2024 08:06:44 -1000 Subject: plugins: Introduce PLUGIN_CB_MEM_REGULAR Use different enumerators for vcpu_udata and vcpu_mem callbacks. Reviewed-by: Pierrick Bouvier Signed-off-by: Richard Henderson --- include/qemu/plugin.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/qemu') diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index b679a22..f5a08b1 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -68,6 +68,7 @@ union qemu_plugin_cb_sig { enum plugin_dyn_cb_type { PLUGIN_CB_REGULAR, + PLUGIN_CB_MEM_REGULAR, PLUGIN_CB_INLINE, }; -- cgit v1.1 From b384c734ecb6d6a4f121d5716f7275e8e350a6fa Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Fri, 15 Mar 2024 10:33:49 -1000 Subject: plugins: Replace pr_ops with a proper debug dump flag The DEBUG_PLUGIN_GEN_OPS ifdef is replaced with "-d op_plugin". The second pr_ops call can be obtained with "-d op". Reviewed-by: Pierrick Bouvier Signed-off-by: Richard Henderson --- include/qemu/log.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/qemu') diff --git a/include/qemu/log.h b/include/qemu/log.h index df59bfa..e10e24c 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -36,6 +36,7 @@ bool qemu_log_separate(void); #define LOG_STRACE (1 << 19) #define LOG_PER_THREAD (1 << 20) #define CPU_LOG_TB_VPU (1 << 21) +#define LOG_TB_OP_PLUGIN (1 << 22) /* Lock/unlock output. */ -- cgit v1.1 From 5e379b08bceb04631401fda674c4c9f7ab1e3f94 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Thu, 14 Mar 2024 19:27:28 -1000 Subject: plugins: Merge qemu_plugin_tb_insn_get to plugin-gen.c Merge qemu_plugin_insn_alloc and qemu_plugin_tb_insn_get into plugin_gen_insn_start, since it is used nowhere else. Reviewed-by: Pierrick Bouvier Signed-off-by: Richard Henderson --- include/qemu/plugin.h | 39 --------------------------------------- 1 file changed, 39 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index f5a08b1..1806252 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -129,14 +129,6 @@ static inline void qemu_plugin_insn_cleanup_fn(gpointer data) g_byte_array_free(insn->data, true); } -static inline struct qemu_plugin_insn *qemu_plugin_insn_alloc(void) -{ - struct qemu_plugin_insn *insn = g_new0(struct qemu_plugin_insn, 1); - - insn->data = g_byte_array_sized_new(4); - return insn; -} - /* Internal context for this TranslationBlock */ struct qemu_plugin_tb { GPtrArray *insns; @@ -154,37 +146,6 @@ struct qemu_plugin_tb { }; /** - * qemu_plugin_tb_insn_get(): get next plugin record for translation. - * @tb: the internal tb context - * @pc: address of instruction - */ -static inline -struct qemu_plugin_insn *qemu_plugin_tb_insn_get(struct qemu_plugin_tb *tb, - uint64_t pc) -{ - struct qemu_plugin_insn *insn; - - if (unlikely(tb->n == tb->insns->len)) { - struct qemu_plugin_insn *new_insn = qemu_plugin_insn_alloc(); - g_ptr_array_add(tb->insns, new_insn); - } - - insn = g_ptr_array_index(tb->insns, tb->n++); - g_byte_array_set_size(insn->data, 0); - insn->calls_helpers = false; - insn->mem_helper = false; - insn->vaddr = pc; - if (insn->insn_cbs) { - g_array_set_size(insn->insn_cbs, 0); - } - if (insn->mem_cbs) { - g_array_set_size(insn->mem_cbs, 0); - } - - return insn; -} - -/** * struct CPUPluginState - per-CPU state for plugins * @event_mask: plugin event bitmap. Modified only via async work. */ -- cgit v1.1