From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PATCH 11/32] plugins: Use translator_st for qemu_plugin_insn_data
Date: Fri, 5 Apr 2024 00:24:38 -1000 [thread overview]
Message-ID: <20240405102459.462551-12-richard.henderson@linaro.org> (raw)
In-Reply-To: <20240405102459.462551-1-richard.henderson@linaro.org>
Use the bytes that we record for the entire TB, rather than
a per-insn GByteArray. Record the length of the insn in
plugin_gen_insn_end rather than infering from the length
of the array.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/qemu/plugin.h | 14 +-------------
accel/tcg/plugin-gen.c | 7 +++++--
accel/tcg/translator.c | 26 --------------------------
plugins/api.c | 12 +++++++-----
tcg/tcg.c | 3 +--
5 files changed, 14 insertions(+), 48 deletions(-)
diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h
index 07b1755990..c32bb97667 100644
--- a/include/qemu/plugin.h
+++ b/include/qemu/plugin.h
@@ -97,11 +97,11 @@ struct qemu_plugin_dyn_cb {
/* Internal context for instrumenting an instruction */
struct qemu_plugin_insn {
- GByteArray *data;
uint64_t vaddr;
void *haddr;
GArray *insn_cbs;
GArray *mem_cbs;
+ uint8_t len;
bool calls_helpers;
/* if set, the instruction calls helpers that might access guest memory */
@@ -116,18 +116,6 @@ struct qemu_plugin_scoreboard {
QLIST_ENTRY(qemu_plugin_scoreboard) entry;
};
-/*
- * qemu_plugin_insn allocate and cleanup functions. We don't expect to
- * cleanup many of these structures. They are reused for each fresh
- * translation.
- */
-
-static inline void qemu_plugin_insn_cleanup_fn(gpointer data)
-{
- struct qemu_plugin_insn *insn = (struct qemu_plugin_insn *) data;
- g_byte_array_free(insn->data, true);
-}
-
/* Internal context for this TranslationBlock */
struct qemu_plugin_tb {
GPtrArray *insns;
diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c
index 94bbad6dc7..be2451be58 100644
--- a/accel/tcg/plugin-gen.c
+++ b/accel/tcg/plugin-gen.c
@@ -346,11 +346,9 @@ void plugin_gen_insn_start(CPUState *cpu, const DisasContextBase *db)
ptb->n = n;
if (n <= ptb->insns->len) {
insn = g_ptr_array_index(ptb->insns, n - 1);
- g_byte_array_set_size(insn->data, 0);
} else {
assert(n - 1 == ptb->insns->len);
insn = g_new0(struct qemu_plugin_insn, 1);
- insn->data = g_byte_array_sized_new(4);
g_ptr_array_add(ptb->insns, insn);
}
@@ -389,6 +387,11 @@ void plugin_gen_insn_start(CPUState *cpu, const DisasContextBase *db)
void plugin_gen_insn_end(void)
{
+ const DisasContextBase *db = tcg_ctx->plugin_db;
+ struct qemu_plugin_insn *pinsn = tcg_ctx->plugin_insn;
+
+ pinsn->len = db->fake_insn ? db->record_len : db->pc_next - pinsn->vaddr;
+
tcg_gen_plugin_cb(PLUGIN_GEN_AFTER_INSN);
}
diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c
index 3421469a31..0a1d26b2e8 100644
--- a/accel/tcg/translator.c
+++ b/accel/tcg/translator.c
@@ -405,27 +405,6 @@ bool translator_st(const DisasContextBase *db, void *dest,
return false;
}
-static void plugin_insn_append(vaddr pc, const void *from, size_t size)
-{
-#ifdef CONFIG_PLUGIN
- struct qemu_plugin_insn *insn = tcg_ctx->plugin_insn;
- size_t off;
-
- if (insn == NULL) {
- return;
- }
- off = pc - insn->vaddr;
- if (off < insn->data->len) {
- g_byte_array_set_size(insn->data, off);
- } else if (off > insn->data->len) {
- /* we have an unexpected gap */
- g_assert_not_reached();
- }
-
- insn->data = g_byte_array_append(insn->data, from, size);
-#endif
-}
-
uint8_t translator_ldub(CPUArchState *env, DisasContextBase *db, vaddr pc)
{
uint8_t raw;
@@ -434,7 +413,6 @@ uint8_t translator_ldub(CPUArchState *env, DisasContextBase *db, vaddr pc)
raw = cpu_ldub_code(env, pc);
record_save(db, pc, &raw, sizeof(raw));
}
- plugin_insn_append(pc, &raw, sizeof(raw));
return raw;
}
@@ -449,7 +427,6 @@ uint16_t translator_lduw(CPUArchState *env, DisasContextBase *db, vaddr pc)
raw = tswap16(tgt);
record_save(db, pc, &raw, sizeof(raw));
}
- plugin_insn_append(pc, &raw, sizeof(raw));
return tgt;
}
@@ -464,7 +441,6 @@ uint32_t translator_ldl(CPUArchState *env, DisasContextBase *db, vaddr pc)
raw = tswap32(tgt);
record_save(db, pc, &raw, sizeof(raw));
}
- plugin_insn_append(pc, &raw, sizeof(raw));
return tgt;
}
@@ -479,7 +455,6 @@ uint64_t translator_ldq(CPUArchState *env, DisasContextBase *db, vaddr pc)
raw = tswap64(tgt);
record_save(db, pc, &raw, sizeof(raw));
}
- plugin_insn_append(pc, &raw, sizeof(raw));
return tgt;
}
@@ -488,5 +463,4 @@ void translator_fake_ldb(DisasContextBase *db, vaddr pc, uint8_t insn8)
assert(pc >= db->pc_first);
db->fake_insn = true;
record_save(db, pc, &insn8, sizeof(insn8));
- plugin_insn_append(pc, &insn8, sizeof(insn8));
}
diff --git a/plugins/api.c b/plugins/api.c
index 4e9125ea29..7b8b7523b3 100644
--- a/plugins/api.c
+++ b/plugins/api.c
@@ -43,6 +43,7 @@
#include "exec/exec-all.h"
#include "exec/gdbstub.h"
#include "exec/ram_addr.h"
+#include "exec/translator.h"
#include "disas/disas.h"
#include "plugin.h"
#ifndef CONFIG_USER_ONLY
@@ -219,14 +220,15 @@ qemu_plugin_tb_get_insn(const struct qemu_plugin_tb *tb, size_t idx)
size_t qemu_plugin_insn_data(const struct qemu_plugin_insn *insn,
void *dest, size_t len)
{
- len = MIN(len, insn->data->len);
- memcpy(dest, insn->data->data, len);
- return len;
+ const DisasContextBase *db = tcg_ctx->plugin_db;
+
+ len = MIN(len, insn->len);
+ return translator_st(db, dest, insn->vaddr, len) ? len : 0;
}
size_t qemu_plugin_insn_size(const struct qemu_plugin_insn *insn)
{
- return insn->data->len;
+ return insn->len;
}
uint64_t qemu_plugin_insn_vaddr(const struct qemu_plugin_insn *insn)
@@ -242,7 +244,7 @@ void *qemu_plugin_insn_haddr(const struct qemu_plugin_insn *insn)
char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn)
{
CPUState *cpu = current_cpu;
- return plugin_disas(cpu, insn->vaddr, insn->data->len);
+ return plugin_disas(cpu, insn->vaddr, insn->len);
}
const char *qemu_plugin_insn_symbol(const struct qemu_plugin_insn *insn)
diff --git a/tcg/tcg.c b/tcg/tcg.c
index d248c52e96..691b2342a2 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -765,8 +765,7 @@ static void alloc_tcg_plugin_context(TCGContext *s)
{
#ifdef CONFIG_PLUGIN
s->plugin_tb = g_new0(struct qemu_plugin_tb, 1);
- s->plugin_tb->insns =
- g_ptr_array_new_with_free_func(qemu_plugin_insn_cleanup_fn);
+ s->plugin_tb->insns = g_ptr_array_new();
#endif
}
--
2.34.1
next prev parent reply other threads:[~2024-04-05 10:27 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-05 10:24 [PATCH 00/32] accel/tcg: Improve disassembly for target and plugin Richard Henderson
2024-04-05 10:24 ` [PATCH 01/32] accel/tcg: Use vaddr in translator_ld* Richard Henderson
2024-04-05 12:34 ` Philippe Mathieu-Daudé
2024-04-05 10:24 ` [PATCH 02/32] accel/tcg: Hide in_same_page outside of a target-specific context Richard Henderson
2024-04-05 12:35 ` Philippe Mathieu-Daudé
2024-04-05 10:24 ` [PATCH 03/32] accel/tcg: Pass DisasContextBase to translator_fake_ldb Richard Henderson
2024-04-05 12:35 ` Philippe Mathieu-Daudé
2024-04-05 10:24 ` [PATCH 04/32] accel/tcg: Reorg translator_ld* Richard Henderson
2024-04-05 10:24 ` [PATCH 05/32] accel/tcg: Cap the translation block when we encounter mmio Richard Henderson
2024-04-05 12:36 ` Philippe Mathieu-Daudé
2024-04-05 10:24 ` [PATCH 06/32] accel/tcg: Record mmio bytes during translation Richard Henderson
2024-04-05 10:24 ` [PATCH 07/32] accel/tcg: Record when translator_fake_ldb is used Richard Henderson
2024-04-05 10:24 ` [PATCH 08/32] accel/tcg: Record DisasContextBase in tcg_ctx for plugins Richard Henderson
2024-04-05 10:24 ` [PATCH 09/32] plugins: Copy memory in qemu_plugin_insn_data Richard Henderson
2024-04-05 10:24 ` [PATCH 10/32] accel/tcg: Implement translator_st Richard Henderson
2024-04-05 10:24 ` Richard Henderson [this message]
2024-04-05 10:24 ` [PATCH 12/32] plugins: Read mem_only directly from TB cflags Richard Henderson
2024-04-05 10:24 ` [PATCH 13/32] plugins: Use DisasContextBase for qemu_plugin_insn_haddr Richard Henderson
2024-04-05 10:24 ` [PATCH 14/32] plugins: Use DisasContextBase for qemu_plugin_tb_vaddr Richard Henderson
2024-04-05 12:40 ` Philippe Mathieu-Daudé
2024-04-05 10:24 ` [PATCH 15/32] plugins: Merge alloc_tcg_plugin_context into plugin_gen_tb_start Richard Henderson
2024-04-05 10:24 ` [PATCH 16/32] accel/tcg: Provide default implementation of disas_log Richard Henderson
2024-04-05 12:44 ` Philippe Mathieu-Daudé
2024-04-05 10:24 ` [PATCH 17/32] accel/tcg: Return bool from TranslatorOps.disas_log Richard Henderson
2024-04-05 12:45 ` Philippe Mathieu-Daudé
2024-04-05 10:24 ` [PATCH 18/32] disas: Split disas.c Richard Henderson
2024-04-05 10:24 ` [PATCH 19/32] disas: Use translator_st to get disassembly data Richard Henderson
2024-04-05 10:24 ` [PATCH 20/32] accel/tcg: Introduce translator_fake_ld Richard Henderson
2024-04-05 12:47 ` Philippe Mathieu-Daudé
2024-04-05 10:24 ` [PATCH 21/32] target/s390x: Fix translator_fake_ld length Richard Henderson
2024-04-05 10:24 ` [PATCH 22/32] target/s390x: Disassemble EXECUTEd instructions Richard Henderson
2024-04-05 10:24 ` [PATCH 23/32] target/hexagon: Use translator_ldl in pkt_crosses_page Richard Henderson
2024-04-05 10:24 ` [PATCH 24/32] target/microblaze: Use translator_ldl Richard Henderson
2024-04-05 12:53 ` Philippe Mathieu-Daudé
2024-04-05 12:59 ` Edgar E. Iglesias
2024-04-05 10:24 ` [PATCH 25/32] target/i386: Use translator_ldub for everything Richard Henderson
2024-04-05 12:57 ` Philippe Mathieu-Daudé
2024-04-05 10:24 ` [PATCH 26/32] target/avr: Use translator_ldl Richard Henderson
2024-04-05 12:56 ` Philippe Mathieu-Daudé
2024-04-05 10:24 ` [PATCH 27/32] target/cris: Use translator_ld* in cris_fetch Richard Henderson
2024-04-05 12:50 ` Philippe Mathieu-Daudé
2024-04-05 12:55 ` Edgar E. Iglesias
2024-04-05 10:24 ` [PATCH 28/32] target/cris: Use cris_fetch in translate_v10.c.inc Richard Henderson
2024-04-05 12:51 ` Philippe Mathieu-Daudé
2024-04-05 12:58 ` Edgar E. Iglesias
2024-04-05 10:24 ` [PATCH 29/32] target/riscv: Use translator_ld* for everything Richard Henderson
2024-04-05 10:24 ` [PATCH 30/32] target/rx: Use translator_ld* Richard Henderson
2024-04-05 12:55 ` Philippe Mathieu-Daudé
2024-04-08 8:53 ` Yoshinori Sato
2024-04-05 10:24 ` [PATCH 31/32] target/xtensa: Use translator_ldub in xtensa_insn_len Richard Henderson
2024-04-05 12:56 ` Philippe Mathieu-Daudé
2024-04-05 10:24 ` [PATCH 32/32] target/s390x: Use translator_lduw in get_next_pc Richard Henderson
2024-04-05 13:15 ` [PATCH 33/32] accel/tcg: Remove cpu_ldsb_code / cpu_ldsw_code Philippe Mathieu-Daudé
2024-04-05 17:48 ` Richard Henderson
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=20240405102459.462551-12-richard.henderson@linaro.org \
--to=richard.henderson@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).