From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
To: Julian Ganz <neither@nut.email>, qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
"Alexandre Iooss" <erdnaxe@crans.org>,
"Mahmoud Mandour" <ma.mandourr@gmail.com>
Subject: Re: [RFC PATCH v3 11/11] tests: add plugin asserting correctness of discon event's to_pc
Date: Wed, 4 Dec 2024 15:33:30 -0800 [thread overview]
Message-ID: <d4b17c7d-c1d2-4e43-8eee-d1667e3ee5a2@linaro.org> (raw)
In-Reply-To: <36d316bf3e8b0aca778c5e8d1acde39a7f361946.1733063076.git.neither@nut.email>
On 12/2/24 11:41, Julian Ganz wrote:
> We recently introduced plugin API for the registration of callbacks for
> discontinuity events, specifically for interrupts, exceptions and host
> call events. The callback receives, among other information, the VCPU
> index and the PC after the event. This change introduces a test plugin
> asserting that particular behaviour.
> ---
> tests/tcg/plugins/discons.c | 95 +++++++++++++++++++++++++++++++++++
> tests/tcg/plugins/meson.build | 2 +-
> 2 files changed, 96 insertions(+), 1 deletion(-)
> create mode 100644 tests/tcg/plugins/discons.c
>
> diff --git a/tests/tcg/plugins/discons.c b/tests/tcg/plugins/discons.c
> new file mode 100644
> index 0000000000..54e52f563a
> --- /dev/null
> +++ b/tests/tcg/plugins/discons.c
> @@ -0,0 +1,95 @@
> +/*
> + * Copyright (C) 2024, Julian Ganz <neither@nut.email>
> + *
> + * License: GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
Would be nice to include a description of the plugin here.
> +#include <stdio.h>
> +
> +#include <qemu-plugin.h>
> +
> +QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
> +
> +struct cpu_state {
> + uint64_t next_pc;
> + bool has_next;
> +};
> +
> +static struct qemu_plugin_scoreboard *states;
> +
> +static bool abort_on_mismatch;
> +
> +static void vcpu_discon(qemu_plugin_id_t id, unsigned int vcpu_index,
> + enum qemu_plugin_discon_type type, uint64_t from_pc,
> + uint64_t to_pc)
> +{
> + struct cpu_state *state = qemu_plugin_scoreboard_find(states, vcpu_index);
> + state->next_pc = to_pc;
> + state->has_next = true;
> +}
> +
> +static void insn_exec(unsigned int vcpu_index, void *userdata)
> +{
> + struct cpu_state *state = qemu_plugin_scoreboard_find(states, vcpu_index);
> + uint64_t pc = (uint64_t) userdata;
> + GString* report;
> +
> + if (state->has_next) {
> + if (state->next_pc != pc) {
> + report = g_string_new("Trap target PC mismatch\n");
> + g_string_append_printf(report,
> + "Expected: %"PRIx64"\nEncountered: %"
> + PRIx64"\n",
> + state->next_pc, pc);
> + qemu_plugin_outs(report->str);
> + if (abort_on_mismatch) {
> + g_abort();
> + }
> + g_string_free(report, true);
> + }
> + state->has_next = false;
> + }
> +}
When booting an arm64 vm, I get this message:
Trap target PC mismatch
Expected: 23faf3a80
Encountered: 23faf3a84
From what I understand, it means that the next_pc we have is incorrect.
> +
> +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
> +{
> + size_t i;
> + size_t n_insns = qemu_plugin_tb_n_insns(tb);
> +
> + for (i = 0; i < n_insns; i++) {
> + struct qemu_plugin_insn * insn = qemu_plugin_tb_get_insn(tb, i);
> + uint64_t pc = qemu_plugin_insn_vaddr(insn);
> + qemu_plugin_register_vcpu_insn_exec_cb(insn, insn_exec,
> + QEMU_PLUGIN_CB_NO_REGS,
> + (void*) pc);
> + }
> +}> +
> +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
> + const qemu_info_t *info,
> + int argc, char **argv)
> +{
> + int i;
> +
> + for (i = 0; i < argc; i++) {
> + char *opt = argv[i];
> + g_auto(GStrv) tokens = g_strsplit(opt, "=", 2);
> + if (g_strcmp0(tokens[0], "abort") == 0) {
> + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &abort_on_mismatch)) {
> + fprintf(stderr, "boolean argument parsing failed: %s\n", opt);
> + return -1;
> + }
> + } else {
> + fprintf(stderr, "option parsing failed: %s\n", opt);
> + return -1;
> + }
> + }
> +
> + states = qemu_plugin_scoreboard_new(sizeof(struct cpu_state));
> +
> + qemu_plugin_register_vcpu_discon_cb(id, QEMU_PLUGIN_DISCON_ALL,
> + vcpu_discon);
> + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans);
> +
> + return 0;
> +}
> diff --git a/tests/tcg/plugins/meson.build b/tests/tcg/plugins/meson.build
> index f847849b1b..f057238da1 100644
> --- a/tests/tcg/plugins/meson.build
> +++ b/tests/tcg/plugins/meson.build
> @@ -1,6 +1,6 @@
> t = []
> if get_option('plugins')
> - foreach i : ['bb', 'empty', 'inline', 'insn', 'mem', 'syscall']
> + foreach i : ['bb', 'discons', 'empty', 'inline', 'insn', 'mem', 'syscall']
> if host_os == 'windows'
> t += shared_module(i, files(i + '.c') + '../../../contrib/plugins/win32_linker.c',
> include_directories: '../../../include/qemu',
next prev parent reply other threads:[~2024-12-04 23:34 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-02 19:26 [RFC PATCH v3 00/11] tcg-plugins: add hooks for discontinuities Julian Ganz
2024-12-02 19:26 ` [RFC PATCH v3 01/11] plugins: add types for callbacks related to certain discontinuities Julian Ganz
2024-12-03 8:45 ` Julian Ganz
2024-12-04 22:41 ` Pierrick Bouvier
2024-12-05 12:40 ` Julian Ganz
2024-12-05 17:56 ` Pierrick Bouvier
2024-12-05 21:50 ` Julian Ganz
2024-12-05 22:14 ` Julian Ganz
2024-12-05 23:03 ` Pierrick Bouvier
2024-12-06 8:58 ` Julian Ganz
2024-12-06 18:59 ` Pierrick Bouvier
2024-12-07 13:38 ` Julian Ganz
2024-12-09 18:52 ` Pierrick Bouvier
2024-12-04 22:45 ` Pierrick Bouvier
2024-12-05 12:44 ` Julian Ganz
2024-12-05 17:35 ` Pierrick Bouvier
2024-12-05 21:25 ` Julian Ganz
2025-01-09 13:52 ` Alex Bennée
2025-01-09 22:28 ` Pierrick Bouvier
2025-01-10 11:43 ` Julian Ganz
2024-12-02 19:26 ` [RFC PATCH v3 02/11] plugins: add API for registering discontinuity callbacks Julian Ganz
2024-12-04 22:45 ` Pierrick Bouvier
2025-01-09 13:57 ` Alex Bennée
2025-01-10 11:40 ` Julian Ganz
2024-12-02 19:26 ` [RFC PATCH v3 03/11] plugins: add hooks for new discontinuity related callbacks Julian Ganz
2024-12-04 22:47 ` Pierrick Bouvier
2025-01-09 13:58 ` Alex Bennée
2024-12-02 19:26 ` [RFC PATCH v3 04/11] contrib/plugins: add plugin showcasing new dicontinuity related API Julian Ganz
2024-12-04 23:14 ` Pierrick Bouvier
2024-12-05 13:00 ` Julian Ganz
2024-12-05 17:23 ` Pierrick Bouvier
2025-01-09 14:04 ` Alex Bennée
2025-01-09 22:10 ` Pierrick Bouvier
2025-01-10 11:49 ` Julian Ganz
2025-01-10 15:15 ` Alex Bennée
2025-01-10 21:02 ` Pierrick Bouvier
2025-01-11 12:15 ` Alex Bennée
2024-12-02 19:26 ` [RFC PATCH v3 05/11] target/alpha: call plugin trap callbacks Julian Ganz
2024-12-04 22:48 ` Pierrick Bouvier
2024-12-02 19:26 ` [RFC PATCH v3 06/11] target/arm: " Julian Ganz
2024-12-02 19:26 ` [RFC PATCH v3 07/11] target/avr: " Julian Ganz
2024-12-02 19:26 ` [RFC PATCH v3 08/11] target/mips: " Julian Ganz
2025-01-09 13:43 ` Alex Bennée
2024-12-02 19:26 ` [RFC PATCH v3 09/11] target/riscv: " Julian Ganz
2024-12-03 4:39 ` Alistair Francis
2024-12-02 19:41 ` [RFC PATCH v3 10/11] target/sparc: " Julian Ganz
2025-01-09 13:46 ` Alex Bennée
2024-12-02 19:41 ` [RFC PATCH v3 11/11] tests: add plugin asserting correctness of discon event's to_pc Julian Ganz
2024-12-04 23:33 ` Pierrick Bouvier [this message]
2024-12-05 13:10 ` Julian Ganz
2024-12-05 17:30 ` Pierrick Bouvier
2024-12-05 21:22 ` Julian Ganz
2024-12-05 22:28 ` Pierrick Bouvier
2024-12-06 8:42 ` Julian Ganz
2024-12-06 19:02 ` Pierrick Bouvier
2024-12-06 19:42 ` Richard Henderson
2024-12-06 20:40 ` Pierrick Bouvier
2024-12-06 22:56 ` Richard Henderson
2024-12-07 13:47 ` Julian Ganz
2024-12-07 13:41 ` Julian Ganz
2024-12-20 11:47 ` Julian Ganz
2024-12-20 21:17 ` Pierrick Bouvier
2024-12-20 21:46 ` Pierrick Bouvier
2025-01-09 16:35 ` Alex Bennée
2025-01-09 16:33 ` Alex Bennée
2025-01-09 22:27 ` Pierrick Bouvier
2025-01-10 11:58 ` Julian Ganz
2024-12-03 8:36 ` [RFC PATCH v3 00/11] tcg-plugins: add hooks for discontinuities Julian Ganz
2024-12-04 22:51 ` Pierrick Bouvier
2025-01-09 16:43 ` 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=d4b17c7d-c1d2-4e43-8eee-d1667e3ee5a2@linaro.org \
--to=pierrick.bouvier@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=erdnaxe@crans.org \
--cc=ma.mandourr@gmail.com \
--cc=neither@nut.email \
--cc=qemu-devel@nongnu.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).