From patchwork Sat Mar 16 01:57:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 780749 Delivered-To: patch@linaro.org Received: by 2002:a5d:46c1:0:b0:33e:7753:30bd with SMTP id g1csp489528wrs; Fri, 15 Mar 2024 18:59:36 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW3lnqd2lJhUqigqEiwBsA7vr9yMlpOGG7G3JohU5N+r1ZtpC7/Ea2C5tTYYK3q8ZHRvAQFCrz9m05QLCWCjkAM X-Google-Smtp-Source: AGHT+IEp6INUaghg6JJH3FJ4xJAYCHE6+6LpEVpYgAnivLL1FnmgHI7o3NtrmekXtkFtF7dSA51+ X-Received: by 2002:a05:622a:344:b0:42e:fa7c:291c with SMTP id r4-20020a05622a034400b0042efa7c291cmr6282940qtw.13.1710554375909; Fri, 15 Mar 2024 18:59:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710554375; cv=none; d=google.com; s=arc-20160816; b=z4ZlD833YX/KtpfqP1UkKqwNkO2bN0g/YI0OyPmScdWcDLkCpMVGHQTpXnd7UZny9h N7nastrGh7Km3kDnRNKTVOa8RX2lqAFjX7knVQillkLrJ8L2EM46nTwCdeeC+rv3yQXs pRluBUEnD3qCOR3Z7IH08QBxR3CDxzxuL4MM7brxe+++LoE7tE69bNP0nANJW8syK/Oc 4BVNAZKM2IJ2WUFsUXYbndGbUYQwUngOSMJ1JzJk/xtvs88nRhrWEGEJ+344rpK3O2VV eDM6rrjVdzL2j14qObChsYMCzf/9j2eYpcb1Ssk36rhYm1wijvqFoZfixwJl3gSvL2tG c8LQ== 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=7nfW9NMKBYgHEbFge3X4GcZHuOXPsIrrYwIsT1Iscy8=; fh=DfUxOGz7MnM49MBgqH5VPROGi+97fYtPWhcEZCG1Y5Q=; b=cPKuZBE4qFLnvZxUPuQ7XFLo0O8GRT/VU8ezi8ZsNiR04T3OXahmykxPPJu0JtfTqu fBc3g7WjfwSQZ8oUnbTCt6hNKSOAgSo97me7XsswEqnKH+wEbP+1ODbvpyVMimmbHn74 My2MGNjmxH6vEy+vyaeux84adtaoh0y/+PZyNpvJpuGdMyr8j2x3ewsmXHROmFIw6mjm b9QjXJJJk6PUf2MM35bW9oa98VWQr8fLDZRIxZEZoAn2mD7Ga+ODOB1DgCFSW72TueVc BUhZyGLZYcHCby7a2I9UDKPCAW+3UDdIzPJX9C63UfzPE/sPwpaXDE6hy/CicXBDT8mV fm2Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wH9mQHDC; 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 w19-20020ac87e93000000b0042ed731ad3esi2703705qtj.598.2024.03.15.18.59.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Mar 2024 18:59:35 -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=wH9mQHDC; 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 1rlJIx-0002q4-U7; Fri, 15 Mar 2024 21:57:47 -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 1rlJIw-0002o5-F9 for qemu-devel@nongnu.org; Fri, 15 Mar 2024 21:57:46 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rlJIu-0000jN-Re for qemu-devel@nongnu.org; Fri, 15 Mar 2024 21:57:46 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1dc49b00bdbso20597895ad.3 for ; Fri, 15 Mar 2024 18:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710554263; x=1711159063; 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=7nfW9NMKBYgHEbFge3X4GcZHuOXPsIrrYwIsT1Iscy8=; b=wH9mQHDC+n/2lF/qyOb2bDJsJAT9iKUQqg8xbVnOYYozynBEGMBT/V4CbQqirt9wqv mEommrnEYan0yHt9tX3GNy4c4mGmGJxW5Rr/SRr+bI8gK11O2rp6sR5izHHgGL8PRPDQ lj6EnkJbO8ymSpZf/X2PdIol/7Mvw+CASRAdW0604EWUmN9IQxH4DRRrYNzwh8nXT8X3 GyivU8oP/v/Yli2IFTt0iVfyg62Aiwg7dKro4VgbMiio3axl4cxL6n6XTHuneZqq7CxT w9SOy72IN2lDoEoFEqU9nmW2voDeAQ83lPoEHANGNjCVgx8gf5fyq2aSBHNUes1LqwEx 46+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710554263; x=1711159063; 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=7nfW9NMKBYgHEbFge3X4GcZHuOXPsIrrYwIsT1Iscy8=; b=I8erLO32o1f2LDxAimvttIR7Zh2c/IMVtEgkfEu/SOYCMfCZE0tiEYRNLjFu9FRq3s 7rP5BTaoILYfFlacUPISLHk2ATPj2t6if3oxaKzoB8xnOmyOb735AIaBrWZLvuuC1b84 ARBnTV4bEYtYGedo3zEpCpb1IfOp/7RSVAx7QPOcD3cFJ5MYVH5Pubkv3Su/eGrggrKM nekDmngNx3j9j7Hevhdo3LAUrgJ9RNlTEJ3Y8Gdv7kXiI3ilBRueeoUNLIfZWsnH/Ja8 BZ7tQ0Qw23saKPerpGgWCzVGhfs2oZfV2ECnFYUgB/+jQ2xlrKGYsqsyk960NkvUS6zR bEMg== X-Gm-Message-State: AOJu0YwGNv/YiwgH1xjvaoh5K7FsaZHq6aCsNm8yjhv008TE6m+5ZePj UcVcxD1lfGEpM+nYagb4svDNJG5JtQP3JPZ+J5u8NLH/7VfWn2Ga+85FLOzhtdePqG0hM7QHztL H X-Received: by 2002:a17:902:f68c:b0:1df:fd30:8b2d with SMTP id l12-20020a170902f68c00b001dffd308b2dmr72873plg.50.1710554263625; Fri, 15 Mar 2024 18:57:43 -0700 (PDT) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id b3-20020a170903228300b001dd42bbb08asm4592985plh.253.2024.03.15.18.57.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 18:57:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, alex.bennee@linaro.org Subject: [PATCH 09/22] plugins: Add PLUGIN_GEN_AFTER_TB Date: Fri, 15 Mar 2024 15:57:07 -1000 Message-Id: <20240316015720.3661236-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240316015720.3661236-1-richard.henderson@linaro.org> References: <20240316015720.3661236-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62f.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 Delay test of plugin_tb->mem_helper until the inject pass. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier --- 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 f92aa80510..aa74e580bd 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -75,6 +75,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, }; @@ -615,20 +616,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, @@ -679,14 +669,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) @@ -812,9 +799,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: