@samitouri / QOSamiQemu / commits / 041dca1e1b

plugins: add userdata to qemu_plugin_register_vcpu_discon_cb

Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Link: https://lore.kernel.org/qemu-devel/20260615193526.2883349-14-pierrick.bouvier@oss.qualcomm.com Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>

Pierrick Bouvier committed Jun 15, 2026 at 12:35 UTC 041dca1e1bd04e7b6c2b22651c3af8a2f4a73517
4 files changed +17 -12
contrib/plugins/traps.c
+3 -2
@@ -25,7 +25,7 @@ static struct qemu_plugin_scoreboard *traps;
25
26 static void vcpu_discon(qemu_plugin_id_t id, unsigned int vcpu_index,
27 enum qemu_plugin_discon_type type, uint64_t from_pc,
28 - uint64_t to_pc)
28 + uint64_t to_pc, void *userdata)
29 {
30 TrapCounters *rec = qemu_plugin_scoreboard_find(traps, vcpu_index);
31 switch (type) {
@@ -75,7 +75,8 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info,
75 traps = qemu_plugin_scoreboard_new(sizeof(TrapCounters));
76
77 qemu_plugin_register_vcpu_discon_cb(id, QEMU_PLUGIN_DISCON_ALL,
78 - vcpu_discon);
78 + vcpu_discon,
79 + NULL);
80
81 qemu_plugin_register_atexit_cb(id, plugin_exit, NULL);
82
include/plugins/qemu-plugin.h
+6 -2
@@ -186,6 +186,7 @@ enum qemu_plugin_discon_type {
186 * @from_pc: the source of the discontinuity, e.g. the PC before the
187 * transition
188 * @to_pc: the PC pointing to the next instruction to be executed
189 + * @userdata: any plugin data to pass to the @cb
190 *
191 * The exact semantics of @from_pc depends on the @type of discontinuity. For
192 * interrupts, @from_pc will point to the next instruction which would have
@@ -198,7 +199,8 @@ enum qemu_plugin_discon_type {
199 typedef void (*qemu_plugin_vcpu_discon_cb_t)(qemu_plugin_id_t id,
200 unsigned int vcpu_index,
201 enum qemu_plugin_discon_type type,
201 - uint64_t from_pc, uint64_t to_pc);
202 + uint64_t from_pc, uint64_t to_pc,
203 + void *userdata);
204
205 /**
206 * qemu_plugin_uninstall() - Uninstall a plugin
@@ -293,6 +295,7 @@ void qemu_plugin_register_vcpu_resume_cb(qemu_plugin_id_t id,
295 * @id: plugin ID
296 * @type: types of discontinuities for which to call the callback
297 * @cb: callback function
298 + * @userdata: any plugin data to pass to the @cb
299 *
300 * The @cb function is called every time a vCPU receives a discontinuity event
301 * of the specified type(s), after the vCPU was prepared to handle the event.
@@ -302,7 +305,8 @@ void qemu_plugin_register_vcpu_resume_cb(qemu_plugin_id_t id,
305 QEMU_PLUGIN_API
306 void qemu_plugin_register_vcpu_discon_cb(qemu_plugin_id_t id,
307 enum qemu_plugin_discon_type type,
305 - qemu_plugin_vcpu_discon_cb_t cb);
308 + qemu_plugin_vcpu_discon_cb_t cb,
309 + void *userdata);
310
311 /** struct qemu_plugin_tb - Opaque handle for a translation block */
312 struct qemu_plugin_tb;
plugins/core.c
+6 -6
@@ -122,8 +122,7 @@ static void plugin_vcpu_cb__discon(CPUState *cpu,
122 /* iterate safely; plugins might uninstall themselves at any time */
123 QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) {
124 qemu_plugin_vcpu_discon_cb_t func = cb->f.vcpu_discon;
125 -
126 - func(cb->ctx->id, cpu->cpu_index, type, from, to);
125 + func(cb->ctx->id, cpu->cpu_index, type, from, to, cb->udata);
126 }
127 }
128 qemu_plugin_set_cb_flags(cpu, QEMU_PLUGIN_CB_NO_REGS);
@@ -656,16 +655,17 @@ void qemu_plugin_register_vcpu_resume_cb(qemu_plugin_id_t id,
655
656 void qemu_plugin_register_vcpu_discon_cb(qemu_plugin_id_t id,
657 enum qemu_plugin_discon_type type,
659 - qemu_plugin_vcpu_discon_cb_t cb)
658 + qemu_plugin_vcpu_discon_cb_t cb,
659 + void *userdata)
660 {
661 if (type & QEMU_PLUGIN_DISCON_INTERRUPT) {
662 - plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_INTERRUPT, cb);
662 + plugin_register_cb_udata(id, QEMU_PLUGIN_EV_VCPU_INTERRUPT, cb, userdata);
663 }
664 if (type & QEMU_PLUGIN_DISCON_EXCEPTION) {
665 - plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_EXCEPTION, cb);
665 + plugin_register_cb_udata(id, QEMU_PLUGIN_EV_VCPU_EXCEPTION, cb, userdata);
666 }
667 if (type & QEMU_PLUGIN_DISCON_HOSTCALL) {
668 - plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_HOSTCALL, cb);
668 + plugin_register_cb_udata(id, QEMU_PLUGIN_EV_VCPU_HOSTCALL, cb, userdata);
669 }
670 }
671
tests/tcg/plugins/discons.c
+2 -2
@@ -98,7 +98,7 @@ static void report_mismatch(const char *pc_name, unsigned int vcpu_index,
98
99 static void vcpu_discon(qemu_plugin_id_t id, unsigned int vcpu_index,
100 enum qemu_plugin_discon_type type, uint64_t from_pc,
101 - uint64_t to_pc)
101 + uint64_t to_pc, void *userdata)
102 {
103 struct cpu_state *state = qemu_plugin_scoreboard_find(states, vcpu_index);
104
@@ -214,7 +214,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
214 has_from);
215
216 qemu_plugin_register_vcpu_discon_cb(id, QEMU_PLUGIN_DISCON_ALL,
217 - vcpu_discon);
217 + vcpu_discon, NULL);
218 qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans);
219
220 return 0;