From patchwork Wed Apr 24 23:02:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 791554 Delivered-To: patch@linaro.org Received: by 2002:a5d:4884:0:b0:346:15ad:a2a with SMTP id g4csp1095685wrq; Wed, 24 Apr 2024 16:03:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUoADmf0UPhKL3hTAr51qAoYk/FXFHr8COJLgaKpcScfAAcAHpmb4j1+SQHuVzEDlk7YRzwz56W5HJQCkn6qWFY X-Google-Smtp-Source: AGHT+IEqPDbJty0joSfY8KAVdytaJskIm2GuRUQdlCdZc25f44TntvOmtavJPD656TZ0yqvjnTCc X-Received: by 2002:a05:622a:40cb:b0:437:ad0a:a831 with SMTP id ch11-20020a05622a40cb00b00437ad0aa831mr5747555qtb.60.1713999786574; Wed, 24 Apr 2024 16:03:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713999786; cv=none; d=google.com; s=arc-20160816; b=RneACk09kFkeuchT3DW1vwMF1BVTPqzhsEKR6JXxqeGyWysb3+nPpc1EjsL/WCZ4As 1hpNn4jpathERkBqzHsYihjZ7IECahenxImaFiEZaxSl9+cwX0+vWsPQwM9coFiQPxQ/ xonQOemuqqSB8dAi5eBB3PE83f4Przpey/oPeWuxsJFlpd1FtIEpJYtVFxWMHEJtwr2/ FZbazqg/ePj8Dj3IEIb1Cxuy3MsU2o6NAYHs8twNLlGPUesaQNX6DWvYo4tAdDs98A+J ekyjaobUnPGGJNtJzRMnftH8rasfkG3p3nXHnsYWL22rafGIXZHOMyP5OFf1vXhw5WjU OfQw== 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=0UiZjyCR2r5scimNCQ/ckI5Hhjnn62PqHF3WAmqYExOAb/EeQHVICS3n26YDsM7Tdv blgQUR0Qh8WXnlOVHkPPMCcq3D8x8TvmyiHOnZXAHyd510bvOX8IXz34tPyVMVd/hw10 pZQZwGazn6KwlM18/nlEAF0oiBJMQpSJWHVGlS5y62zKYFeGpx8KrWDRzK+uOlC1/HG9 lG8JWisY+i2WpKhGhQiFuQUFSFlq6E7XjdE5HOvss132I1qUkB4a8xGkrpluAsKRjBeH RoJplkdDDfOio8prFK7H3Ljrg9CddN6oZqtHQEJKCzRZYPj7uwO2Ef/Ko8RpoGiASI5J RMzw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kHWi8C+B; 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 w22-20020a05622a135600b0043a46e3a099si191738qtk.239.2024.04.24.16.03.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2024 16:03:06 -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=kHWi8C+B; 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 1rzldR-0003l6-UB; Wed, 24 Apr 2024 19:02:41 -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 1rzldO-0003kG-Im for qemu-devel@nongnu.org; Wed, 24 Apr 2024 19:02:38 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rzldM-0002db-Rh for qemu-devel@nongnu.org; Wed, 24 Apr 2024 19:02:38 -0400 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-5dbf7b74402so305092a12.0 for ; Wed, 24 Apr 2024 16:02:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713999755; x=1714604555; 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=kHWi8C+BRybJihUi0HcN0UuWRa+4RHWuuRPEjbOpVwDOzy1XnFThREV/H66pgr1ns2 ZDZtrgqiTA4QNYp0S0KWvJNieqzfig3yqNmYUlBXKSvFZwA/xjGZYUX6FdE2sl8C4swA rag1Jye4c+Fho8cf76HLfUXzsJtLdnVpYhyZ+/5+MRamabnDjLdy81krKDUVLtrhBm3e s18BwMmkR1Up8hVTYS3jGcJhU875xbATNEODD/2M3mdOTNvtngG8Sgus8beIcj2riG4z 0Jm0X6pLSkLadIrPagD+MgrRxHXhtlDWK5etOtiUTRAWU3hFshre9XH+pMPRlDjM+b2k PoBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713999755; x=1714604555; 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=lu0UCSdoKpoLpksZrMf/jbu7iK8/trqiqSC+1vN3LfR4g08uGIu2Ua4m1nKNqFNpsg BE8B7g8JjG5f0QbQfrgq8boD5VP4PByeIiXkwU3uih2f05QAE1/o90sljaVsqh7N5pP3 F4aJpVqVu+dgc/sXuz49Qy3+QoHWSYHBakA+JG1tGog9Xsl1Qsxwen+mNQ/atnf+CgFY DjaFYy58fN8zXATTnsAvJy48A7fTR94efKO9otw429B+AZ75Xm2HYLl/DygikHXqgYus x0ej+xxXb4Te8UucdAoy2oTFn+1H2ue2uqW6rSbCvcZ98v5jQw+OsPlAEY8tyK8piNjj r/4w== X-Gm-Message-State: AOJu0YwJUxVHatlYHGYgJrHLmxuWlwtyn9SnXyYhm6uPVQmlvuO9sUwq b8eISqkU4jdfqZeNE/SDcycqUA1nEWAwK7QZ+iYQoGTROYMGtQR58R33Bbolm/M6b2JxixpKm6K L X-Received: by 2002:a05:6a20:244e:b0:1aa:5aab:567a with SMTP id t14-20020a056a20244e00b001aa5aab567amr4595232pzc.41.1713999755443; Wed, 24 Apr 2024 16:02:35 -0700 (PDT) Received: from stoup.. ([156.19.246.23]) by smtp.gmail.com with ESMTPSA id h5-20020a056a00000500b006ed4aa9d5c0sm11981405pfk.188.2024.04.24.16.02.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 16:02:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier Subject: [PATCH v3 08/20] plugins: Add PLUGIN_GEN_AFTER_TB Date: Wed, 24 Apr 2024 16:02:12 -0700 Message-Id: <20240424230224.941028-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240424230224.941028-1-richard.henderson@linaro.org> References: <20240424230224.941028-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.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: