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 6/7] plugins: prohibit writing to read-only registers
Date: Tue, 24 Feb 2026 17:49:48 +0000 [thread overview]
Message-ID: <87ldgi2fr7.fsf@draig.linaro.org> (raw)
In-Reply-To: <cc5b7b1a-b562-4376-8e4c-f01607bbcf9b@epfl.ch> (Florian Hofhammer's message of "Tue, 24 Feb 2026 16:57:21 +0100")
Florian Hofhammer <florian.hofhammer@epfl.ch> writes:
> The opaque register handle encodes whether a register is read-only in
> the lowest bit and prevents writing to the register via the plugin API
> in this case.
>
> Signed-off-by: Florian Hofhammer <florian.hofhammer@epfl.ch>
> ---
> plugins/api.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/plugins/api.c b/plugins/api.c
> index b2c52d2a09..3a8479ddce 100644
> --- a/plugins/api.c
> +++ b/plugins/api.c
> @@ -424,6 +424,7 @@ static GArray *create_register_handles(GArray *gdbstub_regs)
> for (int i = 0; i < gdbstub_regs->len; i++) {
> GDBRegDesc *grd = &g_array_index(gdbstub_regs, GDBRegDesc, i);
> qemu_plugin_reg_descriptor desc;
> + gint plugin_ro_bit = 0;
>
> /* skip "un-named" regs */
> if (!grd->name) {
> @@ -431,7 +432,6 @@ static GArray *create_register_handles(GArray *gdbstub_regs)
> }
>
> /* Create a record for the plugin */
> - desc.handle = GINT_TO_POINTER(grd->gdb_reg + 1);
> desc.name = g_intern_string(grd->name);
> desc.is_readonly = false;
> if (g_strcmp0(desc.name, pc_str) == 0
> @@ -442,7 +442,9 @@ static GArray *create_register_handles(GArray *gdbstub_regs)
> || g_strcmp0(desc.name, rpc_str) == 0
> ) {
> desc.is_readonly = true;
> + plugin_ro_bit = 1;
> }
> + desc.handle = GINT_TO_POINTER((grd->gdb_reg << 1) | plugin_ro_bit);
> desc.feature = g_intern_string(grd->feature_name);
> g_array_append_val(find_data, desc);
> }
> @@ -467,7 +469,7 @@ bool qemu_plugin_read_register(struct qemu_plugin_register *reg,
> return false;
> }
>
> - return (gdb_read_register(current_cpu, buf, GPOINTER_TO_INT(reg) - 1) > 0);
> + return (gdb_read_register(current_cpu, buf, GPOINTER_TO_INT(reg) >> 1) > 0);
> }
>
> bool qemu_plugin_write_register(struct qemu_plugin_register *reg,
> @@ -476,11 +478,12 @@ bool qemu_plugin_write_register(struct qemu_plugin_register *reg,
> g_assert(current_cpu);
>
> if (buf->len == 0 || (qemu_plugin_get_cb_flags() != QEMU_PLUGIN_CB_RW_REGS &&
> - qemu_plugin_get_cb_flags() != QEMU_PLUGIN_CB_RW_REGS_PC)) {
> + qemu_plugin_get_cb_flags() != QEMU_PLUGIN_CB_RW_REGS_PC)
> + || (GPOINTER_TO_INT(reg) & 1)) {
Maybe this is better as:
g_assert(GPOINTER_TO_INT(reg) & 1 == 0);
if (buf->len == 0 || (qemu_plugin_get_cb_flags() != QEMU_PLUGIN_CB_RW_REGS &&...
again the plugin is trying to do something it shouldn't.
> return false;
> }
>
> - return (gdb_write_register(current_cpu, buf->data, GPOINTER_TO_INT(reg) - 1) > 0);
> + return (gdb_write_register(current_cpu, buf->data, GPOINTER_TO_INT(reg) >> 1) > 0);
> }
>
> void qemu_plugin_set_pc(uint64_t vaddr)
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
next prev parent reply other threads:[~2026-02-24 17:50 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
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 [this message]
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=87ldgi2fr7.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.