qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Julian Ganz <neither@nut.email>
To: qemu-devel@nongnu.org
Cc: "Julian Ganz" <neither@nut.email>,
	"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>
Subject: [PATCH v8 01/25] plugins: add types for callbacks related to certain discontinuities
Date: Sun, 19 Oct 2025 17:14:50 +0200	[thread overview]
Message-ID: <1bff3f2e662e94d8415d7b81bf4433deff3e62bd.1760884672.git.neither@nut.email> (raw)
In-Reply-To: <cover.1760884672.git.neither@nut.email>

The plugin API allows registration of callbacks for a variety of VCPU
related events, such as VCPU reset, idle and resume. However, traps of
any kind, i.e. interrupts or exceptions, were previously not covered.
These kinds of events are arguably quite significant and usually go hand
in hand with a PC discontinuity. On most platforms, the discontinuity
also includes a transition from some "mode" to another. Thus, plugins
for the analysis of (virtualized) embedded systems may benefit from or
even require the possiblity to perform work on the occurance of an
interrupt or exception.

This change introduces the concept of such a discontinuity event in the
form of an enumeration. Currently only traps are covered. Specifically
we (loosely) define interrupts, exceptions and host calls across all
platforms. In addition, this change introduces a type to use for
callback functions related to such events. Since possible modes and the
enumeration of interupts and exceptions vary greatly between different
architectures, the callback type only receives the VCPU id, the type of
event as well as the old and new PC.

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Julian Ganz <neither@nut.email>
---
 include/qemu/plugin.h      |  1 +
 include/qemu/qemu-plugin.h | 44 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h
index f355c7cb8a..8cf20cd96f 100644
--- a/include/qemu/plugin.h
+++ b/include/qemu/plugin.h
@@ -59,6 +59,7 @@ union qemu_plugin_cb_sig {
     qemu_plugin_udata_cb_t           udata;
     qemu_plugin_vcpu_simple_cb_t     vcpu_simple;
     qemu_plugin_vcpu_udata_cb_t      vcpu_udata;
+    qemu_plugin_vcpu_discon_cb_t     vcpu_discon;
     qemu_plugin_vcpu_tb_trans_cb_t   vcpu_tb_trans;
     qemu_plugin_vcpu_mem_cb_t        vcpu_mem;
     qemu_plugin_vcpu_syscall_cb_t    vcpu_syscall;
diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h
index c450106af1..08bf366e36 100644
--- a/include/qemu/qemu-plugin.h
+++ b/include/qemu/qemu-plugin.h
@@ -161,6 +161,50 @@ typedef void (*qemu_plugin_vcpu_simple_cb_t)(qemu_plugin_id_t id,
 typedef void (*qemu_plugin_vcpu_udata_cb_t)(unsigned int vcpu_index,
                                             void *userdata);
 
+
+/**
+ * enum qemu_plugin_discon_type - type of a (potential) PC discontinuity
+ *
+ * @QEMU_PLUGIN_DISCON_INTERRUPT: an interrupt, defined across all architectures
+ *                                as an asynchronous event, usually originating
+ *                                from outside the CPU
+ * @QEMU_PLUGIN_DISCON_EXCEPTION: an exception, defined across all architectures
+ *                                as a synchronous event in response to a
+ *                                specific instruction being executed
+ * @QEMU_PLUGIN_DISCON_HOSTCALL: a host call, functionally a special kind of
+ *                               exception that is not handled by code run by
+ *                               the vCPU but machinery outside the vCPU
+ * @QEMU_PLUGIN_DISCON_ALL: all types of disconinuity events currently covered
+ */
+enum qemu_plugin_discon_type {
+    QEMU_PLUGIN_DISCON_INTERRUPT = 1 << 0,
+    QEMU_PLUGIN_DISCON_EXCEPTION = 1 << 1,
+    QEMU_PLUGIN_DISCON_HOSTCALL = 1 << 2,
+    QEMU_PLUGIN_DISCON_ALL = -1
+};
+
+/**
+ * typedef qemu_plugin_vcpu_discon_cb_t - vcpu discontinuity callback
+ * @id: plugin ID
+ * @vcpu_index: the current vcpu context
+ * @type: the type of discontinuity
+ * @from_pc: the source of the discontinuity, e.g. the PC before the
+ *           transition
+ * @to_pc: the PC pointing to the next instruction to be executed
+ *
+ * The exact semantics of @from_pc depends on the @type of discontinuity. For
+ * interrupts, @from_pc will point to the next instruction which would have
+ * been executed. For exceptions and host calls, @from_pc will point to the
+ * instruction that caused the exception or issued the host call. Note that
+ * in the case of exceptions, the instruction may not be retired and thus not
+ * observable via general instruction exec callbacks. The same may be the case
+ * for some host calls such as hypervisor call "exceptions".
+ */
+typedef void (*qemu_plugin_vcpu_discon_cb_t)(qemu_plugin_id_t id,
+                                             unsigned int vcpu_index,
+                                             enum qemu_plugin_discon_type type,
+                                             uint64_t from_pc, uint64_t to_pc);
+
 /**
  * qemu_plugin_uninstall() - Uninstall a plugin
  * @id: this plugin's opaque ID
-- 
2.49.1



  reply	other threads:[~2025-10-19 15:18 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-19 15:14 [PATCH v8 00/25] tcg-plugins: add hooks for discontinuities Julian Ganz
2025-10-19 15:14 ` Julian Ganz [this message]
2025-10-19 15:14 ` [PATCH v8 02/25] plugins: add API for registering discontinuity callbacks Julian Ganz
2025-10-19 15:14 ` [PATCH v8 03/25] plugins: add hooks for new discontinuity related callbacks Julian Ganz
2025-10-19 15:14 ` [PATCH v8 04/25] contrib/plugins: add plugin showcasing new dicontinuity related API Julian Ganz
2025-10-19 15:14 ` [PATCH v8 05/25] target/alpha: call plugin trap callbacks Julian Ganz
2025-10-21 20:10   ` Philippe Mathieu-Daudé
2025-10-21 20:38     ` Julian Ganz
2025-10-21 20:47       ` Philippe Mathieu-Daudé
2025-10-19 15:14 ` [PATCH v8 06/25] target/arm: " Julian Ganz
2025-10-19 15:14 ` [PATCH v8 07/25] target/avr: " Julian Ganz
2025-10-21 20:10   ` Philippe Mathieu-Daudé
2025-10-19 15:14 ` [PATCH v8 08/25] target/hppa: " Julian Ganz
2025-10-21 19:56   ` Philippe Mathieu-Daudé
2025-10-19 15:14 ` [PATCH v8 09/25] target/i386: " Julian Ganz
2025-10-21 19:57   ` Philippe Mathieu-Daudé
2025-10-19 15:14 ` [PATCH v8 10/25] target/loongarch: " Julian Ganz
2025-10-20  1:36   ` gaosong
2025-10-19 15:15 ` [PATCH v8 11/25] target/m68k: " Julian Ganz
2025-10-21 19:58   ` Philippe Mathieu-Daudé
2025-10-19 15:15 ` [PATCH v8 12/25] target/microblaze: " Julian Ganz
2025-10-21 19:58   ` Philippe Mathieu-Daudé
2025-10-19 15:15 ` [PATCH v8 13/25] target/mips: " Julian Ganz
2025-10-21 19:59   ` Philippe Mathieu-Daudé
2025-10-19 15:15 ` [PATCH v8 14/25] target/openrisc: " Julian Ganz
2025-10-21 19:59   ` Philippe Mathieu-Daudé
2025-10-19 15:15 ` [PATCH v8 15/25] target/ppc: " Julian Ganz
2025-10-19 15:15 ` [PATCH v8 16/25] target/riscv: " Julian Ganz
2025-10-19 15:15 ` [PATCH v8 17/25] target/rx: " Julian Ganz
2025-10-21 20:00   ` Philippe Mathieu-Daudé
2025-10-19 15:15 ` [PATCH v8 18/25] target/s390x: " Julian Ganz
2025-10-21 20:07   ` Philippe Mathieu-Daudé
2025-10-21 20:25     ` Julian Ganz
2025-10-19 15:15 ` [PATCH v8 19/25] target/sh4: " Julian Ganz
2025-10-19 15:15 ` [PATCH v8 20/25] target/sparc: " Julian Ganz
2025-10-21 20:01   ` Philippe Mathieu-Daudé
2025-10-19 15:18 ` [PATCH v8 21/25] target/tricore: " Julian Ganz
2025-10-19 15:18 ` [PATCH v8 22/25] target/xtensa: " Julian Ganz
2025-10-19 15:18 ` [PATCH v8 23/25] tests: add plugin asserting correctness of discon event's to_pc Julian Ganz
2025-10-19 15:18 ` [PATCH v8 24/25] tests: add test for double-traps on rv64 Julian Ganz
2025-10-19 15:18 ` [PATCH v8 25/25] tests: add test with interrupted memory accesses " Julian Ganz
2025-10-21 19:35 ` [PATCH v8 00/25] tcg-plugins: add hooks for discontinuities Alex Bennée
2025-10-23 12:16 ` 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=1bff3f2e662e94d8415d7b81bf4433deff3e62bd.1760884672.git.neither@nut.email \
    --to=neither@nut.email \
    --cc=alex.bennee@linaro.org \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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).