From patchwork Wed May 1 14:37:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 793717 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:54f:b0:34d:5089:5a9e with SMTP id b15csp790558wrf; Wed, 1 May 2024 07:39:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX8wBBTVt0LZBRLpMxXAAIhbS0sowy74nUwPB2kU21TIvFXwxnr4J912H/4TsdS7YELc7Bs60n9oPTf77N/fgah X-Google-Smtp-Source: AGHT+IHgaj7gSOwqtQEYlh037SfZZkwdTj+6M/v2G6VQY/77D/1ZsF96kBOhd8gcBwEuizbru992 X-Received: by 2002:a05:6214:23ca:b0:6a0:7df4:90b8 with SMTP id hr10-20020a05621423ca00b006a07df490b8mr1927680qvb.35.1714574339918; Wed, 01 May 2024 07:38:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1714574339; cv=none; d=google.com; s=arc-20160816; b=ncVuufYjGXH9TBzN/qRo7AeN+n+6Tq/QCjRh6MKZpaxNjLJWgJskC9O3HswpugwpsM /R7bAi+enVXVUMBu1ZYucJIrkZhJcyhgpm9Qfapi1r1fV1qGYH3wkWHD9k/E1vdaP1yG 5vwxSp9Kg7sw55q5FVzsKk1W2zQ3KoUQpXSQn1AyWLO6juipittO8CMm2hq14OEzAMMb 1JrX273Pmvp6E5qayK27nK8j0Lbh4DGXpmpmKQFOlepyMpkf3663cOZr2JbAfXO4jaQB f4dHDtDCWNYIdQ8QUYO9e3mulIx3M3+fwtGtAkuxeh91bHo+CQ/TFWpz285Xh67xtjMw HoEA== 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=LFBHKbfIw86sLSqmp+tY4EU35vlSG5FIWnRvQETF3JHQd4o2eTrSzIIxaetHEvNzRY FfXc4lG0xaflsJQoJgdSvmMCB0bozr4+uw7ygfCnwss39Jfp/VfySpICiVlXvT4dERCK 1BTFCwBrWghf+RygZJhM01dG1cqI6moN00atnwrk4dLZKaBfzrxxvrrX9eb1zSKdKCgx aW2Ya193k4k3w9rma5KqVuH2p+UdPScB90em7Lu/YD5ZIpv8K8yqvAHdB226o4Myz1Ct Ri1kv7K9cx6Drm1cJrrnfoYCFsw46qBbznSV/ouiV6VR0soAdpH4/mwbnwgkFa2tDgon PIFw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="MMLs/dbe"; 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 if14-20020a0562141c4e00b006a0d1f42532si6550776qvb.558.2024.05.01.07.38.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 May 2024 07:38:59 -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="MMLs/dbe"; 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 1s2B6B-0002kY-1o; Wed, 01 May 2024 10:38:19 -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 1s2B5k-0002fv-Fb for qemu-devel@nongnu.org; Wed, 01 May 2024 10:37:53 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s2B5i-00028Q-RS for qemu-devel@nongnu.org; Wed, 01 May 2024 10:37:52 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1e50a04c317so37747405ad.1 for ; Wed, 01 May 2024 07:37:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714574269; x=1715179069; 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=MMLs/dbeVHFyXXwBBndTsbPj9oWUIhTen3YuB0jPMk++YeudGpibkJ5quyr7P+I006 hQ9b10QUI4xQGrqAf0W8oWkbs/LGAzg03t/v89+DyfHMRrR1raUBaols+C673F7ETZd1 ckiQsoIH50Ik8qHKM+ay3OhUV5162eOu71pmGu1XWYzEyzHJ1QihTid1tFi2dlAhx0F+ TjxR3xHXXed4Bs1S9ZCvRj3LntFAXXD6ywKatFcgaZ+palce5wna4OrTymqJJtPpYgfH 0H1D1fV7n553s5gArLBiSZ5PFGIFFjdxwnGLqBCudlaHb/Qqp7XKSgWJwejXJ8CI/MEI aQ5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714574269; x=1715179069; 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=Gx+eK83cjmCzTPkjkkLgZP7dzQ2RP6qcTXdDL01trfFOPQ+/72x8Ce4Vxx9Ejnl20y F2QYkD0o2OX20zWJbF1jWG1/SVVAGUQD/AX8pn58VlnlF2xzKPxthvTto/wcDg5fR/Q0 7Cb8Sgn8pwSYnV/lzrtDMFhyXzffDuwMHHtMRxuFFcbf/4p9EIolZLngfaWilnXjfIw6 txMAFmXA/f/ZrYdPuxUjFmzr7nsTPEnRe6L6+pYM3ctMfqQ3SraTYW91QNgC2zBFA5dH V9DTDhk8BQq44mLlVJY6csvAgfM4VJc0IlOvakWWJDhGfGEheETgbW245wKotgMlHX8w DSJA== X-Gm-Message-State: AOJu0YwTI+7BYtrtqLU8pcM4IEQzqT2bR6CZ/wCE6TQY3pyeST86bXV2 FiqPtjBUN7NkC87n8cC0C7VVp32/0NZlsQk9ApooKcwjmQ06mGJbxRgiIxO/3hHYTEoEPq/gVSA C X-Received: by 2002:a17:902:bb17:b0:1e4:9d6f:593 with SMTP id im23-20020a170902bb1700b001e49d6f0593mr2844010plb.36.1714574269116; Wed, 01 May 2024 07:37:49 -0700 (PDT) Received: from stoup.. (174-21-72-5.tukw.qwest.net. [174.21.72.5]) by smtp.gmail.com with ESMTPSA id h12-20020a170902f54c00b001ebd73f61fcsm5751573plf.121.2024.05.01.07.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 07:37:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier Subject: [PULL 08/20] plugins: Add PLUGIN_GEN_AFTER_TB Date: Wed, 1 May 2024 07:37:27 -0700 Message-Id: <20240501143739.10541-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240501143739.10541-1-richard.henderson@linaro.org> References: <20240501143739.10541-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.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: