[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC 47/48] plugin: support guest hooks
From: |
Emilio G. Cota |
Subject: |
[Qemu-devel] [RFC 47/48] plugin: support guest hooks |
Date: |
Thu, 25 Oct 2018 13:20:56 -0400 |
These "hooks" are callbacks from the guest to plugins. This is
useful when we need guest-host communication, for instance to
signal the beginning/end of a certain "region of interest" in
the guest program. Simulators typically would use "magic"
instructions for this, but that is painful to maintain across
ISAs. Instead, we use plugin-chan PCI device through which we can
relay guest messages to the host.
Signed-off-by: Emilio G. Cota <address@hidden>
---
include/qemu/plugin-api.h | 6 ++++++
include/qemu/plugin.h | 2 ++
plugin.c | 13 +++++++++++++
qemu-plugins.symbols | 1 +
4 files changed, 22 insertions(+)
diff --git a/include/qemu/plugin-api.h b/include/qemu/plugin-api.h
index 5062e20e08..a5faff6a2a 100644
--- a/include/qemu/plugin-api.h
+++ b/include/qemu/plugin-api.h
@@ -234,6 +234,12 @@ void qemu_plugin_register_lockstep_cb(qemu_plugin_id_t id,
void qemu_plugin_end_time_slice(void);
+typedef void (*qemu_plugin_hook_cb_t)(uint32_t cmd, const void *data,
+ size_t size);
+
+void qemu_plugin_register_hook_cb(qemu_plugin_id_t id,
+ qemu_plugin_hook_cb_t cb);
+
/* returns -1 in user-mode */
int qemu_plugin_n_vcpus(void);
diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h
index f3c18d1032..ced265a127 100644
--- a/include/qemu/plugin.h
+++ b/include/qemu/plugin.h
@@ -61,12 +61,14 @@ enum qemu_plugin_event {
QEMU_PLUGIN_EV_LOCKSTEP,
QEMU_PLUGIN_EV_FLUSH,
QEMU_PLUGIN_EV_ATEXIT,
+ QEMU_PLUGIN_EV_HOOK,
QEMU_PLUGIN_EV_MAX,
};
union qemu_plugin_cb_sig {
qemu_plugin_simple_cb_t simple;
qemu_plugin_udata_cb_t udata;
+ qemu_plugin_hook_cb_t hook;
qemu_plugin_vcpu_simple_cb_t vcpu_simple;
qemu_plugin_vcpu_udata_cb_t vcpu_udata;
qemu_plugin_vcpu_tb_trans_cb_t vcpu_tb_trans;
diff --git a/plugin.c b/plugin.c
index 2bbc14e2f3..4004451bdb 100644
--- a/plugin.c
+++ b/plugin.c
@@ -1078,8 +1078,21 @@ void plugin_lockstep_cb(void)
plugin_cb__simple(QEMU_PLUGIN_EV_LOCKSTEP);
}
+void qemu_plugin_register_hook_cb(qemu_plugin_id_t id, qemu_plugin_hook_cb_t
cb)
+{
+ plugin_register_cb(id, QEMU_PLUGIN_EV_HOOK, cb);
+}
+
void plugin_chan_xmit(uint32_t cmd, const void *data, size_t size)
{
+ struct qemu_plugin_cb *cb, *next;
+ enum qemu_plugin_event ev = QEMU_PLUGIN_EV_HOOK;
+
+ QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) {
+ qemu_plugin_hook_cb_t func = cb->f.hook;
+
+ func(cmd, data, size);
+ }
}
static void __attribute__((__constructor__)) plugin_init(void)
diff --git a/qemu-plugins.symbols b/qemu-plugins.symbols
index a3268a40c7..2e17693da8 100644
--- a/qemu-plugins.symbols
+++ b/qemu-plugins.symbols
@@ -31,6 +31,7 @@
qemu_plugin_mem_is_big_endian;
qemu_plugin_mem_is_store;
qemu_plugin_vcpu_for_each;
+ qemu_plugin_register_hook_cb;
qemu_plugin_n_vcpus;
qemu_plugin_n_max_vcpus;
};
--
2.17.1
- [Qemu-devel] [RFC 48/48] plugin: add a couple of very simple examples, (continued)
- [Qemu-devel] [RFC 48/48] plugin: add a couple of very simple examples, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 12/48] atomic_template: define pre/post macros, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 07/48] tcg: export TCGHelperInfo, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 08/48] tcg: export tcg_gen_runtime_helper, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 04/48] exec: introduce qemu_xxhash{2,4,5,6,7}, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 31/48] target/mips: prepare for 2-pass translation (WIP), Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 34/48] target/s390x: prepare for 2-pass translation, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 32/48] target/alpha: prepare for 2-pass translation, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 40/48] plugin: let plugins control the virtual clock, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 24/48] translator: add .ctx_base_offset and .ctx_size to TranslatorOps, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 47/48] plugin: support guest hooks,
Emilio G. Cota <=
- [Qemu-devel] [RFC 25/48] target/arm: prepare for 2-pass translation, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 14/48] plugin: preliminary user-facing API, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 26/48] target/ppc: prepare for 2-pass translation, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 43/48] linux-user: support -plugin option, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 17/48] plugin-gen: add TCG code generation helpers, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 15/48] plugin: add core code, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 11/48] atomic_template: fix indentation in GEN_ATOMIC_HELPER, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 16/48] tcg: add plugin_mask to TB hash, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 05/48] include: move exec/tb-hash-xx.h to qemu/xxhash.h, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 03/48] tcg/README: fix typo s/afterwise/afterwards/, Emilio G. Cota, 2018/10/25