From nobody Wed Apr 8 14:48:16 2026 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1716908506; cv=none; d=zohomail.com; s=zohoarc; b=hMDfT7xszFjAk51BzeqnR1VGc/m7Ird2X5p2yoMrIabktPCikZ6SWoDFVxZcDoGMnF5QECWoo3YO/m4ocCmSJz7/NqvkZyQ/TuwAXn9ksjpBCRbJQDC4IOD5ZyWrwjcqRSH8eDQLNfgwAjLoGcXu2H3O3Vl233BhdM4d+8B18oQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716908506; h=Content-Type: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=zWF1+LjOwHyVGVJbyrAhhwZo8V1u6vIK8N/LCyR6jZU=; b=LUm6R1MmTkrROe877mlb+Mi6aAcqA3bKpBWf+sFEZZ8BTPSvLKYfeJJDOUosPKOjRzLeAF/XfsUd2N8eLal895Sd6tzXn94rXD/i3hvY6y1tZL0pxHxfeapSFWKl3dl6bxImsWjg9ZcDOhj8+daHfMgEJREUo3fI48klKRFvw3E= 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+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1716908506900291.82789997800364; Tue, 28 May 2024 08:01:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sByJT-0000id-VI; Tue, 28 May 2024 11:00:31 -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 1sByJS-0000i7-9z for qemu-devel@nongnu.org; Tue, 28 May 2024 11:00:30 -0400 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sByJN-00078d-As for qemu-devel@nongnu.org; Tue, 28 May 2024 11:00:26 -0400 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a5d67064885so146589566b.1 for ; Tue, 28 May 2024 08:00:24 -0700 (PDT) Received: from m1x-phil.lan ([176.187.214.26]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a626c97a1fbsm620973466b.92.2024.05.28.08.00.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 28 May 2024 08:00:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716908424; x=1717513224; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zWF1+LjOwHyVGVJbyrAhhwZo8V1u6vIK8N/LCyR6jZU=; b=l95LtmX4tXNiOC0AGpE+akSLkmuDfud8vzNpnGwt1uaFbfHBN0yEC2XvLdrScqgwft Jsw0j4+1Cln8ip7Ewou7S8IycRdtVvCM6deHucg6XW2CLmtXY7yyQ4041o77aWPBdlu5 z3MPKHkVddrmeRrJcpWfOFHv0gYD3z8ZqYyk2DnH1tE250smyCq6vwK5B+1U4Wty5rH8 Nm05p9C1KPittcbaZiomwTNeoi1umB6AbSWdr19Obtklg7uatHnUmpIe3V6Ti0YgZCON OLBiPdMMb0P76LmcSjbG9JgOsKRKbePuq1hcyCbdnxPGWx3t2GpNvaUVAmH1231kQEhC ADaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716908424; x=1717513224; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zWF1+LjOwHyVGVJbyrAhhwZo8V1u6vIK8N/LCyR6jZU=; b=eFBi3zAEHiSgFxzx+dOphbvVDKT7Aj9OOrW3Eaq+bxLyu2lR1EqP1ZX4Yl+R+0y+9s QPpuGJhnotEcJZIIyaVlAZ2GYdzWEmBBxsULOglHbXHDLbhOhA/5BIfekTIWjSSnjeCQ gLSMC61jojpbMqaxFgm3KFuk82h0jSjuPjce5voAODQCVsioG1l+KeyvUba30hG4sBsK gOGpn9z+x4nBQfbgx5+HC330ph+zLBZsAa65jxRRmzCNch2JrGNdAWyyYTRZX7H5Rx8x spKYEbGqsCvUdMQZmdrBFpb+tcmFo6qaPxXgIOdnViZbjpOoGlymatjJh27xJTzCXMjy /iaA== X-Gm-Message-State: AOJu0YxI4ys1zxzL37w8QQH4KfMOhmRFwYk9tL5VWzJqgXlUs36NAW8z xu1aly5aANTG0VQkHgK4TGeB3vYCqPe2lWGXzSus1unnAX9q7qQRLmYTxjayc1uOVvGL6VgxNzX Z X-Google-Smtp-Source: AGHT+IHNWTrI15G1eDqVz+vxK3M+54ElXygz0ON5eJNwThgTMQ1Qg87WnCbKBBDnUrmkqXYTT8u11w== X-Received: by 2002:a17:906:5784:b0:a63:7efd:8ec8 with SMTP id a640c23a62f3a-a637efd9bb7mr8040066b.70.1716908423651; Tue, 28 May 2024 08:00:23 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Pierrick Bouvier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , Richard Henderson Subject: [PATCH 5/6] accel: Restrict TCG plugin (un)registration to TCG accel Date: Tue, 28 May 2024 16:59:51 +0200 Message-ID: <20240528145953.65398-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240528145953.65398-1-philmd@linaro.org> References: <20240528145953.65398-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::635; envelope-from=philmd@linaro.org; helo=mail-ej1-x635.google.com 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_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1716908507451100003 Use the AccelClass::cpu_common_[un]realize_assigned() handlers to [un]register the TCG plugin handlers, allowing to remove accel specific code from the common hw/core/cpu-common.c file. Remove the now unnecessary qemu_plugin_vcpu_init_hook() and qemu_plugin_vcpu_exit_hook() stub. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- accel/tcg/internal-common.h | 2 ++ include/qemu/plugin.h | 6 ------ accel/tcg/cpu-exec-common.c | 27 +++++++++++++++++++++++++++ accel/tcg/tcg-all.c | 2 ++ hw/core/cpu-common.c | 25 ------------------------- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/accel/tcg/internal-common.h b/accel/tcg/internal-common.h index ec2c6317b7..d900897c6e 100644 --- a/accel/tcg/internal-common.h +++ b/accel/tcg/internal-common.h @@ -54,6 +54,8 @@ void cpu_restore_state_from_tb(CPUState *cpu, Translation= Block *tb, uintptr_t host_pc); =20 bool tcg_exec_realize_unassigned(CPUState *cpu, Error **errp); +bool tcg_exec_realize_assigned(CPUState *cpu, Error **errp); +void tcg_exec_unrealize_assigned(CPUState *cpu); void tcg_exec_unrealize_unassigned(CPUState *cpu); =20 #endif diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index bc5aef979e..d39d105795 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -221,12 +221,6 @@ static inline int qemu_plugin_load_list(QemuPluginList= *head, Error **errp) return 0; } =20 -static inline void qemu_plugin_vcpu_init_hook(CPUState *cpu) -{ } - -static inline void qemu_plugin_vcpu_exit_hook(CPUState *cpu) -{ } - static inline void qemu_plugin_tb_trans_cb(CPUState *cpu, struct qemu_plugin_tb *tb) { } diff --git a/accel/tcg/cpu-exec-common.c b/accel/tcg/cpu-exec-common.c index bc9b1a260e..3c4a4c9f21 100644 --- a/accel/tcg/cpu-exec-common.c +++ b/accel/tcg/cpu-exec-common.c @@ -56,3 +56,30 @@ void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc) cpu->exception_index =3D EXCP_ATOMIC; cpu_loop_exit_restore(cpu, pc); } + +#ifdef CONFIG_PLUGIN +static void qemu_plugin_vcpu_init__async(CPUState *cpu, run_on_cpu_data un= used) +{ + qemu_plugin_vcpu_init_hook(cpu); +} +#endif + +bool tcg_exec_realize_assigned(CPUState *cpu, Error **errp) +{ +#ifdef CONFIG_PLUGIN + cpu->plugin_state =3D qemu_plugin_create_vcpu_state(); + /* Plugin initialization must wait until the cpu start executing code = */ + async_run_on_cpu(cpu, qemu_plugin_vcpu_init__async, RUN_ON_CPU_NULL); +#endif + + return true; +} + +/* undo the initializations in reverse order */ +void tcg_exec_unrealize_assigned(CPUState *cpu) +{ +#ifdef CONFIG_PLUGIN + /* Call the plugin hook before clearing the cpu is fully unrealized */ + qemu_plugin_vcpu_exit_hook(cpu); +#endif +} diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c index c08a6acc21..a32663f507 100644 --- a/accel/tcg/tcg-all.c +++ b/accel/tcg/tcg-all.c @@ -228,6 +228,8 @@ static void tcg_accel_class_init(ObjectClass *oc, void = *data) ac->name =3D "tcg"; ac->init_machine =3D tcg_init_machine; ac->cpu_common_realize_unassigned =3D tcg_exec_realize_unassigned; + ac->cpu_common_realize_assigned =3D tcg_exec_realize_assigned; + ac->cpu_common_unrealize_assigned =3D tcg_exec_unrealize_assigned; ac->cpu_common_unrealize_unassigned =3D tcg_exec_unrealize_unassigned; ac->allowed =3D &tcg_allowed; ac->gdbstub_supported_sstep_flags =3D tcg_gdbstub_supported_sstep_flag= s; diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 0f0a247f56..fda2c2c1d5 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -30,9 +30,6 @@ #include "hw/boards.h" #include "hw/qdev-properties.h" #include "trace.h" -#ifdef CONFIG_PLUGIN -#include "qemu/plugin.h" -#endif =20 CPUState *cpu_by_arch_id(int64_t id) { @@ -192,13 +189,6 @@ static void cpu_common_parse_features(const char *type= name, char *features, } } =20 -#ifdef CONFIG_PLUGIN -static void qemu_plugin_vcpu_init__async(CPUState *cpu, run_on_cpu_data un= used) -{ - qemu_plugin_vcpu_init_hook(cpu); -} -#endif - static void cpu_common_realizefn(DeviceState *dev, Error **errp) { CPUState *cpu =3D CPU(dev); @@ -222,14 +212,6 @@ static void cpu_common_realizefn(DeviceState *dev, Err= or **errp) cpu_resume(cpu); } =20 - /* Plugin initialization must wait until the cpu start executing code = */ -#ifdef CONFIG_PLUGIN - if (tcg_enabled()) { - cpu->plugin_state =3D qemu_plugin_create_vcpu_state(); - async_run_on_cpu(cpu, qemu_plugin_vcpu_init__async, RUN_ON_CPU_NUL= L); - } -#endif - /* NOTE: latest generic point where the cpu is fully realized */ } =20 @@ -237,13 +219,6 @@ static void cpu_common_unrealizefn(DeviceState *dev) { CPUState *cpu =3D CPU(dev); =20 - /* Call the plugin hook before clearing the cpu is fully unrealized */ -#ifdef CONFIG_PLUGIN - if (tcg_enabled()) { - qemu_plugin_vcpu_exit_hook(cpu); - } -#endif - /* NOTE: latest generic point before the cpu is fully unrealized */ cpu_exec_unrealizefn(cpu); } --=20 2.41.0