From: "Alex Bennée" <alex.bennee@linaro.org>
To: Florian Hofhammer <florian.hofhammer@epfl.ch>
Cc: qemu-devel@nongnu.org, pierrick.bouvier@linaro.org,
richard.henderson@linaro.org, laurent@vivier.eu,
imp@bsdimp.com, berrange@redhat.com
Subject: Re: [PATCH v4 3/7] plugins: add PC diversion API function
Date: Tue, 24 Feb 2026 17:46:01 +0000 [thread overview]
Message-ID: <87wm022fxi.fsf@draig.linaro.org> (raw)
In-Reply-To: <33eb2408-b4c3-4ca4-9555-b2015fa38630@epfl.ch> (Florian Hofhammer's message of "Tue, 24 Feb 2026 16:51:36 +0100")
Florian Hofhammer <florian.hofhammer@epfl.ch> writes:
> This patch adds a plugin API function that allows diverting the program
> counter during execution. A potential use case for this functionality is
> to skip over parts of the code, e.g., by hooking into a specific
> instruction and setting the PC to the next instruction in the callback.
>
> Link: https://lists.nongnu.org/archive/html/qemu-devel/2025-08/msg00656.html
> Signed-off-by: Florian Hofhammer <florian.hofhammer@epfl.ch>
> ---
> include/plugins/qemu-plugin.h | 13 +++++++++++++
> plugins/api.c | 13 +++++++++++++
> 2 files changed, 26 insertions(+)
>
> diff --git a/include/plugins/qemu-plugin.h b/include/plugins/qemu-plugin.h
> index a6ec8e275d..04c884e82b 100644
> --- a/include/plugins/qemu-plugin.h
> +++ b/include/plugins/qemu-plugin.h
> @@ -76,6 +76,7 @@ typedef uint64_t qemu_plugin_id_t;
> *
> * version 6:
> * - changed return value of qemu_plugin_{read,write}_register from int to bool
> + * - added qemu_plugin_set_pc
> */
>
> extern QEMU_PLUGIN_EXPORT int qemu_plugin_version;
> @@ -1042,6 +1043,18 @@ QEMU_PLUGIN_API
> bool qemu_plugin_write_register(struct qemu_plugin_register *handle,
> GByteArray *buf);
>
> +/**
> + * qemu_plugin_set_pc() - set the program counter for the current vCPU
> + *
> + * @vaddr: the new virtual (guest) address for the program counter
> + *
> + * This function sets the program counter for the current vCPU to @vaddr and
> + * resumes execution at that address. This function only returns in case of
> + * errors.
> + */
> +QEMU_PLUGIN_API
> +void qemu_plugin_set_pc(uint64_t vaddr);
> +
> /**
> * qemu_plugin_read_memory_vaddr() - read from memory using a virtual address
> *
> diff --git a/plugins/api.c b/plugins/api.c
> index e754b7c69c..ca3e93a194 100644
> --- a/plugins/api.c
> +++ b/plugins/api.c
> @@ -41,6 +41,7 @@
> #include "qemu/log.h"
> #include "system/memory.h"
> #include "tcg/tcg.h"
> +#include "exec/cpu-common.h"
> #include "exec/gdbstub.h"
> #include "exec/target_page.h"
> #include "exec/translation-block.h"
> @@ -466,6 +467,18 @@ bool qemu_plugin_write_register(struct qemu_plugin_register *reg,
> return (gdb_write_register(current_cpu, buf->data, GPOINTER_TO_INT(reg) - 1) > 0);
> }
>
> +void qemu_plugin_set_pc(uint64_t vaddr)
> +{
> + g_assert(current_cpu);
> +
> + if (qemu_plugin_get_cb_flags() != QEMU_PLUGIN_CB_RW_REGS_PC) {
> + return;
> + }
I think its fine to assert() here - we do it elsewhere in the api, if
the user is holding it wrong we should exit now rather than leave the
plugin more confused in the future.
> +
> + cpu_set_pc(current_cpu, vaddr);
> + cpu_loop_exit(current_cpu);
> +}
> +
> bool qemu_plugin_read_memory_vaddr(uint64_t addr, GByteArray *data, size_t len)
> {
> g_assert(current_cpu);
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
next prev parent reply other threads:[~2026-02-24 17:46 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-24 15:46 [PATCH v4 0/7] Enable PC diversion via the plugin API Florian Hofhammer
2026-02-24 15:48 ` [PATCH v4 1/7] plugins: add flag to specify whether PC is rw Florian Hofhammer
2026-02-24 17:41 ` Alex Bennée
2026-02-24 15:50 ` [PATCH v4 2/7] linux-user: make syscall emulation interruptible Florian Hofhammer
2026-02-24 21:05 ` Pierrick Bouvier
2026-02-25 8:02 ` Florian Hofhammer
2026-02-25 17:00 ` Pierrick Bouvier
2026-02-25 9:25 ` Alex Bennée
2026-02-25 9:29 ` Florian Hofhammer
2026-02-25 12:25 ` Alex Bennée
2026-02-24 15:51 ` [PATCH v4 3/7] plugins: add PC diversion API function Florian Hofhammer
2026-02-24 17:46 ` Alex Bennée [this message]
2026-02-24 20:12 ` Pierrick Bouvier
2026-02-25 7:55 ` Florian Hofhammer
2026-02-24 15:52 ` [PATCH v4 4/7] tests/tcg: add test for qemu_plugin_set_pc API Florian Hofhammer
2026-02-24 16:55 ` Brian Cain
2026-02-24 20:24 ` Pierrick Bouvier
2026-02-25 14:58 ` Florian Hofhammer
2026-02-25 17:04 ` Pierrick Bouvier
2026-02-26 8:08 ` Florian Hofhammer
2026-02-24 20:35 ` Pierrick Bouvier
2026-02-25 7:59 ` Florian Hofhammer
2026-02-25 11:49 ` Florian Hofhammer
2026-02-25 17:07 ` Pierrick Bouvier
2026-02-25 17:09 ` Pierrick Bouvier
2026-02-24 21:28 ` Pierrick Bouvier
2026-02-25 8:03 ` Florian Hofhammer
2026-02-25 16:21 ` Florian Hofhammer
2026-02-25 17:30 ` Pierrick Bouvier
2026-02-25 17:39 ` Pierrick Bouvier
2026-02-26 8:30 ` Florian Hofhammer
2026-02-26 19:47 ` Pierrick Bouvier
2026-02-24 15:53 ` [PATCH v4 5/7] plugins: add read-only property for registers Florian Hofhammer
2026-02-24 17:46 ` Alex Bennée
2026-02-26 11:55 ` Florian Hofhammer
2026-02-26 14:33 ` Alex Bennée
2026-02-26 19:43 ` Pierrick Bouvier
2026-02-24 15:57 ` [PATCH v4 6/7] plugins: prohibit writing to read-only registers Florian Hofhammer
2026-02-24 17:49 ` Alex Bennée
2026-03-02 11:52 ` Florian Hofhammer
2026-03-02 13:03 ` Alex Bennée
2026-03-02 13:06 ` Florian Hofhammer
2026-02-24 15:58 ` [PATCH v4 7/7] tests/tcg/plugins: test register readonly feature Florian Hofhammer
2026-02-24 20:17 ` Pierrick Bouvier
2026-02-25 9:24 ` Alex Bennée
2026-02-24 20:14 ` [PATCH v4 0/7] Enable PC diversion via the plugin API Pierrick Bouvier
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=87wm022fxi.fsf@draig.linaro.org \
--to=alex.bennee@linaro.org \
--cc=berrange@redhat.com \
--cc=florian.hofhammer@epfl.ch \
--cc=imp@bsdimp.com \
--cc=laurent@vivier.eu \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.