mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-09-06 18:05:37 +00:00
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 <pierrick.bouvier@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
36ab430645
commit
db409c01fd
|
@ -83,9 +83,8 @@ void plugin_gen_disable_mem_helpers(void)
|
||||||
static void gen_enable_mem_helper(struct qemu_plugin_tb *ptb,
|
static void gen_enable_mem_helper(struct qemu_plugin_tb *ptb,
|
||||||
struct qemu_plugin_insn *insn)
|
struct qemu_plugin_insn *insn)
|
||||||
{
|
{
|
||||||
GArray *cbs[2];
|
|
||||||
GArray *arr;
|
GArray *arr;
|
||||||
size_t n_cbs;
|
size_t len;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tracking memory accesses performed from helpers requires extra work.
|
* Tracking memory accesses performed from helpers requires extra work.
|
||||||
|
@ -104,22 +103,25 @@ static void gen_enable_mem_helper(struct qemu_plugin_tb *ptb,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cbs[0] = insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_REGULAR];
|
if (!insn->mem_cbs || !insn->mem_cbs->len) {
|
||||||
cbs[1] = insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE];
|
|
||||||
n_cbs = cbs[0]->len + cbs[1]->len;
|
|
||||||
|
|
||||||
if (n_cbs == 0) {
|
|
||||||
insn->mem_helper = false;
|
insn->mem_helper = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
insn->mem_helper = true;
|
insn->mem_helper = true;
|
||||||
ptb->mem_helper = true;
|
ptb->mem_helper = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO: It seems like we should be able to use ref/unref
|
||||||
|
* to avoid needing to actually copy this array.
|
||||||
|
* Alternately, perhaps we could allocate new memory adjacent
|
||||||
|
* to the TranslationBlock itself, so that we do not have to
|
||||||
|
* actively manage the lifetime after this.
|
||||||
|
*/
|
||||||
|
len = insn->mem_cbs->len;
|
||||||
arr = g_array_sized_new(false, false,
|
arr = g_array_sized_new(false, false,
|
||||||
sizeof(struct qemu_plugin_dyn_cb), n_cbs);
|
sizeof(struct qemu_plugin_dyn_cb), len);
|
||||||
g_array_append_vals(arr, cbs[0]->data, cbs[0]->len);
|
memcpy(arr->data, insn->mem_cbs->data,
|
||||||
g_array_append_vals(arr, cbs[1]->data, cbs[1]->len);
|
len * sizeof(struct qemu_plugin_dyn_cb));
|
||||||
|
|
||||||
qemu_plugin_add_dyn_cb_arr(arr);
|
qemu_plugin_add_dyn_cb_arr(arr);
|
||||||
|
|
||||||
tcg_gen_st_ptr(tcg_constant_ptr((intptr_t)arr), tcg_env,
|
tcg_gen_st_ptr(tcg_constant_ptr((intptr_t)arr), tcg_env,
|
||||||
|
@ -288,18 +290,21 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb)
|
||||||
case PLUGIN_GEN_FROM_TB:
|
case PLUGIN_GEN_FROM_TB:
|
||||||
assert(insn == NULL);
|
assert(insn == NULL);
|
||||||
|
|
||||||
cbs = plugin_tb->cbs[PLUGIN_CB_REGULAR];
|
cbs = plugin_tb->cbs;
|
||||||
for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) {
|
for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) {
|
||||||
struct qemu_plugin_dyn_cb *cb =
|
struct qemu_plugin_dyn_cb *cb =
|
||||||
&g_array_index(cbs, struct qemu_plugin_dyn_cb, i);
|
&g_array_index(cbs, struct qemu_plugin_dyn_cb, i);
|
||||||
gen_udata_cb(cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
cbs = plugin_tb->cbs[PLUGIN_CB_INLINE];
|
switch (cb->type) {
|
||||||
for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) {
|
case PLUGIN_CB_REGULAR:
|
||||||
struct qemu_plugin_dyn_cb *cb =
|
gen_udata_cb(cb);
|
||||||
&g_array_index(cbs, struct qemu_plugin_dyn_cb, i);
|
break;
|
||||||
gen_inline_cb(cb);
|
case PLUGIN_CB_INLINE:
|
||||||
|
gen_inline_cb(cb);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
g_assert_not_reached();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -308,18 +313,21 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb)
|
||||||
|
|
||||||
gen_enable_mem_helper(plugin_tb, insn);
|
gen_enable_mem_helper(plugin_tb, insn);
|
||||||
|
|
||||||
cbs = insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_REGULAR];
|
cbs = insn->insn_cbs;
|
||||||
for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) {
|
for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) {
|
||||||
struct qemu_plugin_dyn_cb *cb =
|
struct qemu_plugin_dyn_cb *cb =
|
||||||
&g_array_index(cbs, struct qemu_plugin_dyn_cb, i);
|
&g_array_index(cbs, struct qemu_plugin_dyn_cb, i);
|
||||||
gen_udata_cb(cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
cbs = insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_INLINE];
|
switch (cb->type) {
|
||||||
for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) {
|
case PLUGIN_CB_REGULAR:
|
||||||
struct qemu_plugin_dyn_cb *cb =
|
gen_udata_cb(cb);
|
||||||
&g_array_index(cbs, struct qemu_plugin_dyn_cb, i);
|
break;
|
||||||
gen_inline_cb(cb);
|
case PLUGIN_CB_INLINE:
|
||||||
|
gen_inline_cb(cb);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
g_assert_not_reached();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -346,21 +354,22 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb)
|
||||||
|
|
||||||
tcg_ctx->emit_before_op = op;
|
tcg_ctx->emit_before_op = op;
|
||||||
|
|
||||||
cbs = insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_REGULAR];
|
cbs = insn->mem_cbs;
|
||||||
for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) {
|
for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) {
|
||||||
struct qemu_plugin_dyn_cb *cb =
|
struct qemu_plugin_dyn_cb *cb =
|
||||||
&g_array_index(cbs, struct qemu_plugin_dyn_cb, i);
|
&g_array_index(cbs, struct qemu_plugin_dyn_cb, i);
|
||||||
if (cb->rw & rw) {
|
|
||||||
gen_mem_cb(cb, meminfo, addr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cbs = insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE];
|
|
||||||
for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) {
|
|
||||||
struct qemu_plugin_dyn_cb *cb =
|
|
||||||
&g_array_index(cbs, struct qemu_plugin_dyn_cb, i);
|
|
||||||
if (cb->rw & rw) {
|
if (cb->rw & rw) {
|
||||||
gen_inline_cb(cb);
|
switch (cb->type) {
|
||||||
|
case PLUGIN_CB_REGULAR:
|
||||||
|
gen_mem_cb(cb, meminfo, addr);
|
||||||
|
break;
|
||||||
|
case PLUGIN_CB_INLINE:
|
||||||
|
gen_inline_cb(cb);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
g_assert_not_reached();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,13 +393,10 @@ bool plugin_gen_tb_start(CPUState *cpu, const DisasContextBase *db,
|
||||||
|
|
||||||
if (test_bit(QEMU_PLUGIN_EV_VCPU_TB_TRANS, cpu->plugin_state->event_mask)) {
|
if (test_bit(QEMU_PLUGIN_EV_VCPU_TB_TRANS, cpu->plugin_state->event_mask)) {
|
||||||
struct qemu_plugin_tb *ptb = tcg_ctx->plugin_tb;
|
struct qemu_plugin_tb *ptb = tcg_ctx->plugin_tb;
|
||||||
int i;
|
|
||||||
|
|
||||||
/* reset callbacks */
|
/* reset callbacks */
|
||||||
for (i = 0; i < PLUGIN_N_CB_SUBTYPES; i++) {
|
if (ptb->cbs) {
|
||||||
if (ptb->cbs[i]) {
|
g_array_set_size(ptb->cbs, 0);
|
||||||
g_array_set_size(ptb->cbs[i], 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ptb->n = 0;
|
ptb->n = 0;
|
||||||
|
|
||||||
|
|
|
@ -67,15 +67,8 @@ union qemu_plugin_cb_sig {
|
||||||
};
|
};
|
||||||
|
|
||||||
enum plugin_dyn_cb_type {
|
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_REGULAR,
|
||||||
PLUGIN_CB_INLINE,
|
PLUGIN_CB_INLINE,
|
||||||
PLUGIN_N_CB_SUBTYPES,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -85,7 +78,7 @@ enum plugin_dyn_cb_subtype {
|
||||||
*/
|
*/
|
||||||
struct qemu_plugin_dyn_cb {
|
struct qemu_plugin_dyn_cb {
|
||||||
void *userp;
|
void *userp;
|
||||||
enum plugin_dyn_cb_subtype type;
|
enum plugin_dyn_cb_type type;
|
||||||
/* @rw applies to mem callbacks only (both regular and inline) */
|
/* @rw applies to mem callbacks only (both regular and inline) */
|
||||||
enum qemu_plugin_mem_rw rw;
|
enum qemu_plugin_mem_rw rw;
|
||||||
/* fields specific to each dyn_cb type go here */
|
/* fields specific to each dyn_cb type go here */
|
||||||
|
@ -107,7 +100,8 @@ struct qemu_plugin_insn {
|
||||||
GByteArray *data;
|
GByteArray *data;
|
||||||
uint64_t vaddr;
|
uint64_t vaddr;
|
||||||
void *haddr;
|
void *haddr;
|
||||||
GArray *cbs[PLUGIN_N_CB_TYPES][PLUGIN_N_CB_SUBTYPES];
|
GArray *insn_cbs;
|
||||||
|
GArray *mem_cbs;
|
||||||
bool calls_helpers;
|
bool calls_helpers;
|
||||||
|
|
||||||
/* if set, the instruction calls helpers that might access guest memory */
|
/* 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)
|
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);
|
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++) {
|
insn->data = g_byte_array_sized_new(4);
|
||||||
for (j = 0; j < PLUGIN_N_CB_SUBTYPES; j++) {
|
|
||||||
insn->cbs[i][j] = g_array_new(false, false,
|
|
||||||
sizeof(struct qemu_plugin_dyn_cb));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return insn;
|
return insn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +149,7 @@ struct qemu_plugin_tb {
|
||||||
/* if set, the TB calls helpers that might access guest memory */
|
/* if set, the TB calls helpers that might access guest memory */
|
||||||
bool mem_helper;
|
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)
|
uint64_t pc)
|
||||||
{
|
{
|
||||||
struct qemu_plugin_insn *insn;
|
struct qemu_plugin_insn *insn;
|
||||||
int i, j;
|
|
||||||
|
|
||||||
if (unlikely(tb->n == tb->insns->len)) {
|
if (unlikely(tb->n == tb->insns->len)) {
|
||||||
struct qemu_plugin_insn *new_insn = qemu_plugin_insn_alloc();
|
struct qemu_plugin_insn *new_insn = qemu_plugin_insn_alloc();
|
||||||
g_ptr_array_add(tb->insns, new_insn);
|
g_ptr_array_add(tb->insns, new_insn);
|
||||||
}
|
}
|
||||||
|
|
||||||
insn = g_ptr_array_index(tb->insns, tb->n++);
|
insn = g_ptr_array_index(tb->insns, tb->n++);
|
||||||
g_byte_array_set_size(insn->data, 0);
|
g_byte_array_set_size(insn->data, 0);
|
||||||
insn->calls_helpers = false;
|
insn->calls_helpers = false;
|
||||||
insn->mem_helper = false;
|
insn->mem_helper = false;
|
||||||
insn->vaddr = pc;
|
insn->vaddr = pc;
|
||||||
|
if (insn->insn_cbs) {
|
||||||
for (i = 0; i < PLUGIN_N_CB_TYPES; i++) {
|
g_array_set_size(insn->insn_cbs, 0);
|
||||||
for (j = 0; j < PLUGIN_N_CB_SUBTYPES; j++) {
|
}
|
||||||
g_array_set_size(insn->cbs[i][j], 0);
|
if (insn->mem_cbs) {
|
||||||
}
|
g_array_set_size(insn->mem_cbs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return insn;
|
return insn;
|
||||||
|
|
|
@ -92,8 +92,7 @@ void qemu_plugin_register_vcpu_tb_exec_cb(struct qemu_plugin_tb *tb,
|
||||||
void *udata)
|
void *udata)
|
||||||
{
|
{
|
||||||
if (!tb->mem_only) {
|
if (!tb->mem_only) {
|
||||||
plugin_register_dyn_cb__udata(&tb->cbs[PLUGIN_CB_REGULAR],
|
plugin_register_dyn_cb__udata(&tb->cbs, cb, flags, udata);
|
||||||
cb, flags, udata);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,8 +103,7 @@ void qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu(
|
||||||
uint64_t imm)
|
uint64_t imm)
|
||||||
{
|
{
|
||||||
if (!tb->mem_only) {
|
if (!tb->mem_only) {
|
||||||
plugin_register_inline_op_on_entry(
|
plugin_register_inline_op_on_entry(&tb->cbs, 0, op, entry, imm);
|
||||||
&tb->cbs[PLUGIN_CB_INLINE], 0, op, entry, imm);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,8 +113,7 @@ void qemu_plugin_register_vcpu_insn_exec_cb(struct qemu_plugin_insn *insn,
|
||||||
void *udata)
|
void *udata)
|
||||||
{
|
{
|
||||||
if (!insn->mem_only) {
|
if (!insn->mem_only) {
|
||||||
plugin_register_dyn_cb__udata(
|
plugin_register_dyn_cb__udata(&insn->insn_cbs, cb, flags, udata);
|
||||||
&insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_REGULAR], cb, flags, udata);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,8 +124,7 @@ void qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu(
|
||||||
uint64_t imm)
|
uint64_t imm)
|
||||||
{
|
{
|
||||||
if (!insn->mem_only) {
|
if (!insn->mem_only) {
|
||||||
plugin_register_inline_op_on_entry(
|
plugin_register_inline_op_on_entry(&insn->insn_cbs, 0, op, entry, imm);
|
||||||
&insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_INLINE], 0, op, entry, imm);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,8 +139,7 @@ void qemu_plugin_register_vcpu_mem_cb(struct qemu_plugin_insn *insn,
|
||||||
enum qemu_plugin_mem_rw rw,
|
enum qemu_plugin_mem_rw rw,
|
||||||
void *udata)
|
void *udata)
|
||||||
{
|
{
|
||||||
plugin_register_vcpu_mem_cb(&insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_REGULAR],
|
plugin_register_vcpu_mem_cb(&insn->mem_cbs, cb, flags, rw, udata);
|
||||||
cb, flags, rw, udata);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void qemu_plugin_register_vcpu_mem_inline_per_vcpu(
|
void qemu_plugin_register_vcpu_mem_inline_per_vcpu(
|
||||||
|
@ -154,8 +149,7 @@ void qemu_plugin_register_vcpu_mem_inline_per_vcpu(
|
||||||
qemu_plugin_u64 entry,
|
qemu_plugin_u64 entry,
|
||||||
uint64_t imm)
|
uint64_t imm)
|
||||||
{
|
{
|
||||||
plugin_register_inline_op_on_entry(
|
plugin_register_inline_op_on_entry(&insn->mem_cbs, rw, op, entry, imm);
|
||||||
&insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE], rw, op, entry, imm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void qemu_plugin_register_vcpu_tb_trans_cb(qemu_plugin_id_t id,
|
void qemu_plugin_register_vcpu_tb_trans_cb(qemu_plugin_id_t id,
|
||||||
|
|
Loading…
Reference in a new issue