From patchwork Sat Oct 21 12:24:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Ganz X-Patchwork-Id: 13431515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 79237C07545 for ; Sat, 21 Oct 2023 13:49:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1quCLj-0003aR-PL; Sat, 21 Oct 2023 09:49:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1quB2m-00072F-V1 for qemu-devel@nongnu.org; Sat, 21 Oct 2023 08:25:29 -0400 Received: from skiff.uberspace.de ([185.26.156.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1quB2g-0005pH-0C for qemu-devel@nongnu.org; Sat, 21 Oct 2023 08:25:27 -0400 Received: (qmail 24468 invoked by uid 990); 21 Oct 2023 12:25:11 -0000 Authentication-Results: skiff.uberspace.de; auth=pass (plain) From: Julian Ganz To: qemu-devel@nongnu.org Cc: Julian Ganz , Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PATCH] tcg-plugins: add a hook for interrupts, exceptions and traps Date: Sat, 21 Oct 2023 14:24:54 +0200 Message-ID: <20231021122502.26746-1-neither@nut.email> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Rspamd-Bar: ++ X-Rspamd-Report: SUSPICIOUS_RECIPS(1.5) BAYES_HAM(-0.029244) MID_CONTAINS_FROM(1) MIME_GOOD(-0.1) R_MISSING_CHARSET(0.5) X-Rspamd-Score: 2.870755 Received: from unknown (HELO unkown) (::1) by skiff.uberspace.de (Haraka/3.0.1) with ESMTPSA; Sat, 21 Oct 2023 14:25:10 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nut.email; s=uberspace; h=from; bh=DA0CCytzGZMMSzo+EOqLJ2yK0ag/lo+92Eu/lmy4vWQ=; b=EiWALQsmgpd55YP0q2OYFYdZzbpaGFyqTXh9qteHTSSMvqcW1/HZsMblyx2hjNX5gasjqNRu42 GOiw7J2No6zVjIpIIX8IKvFN0XCsqO7hTFK+QUWCMOC812LSQZ01ibT20SwsazEW7AoQFXjPc2iX BuohL0watcFXkOox0oSpIhPhY51Wtp8/M+VcLqvDszskB3gbhiXs6UOPBNrvhWTUcK1RTu8Q0fpf S/6buN6cEvTPhm5xpzQlxiJ7fFh0/7WGi4ydzohyLSfNU0lBrFUeWR9qM2P9CYDny1+SeEeKqVRC mjNiBp16TkiYzPX9X0FfIJCBWcWJcLh/CyRdSGYqt+I60Hn9ti/jL6+JpNiR5mHqEP+wJBMJreAy eGV0O7W7aEno/9wY2acxkhWVKxgftxVjukESZEaykmvaHcw8AKX6pa+etXbmFB0hPH3wwlqvLn81 fGL1AZVdT6IOrbggKqIZ668LfzH2u3/PmDXuXwh/2eKv+38XrunUfOxzE28knCyoFHNM7Pz1wN+I MmAVVGzPk5OJA1lf7LR6/sRQOPOAzCe7eLbDra2pzOLHRf8Z1/d9SXbUnWoW3FOb9g4VhucTo2Gc IwSvL7mU7CMMUnCb13SA4CgN1m2J/I5OefV4iIgzugntNwGgx/tPuwQN5k6Q0qVgk8HDpt3/I33f Y= Received-SPF: none client-ip=185.26.156.131; envelope-from=neither@nut.email; helo=skiff.uberspace.de X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, MSGID_FROM_MTA_HEADER=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 21 Oct 2023 09:48:44 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Some analysis greatly benefits, or depends on, information about interrupts. For example, we may need to handle the execution of a new translation block differently if it is not the result of normal program flow but of an interrupt. Even with the existing interfaces, it is more or less possible to discern these situations using some heuristice. For example, the PC landing in a trap vector is a strong indicator that a trap, i.e. an interrupt or event occured. However, such heuristics require knowledge about the architecture and may be prone to errors. The callback introduced by this change provides a generic and easy-to-use interface for plugin authors. It allows them to register a callback in which they may alter some plugin-internal state to convey the firing of an interrupt for a given CPU, or perform some stand-alone analysis based on the interrupt and, for example, the CPU state. Signed-off-by: Julian Ganz --- accel/tcg/cpu-exec.c | 3 +++ include/qemu/plugin-event.h | 1 + include/qemu/plugin.h | 4 ++++ include/qemu/qemu-plugin.h | 11 +++++++++++ plugins/core.c | 12 ++++++++++++ plugins/qemu-plugins.symbols | 1 + 6 files changed, 32 insertions(+) diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 1a5bc90220..e094d9236d 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -754,6 +754,8 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret) qemu_mutex_unlock_iothread(); cpu->exception_index = -1; + qemu_plugin_vcpu_interrupt_cb(cpu); + if (unlikely(cpu->singlestep_enabled)) { /* * After processing the exception, ensure an EXCP_DEBUG is @@ -866,6 +868,7 @@ static inline bool cpu_handle_interrupt(CPUState *cpu, if (need_replay_interrupt(interrupt_request)) { replay_interrupt(); } + qemu_plugin_vcpu_interrupt_cb(cpu); /* * After processing the interrupt, ensure an EXCP_DEBUG is * raised when single-stepping so that GDB doesn't miss the diff --git a/include/qemu/plugin-event.h b/include/qemu/plugin-event.h index 7056d8427b..d085bdda4e 100644 --- a/include/qemu/plugin-event.h +++ b/include/qemu/plugin-event.h @@ -20,6 +20,7 @@ enum qemu_plugin_event { QEMU_PLUGIN_EV_VCPU_SYSCALL_RET, QEMU_PLUGIN_EV_FLUSH, QEMU_PLUGIN_EV_ATEXIT, + QEMU_PLUGIN_EV_VCPU_INTERRUPT, QEMU_PLUGIN_EV_MAX, /* total number of plugin events we support */ }; diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 7fdc3a4849..f942e45f41 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -190,6 +190,7 @@ void qemu_plugin_vcpu_exit_hook(CPUState *cpu); void qemu_plugin_tb_trans_cb(CPUState *cpu, struct qemu_plugin_tb *tb); void qemu_plugin_vcpu_idle_cb(CPUState *cpu); void qemu_plugin_vcpu_resume_cb(CPUState *cpu); +void qemu_plugin_vcpu_interrupt_cb(CPUState *cpu); void qemu_plugin_vcpu_syscall(CPUState *cpu, int64_t num, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, @@ -270,6 +271,9 @@ static inline void qemu_plugin_vcpu_idle_cb(CPUState *cpu) static inline void qemu_plugin_vcpu_resume_cb(CPUState *cpu) { } +static inline void qemu_plugin_vcpu_interrupt_cb(CPUState *cpu) +{ } + static inline void qemu_plugin_vcpu_syscall(CPUState *cpu, int64_t num, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, uint64_t a6, diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 50a9957279..2eb4b325fe 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -206,6 +206,17 @@ void qemu_plugin_register_vcpu_idle_cb(qemu_plugin_id_t id, void qemu_plugin_register_vcpu_resume_cb(qemu_plugin_id_t id, qemu_plugin_vcpu_simple_cb_t cb); +/** + * qemu_plugin_register_vcpu_interrupt_cb() - register a vCPU interrupt callback + * @id: plugin ID + * @cb: callback function + * + * The @cb function is called every time a vCPU receives an interrupt, exception + * or trap. + */ +void qemu_plugin_register_vcpu_interrupt_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_simple_cb_t cb); + /** struct qemu_plugin_tb - Opaque handle for a translation block */ struct qemu_plugin_tb; /** struct qemu_plugin_insn - Opaque handle for a translated instruction */ diff --git a/plugins/core.c b/plugins/core.c index fcd33a2bff..3658bdef45 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -103,6 +103,7 @@ static void plugin_vcpu_cb__simple(CPUState *cpu, enum qemu_plugin_event ev) case QEMU_PLUGIN_EV_VCPU_EXIT: case QEMU_PLUGIN_EV_VCPU_IDLE: case QEMU_PLUGIN_EV_VCPU_RESUME: + case QEMU_PLUGIN_EV_VCPU_INTERRUPT: /* iterate safely; plugins might uninstall themselves at any time */ QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) { qemu_plugin_vcpu_simple_cb_t func = cb->f.vcpu_simple; @@ -400,6 +401,11 @@ void qemu_plugin_vcpu_resume_cb(CPUState *cpu) plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_RESUME); } +void qemu_plugin_vcpu_interrupt_cb(CPUState *cpu) +{ + plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_INTERRUPT); +} + void qemu_plugin_register_vcpu_idle_cb(qemu_plugin_id_t id, qemu_plugin_vcpu_simple_cb_t cb) { @@ -412,6 +418,12 @@ void qemu_plugin_register_vcpu_resume_cb(qemu_plugin_id_t id, plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_RESUME, cb); } +void qemu_plugin_register_vcpu_interrupt_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_simple_cb_t cb) +{ + plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_INTERRUPT, cb); +} + void qemu_plugin_register_flush_cb(qemu_plugin_id_t id, qemu_plugin_simple_cb_t cb) { diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 71f6c90549..1fddb4b9fd 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -35,6 +35,7 @@ qemu_plugin_register_vcpu_tb_exec_cb; qemu_plugin_register_vcpu_tb_exec_inline; qemu_plugin_register_vcpu_tb_trans_cb; + qemu_plugin_register_vcpu_interrupt_cb; qemu_plugin_reset; qemu_plugin_start_code; qemu_plugin_tb_get_insn; From patchwork Sat Oct 19 16:39:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Ganz X-Patchwork-Id: 13842822 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8A148D3C921 for ; Sat, 19 Oct 2024 16:40:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2CUy-00021w-Vz; Sat, 19 Oct 2024 12:40:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t2CUs-0001vX-Ts for qemu-devel@nongnu.org; Sat, 19 Oct 2024 12:40:10 -0400 Received: from mailgate02.uberspace.is ([2a00:d0c0:200:0:1c7b:a6ff:fee0:8ea4]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t2CUq-0003gr-2F for qemu-devel@nongnu.org; Sat, 19 Oct 2024 12:40:10 -0400 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate02.uberspace.is (Postfix) with ESMTPS id 3B4681802EC for ; Sat, 19 Oct 2024 18:39:58 +0200 (CEST) Received: (qmail 9732 invoked by uid 990); 19 Oct 2024 16:39:58 -0000 Authentication-Results: skiff.uberspace.de; auth=pass (plain) Received: from unknown (HELO unkown) (::1) by skiff.uberspace.de (Haraka/3.0.1) with ESMTPSA; Sat, 19 Oct 2024 18:39:57 +0200 From: Julian Ganz To: qemu-devel@nongnu.org Cc: Julian Ganz , =?utf-8?q?Alex_Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour , Pierrick Bouvier Subject: [RFC PATCH v2 2/7] plugins: add hooks for new trap related callbacks Date: Sat, 19 Oct 2024 18:39:35 +0200 Message-ID: <7ac6b4373e393e99070470818f6197fa34f9e3a9.1729355735.git.neither@nut.email> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: <20231021122502.26746-1-neither@nut.email> MIME-Version: 1.0 X-Rspamd-Bar: ---- X-Rspamd-Report: REPLY(-4) SUSPICIOUS_RECIPS(1.5) MID_CONTAINS_FROM(1) MIME_GOOD(-0.1) BAYES_HAM(-2.999999) R_MISSING_CHARSET(0.5) X-Rspamd-Score: -4.099999 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nut.email; s=uberspace; h=from:to:cc:subject:date; bh=2PREUqFIHRAtdmmzZJyaj9MVcqZad6TdGsxcSG5umK0=; b=PMi/3/uaxWjE6nzJF/yJC5e+P9c+r3VFvQcRZ+1Gx/D2sw31UPrBhhCPYHxz4H0t9lk95IARPd jARxKLEk+vnOFtVICZKH1gB1wugBdISWL0d2FACRpCbiXh2+JTBvppZcpXrooDe/QCfGKVLFDrtn asbRMeqDUxFqHnQ7LO72hrQMSwGe4c0SUQ8eQ5eINjL90GzD3kwzpIUafvpMUzlLmsh6zPpRzMq8 e2GIdzw1eYuDw8cMdFxMx7rEoup0CMGqclsco2N7w36tZyi0G4TwuW4xLdgDoJCAwoZrd9iLh2No 9ZX/DKRcoYkeKEtFO/tzEaMAJnGTxalgcHQlAbHVnLkNu1qaseZ2Cyw85JZS+6cL+oU+u6B2+tDV BjbT8lOG7QUvwV1SSjrB81Q0ka4MQpESZjH34VsNGJXs8F+3sT7fpc/EAg5au2oWgrPMAJtjy/j9 /oTdCasD+Fhq3ulvXSqGJ7Rx1w3N04295pFxeb7IJ9scrEkFLrv09noQu3GfCKuocxJD+Mvo777Y 7niwnl+cOUlBlatrlsgUW6RVRGeMTyOZj7Os+6UxSII+1NmdieT74IVWGrW9e+VxCsi/DORBE6Ju T321xahybeJZvBRwE0w0lgzlcyu1I3k7+vVidVy5r9bVfCsh/UqiBbQ9Zkk9hsfBXlpJ8mNuoZUw k= Received-SPF: pass client-ip=2a00:d0c0:200:0:1c7b:a6ff:fee0:8ea4; envelope-from=neither@nut.email; helo=mailgate02.uberspace.is X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The plugin API allows registration of callbacks for a variety of VCPU related events, such as VCPU reset, idle and resume. In addition, we recently introduced API for registering callbacks for trap events, specifically for interrupts, exceptions and semihosting events. This change introduces the corresponding hooks called from target specific code inside qemu. Signed-off-by: Julian Ganz --- include/qemu/plugin.h | 12 ++++++++++++ plugins/core.c | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 9726a9ebf3..71f03b83f4 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -160,6 +160,9 @@ void qemu_plugin_vcpu_exit_hook(CPUState *cpu); void qemu_plugin_tb_trans_cb(CPUState *cpu, struct qemu_plugin_tb *tb); void qemu_plugin_vcpu_idle_cb(CPUState *cpu); void qemu_plugin_vcpu_resume_cb(CPUState *cpu); +void qemu_plugin_vcpu_interrupt_cb(CPUState *cpu); +void qemu_plugin_vcpu_exception_cb(CPUState *cpu); +void qemu_plugin_vcpu_semihosting_cb(CPUState *cpu); void qemu_plugin_vcpu_syscall(CPUState *cpu, int64_t num, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, @@ -242,6 +245,15 @@ static inline void qemu_plugin_vcpu_idle_cb(CPUState *cpu) static inline void qemu_plugin_vcpu_resume_cb(CPUState *cpu) { } +void qemu_plugin_vcpu_interrupt_cb(CPUState *cpu) +{ } + +void qemu_plugin_vcpu_exception_cb(CPUState *cpu) +{ } + +void qemu_plugin_vcpu_semihosting_cb(CPUState *cpu) +{ } + static inline void qemu_plugin_vcpu_syscall(CPUState *cpu, int64_t num, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, uint64_t a6, diff --git a/plugins/core.c b/plugins/core.c index 9de997069c..4f80f1cb72 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -100,6 +100,9 @@ static void plugin_vcpu_cb__simple(CPUState *cpu, enum qemu_plugin_event ev) case QEMU_PLUGIN_EV_VCPU_EXIT: case QEMU_PLUGIN_EV_VCPU_IDLE: case QEMU_PLUGIN_EV_VCPU_RESUME: + case QEMU_PLUGIN_EV_VCPU_INTERRUPT: + case QEMU_PLUGIN_EV_VCPU_EXCEPTION: + case QEMU_PLUGIN_EV_VCPU_SEMIHOSTING: /* iterate safely; plugins might uninstall themselves at any time */ QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) { qemu_plugin_vcpu_simple_cb_t func = cb->f.vcpu_simple; @@ -547,6 +550,27 @@ void qemu_plugin_vcpu_resume_cb(CPUState *cpu) } } +void qemu_plugin_vcpu_interrupt_cb(CPUState *cpu) +{ + if (cpu->cpu_index < plugin.num_vcpus) { + plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_INTERRUPT); + } +} + +void qemu_plugin_vcpu_exception_cb(CPUState *cpu) +{ + if (cpu->cpu_index < plugin.num_vcpus) { + plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_EXCEPTION); + } +} + +void qemu_plugin_vcpu_semihosting_cb(CPUState *cpu) +{ + if (cpu->cpu_index < plugin.num_vcpus) { + plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_SEMIHOSTING); + } +} + void qemu_plugin_register_vcpu_idle_cb(qemu_plugin_id_t id, qemu_plugin_vcpu_simple_cb_t cb) { From patchwork Sat Oct 19 16:39:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Ganz X-Patchwork-Id: 13842820 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5464FD3C920 for ; Sat, 19 Oct 2024 16:40:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2CUu-0001xr-TW; Sat, 19 Oct 2024 12:40:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t2CUr-0001v6-6L for qemu-devel@nongnu.org; Sat, 19 Oct 2024 12:40:09 -0400 Received: from mailgate02.uberspace.is ([185.26.156.114]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t2CUp-0003h0-Az for qemu-devel@nongnu.org; Sat, 19 Oct 2024 12:40:08 -0400 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate02.uberspace.is (Postfix) with ESMTPS id BAF9E180363 for ; Sat, 19 Oct 2024 18:39:58 +0200 (CEST) Received: (qmail 9755 invoked by uid 990); 19 Oct 2024 16:39:58 -0000 Authentication-Results: skiff.uberspace.de; auth=pass (plain) Received: from unknown (HELO unkown) (::1) by skiff.uberspace.de (Haraka/3.0.1) with ESMTPSA; Sat, 19 Oct 2024 18:39:58 +0200 From: Julian Ganz To: qemu-devel@nongnu.org Cc: Julian Ganz , =?utf-8?q?Alex_Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour , Pierrick Bouvier Subject: [RFC PATCH v2 3/7] contrib/plugins: add plugin showcasing new trap related API Date: Sat, 19 Oct 2024 18:39:36 +0200 Message-ID: <1a2a379011c3636cfc516a3d246566acf14dd44f.1729355735.git.neither@nut.email> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: <20231021122502.26746-1-neither@nut.email> MIME-Version: 1.0 X-Rspamd-Bar: ---- X-Rspamd-Report: REPLY(-4) SUSPICIOUS_RECIPS(1.5) MID_CONTAINS_FROM(1) MIME_GOOD(-0.1) BAYES_HAM(-2.999999) R_MISSING_CHARSET(0.5) X-Rspamd-Score: -4.099999 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nut.email; s=uberspace; h=from:to:cc:subject:date; bh=bLp2Ya8EFnauSsMyOa8SMgEYE21yarlDHCE17UCplxA=; b=JheoeNHMF8IN71/x8thC36JxGDHBrOsrvGS/Db9bau+76mkcuTymlMZsX8YjVhL2ywIr6+Lh5X 73F4cE3M3C5p5ddlYzOb0jrQFOuUD7+eieN5f0uxzHRUjhvW9odyWFpyoTYT+ZcjGRSGRejGT/Vo ToBZiFe9Oo51MsqxJN+LG8HSdSZWzQRM5CXenuiTkNgeWDvc4hVK/3ZiHB1NUQI2rGPaLazoRWFA pI3cChuM427V38P7mO5MBUYFHHV/ny3Ty2IZJRtJLDvOzrnaMlAsyO4mQDixXyV/Vkgl4I8mhROR pL/xc5XTn8Gy++6g3yr5psvgEDJhJxWIi/VHWQFGv7gLThMhFNxwNPg9xkrgsNYlrze0OLaee/Jt +YOiVKYbNWnDvzzy+vqttTMZZEpL9y0j7r6ofzK4NjmJrCyF7tUnEUKb9Sww05Tz7fEnOuPbQEyk Aey+SMN6wPoKbqwo3IbtfCgGi+qHuAC6FRP7KdoIcJ58T2Piv96onY/y5UaZuSScwTjxnEAR/71G 1M70O4JPY4cURpwZyyqLpzten2EqlN39ImLlGPn99wCVhLSKl5BK/BwKNuolLpL/17rPYEauGbwd AGgLrk/Ik5p9+QfpGmOiUe/B5zBQjlLQyo1/9jZJAqDZUc4jetEk+lgBHanfcrjTpCBfMXOIIoy3 g= Received-SPF: pass client-ip=185.26.156.114; envelope-from=neither@nut.email; helo=mailgate02.uberspace.is X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NEW_PRODUCTS=1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We recently introduced new plugin API for registration of trap related callbacks. This change introduces a minimal plugin showcasing the new API. It simply counts the occurances of interrupts, exceptions and semihosting events per CPU and reports the counts when exitting. Signed-off-by: Julian Ganz --- contrib/plugins/Makefile | 1 + contrib/plugins/traps.c | 89 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 contrib/plugins/traps.c diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile index bbddd4800f..6085fd701f 100644 --- a/contrib/plugins/Makefile +++ b/contrib/plugins/Makefile @@ -31,6 +31,7 @@ NAMES += drcov NAMES += ips NAMES += stoptrigger NAMES += cflow +NAMES += traps ifeq ($(CONFIG_WIN32),y) SO_SUFFIX := .dll diff --git a/contrib/plugins/traps.c b/contrib/plugins/traps.c new file mode 100644 index 0000000000..2a38dbb8b3 --- /dev/null +++ b/contrib/plugins/traps.c @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2024, Julian Ganz + * + * Traps - count traps + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include + +#include + +QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; + +typedef struct { + uint64_t interrupts; + uint64_t exceptions; + uint64_t semihosting; + bool active; +} TrapCounters; + +static TrapCounters *traps; +size_t max_vcpus; + +static void vcpu_init(qemu_plugin_id_t id, unsigned int vcpu_index) +{ + traps[vcpu_index].active = true; +} + +static void vcpu_interrupt(qemu_plugin_id_t id, unsigned int vcpu_index) +{ + traps[vcpu_index].interrupts++; +} + +static void vcpu_exception(qemu_plugin_id_t id, unsigned int vcpu_index) +{ + traps[vcpu_index].exceptions++; +} + +static void vcpu_semihosting(qemu_plugin_id_t id, unsigned int vcpu_index) +{ + traps[vcpu_index].semihosting++; +} + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + g_autoptr(GString) report; + report = g_string_new("VCPU, interrupts, exceptions, semihosting\n"); + int vcpu; + + for (vcpu = 0; vcpu < max_vcpus; vcpu++) { + TrapCounters *rec = &traps[vcpu]; + if (rec->active) { + g_string_append_printf(report, + "% 4d, % 10"PRId64", % 10"PRId64", % 10" + PRId64"\n", + vcpu, + rec->interrupts, rec->exceptions, + rec->semihosting); + } + } + + qemu_plugin_outs(report->str); +} + +QEMU_PLUGIN_EXPORT +int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, + int argc, char **argv) +{ + if (!info->system_emulation) { + fputs("trap plugin can only be used in system emulation mode.\n", + stderr); + return -1; + } + + max_vcpus = info->system.max_vcpus; + traps = calloc(max_vcpus, sizeof(TrapCounters)); + qemu_plugin_register_vcpu_init_cb(id, vcpu_init); + qemu_plugin_vcpu_for_each(id, vcpu_init); + + qemu_plugin_register_vcpu_interrupt_cb(id, vcpu_interrupt); + qemu_plugin_register_vcpu_exception_cb(id, vcpu_exception); + qemu_plugin_register_vcpu_semihosting_cb(id, vcpu_semihosting); + + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + + return 0; +} From patchwork Sat Oct 19 16:39:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Ganz X-Patchwork-Id: 13842821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C9A04D3C922 for ; Sat, 19 Oct 2024 16:40:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2CUt-0001vT-AI; Sat, 19 Oct 2024 12:40:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t2CUr-0001v7-76 for qemu-devel@nongnu.org; Sat, 19 Oct 2024 12:40:09 -0400 Received: from mailgate02.uberspace.is ([185.26.156.114]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t2CUo-0003h3-TD for qemu-devel@nongnu.org; Sat, 19 Oct 2024 12:40:08 -0400 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate02.uberspace.is (Postfix) with ESMTPS id 02A3217F9F4 for ; Sat, 19 Oct 2024 18:39:59 +0200 (CEST) Received: (qmail 9771 invoked by uid 990); 19 Oct 2024 16:39:58 -0000 Authentication-Results: skiff.uberspace.de; auth=pass (plain) Received: from unknown (HELO unkown) (::1) by skiff.uberspace.de (Haraka/3.0.1) with ESMTPSA; Sat, 19 Oct 2024 18:39:58 +0200 From: Julian Ganz To: qemu-devel@nongnu.org Cc: Julian Ganz , Peter Maydell , qemu-arm@nongnu.org (open list:ARM TCG CPUs) Subject: [RFC PATCH v2 4/7] target/arm: call plugin trap callbacks Date: Sat, 19 Oct 2024 18:39:37 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: <20231021122502.26746-1-neither@nut.email> MIME-Version: 1.0 X-Rspamd-Bar: ----- X-Rspamd-Report: REPLY(-4) BAYES_HAM(-2.83479) MID_CONTAINS_FROM(1) MIME_GOOD(-0.1) R_MISSING_CHARSET(0.5) X-Rspamd-Score: -5.43479 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nut.email; s=uberspace; h=from:to:cc:subject:date; bh=QW5b+c8GerXmJWDNBXe+kTqzYLQkqZ+V6ikpQTJsG78=; b=Dwzd9ejyKQW+iC6emONffpP14xKf6tH85Pp3LCf3wawqHFZHM/nrBRRrnN6hfpmuiG0hKnFrbS aG1W1P4Ng/k+3WOVGgNAt3JRZXw6nz1rIuhdLlJOvcdUxralJIuUsXx64Dle78VjR9ptrelCQcmn LmDZZW85shk1H1Aff2YA6d+aphCSSbLZeEPyyHU3btUfOl/drs/gwk+WEwQfRekg16p5xY3n80YR n7ODFibt+cbEiqIXAidJdKi0v0kB6VPAtBH6weFMhmnBMmb+nIwc/jVSPaSkh6khhELYYw7oZtLm MMk9JDzpl5FGJFSht3FqhYbiz5G/y+bUB2wolQxCr/PnSUWd+es1s3jlaCJ0kwkHT8hwa2Hld8vA lMGA25QrST6h39s4uABTlZYHCAk6/C8Wg+aIIKyYku+zyc7s7kOiq/R4vgjQOnz7NWxKbL7ZThQp I741x7rweD3RQn6YeMN3C3mKAWrEmEslDKMSBktaKbHpbAhQ54/ipb4FcnGq8PY6lDVPg3wunQHx 1XhMKbYTo6wcOgh/wVD9o8gcj+E9shLe6UaSPuAS74gAtlpsxENLaTpGKmcMwFh//FaFTwNMzP+v IDSBExGb7Yiz7Im9VCZ6/CdnCCzhRvJ5+MrwCYtKHh5InX4ftzuAiZR0zDyD4KDHuImo3srsdA6E w= Received-SPF: pass client-ip=185.26.156.114; envelope-from=neither@nut.email; helo=mailgate02.uberspace.is X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We recently introduced API for registering callbacks for trap related events as well as the corresponding hook functions. Due to differences between architectures, the latter need to be called from target specific code. This change places hooks for ARM (and Aarch64) targets. We decided to treat the (V)IRQ, (VI/VF)NMI, (V)FIQ and VSERR exceptions as interrupts since they are, presumably, async in nature. Signed-off-by: Julian Ganz --- target/arm/helper.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/target/arm/helper.c b/target/arm/helper.c index 0a731a38e8..f636e216c8 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -31,6 +31,7 @@ #endif #include "cpregs.h" #include "target/arm/gtimer.h" +#include "qemu/plugin.h" #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */ @@ -11147,6 +11148,24 @@ static void take_aarch32_exception(CPUARMState *env, int new_mode, } } +static void arm_do_plugin_vcpu_interrupt_cb(CPUState *cs) +{ + switch (cs->exception_index) { + case EXCP_IRQ: + case EXCP_VIRQ: + case EXCP_NMI: + case EXCP_VINMI: + case EXCP_FIQ: + case EXCP_VFIQ: + case EXCP_VFNMI: + case EXCP_VSERR: + qemu_plugin_vcpu_interrupt_cb(cs); + break; + default: + qemu_plugin_vcpu_exception_cb(cs); + } +} + static void arm_cpu_do_interrupt_aarch32_hyp(CPUState *cs) { /* @@ -11819,6 +11838,7 @@ void arm_cpu_do_interrupt(CPUState *cs) if (tcg_enabled() && arm_is_psci_call(cpu, cs->exception_index)) { arm_handle_psci_call(cpu); qemu_log_mask(CPU_LOG_INT, "...handled as PSCI call\n"); + arm_do_plugin_vcpu_interrupt_cb(cs); return; } @@ -11830,6 +11850,7 @@ void arm_cpu_do_interrupt(CPUState *cs) #ifdef CONFIG_TCG if (cs->exception_index == EXCP_SEMIHOST) { tcg_handle_semihosting(cs); + qemu_plugin_vcpu_semihosting_cb(cs); return; } #endif @@ -11855,6 +11876,8 @@ void arm_cpu_do_interrupt(CPUState *cs) if (!kvm_enabled()) { cs->interrupt_request |= CPU_INTERRUPT_EXITTB; } + + arm_do_plugin_vcpu_interrupt_cb(cs); } #endif /* !CONFIG_USER_ONLY */ From patchwork Sat Oct 19 16:39:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Ganz X-Patchwork-Id: 13842823 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9EE80D3C920 for ; Sat, 19 Oct 2024 16:41:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2CUx-0001zm-6H; Sat, 19 Oct 2024 12:40:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t2CUt-0001wV-JJ for qemu-devel@nongnu.org; Sat, 19 Oct 2024 12:40:11 -0400 Received: from mailgate02.uberspace.is ([185.26.156.114]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t2CUs-0003xC-3q for qemu-devel@nongnu.org; Sat, 19 Oct 2024 12:40:11 -0400 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate02.uberspace.is (Postfix) with ESMTPS id 904C917F838 for ; Sat, 19 Oct 2024 18:39:59 +0200 (CEST) Received: (qmail 9787 invoked by uid 990); 19 Oct 2024 16:39:59 -0000 Authentication-Results: skiff.uberspace.de; auth=pass (plain) Received: from unknown (HELO unkown) (::1) by skiff.uberspace.de (Haraka/3.0.1) with ESMTPSA; Sat, 19 Oct 2024 18:39:59 +0200 From: Julian Ganz To: qemu-devel@nongnu.org Cc: Julian Ganz , Michael Rolnik Subject: [RFC PATCH v2 5/7] target/avr: call plugin trap callbacks Date: Sat, 19 Oct 2024 18:39:38 +0200 Message-ID: <5807fbae77440ce091c1480a173e371a72142952.1729355735.git.neither@nut.email> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: <20231021122502.26746-1-neither@nut.email> MIME-Version: 1.0 X-Rspamd-Bar: ----- X-Rspamd-Report: REPLY(-4) BAYES_HAM(-2.955061) MID_CONTAINS_FROM(1) MIME_GOOD(-0.1) R_MISSING_CHARSET(0.5) X-Rspamd-Score: -5.555061 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nut.email; s=uberspace; h=from:to:cc:subject:date; bh=3kEDEfs2NK+O76NkQpJ9J9wdE/Guadg1wnJP/wNvu24=; b=oL2YfM2sk5MpdnW86mImRU62igmM9MjOSYjboKOGIu1YkkUy7wFrnxDLp7m9lpwf3pclQ/wpE7 wtrnF4hWQkb5y5HTD4NMxxrdx3LoAU7MXIvU9SWXsDjQEbJDK0GppXrnyFb2i6oVfNcWXWEU5Dlg MdzR3ho/AaU9BnwTNKz7vMyTjCFdxcQDkUtq4Lo+ZZNX0yMLZcN4Jmrc9XwBQnyHPA5HpjjQm7OO P1pKedCoI/Rr0XEUaX/KspdT4EwEvosqizSUwfupWiJB1Ai3+W6EH6CXVjHnO6jyrLv9aQTANqHS OV8Ob2MReoHawOJg5fQmkx18EKzfwZzpqEfC2b2mZoyP6qmBdLVlk+ftesPyLNDZ6kBrTQCezO19 zGO8GQfFZVIHI7pX1CndzZ2AUgUrTUNnDz/0FbOCS2wSkqPXK55zdTrEoV35xQtfXqPQVqkpcEPe ThXSz9i0QecFaIe/c4BJHCOxY765f4/uMZrCe5FaLC+FL2YnITG+mMInQXdrecEgJCtE6i3lxnMy z+kRKN6xSuRdDbBOyauCozvR8m8yI6bb8cBlGOe/xu5UOrvdlwTxSLnmXWPJlR7jAlWJmoPCLFT+ zD3jZa+wgIjRA5Fdf2mdPsurVvt/5AOgwL9/Q6VegPh4U6AtX6H5WrxzILzCGkua/PJKgjdpFue6 k= Received-SPF: pass client-ip=185.26.156.114; envelope-from=neither@nut.email; helo=mailgate02.uberspace.is X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We recently introduced API for registering callbacks for trap related events as well as the corresponding hook functions. Due to differences between architectures, the latter need to be called from target specific code. This change places the hook for AVR targets. That architecture appears to only know interrupts. Signed-off-by: Julian Ganz Reviewed-by: Michael Rolnik --- target/avr/helper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/avr/helper.c b/target/avr/helper.c index 345708a1b3..be94552674 100644 --- a/target/avr/helper.c +++ b/target/avr/helper.c @@ -28,6 +28,7 @@ #include "exec/cpu_ldst.h" #include "exec/address-spaces.h" #include "exec/helper-proto.h" +#include "qemu/plugin.h" bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request) { @@ -97,6 +98,8 @@ void avr_cpu_do_interrupt(CPUState *cs) env->sregI = 0; /* clear Global Interrupt Flag */ cs->exception_index = -1; + + qemu_plugin_vcpu_interrupt_cb(cs); } hwaddr avr_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) From patchwork Sat Oct 19 16:39:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Ganz X-Patchwork-Id: 13842824 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0E943D3C921 for ; Sat, 19 Oct 2024 16:41:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2CUz-00022u-L6; Sat, 19 Oct 2024 12:40:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t2CUt-0001wf-QH for qemu-devel@nongnu.org; Sat, 19 Oct 2024 12:40:11 -0400 Received: from mailgate02.uberspace.is ([185.26.156.114]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t2CUs-0003xH-4E for qemu-devel@nongnu.org; Sat, 19 Oct 2024 12:40:11 -0400 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate02.uberspace.is (Postfix) with ESMTPS id E1C79180379 for ; Sat, 19 Oct 2024 18:39:59 +0200 (CEST) Received: (qmail 9805 invoked by uid 990); 19 Oct 2024 16:39:59 -0000 Authentication-Results: skiff.uberspace.de; auth=pass (plain) Received: from unknown (HELO unkown) (::1) by skiff.uberspace.de (Haraka/3.0.1) with ESMTPSA; Sat, 19 Oct 2024 18:39:59 +0200 From: Julian Ganz To: qemu-devel@nongnu.org Cc: Julian Ganz , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , qemu-riscv@nongnu.org (open list:RISC-V TCG CPUs) Subject: [RFC PATCH v2 6/7] target/riscv: call plugin trap callbacks Date: Sat, 19 Oct 2024 18:39:39 +0200 Message-ID: <4a0a1da117dcb66eb3050570869bedcfefb86100.1729355735.git.neither@nut.email> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: <20231021122502.26746-1-neither@nut.email> MIME-Version: 1.0 X-Rspamd-Bar: ---- X-Rspamd-Report: REPLY(-4) SUSPICIOUS_RECIPS(1.5) MID_CONTAINS_FROM(1) MIME_GOOD(-0.1) BAYES_HAM(-2.969764) R_MISSING_CHARSET(0.5) X-Rspamd-Score: -4.069764 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nut.email; s=uberspace; h=from:to:cc:subject:date; bh=Wfx4XlJFAqOqDm2oM4VSKIM/3Bzy+eWnXxIR053cDbE=; b=GGpDg7Q2r5mudjMMjpc6s18O8YwbcCOPWTpTIc1spDDuSmgxYjTTZuoarql1YV+7Z/mFjM4k8S UL9re4W2/bDt4I4Vlbl8a/SKj0d0aRJySqIc+E85g6MI3/HhwP1FqOAoLgs4yWe4zRWlk1GU3XCg nphtdwZiloeeIQ3xtCjjtAwik6jueAOFgT+Q1TUrm8Oi3hG+xMUPALthdq5DjOkWReVvqqq/a99C bQAMXV3NrO/FRuRz7zrEWvDz8e4NnTxMZp8BoVlL8LmyUW9RFjYijaIEx5aWGIVbvcraIxYfr9Ip LQzpiydyOLb7x+cTdYtaW4xXIIn4AqZfguMe5wTQUZlyR1EL4ltxOrog04lax/SU6MIGwYISIyyg 0lJIVa0vVKl2wZBsRWcSRKvnpv//U0l0htoo5/BxXA1l+9xuDI+mdWPw7+hTepob/ewsTBEP78uG z2K2D06E1OcrHIwqsyVNScsWCfxkdCggzSXyIxNPY6/WbWwF5XwJ8qnRyDcfBqdBAuPsJc0NFdtJ ntnZpFxZad14+f/w92ud5WB9TmDLz5G9MV5WBBikUljRwTqhpvXAB52eBU7jJOhdwXsKSyTNeYIb oKPMNGvEBrkdmplswB1gDi2x6VVxbxclmkV5nNxrLY6IzVs7cRdJIUq41oDDqW5owBPaBKae75ne 8= Received-SPF: pass client-ip=185.26.156.114; envelope-from=neither@nut.email; helo=mailgate02.uberspace.is X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We recently introduced API for registering callbacks for trap related events as well as the corresponding hook functions. Due to differences between architectures, the latter need to be called from target specific code. This change places hooks for RISC-V targets. Signed-off-by: Julian Ganz --- target/riscv/cpu_helper.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index a935377b4a..2a95869339 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -33,6 +33,7 @@ #include "cpu_bits.h" #include "debug.h" #include "tcg/oversized-guest.h" +#include "qemu/plugin.h" int riscv_env_mmu_index(CPURISCVState *env, bool ifetch) { @@ -1678,6 +1679,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) case RISCV_EXCP_SEMIHOST: do_common_semihosting(cs); env->pc += 4; + qemu_plugin_vcpu_semihosting_cb(cs); return; #endif case RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT: @@ -1839,6 +1841,12 @@ void riscv_cpu_do_interrupt(CPUState *cs) riscv_cpu_set_mode(env, PRV_M, virt); } + if (async) { + qemu_plugin_vcpu_interrupt_cb(cs); + } else { + qemu_plugin_vcpu_exception_cb(cs); + } + /* * NOTE: it is not necessary to yield load reservations here. It is only * necessary for an SC from "another hart" to cause a load reservation