From nobody Fri Nov 14 23:30:24 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1759744692; cv=none; d=zohomail.com; s=zohoarc; b=n6ndSePXDvg4mISxKdZUg9liznkOTKTHO26/D59Y/CNgsqcme8lSfQ1YcA1oURJbsBT88YUxhXFvwdn3M7UVctiMTCZdQroJz9ho8PSk9yvaL5MrYAnIDhnrw99/Vmv7esPyDxqe1mBqe+3CbDjpVVV0ncEOCWeORHYMbF+YXHs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759744692; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=i/MZpPxHebC+LKh7MnrWukgXH3udOcPrsCodUFmkm/s=; b=E9RyJ9yn2NEYxCzIVpQNdNsnVnZIEbqwN/iWkVNUQjWJACcfkNmRo9uVEfPspoH+rmo257XyYeDmxX1sNHPmtesQsPjj1Y0dPKoAqqqXJa3wFPvojRbRwzKysNqx0aoIBu2wwQJ72bhYXegW/HIIx4iy0qllPjcPzRLnbZDFrPo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1759744692625657.7102200576469; Mon, 6 Oct 2025 02:58:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v5hyd-0006NC-Rq; Mon, 06 Oct 2025 05:57:56 -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 1v5hyb-0006Le-Ch for qemu-devel@nongnu.org; Mon, 06 Oct 2025 05:57:53 -0400 Received: from mailgate01.uberspace.is ([95.143.172.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v5hyZ-0003ot-5b for qemu-devel@nongnu.org; Mon, 06 Oct 2025 05:57:53 -0400 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate01.uberspace.is (Postfix) with ESMTPS id EEA1760B93 for ; Mon, 6 Oct 2025 11:57:38 +0200 (CEST) Received: (qmail 18700 invoked by uid 990); 6 Oct 2025 09:57:38 -0000 Received: from unknown (HELO unkown) (::1) by skiff.uberspace.de (Haraka/3.0.1) with ESMTPSA; Mon, 06 Oct 2025 11:57:38 +0200 Authentication-Results: skiff.uberspace.de; auth=pass (plain) From: Julian Ganz To: qemu-devel@nongnu.org Cc: Julian Ganz , Peter Maydell , qemu-arm@nongnu.org (open list:ARM TCG CPUs) Subject: [PATCH v7 06/25] target/arm: call plugin trap callbacks Date: Mon, 6 Oct 2025 11:57:01 +0200 Message-ID: <77e01129000585067c2f89d4c1a1efe027e6b0d9.1759744337.git.neither@nut.email> X-Mailer: git-send-email 2.49.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Bar: ----- X-Rspamd-Report: REPLY(-4) BAYES_HAM(-2.999826) MID_CONTAINS_FROM(1) MIME_GOOD(-0.1) R_MISSING_CHARSET(0.5) X-Rspamd-Score: -5.599826 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nut.email; s=uberspace; h=from:to:cc:subject:date; bh=CcFiwhLtnsO0cl2Wu96ob52uGEm+WsI+gx83eM8jdCg=; b=S7D6+gA+SQp4it3Ej3VTL7Ongs1wZi+Hqnm3S3xct+dfWPqjyGCl8HwbO/I7hk0Fe9Y6quQ3OM uNmUGn00zl0H+QxrXTnLCaGZZwGvnPGNYOMVHCa/TfeuG+bxcAjt2qNOHPE8baib6kvLJUNFgRwe LlrfswtZCPmmGwFEBxXKmrtPoi3oc7NJY7Gpi8XAfAjWR8EcDTkTMSwzhssHb738ki7csnUZNE9M imOoe2MEgKgNAkGXs2lt2g8vls1kfKFl2PS65xELZua78/sFXz4bN2PC6//5RNDy5Qy7C8g8WgtQ l6GXAmagQ4swC/9YmqZXq2wYcOknvjTd2QxmoodaRR4fqaN2PIssdr/5N7xWxlUOflqgQuH7OZNd RYN6WfU5AZFFciZC9xW2QM1jO1f5koXQVZ1XEH4CHni1tpDVnoZAXB4faGhK6peteZSOW294ahy6 JAf+zpxpQ/yvUE2hrmDT9r92bit5/xeJCZcRghKV2beNCsEcNu+DdGdOFTApnZG1R819g35r4WCy 6IVm77cXnlq5n0DxgPqo4qT5M8InryWzhMOEY9PSEzeWQ9DCrl6lzEW6JPUQR692FQsQjn3t9wXr 7a6VbMLbP9bs61i7rdVi5kmL91jxiatSas2l/NrpLHANasoFU7F6DZRUIO3N6Qdhc8nis+QQpH6v 8= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=95.143.172.20; envelope-from=neither@nut.email; helo=mailgate01.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=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @nut.email) X-ZM-MESSAGEID: 1759744697901116600 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Richard Henderson --- target/arm/helper.c | 24 ++++++++++++++++++++++++ target/arm/internals.h | 1 + target/arm/tcg/m_helper.c | 5 +++++ 3 files changed, 30 insertions(+) diff --git a/target/arm/helper.c b/target/arm/helper.c index aa730addf2..2916db4094 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -34,6 +34,7 @@ #endif #include "cpregs.h" #include "target/arm/gtimer.h" +#include "qemu/plugin.h" =20 #define HELPER_H "tcg/helper.h" #include "exec/helper-proto.h.inc" @@ -8439,6 +8440,24 @@ static void take_aarch32_exception(CPUARMState *env,= int new_mode, } } =20 +void arm_do_plugin_vcpu_discon_cb(CPUState *cs, uint64_t from) +{ + 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); + break; + default: + qemu_plugin_vcpu_exception_cb(cs, from); + } +} + static void arm_cpu_do_interrupt_aarch32_hyp(CPUState *cs) { /* @@ -9105,6 +9124,7 @@ void arm_cpu_do_interrupt(CPUState *cs) ARMCPU *cpu =3D ARM_CPU(cs); CPUARMState *env =3D &cpu->env; unsigned int new_el =3D env->exception.target_el; + uint64_t last_pc =3D cs->cc->get_pc(cs); =20 assert(!arm_feature(env, ARM_FEATURE_M)); =20 @@ -9121,6 +9141,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); return; } =20 @@ -9132,6 +9153,7 @@ void arm_cpu_do_interrupt(CPUState *cs) #ifdef CONFIG_TCG if (cs->exception_index =3D=3D EXCP_SEMIHOST) { tcg_handle_semihosting(cs); + qemu_plugin_vcpu_hostcall_cb(cs, last_pc); return; } #endif @@ -9157,6 +9179,8 @@ void arm_cpu_do_interrupt(CPUState *cs) if (!kvm_enabled()) { cpu_set_interrupt(cs, CPU_INTERRUPT_EXITTB); } + + arm_do_plugin_vcpu_discon_cb(cs, last_pc); } #endif /* !CONFIG_USER_ONLY */ =20 diff --git a/target/arm/internals.h b/target/arm/internals.h index 1d958dbf68..6cbab5a8e5 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -373,6 +373,7 @@ static inline int r14_bank_number(int mode) =20 void arm_cpu_register(const ARMCPUInfo *info); =20 +void arm_do_plugin_vcpu_discon_cb(CPUState *cs, uint64_t from); void register_cp_regs_for_features(ARMCPU *cpu); void init_cpreg_list(ARMCPU *cpu); =20 diff --git a/target/arm/tcg/m_helper.c b/target/arm/tcg/m_helper.c index d856e3bc8e..3fb24c7790 100644 --- a/target/arm/tcg/m_helper.c +++ b/target/arm/tcg/m_helper.c @@ -23,6 +23,7 @@ #if !defined(CONFIG_USER_ONLY) #include "hw/intc/armv7m_nvic.h" #endif +#include "qemu/plugin.h" =20 static void v7m_msr_xpsr(CPUARMState *env, uint32_t mask, uint32_t reg, uint32_t val) @@ -2194,6 +2195,7 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) CPUARMState *env =3D &cpu->env; uint32_t lr; bool ignore_stackfaults; + uint64_t last_pc =3D env->regs[15]; =20 arm_log_exception(cs); =20 @@ -2361,6 +2363,7 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) g_assert_not_reached(); #endif env->regs[15] +=3D env->thumb ? 2 : 4; + qemu_plugin_vcpu_hostcall_cb(cs, last_pc); return; case EXCP_BKPT: armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_DEBUG, false); @@ -2427,6 +2430,8 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) =20 ignore_stackfaults =3D v7m_push_stack(cpu); v7m_exception_taken(cpu, lr, false, ignore_stackfaults); + + arm_do_plugin_vcpu_discon_cb(cs, last_pc); } =20 uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg) --=20 2.49.1