From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: pierrick.bouvier@linaro.org, alex.bennee@linaro.org
Subject: [PATCH v2 2/9] accel/tcg: Set CPUState.plugin_ra before all plugin callbacks
Date: Wed, 5 Jun 2024 20:29:19 -0700 [thread overview]
Message-ID: <20240606032926.83599-3-richard.henderson@linaro.org> (raw)
In-Reply-To: <20240606032926.83599-1-richard.henderson@linaro.org>
Store a host code address to use with the tcg unwinder when called
from a plugin. Generate one such store per guest insn that uses
a plugin callback.
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/hw/core/cpu.h | 4 +---
accel/tcg/plugin-gen.c | 49 +++++++++++++++++++++++++++++++++++++-----
2 files changed, 45 insertions(+), 8 deletions(-)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index a2c8536943..19b7fcc9f3 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -354,9 +354,7 @@ typedef union IcountDecr {
typedef struct CPUNegativeOffsetState {
CPUTLB tlb;
#ifdef CONFIG_PLUGIN
- /*
- * The callback pointer are accessed via TCG (see gen_empty_mem_helper).
- */
+ uintptr_t plugin_ra;
GArray *plugin_mem_cbs;
#endif
IcountDecr icount_decr;
diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c
index cc1634e7a6..650e3810e6 100644
--- a/accel/tcg/plugin-gen.c
+++ b/accel/tcg/plugin-gen.c
@@ -37,6 +37,12 @@ enum plugin_gen_from {
PLUGIN_GEN_AFTER_TB,
};
+enum plugin_gen_ra {
+ GEN_RA_DONE,
+ GEN_RA_FROM_TB,
+ GEN_RA_FROM_INSN,
+};
+
/* called before finishing a TB with exit_tb, goto_tb or goto_ptr */
void plugin_gen_disable_mem_helpers(void)
{
@@ -213,11 +219,37 @@ static void gen_mem_cb(struct qemu_plugin_regular_cb *cb,
tcg_temp_free_i32(cpu_index);
}
-static void inject_cb(struct qemu_plugin_dyn_cb *cb)
+static void inject_ra(enum plugin_gen_ra *gen_ra)
+{
+ TCGv_ptr ra;
+ switch (*gen_ra) {
+ case GEN_RA_DONE:
+ return;
+ case GEN_RA_FROM_TB:
+ ra = tcg_constant_ptr(NULL);
+ break;
+ case GEN_RA_FROM_INSN:
+ ra = tcg_temp_ebb_new_ptr();
+ tcg_gen_plugin_pc(ra);
+ break;
+ default:
+ g_assert_not_reached();
+ }
+
+ tcg_gen_st_ptr(ra, tcg_env,
+ offsetof(CPUState, neg.plugin_ra) -
+ offsetof(ArchCPU, env));
+ tcg_temp_free_ptr(ra);
+ *gen_ra = GEN_RA_DONE;
+}
+
+static void inject_cb(struct qemu_plugin_dyn_cb *cb,
+ enum plugin_gen_ra *gen_ra)
{
switch (cb->type) {
case PLUGIN_CB_REGULAR:
+ inject_ra(gen_ra);
gen_udata_cb(&cb->regular);
break;
case PLUGIN_CB_COND:
@@ -235,19 +267,21 @@ static void inject_cb(struct qemu_plugin_dyn_cb *cb)
}
static void inject_mem_cb(struct qemu_plugin_dyn_cb *cb,
+ enum plugin_gen_ra *gen_ra,
enum qemu_plugin_mem_rw rw,
qemu_plugin_meminfo_t meminfo, TCGv_i64 addr)
{
switch (cb->type) {
case PLUGIN_CB_MEM_REGULAR:
if (rw && cb->regular.rw) {
+ inject_ra(gen_ra);
gen_mem_cb(&cb->regular, meminfo, addr);
}
break;
case PLUGIN_CB_INLINE_ADD_U64:
case PLUGIN_CB_INLINE_STORE_U64:
if (rw && cb->inline_insn.rw) {
- inject_cb(cb);
+ inject_cb(cb, gen_ra);
}
break;
default:
@@ -260,6 +294,7 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb)
{
TCGOp *op, *next;
int insn_idx = -1;
+ enum plugin_gen_ra gen_ra;
if (unlikely(qemu_loglevel_mask(LOG_TB_OP_PLUGIN)
&& qemu_log_in_addr_range(tcg_ctx->plugin_db->pc_first))) {
@@ -279,10 +314,12 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb)
*/
memset(tcg_ctx->free_temps, 0, sizeof(tcg_ctx->free_temps));
+ gen_ra = GEN_RA_FROM_TB;
QTAILQ_FOREACH_SAFE(op, &tcg_ctx->ops, link, next) {
switch (op->opc) {
case INDEX_op_insn_start:
insn_idx++;
+ gen_ra = GEN_RA_FROM_INSN;
break;
case INDEX_op_plugin_cb:
@@ -318,7 +355,8 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb)
cbs = plugin_tb->cbs;
for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) {
inject_cb(
- &g_array_index(cbs, struct qemu_plugin_dyn_cb, i));
+ &g_array_index(cbs, struct qemu_plugin_dyn_cb, i),
+ &gen_ra);
}
break;
@@ -330,7 +368,8 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb)
cbs = insn->insn_cbs;
for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) {
inject_cb(
- &g_array_index(cbs, struct qemu_plugin_dyn_cb, i));
+ &g_array_index(cbs, struct qemu_plugin_dyn_cb, i),
+ &gen_ra);
}
break;
@@ -362,7 +401,7 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb)
cbs = insn->mem_cbs;
for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) {
inject_mem_cb(&g_array_index(cbs, struct qemu_plugin_dyn_cb, i),
- rw, meminfo, addr);
+ &gen_ra, rw, meminfo, addr);
}
tcg_ctx->emit_before_op = NULL;
--
2.34.1
next prev parent reply other threads:[~2024-06-06 3:31 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-06 3:29 [PATCH v2 0/9] plugins: Use unwind info for special gdb registers Richard Henderson
2024-06-06 3:29 ` [PATCH v2 1/9] tcg: Introduce INDEX_op_plugin_pc Richard Henderson
2024-06-06 9:40 ` Alex Bennée
2024-06-06 3:29 ` Richard Henderson [this message]
2024-06-06 9:44 ` [PATCH v2 2/9] accel/tcg: Set CPUState.plugin_ra before all plugin callbacks Alex Bennée
2024-06-06 3:29 ` [PATCH v2 3/9] accel/tcg: Return the TranslationBlock from cpu_unwind_state_data Richard Henderson
2024-06-06 9:45 ` Alex Bennée
2024-06-06 3:29 ` [PATCH v2 4/9] plugins: Introduce TCGCPUOps callbacks for mid-tb register reads Richard Henderson
2024-06-06 9:47 ` Alex Bennée
2024-06-06 10:22 ` Alex Bennée
2024-06-06 3:29 ` [PATCH v2 5/9] target/i386: Split out gdb-internal.h Richard Henderson
2024-06-06 6:51 ` Philippe Mathieu-Daudé
2024-06-06 15:27 ` Richard Henderson
2024-06-06 3:29 ` [PATCH v2 6/9] target/i386: Introduce cpu_compute_eflags_ccop Richard Henderson
2024-06-06 3:29 ` [PATCH v2 7/9] target/i386: Implement TCGCPUOps for plugin register reads Richard Henderson
2024-06-06 9:52 ` Alex Bennée
2024-06-06 3:29 ` [PATCH v2 8/9] target/arm: Add aarch64_tcg_ops Richard Henderson
2024-06-12 14:36 ` Alex Bennée
2024-06-12 15:45 ` Richard Henderson
2024-06-13 12:35 ` Alex Bennée
2024-06-06 3:29 ` [PATCH v2 9/9] target/arm: Implement TCGCPUOps for plugin register reads Richard Henderson
2024-06-06 6:55 ` [PATCH v2 0/9] plugins: Use unwind info for special gdb registers Philippe Mathieu-Daudé
2024-06-12 14:39 ` Alex Bennée
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240606032926.83599-3-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).