From patchwork Thu Apr 4 23:05:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 785842 Delivered-To: patch@linaro.org Received: by 2002:adf:f001:0:b0:33e:7753:30bd with SMTP id j1csp1074017wro; Thu, 4 Apr 2024 16:07:37 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW78ceGCslP3njRtvNPCdD3cPROYJPTGtr4+9Z+MPc0caVfoYvCEYHMdeDWlCFaWOdcT25LusY3TtfDWrEsbRf5 X-Google-Smtp-Source: AGHT+IHfkeDpaSsc7Ps+GmZnkN6/xjz9gpbAThZ7BWoCNslILGXPU8/c4GcDGMOYI9f4LQaLhbqj X-Received: by 2002:ac8:5742:0:b0:432:e325:2c27 with SMTP id 2-20020ac85742000000b00432e3252c27mr1317602qtx.52.1712272057009; Thu, 04 Apr 2024 16:07:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712272056; cv=none; d=google.com; s=arc-20160816; b=l359VRuVhmCU0PN9EO9Ji77JIWdGCeNq1SEmO9978U1KuaQOmKOO7siBjZc/iDAa/K jlbVrVc7fqgtGIKafE4fEhv2xFJ+VASx06Gqbl3pvQGY+ufhtw+UXZ+G1PNc28pyZLu/ GdbzFC1Zi1O/P6qHsWjfrWVDct1eQwj+SECD3RGBekXsCJfjgo1ATFEx6F66qzbJaGNt MBtLMfMe3AowFfT96Z9IcUhITXzi3yvLfmHZ4KlvF5pBI//zUf5fjm+bCaB6FQgn/aDM yHNdmDfanX9IncyttJoGy9yIaUN6sxcui/fdGEQahtMUQzoDyCBarmVJ0dujFdAdbwk/ tWjA== 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=6NiZ3HGz3Hc6pId3zVyG1cXL7lbYUMaIMlfQHI2GKrk=; fh=vm85eyWrvOAHduw3sqEA+cYBqvHB7M0MHFcRJg7VWOo=; b=vc9Bu6OPNZlS2zArVyeNLOD8RlyGYn85micaK+XfYeZO4F4U36A/Sjs+E6+XKAzLpy Q/gUqaP3QJNhYlHBkt4jbcnslkzhyxO9feDA1NBcrT5m2QHOk0m92D7YLXhaMDzhCTGk io/qOMShrvzxcVVG8WgmXTLm6zjGqGc37RoCTvCf42/wAxzlMqkkNQeJcqTm8oSZ4zbh 6WlVqnMotDLx9NOXCD5h+vFrDCmzkt5EM9RH686l8d18Ak5HCgclEFrooecgOmCQFy8G EPcoJCUXRihR9Qt/s1lPrjE6RiVFqi6S9WRVxBmCNGG5fywvt+qsdrVubaKLCid6sJwq Ue4A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rCCTP2zw; 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 g17-20020ac85d51000000b00432f4f733b8si434645qtx.52.2024.04.04.16.07.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Apr 2024 16:07:36 -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=rCCTP2zw; 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 1rsWAD-00022o-14; Thu, 04 Apr 2024 19:06:34 -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 1rsWA8-00022D-NF for qemu-devel@nongnu.org; Thu, 04 Apr 2024 19:06:28 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rsWA6-0007jp-UV for qemu-devel@nongnu.org; Thu, 04 Apr 2024 19:06:28 -0400 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2a07b092c4fso1232885a91.0 for ; Thu, 04 Apr 2024 16:06:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712271985; x=1712876785; 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=6NiZ3HGz3Hc6pId3zVyG1cXL7lbYUMaIMlfQHI2GKrk=; b=rCCTP2zwJvm18oRXgEFscdvyGX57x5QUf+fhHUK7aHK87NFXdLCtYa215hquSP6Zwc I/W1mHDsmyXk9+Lsx8NzzDhK2kH3TLdOPyn1NLRjTHHCIwY3Af4wK5dI7jX4/2yYVzHF rccri7misYY0GOdPwhOgzpZ1EqvJZ3yf3rSSgtyvuZP8a+RFMijAq8bKu+tZdO1I5Ax9 /yIVtF2WP5QHzc8C3iyesn+gtAPXVd7eIf2rfwKrqhzduvE6iahThiqSmHNJeGDzjdAh k6kLZCVFszdle5Wu70Vf1u6Nc2Y9ExcJsP6y2wWfgi2fOcFtFbRKMZ2LUi042N1OjnLK sePw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712271985; x=1712876785; 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=6NiZ3HGz3Hc6pId3zVyG1cXL7lbYUMaIMlfQHI2GKrk=; b=KEM9daKXV5mq9qmNp56udsylDuPbUzVxMvoy2GCKvu9HYNuVV+vfIfWhY5kFavGJB5 0euoEea6gl/BpPejnbUN2JJIJQU2NdlO3Knt9aSUakyJ6FH/e4U1AeYRwfAekJU6Z51t 7e0QZEIitgcQWBx3Fn1D5y2ks60O90HmAVRGrCn4MyXMVbIJfWi/47vAY2RjXEfd3dvZ i4XiUW9MbbMOKeu6Yuc3NrR+Ve8lHRG8xMxMhSrlxRZz88J7ogvXqTdNIYykh+Q3+oQ9 Uo1F6M337tHRoLsAC9lwMWo8IvksJBjqX4rlXCn1I83l6tYvMu0d2R2CGZyLetS0ed5w NHdw== X-Gm-Message-State: AOJu0YzkXfIhkUjKOYgrHW73EAhzyPcMVasvCyRlXKQIk4paK7bKygBn CPQbOEZ19mVdlxmUsK1+eReP9l/zU2rFI59q7WdR9zt9HSO0qbXPQAprpqfrMEQ98sC70Mclb5+ k X-Received: by 2002:a17:90a:15c9:b0:29f:67ad:7db0 with SMTP id w9-20020a17090a15c900b0029f67ad7db0mr1124772pjd.11.1712271985670; Thu, 04 Apr 2024 16:06:25 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id q36-20020a17090a17a700b002a2f3cfc92asm1052592pja.16.2024.04.04.16.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 16:06:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier Subject: [PATCH v2 09/21] plugins: Add PLUGIN_GEN_AFTER_TB Date: Thu, 4 Apr 2024 13:05:59 -1000 Message-Id: <20240404230611.21231-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240404230611.21231-1-richard.henderson@linaro.org> References: <20240404230611.21231-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.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 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 Delay test of plugin_tb->mem_helper until the inject pass. Reviewed-by: Pierrick Bouvier Signed-off-by: Richard Henderson --- accel/tcg/plugin-gen.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index c803fe8e96..1faa49cb8f 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -69,6 +69,7 @@ enum plugin_gen_from { PLUGIN_GEN_FROM_INSN, PLUGIN_GEN_FROM_MEM, PLUGIN_GEN_AFTER_INSN, + PLUGIN_GEN_AFTER_TB, PLUGIN_GEN_N_FROMS, }; @@ -609,20 +610,9 @@ static void inject_mem_enable_helper(struct qemu_plugin_tb *ptb, /* called before finishing a TB with exit_tb, goto_tb or goto_ptr */ void plugin_gen_disable_mem_helpers(void) { - /* - * We could emit the clearing unconditionally and be done. However, this can - * be wasteful if for instance plugins don't track memory accesses, or if - * most TBs don't use helpers. Instead, emit the clearing iff the TB calls - * helpers that might access guest memory. - * - * Note: we do not reset plugin_tb->mem_helper here; a TB might have several - * exit points, and we want to emit the clearing from all of them. - */ - if (!tcg_ctx->plugin_tb->mem_helper) { - return; + if (tcg_ctx->plugin_insn) { + tcg_gen_plugin_cb(PLUGIN_GEN_AFTER_TB); } - tcg_gen_st_ptr(tcg_constant_ptr(NULL), tcg_env, - offsetof(CPUState, plugin_mem_cbs) - offsetof(ArchCPU, env)); } static void plugin_gen_insn_udata(const struct qemu_plugin_tb *ptb, @@ -673,14 +663,11 @@ static void plugin_gen_enable_mem_helper(struct qemu_plugin_tb *ptb, inject_mem_enable_helper(ptb, insn, begin_op); } -static void gen_disable_mem_helper(struct qemu_plugin_tb *ptb, - struct qemu_plugin_insn *insn) +static void gen_disable_mem_helper(void) { - if (insn->mem_helper) { - tcg_gen_st_ptr(tcg_constant_ptr(0), tcg_env, - offsetof(CPUState, plugin_mem_cbs) - - offsetof(ArchCPU, env)); - } + tcg_gen_st_ptr(tcg_constant_ptr(0), tcg_env, + offsetof(CPUState, plugin_mem_cbs) - + offsetof(ArchCPU, env)); } static void gen_udata_cb(struct qemu_plugin_dyn_cb *cb) @@ -806,9 +793,17 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) tcg_ctx->emit_before_op = op; switch (from) { + case PLUGIN_GEN_AFTER_TB: + if (plugin_tb->mem_helper) { + gen_disable_mem_helper(); + } + break; + case PLUGIN_GEN_AFTER_INSN: assert(insn != NULL); - gen_disable_mem_helper(plugin_tb, insn); + if (insn->mem_helper) { + gen_disable_mem_helper(); + } break; case PLUGIN_GEN_FROM_TB: