From patchwork Mon Dec 2 19:26:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Ganz X-Patchwork-Id: 13891238 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 461EEE69E86 for ; Mon, 2 Dec 2024 19:29:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIC53-0005ks-Ge; Mon, 02 Dec 2024 14:27:37 -0500 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 1tIC4r-0005ik-Ct for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:26 -0500 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 1tIC4o-0001uR-NJ for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:24 -0500 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate02.uberspace.is (Postfix) with ESMTPS id A03FB1809E9 for ; Mon, 2 Dec 2024 20:27:12 +0100 (CET) Received: (qmail 7102 invoked by uid 990); 2 Dec 2024 19:27:12 -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; Mon, 02 Dec 2024 20:27:12 +0100 From: Julian Ganz To: qemu-devel@nongnu.org Cc: Julian Ganz Subject: [RFC PATCH v3 01/11] plugins: add types for callbacks related to certain discontinuities Date: Mon, 2 Dec 2024 20:26:42 +0100 Message-ID: <5e624b7244f1b0b294b28cd513aab04b6b294b1d.1733063076.git.neither@nut.email> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Bar: ----- X-Rspamd-Report: REPLY(-4) BAYES_HAM(-3) MID_CONTAINS_FROM(1) MIME_GOOD(-0.1) R_MISSING_CHARSET(0.5) X-Rspamd-Score: -5.6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nut.email; s=uberspace; h=from:to:cc:subject:date; bh=tAi2zcFE42Zy0HQebMGAgdPSPQ9ADTpaTuyuJAMYySI=; b=Hab6ABI7rYxdTJpQGpJTwZEhSMOdwE+4ELHjiiyeU8BdmKMljhjspC8EdCLqyY4Usn8RsOGcRO ZGPP9KUvOai42fcqapbtn/W9+9iWwFVi4O+drk+9DCjyQ6sWwC/Bvv21SIOQc8u2nUaorBJQmeO/ W45RYQAv7Z7VDLCfh4J+d2koLw7wUSUKkauXbvI3gUC2R57q7EKNhu+pby14pAcAVg0zA8wRchaZ AzZnAA6eT+ehoWvQBE+Gq7MeWMNCPjkt+ic1TfKwf7uHx/9Hw7CuyF7QQC/NDUk7xnrIHaKZhVOe CeqMRRzYVEee6dJUNLMxLpUmhpKbR58AyfmM0m+2X291MgPIEdyOAkUDRlIfe5QKxvi9OjpWbxYy fq18j5lPAdeBoC9q90gvJJUKr0lFbEm6bkVKvE7ldBm0g0SL4dz7kDp/C0OTYxqcT/tpEGZfUdgn iVpeTKQpPDZxwgOR0uodTG979R2yR54XSH+1kfClG6F2LoLUZ1lPluT18EXmqHWLvGJt/waATBsI AgnAKcDOnJKepAXtWlldCy8sYkjWkg1AIZGbD6/ZqX86ugdy9x5AJwpcvkxsl7Xs0xPZaE0FR0is Yc3D9HeePNgIFq7kNfUurm1whbXu6Vz3iLinvJKSr17UHI+RiHHosm5UFJqeTSEPERYIawoYLxO/ 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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 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. --- include/qemu/plugin.h | 1 + include/qemu/qemu-plugin.h | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 9726a9ebf3..27a176b631 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 0fba36ae02..9c67374b7e 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -154,6 +154,49 @@ 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, + QEMU_PLUGIN_DISCON_EXCEPTION = 2, + QEMU_PLUGIN_DISCON_HOSTCALL = 4, + QEMU_PLUGIN_DISCON_ALL = 7 +}; + +/** + * typedef qemu_plugin_vcpu_discon_cb_t - vcpu discontinuity callback + * @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 excact 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 is not 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 From patchwork Mon Dec 2 19:26:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Ganz X-Patchwork-Id: 13891237 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 8FFBBE69E86 for ; Mon, 2 Dec 2024 19:29:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIC56-0005lG-D2; Mon, 02 Dec 2024 14:27:40 -0500 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 1tIC4r-0005ij-Cu for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:26 -0500 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 1tIC4n-0001uj-LV for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:24 -0500 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate02.uberspace.is (Postfix) with ESMTPS id DA1A61809F3 for ; Mon, 2 Dec 2024 20:27:12 +0100 (CET) Received: (qmail 7114 invoked by uid 990); 2 Dec 2024 19:27:12 -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; Mon, 02 Dec 2024 20:27:12 +0100 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 v3 02/11] plugins: add API for registering discontinuity callbacks Date: Mon, 2 Dec 2024 20:26:43 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: 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(-3) R_MISSING_CHARSET(0.5) X-Rspamd-Score: -4.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nut.email; s=uberspace; h=from:to:cc:subject:date; bh=aJDEWw/vgtoK+ozg8zQ+6xYZJOVjyXSFJiZhR8xeimY=; b=nt++v4fG3WGfL9Oqx4bXxjTCmhDqH7n3ZTr1bnxwLwwg2b8uRJggWoaE0kBsjyvlQjK//We6rl gcUODlu+KKlAIieKErXD3jccsnhMgW/eNX1fJTa3rI3u+TByNNIy2O/D9bJg6o/xgRSFl9rWUnev ar1ndsP02VWPf4Jk8MXmsHQKv/i34iQP4OXI2KNzYdrc8JMAkgsW/5yhWekIxkQ204vGFQvbNR3Y AX9Sqi55C3YTTpcKsxQ8DOTUaz0vyo1a3xq7ObjM3guf5bzSTC9uHF7V91++X4DHH+ABCRQ3z/TM shLMK3h8u2Ji8NNVY39+wJxATOZP/QKAPi/zw6nOyFZLH+vHJYd20rO8KOBdyiyv/SaQ8mdbY7X1 7M/JJwFjBI5ZEiUAWE2w+p4vtqIqDjWgl+ySe6B+dTEQ+dq1oWfRCIvbuWs5WW71xwJskV6+3WMw TdwftUW8JSwlgj6hIkdUUYISnBFxVpjR8N5aLRkQGfjiT0x33ZsbynQeS+On9gZqgc5PIWWxC94s osKOcd5Azexk9zWLjhj9Zl9qCu9XSB1hbaKuEYxfJxOE5TKpUfER+Q1+lxeHNZrLYTcOglOtNFKD hcw7ujvVc7D2ISJY8TV7e9gvZ3CXwgQ7IXQUIMcH/PjTObjv1yTJBmHpOArovJIyH6FDxDctOw8Q o= 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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 The plugin API allows registration of callbacks for a variety of VCPU related events, such as VCPU reset, idle and resume. In addition to those events, we recently defined discontinuity events, which include traps. This change introduces a function to register callbacks for these events. We define one distinct plugin event type for each type of discontinuity, granting fine control to plugins in term of which events they receive. Reviewed-by: Pierrick Bouvier --- include/qemu/plugin-event.h | 3 +++ include/qemu/qemu-plugin.h | 15 +++++++++++++++ plugins/core.c | 15 +++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/include/qemu/plugin-event.h b/include/qemu/plugin-event.h index 7056d8427b..1100dae212 100644 --- a/include/qemu/plugin-event.h +++ b/include/qemu/plugin-event.h @@ -20,6 +20,9 @@ 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_VCPU_EXCEPTION, + QEMU_PLUGIN_EV_VCPU_HOSTCALL, QEMU_PLUGIN_EV_MAX, /* total number of plugin events we support */ }; diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 9c67374b7e..f998a465e5 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -273,6 +273,21 @@ QEMU_PLUGIN_API void qemu_plugin_register_vcpu_resume_cb(qemu_plugin_id_t id, qemu_plugin_vcpu_simple_cb_t cb); +/** + * qemu_plugin_register_vcpu_discon_cb() - register a discontinuity callback + * @id: plugin ID + * @cb: callback function + * + * The @cb function is called every time a vCPU receives a discontinuity event + * of the specified type(s), after the vCPU was prepared to handle the event. + * Preparation usually entails updating the PC to some interrupt handler or trap + * vector entry. + */ +QEMU_PLUGIN_API +void qemu_plugin_register_vcpu_discon_cb(qemu_plugin_id_t id, + enum qemu_plugin_discon_type type, + qemu_plugin_vcpu_discon_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 bb105e8e68..a89a4a0315 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -559,6 +559,21 @@ 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_discon_cb(qemu_plugin_id_t id, + enum qemu_plugin_discon_type type, + qemu_plugin_vcpu_discon_cb_t cb) +{ + if (type & QEMU_PLUGIN_DISCON_INTERRUPT) { + plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_INTERRUPT, cb); + } + if (type & QEMU_PLUGIN_DISCON_EXCEPTION) { + plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_EXCEPTION, cb); + } + if (type & QEMU_PLUGIN_DISCON_HOSTCALL) { + plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_HOSTCALL, cb); + } +} + void qemu_plugin_register_flush_cb(qemu_plugin_id_t id, qemu_plugin_simple_cb_t cb) { From patchwork Mon Dec 2 19:26:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Ganz X-Patchwork-Id: 13891239 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 9592CE69E81 for ; Mon, 2 Dec 2024 19:29:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIC4x-0005jj-V5; Mon, 02 Dec 2024 14:27:32 -0500 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 1tIC4p-0005iQ-EU for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:24 -0500 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 1tIC4n-0001vZ-Kk for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:23 -0500 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate02.uberspace.is (Postfix) with ESMTPS id 32F41180BF2 for ; Mon, 2 Dec 2024 20:27:13 +0100 (CET) Received: (qmail 7132 invoked by uid 990); 2 Dec 2024 19:27:13 -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; Mon, 02 Dec 2024 20:27:13 +0100 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 v3 03/11] plugins: add hooks for new discontinuity related callbacks Date: Mon, 2 Dec 2024 20:26:44 +0100 Message-ID: <18b8687e6310a68283b8b3ed72ad38479114bc51.1733063076.git.neither@nut.email> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: 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(-3) R_MISSING_CHARSET(0.5) X-Rspamd-Score: -4.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nut.email; s=uberspace; h=from:to:cc:subject:date; bh=874xBqS2kmQpv4fNE2Ynkwrhjf+s677m67u0HdCGqsQ=; b=Avdp6UkyEukb5eg1TMLBI/t3qK05CHk5uzBoeJF1El4LScuY6taO+w/JXIkJUEGwsrcSkjHjRH K/gdIXdEQyTj+U01JwXdLfSCVPt/8V29qC++H/x3hPgEPlBTCWBscD4zSKkkVBclWmC9yim5Nv6p WHYmQ9U1kbRvbkV23oBnXFI3fztfLkIc+fB096cjHQAtZ4Xfb/emLFB1nIoO49udXR9ESO2fvkqx yGzyJJhQ6LQDBtVlMMfy7dEgwpauALLJIvPZ7N2tUKwywb6n7pS1s1KxfW7Hk+eE1VOxf+F0wWUd HlVPH3I3VQTRXzBxJMcvBjj0PF27XsuxAiN9swv1NlDqi05DSV87n9mSlJrXRZw7TgDH/bjHz6yS SMEL7l3NEO11ZYZGpGeVAP+JNpD1KzNlXPmrhauY2t7yP5Gkj+5jRNeTiH+Cs92fdD6WmBARlr3g ZIy3M8SaKaNG2ez/6Rx/5brTW9GTKdHl+nipcVadxSOzYTWfIf1L2KMzROMLYTwjlWGV0G6u+XoA ycoqtzczR81/TBX8y1RDvNu0jOM97TbN1UkvytVhktV5cho3Ema1sJjToem/9TnrTTiHPjz7Fpsv K2uDi5TOq/2gLDLmfwPGNmNaIb501Bdi0DhyKPOHfOupiocibb674ANcJUk7JfuprLrMvsnQE5rC 0= 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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 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 discontinuity events, specifically for interrupts, exceptions and host calls. This change introduces the corresponding hooks called from target specific code inside qemu. Reviewed-by: Pierrick Bouvier --- include/qemu/plugin.h | 12 ++++++++++ plugins/core.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 27a176b631..3de9cb3fe4 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -161,6 +161,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, uint64_t from, uint64_t to); +void qemu_plugin_vcpu_exception_cb(CPUState *cpu, uint64_t from, uint64_t to); +void qemu_plugin_vcpu_hostcall_cb(CPUState *cpu, uint64_t from, uint64_t to); 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, @@ -243,6 +246,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, uint64_t from, uint64_t to) +{ } + +void qemu_plugin_vcpu_exception_cb(CPUState *cpu, uint64_t from, uint64_t to) +{ } + +void qemu_plugin_vcpu_hostcall_cb(CPUState *cpu, uint64_t from, uint64_t to) +{ } + 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 a89a4a0315..2c9637334f 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -112,6 +112,43 @@ static void plugin_vcpu_cb__simple(CPUState *cpu, enum qemu_plugin_event ev) } } +/* + * Disable CFI checks. + * The callback function has been loaded from an external library so we do not + * have type information + */ +QEMU_DISABLE_CFI +static void plugin_vcpu_cb__discon(CPUState *cpu, + enum qemu_plugin_discon_type type, + uint64_t from, uint64_t to) +{ + struct qemu_plugin_cb *cb, *next; + enum qemu_plugin_event ev; + + if (cpu->cpu_index < plugin.num_vcpus) { + switch (type) { + case QEMU_PLUGIN_DISCON_INTERRUPT: + ev = QEMU_PLUGIN_EV_VCPU_INTERRUPT; + break; + case QEMU_PLUGIN_DISCON_EXCEPTION: + ev = QEMU_PLUGIN_EV_VCPU_EXCEPTION; + break; + case QEMU_PLUGIN_DISCON_HOSTCALL: + ev = QEMU_PLUGIN_EV_VCPU_HOSTCALL; + break; + default: + g_assert_not_reached(); + } + + /* iterate safely; plugins might uninstall themselves at any time */ + QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) { + qemu_plugin_vcpu_discon_cb_t func = cb->f.vcpu_discon; + + func(cb->ctx->id, cpu->cpu_index, type, from, to); + } + } +} + /* * Disable CFI checks. * The callback function has been loaded from an external library so we do not @@ -547,6 +584,21 @@ void qemu_plugin_vcpu_resume_cb(CPUState *cpu) } } +void qemu_plugin_vcpu_interrupt_cb(CPUState *cpu, uint64_t from, uint64_t to) +{ + plugin_vcpu_cb__discon(cpu, QEMU_PLUGIN_DISCON_INTERRUPT, from, to); +} + +void qemu_plugin_vcpu_exception_cb(CPUState *cpu, uint64_t from, uint64_t to) +{ + plugin_vcpu_cb__discon(cpu, QEMU_PLUGIN_DISCON_EXCEPTION, from, to); +} + +void qemu_plugin_vcpu_hostcall_cb(CPUState *cpu, uint64_t from, uint64_t to) +{ + plugin_vcpu_cb__discon(cpu, QEMU_PLUGIN_DISCON_HOSTCALL, from, to); +} + void qemu_plugin_register_vcpu_idle_cb(qemu_plugin_id_t id, qemu_plugin_vcpu_simple_cb_t cb) { From patchwork Mon Dec 2 19:26:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Ganz X-Patchwork-Id: 13891234 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 A7368E69E81 for ; Mon, 2 Dec 2024 19:28:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIC4v-0005jM-LZ; Mon, 02 Dec 2024 14:27:31 -0500 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 1tIC4p-0005iP-Gv for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:24 -0500 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 1tIC4n-0001vh-LR for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:23 -0500 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate02.uberspace.is (Postfix) with ESMTPS id 848321809F2 for ; Mon, 2 Dec 2024 20:27:13 +0100 (CET) Received: (qmail 7147 invoked by uid 990); 2 Dec 2024 19:27:13 -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; Mon, 02 Dec 2024 20:27:13 +0100 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 v3 04/11] contrib/plugins: add plugin showcasing new dicontinuity related API Date: Mon, 2 Dec 2024 20:26:45 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: 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=g9B6AqNiMy12KKOQEL7zgcI6TA//xAnrob0uJmdHo/Y=; b=eXchSWQUltJXuL/BJ/8EBNxJYKN4f4DxMv7RtVY06hGkxm/7AI1Nngn1WZRjpex4bKslfxVHNI pVJySXWxT1twdxJIigguWPS4O2cXfmvTffV8crBi7Uz7SixOAmC5FarTSbcNO/n4Li+mq3FCxtTt aZgXND99w7s7ZKCtKHAnoQ7p7XBZUAqqpEj1r9ZrWAMEcPlsCKmjpAF2FIbEYIsiQ7/xOtLmw987 w5eFD6wamcNLvd6HUC8cHCYkQVBg1NDUuPUOeCiTsaXmvos7rdwx1uXxaaU5qGZ0D7xgQCMGyxUI r1A8nW6u2y8Flu3WJaQC5fs/haf2GocNuW1bdJHxSG7U1gNAUn+4T9+zsSPg8zkBwXLM/Bgt/lIU fZSJTIR4+7uCQphWVjDSNXIAVxL/hQUc3ThC8Pi00uhZbIfojwmFthQ04RChLAiGpzAd0UFF1c9N 8p7XHZbndq/5QW4BDvvpp8C3DBbJXo6mVQwHiYwyrklaQPgjsvsr076xfdc6POCxPcZCv87WkWiH 5NyeSjr55+vNJ3J6yMA5oJnnsPddO17a4YYh4drG0XrQ2B6JXjPoUTXIfK6z+NZvag0V0nvwWyI8 9y1Fcm/fFVinmmasVus5sjl9VL8Ej2ffsjuK3HTJy5dPxr4UiAjSjf5oKmayTLK/ToU0FEFuCJ1d 0= 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: -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, 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 discontinuity related callbacks. This change introduces a minimal plugin showcasing the new API. It simply counts the occurances of interrupts, exceptions and host calls per CPU and reports the counts when exitting. --- contrib/plugins/meson.build | 3 +- contrib/plugins/traps.c | 96 +++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 contrib/plugins/traps.c diff --git a/contrib/plugins/meson.build b/contrib/plugins/meson.build index 63a32c2b4f..9a3015e1c1 100644 --- a/contrib/plugins/meson.build +++ b/contrib/plugins/meson.build @@ -1,5 +1,6 @@ contrib_plugins = ['bbv', 'cache', 'cflow', 'drcov', 'execlog', 'hotblocks', - 'hotpages', 'howvec', 'hwprofile', 'ips', 'stoptrigger'] + 'hotpages', 'howvec', 'hwprofile', 'ips', 'stoptrigger', + 'traps'] if host_os != 'windows' # lockstep uses socket.h contrib_plugins += 'lockstep' diff --git a/contrib/plugins/traps.c b/contrib/plugins/traps.c new file mode 100644 index 0000000000..ecd4beac5f --- /dev/null +++ b/contrib/plugins/traps.c @@ -0,0 +1,96 @@ +/* + * 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 hostcalls; + bool active; +} TrapCounters; + +static struct qemu_plugin_scoreboard *traps; +static size_t max_vcpus; + +static void vcpu_init(qemu_plugin_id_t id, unsigned int vcpu_index) +{ + TrapCounters* rec = qemu_plugin_scoreboard_find(traps, vcpu_index); + rec->active = true; +} + +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) +{ + TrapCounters* rec = qemu_plugin_scoreboard_find(traps, vcpu_index); + switch (type) { + case QEMU_PLUGIN_DISCON_INTERRUPT: + rec->interrupts++; + break; + case QEMU_PLUGIN_DISCON_EXCEPTION: + rec->exceptions++; + break; + case QEMU_PLUGIN_DISCON_HOSTCALL: + rec->hostcalls++; + break; + default: + /* unreachable */ + break; + } +} + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + g_autoptr(GString) report; + report = g_string_new("VCPU, interrupts, exceptions, hostcalls\n"); + int vcpu; + + for (vcpu = 0; vcpu < max_vcpus; vcpu++) { + TrapCounters *rec = qemu_plugin_scoreboard_find(traps, vcpu); + if (rec->active) { + g_string_append_printf(report, + "% 4d, % 10"PRId64", % 10"PRId64", % 10" + PRId64"\n", + vcpu, + rec->interrupts, rec->exceptions, + rec->hostcalls); + } + } + + qemu_plugin_outs(report->str); + qemu_plugin_scoreboard_free(traps); +} + +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 = qemu_plugin_scoreboard_new(sizeof(TrapCounters)); + qemu_plugin_register_vcpu_init_cb(id, vcpu_init); + qemu_plugin_vcpu_for_each(id, vcpu_init); + + qemu_plugin_register_vcpu_discon_cb(id, QEMU_PLUGIN_DISCON_TRAPS, + vcpu_discon); + + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + + return 0; +} From patchwork Mon Dec 2 19:26:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Ganz X-Patchwork-Id: 13891241 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 DDB9DE69E86 for ; Mon, 2 Dec 2024 19:29:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIC53-0005kt-Fp; Mon, 02 Dec 2024 14:27:37 -0500 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 1tIC4s-0005iv-Dd for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:26 -0500 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 1tIC4q-0001x9-8x for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:26 -0500 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate02.uberspace.is (Postfix) with ESMTPS id BDCEC180BF1 for ; Mon, 2 Dec 2024 20:27:13 +0100 (CET) Received: (qmail 7167 invoked by uid 990); 2 Dec 2024 19:27:13 -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; Mon, 02 Dec 2024 20:27:13 +0100 From: Julian Ganz To: qemu-devel@nongnu.org Cc: Julian Ganz , Richard Henderson Subject: [RFC PATCH v3 05/11] target/alpha: call plugin trap callbacks Date: Mon, 2 Dec 2024 20:26:46 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Bar: ----- X-Rspamd-Report: REPLY(-4) BAYES_HAM(-2.999029) MID_CONTAINS_FROM(1) MIME_GOOD(-0.1) R_MISSING_CHARSET(0.5) X-Rspamd-Score: -5.599029 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nut.email; s=uberspace; h=from:to:cc:subject:date; bh=tpIDjpcFqj+Wp3kuZs4WF3UD19WsYadFBbweXL6VAzk=; b=S/nzySFcp1lYl3EoIp6r5nNpEiGidmumBxgHqHVyKEGQyzdZbEFxe24yZjNHzgTQlyyK5WW08d KO8JM6mnZAp2DCyzuXlbi0Yv0lg/vmMtid4mcqCQwlybS+5RE3PKf1o2mTlS8zuynqg80JuxNf5F qLL2KJzBCohtsJaoAsu1eQLyYurfu76d05LHDLcAQ1+p0laQJWR5q7ZxhdQCVrWkOYKb0zaf7vqd d/lDGFqVmkNZxzKDgzjFBeTybetfuJy1z9C8WkHDivjv94sXXnVdTpMEbQBkdc7XUYG1mE1XJ7Ps /VaZiH4yxuUZKJytHCkV+u8s/qVjpeLIZonrf30I0lrx2qvfF9iWuK4LgGAoNbj4fkSmleYhYSqk /vfbdQrQEzndveMQHRP/gLCirM7kR704Yhp9VN5GfurPy7B02cioE5k9w9wdbU5GHdyVmNIop2r2 A1jctISQuKHL4Dt0Hy5TierOCCBu6iCWDBNoWHsXlkf5NU0fYvTfAOmde5qslb4UhYF3/5C/de/e m4huXTe0EcV8JKmv7d4PHATzTEl4/oFnf/rsB+yBxX3zPr0WolPdhFW+1c23ZXa6cjxSc4nV2yTT jI54DsRhU41JzkNGdiQix+8E2dCfy673SwwY/d646gH4VdsU2wfwLd2gYxVs/Saf2guR9e0gCBqb 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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 Alpha targets. --- target/alpha/helper.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/target/alpha/helper.c b/target/alpha/helper.c index 2f1000c99f..acc92402af 100644 --- a/target/alpha/helper.c +++ b/target/alpha/helper.c @@ -25,6 +25,7 @@ #include "fpu/softfloat-types.h" #include "exec/helper-proto.h" #include "qemu/qemu-print.h" +#include "qemu/plugin.h" #define CONVERT_BIT(X, SRC, DST) \ @@ -326,6 +327,7 @@ void alpha_cpu_do_interrupt(CPUState *cs) { CPUAlphaState *env = cpu_env(cs); int i = cs->exception_index; + uint64_t last_pc = env->pc; if (qemu_loglevel_mask(CPU_LOG_INT)) { static int count; @@ -429,6 +431,16 @@ void alpha_cpu_do_interrupt(CPUState *cs) /* Switch to PALmode. */ env->flags |= ENV_FLAG_PAL_MODE; + + switch (i) { + case EXCP_SMP_INTERRUPT: + case EXCP_CLK_INTERRUPT: + case EXCP_DEV_INTERRUPT: + qemu_plugin_vcpu_interrupt_cb(cs, last_pc, env->pc); + break; + qemu_plugin_vcpu_exception_cb(cs, last_pc, env->pc); + default: + } } bool alpha_cpu_exec_interrupt(CPUState *cs, int interrupt_request) From patchwork Mon Dec 2 19:26:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Ganz X-Patchwork-Id: 13891243 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 73117E69E88 for ; Mon, 2 Dec 2024 19:30:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIC58-0005li-9T; Mon, 02 Dec 2024 14:27:42 -0500 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 1tIC4u-0005jU-QR for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:29 -0500 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 1tIC4r-0001xG-4r for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:27 -0500 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate02.uberspace.is (Postfix) with ESMTPS id 1F366180C08 for ; Mon, 2 Dec 2024 20:27:14 +0100 (CET) Received: (qmail 7181 invoked by uid 990); 2 Dec 2024 19:27:14 -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; Mon, 02 Dec 2024 20:27:13 +0100 From: Julian Ganz To: qemu-devel@nongnu.org Cc: Julian Ganz , =?utf-8?q?Alex_Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour , Pierrick Bouvier , Peter Maydell , qemu-arm@nongnu.org (open list:ARM TCG CPUs) Subject: [RFC PATCH v3 06/11] target/arm: call plugin trap callbacks Date: Mon, 2 Dec 2024 20:26:47 +0100 Message-ID: <5c4b8e6f913e3257fee662708a69902676edc628.1733063076.git.neither@nut.email> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: 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=n9gM0kBmO83WxtZS2NBl9dSShYXqE3eiFoCKNq/tViA=; b=Qxuwp23H6cgGzKlkzOADioJ0R0jHv2nPMzgCIY3OPj4UuYV6eO//sTyjc9gVjfKPMcmNcxlHSn qo/nsDxI00UZbaTYDN5sz75C3AMupRMK94EPcAdeGn1HP7OGACBW1TJKqSU/IKnbzGiGLX8VS3Ds NeSXVp6EumTrEVn4MgQ9WghRvQtyJQ4HoZDqKvvQw57x+IFkcnCmkt439IiUPPa5byek2iT2q9gs pkYsoHam2jO21gU4d+B6RNYPe++4DJufyix7Uoj1Q4zvk76tGTyrfrh08N+YRv0pKXDb9UuuRiRX 1Gh8OWtDAEVBHUiHm1gavTJQKOcN+mtJeqjzO0w2Xzc45QSMMotoZcWXUlbgMRuNTqH5qGNEvTCb AfaoVBZwrC69yQuqfLGkXv7wRLjdET7hNyt+cqSnc21ArpXR3jMXYn0ntEJkj4JDxU0qGRDsaxEv yV8cpmbUMlFqk9z2/XnEDodGbKU4EY5ScVf9FLldontf0RrwQs3DvjSCLNcIHbt36+XbistADyqo uqshKlE0bjmWYUHoCil7KOPYDhdzF/VLhao82Zj4mBG+GFiJ7kY31XRtb90TartdYWsmBWLyvlb5 jLVglESze1TN65VObf9PkpuCgNUur2/cqHuktBQyPxd1vfmQ8WPRQFox4JAA7sEmo5/c3XMQIzSU 0= 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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. --- contrib/plugins/traps.c | 2 +- target/arm/helper.c | 25 +++++++++++++++++++++++++ target/arm/tcg/m_helper.c | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/contrib/plugins/traps.c b/contrib/plugins/traps.c index ecd4beac5f..cdb503e499 100644 --- a/contrib/plugins/traps.c +++ b/contrib/plugins/traps.c @@ -87,7 +87,7 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, qemu_plugin_register_vcpu_init_cb(id, vcpu_init); qemu_plugin_vcpu_for_each(id, vcpu_init); - qemu_plugin_register_vcpu_discon_cb(id, QEMU_PLUGIN_DISCON_TRAPS, + qemu_plugin_register_vcpu_discon_cb(id, QEMU_PLUGIN_DISCON_ALL, vcpu_discon); qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); diff --git a/target/arm/helper.c b/target/arm/helper.c index f38eb054c0..57f274a037 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 */ @@ -11166,6 +11167,25 @@ static void take_aarch32_exception(CPUARMState *env, int new_mode, } } +static void arm_do_plugin_vcpu_interrupt_cb(CPUState *cs, uint64_t from, + uint64_t to) +{ + 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, from, to); + break; + default: + qemu_plugin_vcpu_exception_cb(cs, from, to); + } +} + static void arm_cpu_do_interrupt_aarch32_hyp(CPUState *cs) { /* @@ -11822,6 +11842,7 @@ void arm_cpu_do_interrupt(CPUState *cs) ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; unsigned int new_el = env->exception.target_el; + uint64_t last_pc = env->pc; assert(!arm_feature(env, ARM_FEATURE_M)); @@ -11838,6 +11859,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"); + qemu_plugin_vcpu_hostcall_cb(cs, last_pc, env->pc); return; } @@ -11849,6 +11871,7 @@ void arm_cpu_do_interrupt(CPUState *cs) #ifdef CONFIG_TCG if (cs->exception_index == EXCP_SEMIHOST) { tcg_handle_semihosting(cs); + qemu_plugin_vcpu_hostcall_cb(cs, last_pc, env->pc); return; } #endif @@ -11874,6 +11897,8 @@ void arm_cpu_do_interrupt(CPUState *cs) if (!kvm_enabled()) { cs->interrupt_request |= CPU_INTERRUPT_EXITTB; } + + arm_do_plugin_vcpu_interrupt_cb(cs, last_pc, env->pc); } #endif /* !CONFIG_USER_ONLY */ diff --git a/target/arm/tcg/m_helper.c b/target/arm/tcg/m_helper.c index f7354f3c6e..3a8b55db82 100644 --- a/target/arm/tcg/m_helper.c +++ b/target/arm/tcg/m_helper.c @@ -24,6 +24,7 @@ #if !defined(CONFIG_USER_ONLY) #include "hw/intc/armv7m_nvic.h" #endif +#include "qemu/plugin.h" static void v7m_msr_xpsr(CPUARMState *env, uint32_t mask, uint32_t reg, uint32_t val) @@ -2186,6 +2187,7 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) CPUARMState *env = &cpu->env; uint32_t lr; bool ignore_stackfaults; + uint64_t last_pc = env->pc; arm_log_exception(cs); @@ -2353,6 +2355,7 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) g_assert_not_reached(); #endif env->regs[15] += env->thumb ? 2 : 4; + qemu_plugin_vcpu_hostcall_cb(cs, last_pc, env->pc); return; case EXCP_BKPT: armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_DEBUG, false); @@ -2419,6 +2422,21 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) ignore_stackfaults = v7m_push_stack(cpu); v7m_exception_taken(cpu, lr, false, ignore_stackfaults); + + 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, last_pc, env->pc); + break; + default: + qemu_plugin_vcpu_exception_cb(cs, last_pc, env->pc); + } } uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg) From patchwork Mon Dec 2 19:26:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Ganz X-Patchwork-Id: 13891242 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 61AAFE69E81 for ; Mon, 2 Dec 2024 19:30:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIC58-0005lf-6Y; Mon, 02 Dec 2024 14:27:42 -0500 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 1tIC4t-0005jL-Gx for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:28 -0500 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 1tIC4r-0001xA-66 for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:27 -0500 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate02.uberspace.is (Postfix) with ESMTPS id 5618B180BEB for ; Mon, 2 Dec 2024 20:27:14 +0100 (CET) Received: (qmail 7211 invoked by uid 990); 2 Dec 2024 19:27:14 -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; Mon, 02 Dec 2024 20:27:14 +0100 From: Julian Ganz To: qemu-devel@nongnu.org Cc: Julian Ganz , Michael Rolnik Subject: [RFC PATCH v3 07/11] target/avr: call plugin trap callbacks Date: Mon, 2 Dec 2024 20:26:48 +0100 Message-ID: <0ae13652185055396331a25ead6153a8a0ccd505.1733063076.git.neither@nut.email> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Bar: ----- X-Rspamd-Report: REPLY(-4) BAYES_HAM(-2.983021) MID_CONTAINS_FROM(1) MIME_GOOD(-0.1) R_MISSING_CHARSET(0.5) X-Rspamd-Score: -5.583021 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nut.email; s=uberspace; h=from:to:cc:subject:date; bh=XAuE3s6qJPdddn1nfG6DGmf8hukkjU3RTPMm/BzvJLU=; b=huSyqV1HGzwUja/LzPpzNrBG+oZMZsk7OJlyyWVtWpgdcaXtWptLdC5b6t9dqRGWlyRrWG0dwj Qevoxz3EqC3ut5Pr6gJyC0al+ZOwdta3bpuW/Nc2hDAi/pBCc5DWm/jI3ZzXSZWbr5+1cnBd+KSR GBd0qB1TS8tuRngz8fTlg0ULppWtIwR6titrhFA9C39kL10cEHBPw/nVS96Nc9EQfItuVDAmXQYC InNdd9cFg5uExf8oLn8Ksde2DjfRzqdss+dflMzEG6XAC0jAdXdGIx1a5AhI5DgIz4ZRqdjBKZek kdvNCTWJQB8oGUWAytmcw+UyhHCh+YVJ0NIaVl0fmgQCAf6qxALt8CrWJ3Lj16c5VzLtYOSmghhu VYy+/9DPVpyYqO47AlH3wiTXSPVSM5Jm6zK7/Y5yrkY3f3p+P5nUFsZq9CfeBH5BEifllibxghBw W5zh3kt3ajkcWQK4ttU1fm/vYHP1EEfc8th9DtmhD/X/tXQgQ3y3BNgqc5+T60mw0jtrxq4mL5EP Im1rIrYmqst7jqba9wGXTs41d3wizst127hBhdgOixBndsFIAm+05RDJUaYB6XleDODUjQkBiUVP ECBUDsDBU/fTZDPo4msnZsRVqB/ImyT9FbuO4KmZRbkgn8mizrtS7vrNAP+0byOjzytN434Yydie o= 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 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. --- target/avr/helper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/avr/helper.c b/target/avr/helper.c index 345708a1b3..ba7704f2f1 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, ret, env->pc_w); } hwaddr avr_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) From patchwork Mon Dec 2 19:26:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Ganz X-Patchwork-Id: 13891240 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 1266CE69E88 for ; Mon, 2 Dec 2024 19:29:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIC56-0005lE-D2; Mon, 02 Dec 2024 14:27:40 -0500 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 1tIC4u-0005jW-Qn for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:29 -0500 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 1tIC4s-0001xs-8i for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:27 -0500 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate02.uberspace.is (Postfix) with ESMTPS id 9BC911813A1 for ; Mon, 2 Dec 2024 20:27:14 +0100 (CET) Received: (qmail 7226 invoked by uid 990); 2 Dec 2024 19:27:14 -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; Mon, 02 Dec 2024 20:27:14 +0100 From: Julian Ganz To: qemu-devel@nongnu.org Cc: Julian Ganz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo Subject: [RFC PATCH v3 08/11] target/mips: call plugin trap callbacks Date: Mon, 2 Dec 2024 20:26:49 +0100 Message-ID: <5a165b308d75718e185806607df583596270181d.1733063076.git.neither@nut.email> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Bar: ----- X-Rspamd-Report: REPLY(-4) BAYES_HAM(-2.996924) MID_CONTAINS_FROM(1) MIME_GOOD(-0.1) R_MISSING_CHARSET(0.5) X-Rspamd-Score: -5.596924 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nut.email; s=uberspace; h=from:to:cc:subject:date; bh=G/yQbucoo3BelvfnOkzi6vySBLKkOgQVCeL/JBJq6fE=; b=E0lpN0r8ej55GoeN4hA2gPFBKwaX8gsPLd87N3F7+7pZsvxfbb3LCwJ4ppCogJIxRO9V4p6j0N psM0WACp0VdYpr3JglN1eWymPHtgzwAcard//031dZPcZoCQ07giptwhnjj0EiMrZM1tMIbPxMcO GJ5EWcC66yI5o5WLVkJAspj1kTO9NcSz699daxmD7LNU2GarJIetAKZV7Z2RfEYi2a3Nhb+ft9cs 252Ua/QouPqjr1tNaGtnyO+hAVHvXmyrMPgLs03Jg/40O2QpcePNNBLIos8XnO8lJUtHHvk2k8P0 sKxIbHOWa0HM+v/QTgQksaCYqw3UtU0jMu7zEdVTSEir/ObtfDa8u3NUUhOMRMXm1wVkmY2JWG+a bszGhgl74/quRt2tUBgC8vxYM0LESQVyqWa/bwQbtbSLcc0y2YLDOp7S77TT5bgn6lxThRsDRDMz tjIZSm1H9lJg1Zh7IS4nrVFcRA1XQGjhDcPvhkys8743ZpJ4107iXA8hx4xeuN95yo2QfhLpZS0K 8ju8qNN4sThDprCkHum+eo4bC0W4yYE2NmTtDQ566KnwctLqYEuubIJd0OdomrsLcjpFdTvsgFMw ssr9uoidTWdFFEI/kAPZhLNZOAsJ/k631WvNowtyBoFZQVXcO2H55RasN5Dx8Li4OnG4w7SlLRJ6 o= 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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 MIPS targets. --- target/mips/tcg/sysemu/tlb_helper.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/target/mips/tcg/sysemu/tlb_helper.c b/target/mips/tcg/sysemu/tlb_helper.c index e98bb95951..2b19975d53 100644 --- a/target/mips/tcg/sysemu/tlb_helper.c +++ b/target/mips/tcg/sysemu/tlb_helper.c @@ -18,6 +18,7 @@ */ #include "qemu/osdep.h" #include "qemu/bitops.h" +#include "qemu/plugin.h" #include "cpu.h" #include "internal.h" @@ -1033,6 +1034,7 @@ void mips_cpu_do_interrupt(CPUState *cs) bool update_badinstr = 0; target_ulong offset; int cause = -1; + uint64_t last_pc = env->active_tc.PC; if (qemu_loglevel_mask(CPU_LOG_INT) && cs->exception_index != EXCP_EXT_INTERRUPT) { @@ -1051,6 +1053,7 @@ void mips_cpu_do_interrupt(CPUState *cs) cs->exception_index = EXCP_NONE; mips_semihosting(env); env->active_tc.PC += env->error_code; + qemu_plugin_vcpu_hostcall_cb(cs, last_pc, env->active_tc.PC); return; case EXCP_DSS: env->CP0_Debug |= 1 << CP0DB_DSS; @@ -1335,6 +1338,14 @@ void mips_cpu_do_interrupt(CPUState *cs) env->CP0_Status, env->CP0_Cause, env->CP0_BadVAddr, env->CP0_DEPC); } + switch (cs->exception_index) { + case EXCP_NMI: + case EXCP_EXT_INTERRUPT: + qemu_plugin_vcpu_interrupt_cb(cs, last_pc, env->active_tc.PC); + break; + default: + qemu_plugin_vcpu_exception_cb(cs, last_pc, env->active_tc.PC); + } cs->exception_index = EXCP_NONE; } From patchwork Mon Dec 2 19:26:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Ganz X-Patchwork-Id: 13891235 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 38FD0E69E88 for ; Mon, 2 Dec 2024 19:28:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIC55-0005l1-U3; Mon, 02 Dec 2024 14:27:39 -0500 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 1tIC4u-0005jT-QL for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:29 -0500 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 1tIC4s-0001xv-8Q for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:27:27 -0500 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate02.uberspace.is (Postfix) with ESMTPS id EE6681813AA for ; Mon, 2 Dec 2024 20:27:14 +0100 (CET) Received: (qmail 7256 invoked by uid 990); 2 Dec 2024 19:27:14 -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; Mon, 02 Dec 2024 20:27:14 +0100 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 v3 09/11] target/riscv: call plugin trap callbacks Date: Mon, 2 Dec 2024 20:26:50 +0100 Message-ID: <1f9b7a8c8bca228529957a5ca62ad778870215ff.1733063076.git.neither@nut.email> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: 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.901804) R_MISSING_CHARSET(0.5) X-Rspamd-Score: -4.001804 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nut.email; s=uberspace; h=from:to:cc:subject:date; bh=4ZMPM+8dJ9Y3dLwFuA+XfDA4K4aLDiwK7sDI2OBteRM=; b=Cu0qkyvh+znyNjz3jL4sRpu57oKBQ5Tj1UzPtNuZMAXr1utoRcgK05xEl/SorY7xkCLVleP8VD pfd1/eMAd4H8PwFzR3udEZi9I1/imj2Go7SqZmtYGbaxYMa2e/xiR/rQpzMSZi4hou36YlegAIzS +EqdrmGS/xKZOd9Ye6+Ji0u51n+MCr3aXVpvMa3oxlayj3SL4gLuTVKFfTVM/AfuZzy/10UTsYWq IM8CUzfgOwCG/ZZIYmyKoUSa/eyc/YdoWNRi9VOWUV8C28NczuIv/SCfrJ2YytY10uo1LP0uRejp sr9/pSAKl0ilcV83WNntwz4Z1rlgYNFRPrHvPnzNUWPg4f+YYuKG5H6hMD/lb7da90hGr2ZYSCnr HgWvmTyg9I/k/uOMUEQZWM6rBsjO+qxZjK4Q15dQup2MqAN91g413HzbEEKdXpoZAQt2oCDfxCH5 OHQuU75dgxE4Y7M5nVw5jBIyUkQLVohl8fXPx87BtV3pQ5dxXM4OtvbWIQ41xkSe1yC6kAuq+tqb DNtYfh9Wb2q66+dlw2dOz8IutwymwTAciCdvVA67RHY4HYoZBbH61JGPJ5Qiov6G3se+OhWsnN+Q iR4PNFqCMciZttTAG0I0858PrPbimuIVglKGVfO5S9/CLvobbe+9ox8BNLB+NosMgA/5/3NNUlLd Y= 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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. Reviewed-by: Alistair Francis --- target/riscv/cpu_helper.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 0a3ead69ea..6da9bd4629 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -34,6 +34,7 @@ #include "debug.h" #include "tcg/oversized-guest.h" #include "pmp.h" +#include "qemu/plugin.h" int riscv_env_mmu_index(CPURISCVState *env, bool ifetch) { @@ -1806,6 +1807,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) !(env->mip & (1 << cause)); bool vs_injected = env->hvip & (1 << cause) & env->hvien && !(env->mip & (1 << cause)); + uint64_t last_pc = env-> pc; target_ulong tval = 0; target_ulong tinst = 0; target_ulong htval = 0; @@ -1820,6 +1822,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) case RISCV_EXCP_SEMIHOST: do_common_semihosting(cs); env->pc += 4; + qemu_plugin_vcpu_hostcall_cb(cs, last_pc, env->pc); return; #endif case RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT: @@ -1999,6 +2002,12 @@ void riscv_cpu_do_interrupt(CPUState *cs) riscv_cpu_set_mode(env, PRV_M, virt); } + if (async) { + qemu_plugin_vcpu_interrupt_cb(cs, last_pc, env->pc); + } else { + qemu_plugin_vcpu_exception_cb(cs, last_pc, env->pc); + } + /* * Interrupt/exception/trap delivery is asynchronous event and as per * zicfilp spec CPU should clear up the ELP state. No harm in clearing From patchwork Mon Dec 2 19:41: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: 13891249 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 B5474E69E8C for ; Mon, 2 Dec 2024 19:42:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tICJ0-00066L-JE; Mon, 02 Dec 2024 14:42:02 -0500 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 1tICIz-00065m-8K for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:42:01 -0500 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 1tICIw-0005tE-EB for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:42:01 -0500 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate02.uberspace.is (Postfix) with ESMTPS id 9A0AC18043B for ; Mon, 2 Dec 2024 20:41:54 +0100 (CET) Received: (qmail 24763 invoked by uid 990); 2 Dec 2024 19:41:54 -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; Mon, 02 Dec 2024 20:41:54 +0100 From: Julian Ganz To: qemu-devel@nongnu.org Cc: Julian Ganz , Mark Cave-Ayland , Artyom Tarasenko Subject: [RFC PATCH v3 10/11] target/sparc: call plugin trap callbacks Date: Mon, 2 Dec 2024 20:41:36 +0100 Message-ID: <51c6069c8a2d50d70d21a10c167066e5f0aa096a.1733063076.git.neither@nut.email> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Bar: ----- X-Rspamd-Report: REPLY(-4) BAYES_HAM(-2.997331) MID_CONTAINS_FROM(1) MIME_GOOD(-0.1) R_MISSING_CHARSET(0.5) X-Rspamd-Score: -5.597331 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nut.email; s=uberspace; h=from:to:cc:subject:date; bh=eSQdBohJLxjuj+kUUKx0s/tIbRONVYZrlcGAeQZ/qZ8=; b=pKJ+TnM6ikj6JciNMVJ3o577JdXH+5cErtvdAuTp+n+jYpazKFIdaAH4TPjJC6wASw2W4SacSs kPEdgnfOOUBcJqd4gWL9PPmegnb283b8viLjIpwMU53jDxDwDZ7VzOkSmotG9Pi0VoZgud/mx6H3 R4rvriOdiTbzOOhDSXLByX4UyeQvfQauh4QkaHX3ihyXvcfyWVK2y5dCoRLNYcdX+Jk4uQZRBJ+X m6uydibpB3heoAqh/74TAxLGIaGfCxC7Lh2Q0iJ/RWWXv9mc9F4HYJZVS+WTo8nhNuodcpky6f/5 kvbVDvNiYNvOt7CsTdJq4B28QFCm5LIE/7rZlsdKBaZ5/30/QynYtz7m7vOFja6uqnMAkz2Zb8zb 56JniMgdwrnrBMLQsBYvyph3FACcT1OZ/HsRu6J94v3usoOo/qLQtPAT9w2us51hrSsCZFt3rpav kTzcW+2nfT3IffUb8N2wvPRpAa8kipkv5GFBReW1X1tmv0Njzfy1HH4gASmnmUwM2Jp5kUOs6Bvo xpKPStTM7ptxdNAyvgzilYF1bxpSM9aQxS0X3saFYOedY1RSSAfbcXUMah13alX4SMxxhfygDYA+ S9wdmwS2b8nAjmtZr/GszeUOC1Ej11ynII7jcysofKO9Uss0bhBLPNgoXWnWuLatPho15PYmqOrK 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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 SPARC (32bit and 64bit) targets. We treat any interrupt other than EXTINT and IVEC as exceptions as they appear to be synchroneous events. --- target/sparc/int32_helper.c | 7 +++++++ target/sparc/int64_helper.c | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/target/sparc/int32_helper.c b/target/sparc/int32_helper.c index f2dd8bcb2e..86b21eecb6 100644 --- a/target/sparc/int32_helper.c +++ b/target/sparc/int32_helper.c @@ -24,6 +24,7 @@ #include "exec/cpu_ldst.h" #include "exec/log.h" #include "sysemu/runstate.h" +#include "qemu/plugin.h" static const char * const excp_names[0x80] = { [TT_TFAULT] = "Instruction Access Fault", @@ -172,4 +173,10 @@ void sparc_cpu_do_interrupt(CPUState *cs) env->qemu_irq_ack(env, intno); } #endif + + if (intno == TT_EXTINT) { + qemu_plugin_vcpu_interrupt_cb(cs, env->regwptr[9], env->pc); + } else { + qemu_plugin_vcpu_exception_cb(cs, env->regwptr[9], env->pc); + } } diff --git a/target/sparc/int64_helper.c b/target/sparc/int64_helper.c index bd14c7a0db..9f0e7206d3 100644 --- a/target/sparc/int64_helper.c +++ b/target/sparc/int64_helper.c @@ -23,6 +23,7 @@ #include "exec/helper-proto.h" #include "exec/log.h" #include "trace.h" +#include "qemu/plugin.h" #define DEBUG_PCALL @@ -253,6 +254,15 @@ void sparc_cpu_do_interrupt(CPUState *cs) } env->npc = env->pc + 4; cs->exception_index = -1; + + switch (intno) { + case TT_EXTINT: + case TT_IVEC: + qemu_plugin_vcpu_interrupt_cb(cs, tsptr->tpc, env->pc); + break; + default: + qemu_plugin_vcpu_exception_cb(cs, tsptr->tpc, env->pc); + } } trap_state *cpu_tsptr(CPUSPARCState* env) From patchwork Mon Dec 2 19:41: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: 13891248 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 AF2CEE69E8B for ; Mon, 2 Dec 2024 19:42:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tICJ5-00066t-Vy; Mon, 02 Dec 2024 14:42:08 -0500 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 1tICIz-00065o-CA for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:42:01 -0500 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 1tICIw-0005tG-Fk for qemu-devel@nongnu.org; Mon, 02 Dec 2024 14:42:01 -0500 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate02.uberspace.is (Postfix) with ESMTPS id EDA3A180C05 for ; Mon, 2 Dec 2024 20:41:54 +0100 (CET) Received: (qmail 24777 invoked by uid 990); 2 Dec 2024 19:41:54 -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; Mon, 02 Dec 2024 20:41:54 +0100 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 v3 11/11] tests: add plugin asserting correctness of discon event's to_pc Date: Mon, 2 Dec 2024 20:41:37 +0100 Message-ID: <36d316bf3e8b0aca778c5e8d1acde39a7f361946.1733063076.git.neither@nut.email> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: 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=QtNoualSp5HK6fG+v1BpfCUxVztYUqkQxOY+K+yjyko=; b=CG74BC7/MzXp7v0ggJFuEg1UG+J9u58DLlQhXqDVmS9ZK82LLgejy6kWi7It27WoNtSpJ5cQE2 eNuVUuN40Zo2Y/VdxSaHF59mgnm1AJwPrP/uB9fmdDX0R9MnLiThdeOLolnMXKouoHvhvnpOQDHZ o5Um+PrQMx97rmGAaEFYtMUPa7uGSmWKFppCC1Ea8ejXLv894KGn0fVpzBMKps2f3Oi2ihwKAsLy LhjtnaC+xHUnzqvE8CsU8iH3pyQoi7lYB16Glip9HCzxxA051ATF4iVG7VZBuHIwpaN2QHDD85S5 lrtY3pErn77TymZVkAZSRna0Vzuk8BxXSbJi9rDRM0IQb7Zuw1RDp/qGHbfITPKLXQzUqVWkTEWP roxnBoELl9HOHqn9Q+l2QNWnVFGV9iS2nvFjDvqe4trlOYvCu0guqslC3xCeFyqwN45O9pIKtaLm BF2qGVEGL7yWO4EC1gs9WEi/eg1KW0T54wbhAmhJjSZN8kW6MTpRDj/kJwZGTXnZ6wnHr3lSEu/c LhA428EQwSIePTA/dQo2O5ezeZ9UWelCKY1anDjip1s7to8BCVaAF+6wpEAfoNjONPVcnjkRGNix SwyhNygbFbH5nEi7d+Rt5ju1pmB07bVQTsrpxD6eX52bxy4OqbEmIbLkYZPgApbwO0Fls53wXU3E c= 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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 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 + * + * 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; + +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; + } +} + +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',