From patchwork Tue May 28 14:59:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 799500 Delivered-To: patch@linaro.org Received: by 2002:adf:e110:0:b0:35b:5a80:51b4 with SMTP id t16csp280960wrz; Tue, 28 May 2024 08:01:46 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXObttrYUUEDsAMgCZN4kPK68cKjl3WG/0zIS52wEpFKNjC2IWRlvfNp7hVqMnEUcLyZ9cBIIJT0AcaXKOh7edD X-Google-Smtp-Source: AGHT+IHPLXAPZKRM2fw7oEF76S2xmhQKO1wap0TSYkFSwJPDavHQlzM3dBySLa9wNYt8zL0n4zpa X-Received: by 2002:a05:6358:7a97:b0:17b:f721:4565 with SMTP id e5c5f4694b2df-197e50f4f37mr1549383855d.9.1716908506583; Tue, 28 May 2024 08:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716908506; cv=none; d=google.com; s=arc-20160816; b=rfg1Dwahkxyo+Guk1x6SsQLs+yNtK6MTf3n1/I6NyWv7yivVrKm/Hodu7njPx+65t8 QTeHnz02OpIcWqwNey1+hiWb+VFTF35o6NjQZ1bLlDzNXgGUeR+0bAlOV1YwoFqXo+CB iTRrsuS2onG8u2BEVjYWNTlC53it8RDrUvUF9XPSJIkcz542yy5TbeXks/Drd7KIQeoX G0VRYmn3gyiqs6JbwAhhTsifPYXmYjnjsJgsdYxcE7BlPxlpMfGhs7crOyXxhnoZ8KLv oz+7bvc25UftM1RE141XPsV9NC3mVIVgtNy4OdQl3Yn3C8B+pQZtlCmnftIAXr6sOIEn FT/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zWF1+LjOwHyVGVJbyrAhhwZo8V1u6vIK8N/LCyR6jZU=; fh=g71ocj76I19MS7AD71vLKnbNbl87LKTjuBKf8cOVRXA=; b=YHFuSm/R9+5mSjy0hz5dtG4Ou1Cqs0+qa1SWWpvhNGsYyTLBFl3s9/LohWloW9G7bl weQq/wfae4oKxBPZsm+k1O1IflHztKCrbcd5JJu3f3zQFkrvQBqJO24+cAMqzX5ePuNK CG2SGnXjJ1cs31YLx2mnSFANDJo5MQQsVIIdHls8Ph2xtC7tHscWipfWRIth80y3IPho v3UXlmGcJGYy1mAXHGd+RyZmv/ILEWtKmTeZe5iUrHY4llrNBV6ckMHigxhtyvahuEvZ ow5ZkXSI6BIAprmI5v8eZKz7q0n+ByVVMe7JEsZx5bLBiFHEGMhwF2HvLqP8TLb+RGYl Vipg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=l95LtmX4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-794abcabb2esi1030069885a.117.2024.05.28.08.01.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 May 2024 08:01:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=l95LtmX4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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é --- 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, TranslationBlock *tb, uintptr_t host_pc); 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); #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; } -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 = EXCP_ATOMIC; cpu_loop_exit_restore(cpu, pc); } + +#ifdef CONFIG_PLUGIN +static void qemu_plugin_vcpu_init__async(CPUState *cpu, run_on_cpu_data unused) +{ + qemu_plugin_vcpu_init_hook(cpu); +} +#endif + +bool tcg_exec_realize_assigned(CPUState *cpu, Error **errp) +{ +#ifdef CONFIG_PLUGIN + cpu->plugin_state = 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 = "tcg"; ac->init_machine = tcg_init_machine; ac->cpu_common_realize_unassigned = tcg_exec_realize_unassigned; + ac->cpu_common_realize_assigned = tcg_exec_realize_assigned; + ac->cpu_common_unrealize_assigned = tcg_exec_unrealize_assigned; ac->cpu_common_unrealize_unassigned = tcg_exec_unrealize_unassigned; ac->allowed = &tcg_allowed; ac->gdbstub_supported_sstep_flags = tcg_gdbstub_supported_sstep_flags; 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 CPUState *cpu_by_arch_id(int64_t id) { @@ -192,13 +189,6 @@ static void cpu_common_parse_features(const char *typename, char *features, } } -#ifdef CONFIG_PLUGIN -static void qemu_plugin_vcpu_init__async(CPUState *cpu, run_on_cpu_data unused) -{ - qemu_plugin_vcpu_init_hook(cpu); -} -#endif - static void cpu_common_realizefn(DeviceState *dev, Error **errp) { CPUState *cpu = CPU(dev); @@ -222,14 +212,6 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) cpu_resume(cpu); } - /* Plugin initialization must wait until the cpu start executing code */ -#ifdef CONFIG_PLUGIN - if (tcg_enabled()) { - cpu->plugin_state = qemu_plugin_create_vcpu_state(); - async_run_on_cpu(cpu, qemu_plugin_vcpu_init__async, RUN_ON_CPU_NULL); - } -#endif - /* NOTE: latest generic point where the cpu is fully realized */ } @@ -237,13 +219,6 @@ static void cpu_common_unrealizefn(DeviceState *dev) { CPUState *cpu = CPU(dev); - /* 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); }