From patchwork Sun Jan 8 16:47:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 13092589 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F27BDC53210 for ; Sun, 8 Jan 2023 16:48:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pEYqG-0006jB-Vp; Sun, 08 Jan 2023 11:48:17 -0500 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 1pEYqC-0006ed-Lk for qemu-devel@nongnu.org; Sun, 08 Jan 2023 11:48:13 -0500 Received: from mail-qt1-x834.google.com ([2607:f8b0:4864:20::834]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pEYqB-0000OX-0G for qemu-devel@nongnu.org; Sun, 08 Jan 2023 11:48:12 -0500 Received: by mail-qt1-x834.google.com with SMTP id h26so6187094qtu.2 for ; Sun, 08 Jan 2023 08:48:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap-org.20210112.gappssmtp.com; s=20210112; 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=d92HqZO3HGiFOo1ukeBZZ1sHajJw5wbqCOY5xB+iG3Y=; b=i1T1hhedKv82+w3CXqbSpjPXjY44utNEg38vZv2h1443abOjQYcSJlSbwRADz5RxzL DtqnFau3spj+1JbhD6HY7j+e0sX+fHTl+YGuaXKAcCmCY8Y8hknN00ufrpORWRv0TKg/ lQEqGA/o9B6QDL8/RDBYpjxaOh0oGbQx+pRYydew8PQFjUVf4kGN+7g9k/0lOeGLhKWz cNYLMcecep8SVJpAJkw7GlwC/kDc1xnQ+RWupehaGN/3vDR7tcCyCqjPIGEo5L9S9kGk H1k+kfo9fY8nHX2/2b4ptDF+jJf7AMkinDhD9JBU07QXnQsMe1ydizgbvEpCGQQHGgID 4FEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=d92HqZO3HGiFOo1ukeBZZ1sHajJw5wbqCOY5xB+iG3Y=; b=qVz2DxuJ1MQeRfp102jHReK1ge0tKFtU2dqb4MV/EU4+Wt7RK5u7E3eoyulePWfih8 MFdrIfOtu21pBHszsiGbb+tZ6I+YHuH6rVB/EETCxVlTW+keoyrmVVJtWcgENvgU+Ag/ 09dcrbyA0bdeyuNKB/VXC+ZuaQA33iVRQShIb5HPJUplBmr/ou1OcjyEyxyQlikoZY74 ZYQ5tvGEaN55ntVQtHy5xI3jBPeF2Zu5sanQR2VsDjmllltz1XeL4ar9CwIFPirn04jz pc5SOVfUy4au2rxU6Rryhuuyq8Sk1XLHcspRZEdMOB7iGhpC2QWYYgiXFtdqNApp4qLn kW2A== X-Gm-Message-State: AFqh2ko0QuldFS2OUOoX9b1YfBQZwvBo3WIrUAHzLMCbpawkgaNhOp9j fgmWc3NBbVW4k6pAlc4IdkIqHYUeyI4kTRIYWm4G/g== X-Google-Smtp-Source: AMrXdXtKIFpPDvDySKVHQC06IzxOpADUPEQv9FxYQ9uwIrUoiFCfO6cUF3HalYRlklke9wKRN+ONYw== X-Received: by 2002:a05:622a:4d06:b0:3a9:9217:9e6c with SMTP id fd6-20020a05622a4d0600b003a992179e6cmr97761509qtb.55.1673196487264; Sun, 08 Jan 2023 08:48:07 -0800 (PST) Received: from localhost ([185.156.46.146]) by smtp.gmail.com with ESMTPSA id y19-20020a05620a44d300b006fba44843a5sm3944808qkp.52.2023.01.08.08.48.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 08:48:06 -0800 (PST) From: Emilio Cota To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson , Aaron Lindsay , Emilio Cota Subject: [PATCH 1/4] plugins: fix optimization in plugin_gen_disable_mem_helpers Date: Sun, 8 Jan 2023 11:47:28 -0500 Message-Id: <20230108164731.61469-2-cota@braap.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230108164731.61469-1-cota@braap.org> References: <20230108164731.61469-1-cota@braap.org> MIME-Version: 1.0 Received-SPF: softfail client-ip=2607:f8b0:4864:20::834; envelope-from=cota@braap.org; helo=mail-qt1-x834.google.com X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We were mistakenly checking tcg_ctx->plugin_insn as a canary to know whether the TB had emitted helpers that might have accessed memory. The problem is that tcg_ctx->plugin_insn gets updated on every instruction in the TB, which results in us wrongly performing the optimization (i.e. not clearing cpu->plugin_mem_cbs) way too often, since it's not rare that the last instruction in the TB doesn't use helpers. Fix it by tracking a per-TB canary. While at it, expand documentation. Related: #1381 Signed-off-by: Emilio Cota Tested-by: Aaron Lindsay --- accel/tcg/plugin-gen.c | 26 ++++++++++++++++++-------- include/qemu/plugin.h | 7 +++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index c7d6514840..17a686bd9e 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -579,7 +579,8 @@ static void inject_mem_helper(TCGOp *begin_op, GArray *arr) * is possible that the code we generate after the instruction is * dead, we also add checks before generating tb_exit etc. */ -static void inject_mem_enable_helper(struct qemu_plugin_insn *plugin_insn, +static void inject_mem_enable_helper(struct qemu_plugin_tb *ptb, + struct qemu_plugin_insn *plugin_insn, TCGOp *begin_op) { GArray *cbs[2]; @@ -599,6 +600,7 @@ static void inject_mem_enable_helper(struct qemu_plugin_insn *plugin_insn, rm_ops(begin_op); return; } + ptb->mem_helper = true; arr = g_array_sized_new(false, false, sizeof(struct qemu_plugin_dyn_cb), n_cbs); @@ -626,15 +628,22 @@ void plugin_gen_disable_mem_helpers(void) { TCGv_ptr ptr; - if (likely(tcg_ctx->plugin_insn == NULL || - !tcg_ctx->plugin_insn->mem_helper)) { + /* + * 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; } ptr = tcg_const_ptr(NULL); tcg_gen_st_ptr(ptr, cpu_env, offsetof(CPUState, plugin_mem_cbs) - offsetof(ArchCPU, env)); tcg_temp_free_ptr(ptr); - tcg_ctx->plugin_insn->mem_helper = false; } static void plugin_gen_tb_udata(const struct qemu_plugin_tb *ptb, @@ -682,14 +691,14 @@ static void plugin_gen_mem_inline(const struct qemu_plugin_tb *ptb, inject_inline_cb(cbs, begin_op, op_rw); } -static void plugin_gen_enable_mem_helper(const struct qemu_plugin_tb *ptb, +static void plugin_gen_enable_mem_helper(struct qemu_plugin_tb *ptb, TCGOp *begin_op, int insn_idx) { struct qemu_plugin_insn *insn = g_ptr_array_index(ptb->insns, insn_idx); - inject_mem_enable_helper(insn, begin_op); + inject_mem_enable_helper(ptb, insn, begin_op); } -static void plugin_gen_disable_mem_helper(const struct qemu_plugin_tb *ptb, +static void plugin_gen_disable_mem_helper(struct qemu_plugin_tb *ptb, TCGOp *begin_op, int insn_idx) { struct qemu_plugin_insn *insn = g_ptr_array_index(ptb->insns, insn_idx); @@ -750,7 +759,7 @@ static void pr_ops(void) #endif } -static void plugin_gen_inject(const struct qemu_plugin_tb *plugin_tb) +static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) { TCGOp *op; int insn_idx = -1; @@ -870,6 +879,7 @@ bool plugin_gen_tb_start(CPUState *cpu, const DisasContextBase *db, ptb->haddr1 = db->host_addr[0]; ptb->haddr2 = NULL; ptb->mem_only = mem_only; + ptb->mem_helper = false; plugin_gen_empty_callback(PLUGIN_GEN_FROM_TB); } diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index a772e14193..e0ebedef84 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -118,7 +118,10 @@ struct qemu_plugin_insn { void *haddr; GArray *cbs[PLUGIN_N_CB_TYPES][PLUGIN_N_CB_SUBTYPES]; bool calls_helpers; + + /* if set, the instruction calls helpers that might access guest memory */ bool mem_helper; + bool mem_only; }; @@ -158,6 +161,10 @@ struct qemu_plugin_tb { void *haddr1; void *haddr2; bool mem_only; + + /* if set, the TB calls helpers that might access guest memory */ + bool mem_helper; + GArray *cbs[PLUGIN_N_CB_SUBTYPES]; }; From patchwork Sun Jan 8 16:47:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 13092587 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CEC9AC54EBE for ; Sun, 8 Jan 2023 16:48:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pEYqG-0006in-OY; Sun, 08 Jan 2023 11:48:16 -0500 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 1pEYqE-0006gA-J0 for qemu-devel@nongnu.org; Sun, 08 Jan 2023 11:48:14 -0500 Received: from mail-qv1-xf33.google.com ([2607:f8b0:4864:20::f33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pEYqD-0000Q9-40 for qemu-devel@nongnu.org; Sun, 08 Jan 2023 11:48:14 -0500 Received: by mail-qv1-xf33.google.com with SMTP id j9so4694794qvt.0 for ; Sun, 08 Jan 2023 08:48:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap-org.20210112.gappssmtp.com; s=20210112; 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=bfHq7d6gEeqDcPDN5XCy/P/V1tIeaifeaACu/hJYYAI=; b=0kTMznWqh+avjIW3JXqlsnVR8vzd7KkcmsE6WgY1wVx9OqjeYaDq0YeJVZhlV5+3Rw jeG2wcF5pBd1gRONVdFO9e3X5gfjuAMJcxkDnontL028yo2/4RiCaBRL9iEdlqy6ZiiU kJ1mlhO0fQI84Kl5odNfsn/swEOsby9rQAJExODqhOH6kVI8QRFZqCC+H2wTVjcUcmIO W99oF5vLewauU8DtwSNZRvGkDtEopplI8vlxwGO+asXhj4lY/3IrHLyzEJagyrvsVBvY zt4qGcs7SAnq8/SPY9UyuVbu3FX9h9xUASFr+mHnryTNsHX5nQbe3Zm2W6p2jIsFKUAH BGMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=bfHq7d6gEeqDcPDN5XCy/P/V1tIeaifeaACu/hJYYAI=; b=64mF/fDJuixUY1wv3qpjy+R+3fTBtLbT94/AmAWUQR+drLaztIH7MbGEjQXhf3A+qG wgjlm5AycUILGVw9o0FWS36s10qfb0+TlGxfpLAwnZAQgfliysdiQlCZZNqdrUhb/DiH jLVQYO82fl8qto8bsB3hADjYJTRsXGDIeAVmDUBGS5u3pYnc9Oqs0lW0onE220ktmrwN 7U3AhdxB+v9duhsBPHT7VgoQvNlLN4imU0KKk+qSehXlSB3DBAGGy/HINYOwI04O/hRV 7lOzqlj2c+237Xg8hDQAtU88y1Da9C1HON3JGgQtfEWDwEqObBVgGkn5YyCda18PavCk JJ1A== X-Gm-Message-State: AFqh2krvcflTh2DQlJmDlafm0v/z8miAeMMpdlmrlRXoF/L/uwXXHqe1 yPglJl0zbrxV8GeIP/yc2N1x/wVd+i5iOGWWS+Y5DA== X-Google-Smtp-Source: AMrXdXt3KLZnifqhYTxinAzAtqiiTLprsDw1jeoXfeiiY0aQBO/ez4Z5tDi71xQAG9JKGDagCuVZLg== X-Received: by 2002:a05:6214:5a07:b0:532:1ebe:84c8 with SMTP id lu7-20020a0562145a0700b005321ebe84c8mr11351759qvb.2.1673196491988; Sun, 08 Jan 2023 08:48:11 -0800 (PST) Received: from localhost ([185.156.46.146]) by smtp.gmail.com with ESMTPSA id y10-20020a05620a25ca00b006fa4cac54a5sm3915882qko.72.2023.01.08.08.48.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 08:48:11 -0800 (PST) From: Emilio Cota To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson , Aaron Lindsay , Emilio Cota Subject: [PATCH 2/4] translator: always pair plugin_gen_insn_{start, end} calls Date: Sun, 8 Jan 2023 11:47:29 -0500 Message-Id: <20230108164731.61469-3-cota@braap.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230108164731.61469-1-cota@braap.org> References: <20230108164731.61469-1-cota@braap.org> MIME-Version: 1.0 Received-SPF: softfail client-ip=2607:f8b0:4864:20::f33; envelope-from=cota@braap.org; helo=mail-qv1-xf33.google.com X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Related: #1381 Signed-off-by: Emilio Cota Reviewed-by: Philippe Mathieu-Daudé Tested-by: Aaron Lindsay --- accel/tcg/translator.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index 061519691f..ef5193c67e 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -100,19 +100,24 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int max_insns, ops->translate_insn(db, cpu); } - /* Stop translation if translate_insn so indicated. */ - if (db->is_jmp != DISAS_NEXT) { - break; - } - /* * We can't instrument after instructions that change control * flow although this only really affects post-load operations. + * + * Calling plugin_gen_insn_end() before we possibly stop translation + * is important. Even if this ends up as dead code, plugin generation + * needs to see a matching plugin_gen_insn_{start,end}() pair in order + * to accurately track instrumented helpers that might access memory. */ if (plugin_enabled) { plugin_gen_insn_end(); } + /* Stop translation if translate_insn so indicated. */ + if (db->is_jmp != DISAS_NEXT) { + break; + } + /* Stop translation if the output buffer is full, or we have executed all of the allowed instructions. */ if (tcg_op_buf_full() || db->num_insns >= db->max_insns) { From patchwork Sun Jan 8 16:47:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 13092590 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2819CC53210 for ; Sun, 8 Jan 2023 16:48:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pEYqI-0006md-E9; Sun, 08 Jan 2023 11:48:18 -0500 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 1pEYqH-0006jk-5p for qemu-devel@nongnu.org; Sun, 08 Jan 2023 11:48:17 -0500 Received: from mail-qt1-x835.google.com ([2607:f8b0:4864:20::835]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pEYqF-0000RF-Kc for qemu-devel@nongnu.org; Sun, 08 Jan 2023 11:48:16 -0500 Received: by mail-qt1-x835.google.com with SMTP id a16so6066010qtw.10 for ; Sun, 08 Jan 2023 08:48:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap-org.20210112.gappssmtp.com; s=20210112; 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=aaox4hWeUonfLH9h27CRl8dbbaN6wq8FriB4sD8Tzls=; b=cs8ThutuSniVZr9lXiuMr2nxzejs1YJPLGfk+HJmL6t9qhUUdTAjOX2tg6AEqsNYKH 0xTjWBn9PmRwHWfdfnPLlLwUuPo5f30gPA+cGIi2M8bsSsKD6G3sy/QvIorKZuezZ2Si z1awLF/QNaz+p+e1PJO/ups7/zXSRwJvFlDznslzwAldP1Q8aSs6Fs+AmteM+atq0xt4 O+zRT6jW8F6XzhMVN95tKM8BSmrEbYiaspxDqBN813IgK4cA4AAA7k48iGrum8+BF1d8 /m0KYLv5ssn+HuuBc+9GDD/xtCUXdcA57uT/vRBHUyiLakBdxmeN4KqZnGsVBafzzFMX 5mKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=aaox4hWeUonfLH9h27CRl8dbbaN6wq8FriB4sD8Tzls=; b=fShNzRmicXQT5+r6igJR8uh0FJXTYFvSkjnm/VqJnSCexiw5wpwNndHsjZp2VLSavy W3FmuQ3OPtHH/VU+q1ulfRp2E9vp72nYWOgKf8aqalTPYgQzXZOVLPq/HQ57WGDqYB5B /oBkyfEN72/fWrLBbhVAW7CX3VNn97RzxRd+yZuoiHOjJcZdI+sUoiA4CZTxvUk04KmH zH7dDY8VqSGERQiLG4g1s/nXTqF0/+Io6dnsIsnV8WcgwqOV3jiKsEAtzNT//5bzOTUv XZdVIJSus7VfCMHRpsDXHfB6HQztzSCLl2plFsBAWDkheLL00cd+8N+Pd0uoxjWvQq1H gBvg== X-Gm-Message-State: AFqh2kpt3OkdIiBagonitNde3ElHKSiXI09pEML1NSvm7GrwY/HQjX9Z T1JZCeyxNSl2HG6Rr6H2iY3wTeZo4mmRF6aBd9N08Q== X-Google-Smtp-Source: AMrXdXsKSaneRLjlZbHZ+fJdM1mwTrjxWbk5PMBpMBqTyf82ZPlERlEAn8LNuiWMSOOddKjpm4+i4A== X-Received: by 2002:ac8:4a93:0:b0:3a7:ec9b:e00b with SMTP id l19-20020ac84a93000000b003a7ec9be00bmr84094402qtq.68.1673196494520; Sun, 08 Jan 2023 08:48:14 -0800 (PST) Received: from localhost ([185.156.46.146]) by smtp.gmail.com with ESMTPSA id d8-20020ac84e28000000b0039c7b9522ecsm3423049qtw.35.2023.01.08.08.48.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 08:48:14 -0800 (PST) From: Emilio Cota To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson , Aaron Lindsay , Emilio Cota Subject: [PATCH 3/4] tcg: exclude lookup_tb_ptr from helper instrumentation Date: Sun, 8 Jan 2023 11:47:30 -0500 Message-Id: <20230108164731.61469-4-cota@braap.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230108164731.61469-1-cota@braap.org> References: <20230108164731.61469-1-cota@braap.org> MIME-Version: 1.0 Received-SPF: softfail client-ip=2607:f8b0:4864:20::835; envelope-from=cota@braap.org; helo=mail-qt1-x835.google.com X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org It is internal to TCG and therefore we know it does not access guest memory. Related: #1381 Signed-off-by: Emilio Cota --- tcg/tcg.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index da91779890..ee67eefc0c 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1652,8 +1652,10 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args) op = tcg_op_alloc(INDEX_op_call, total_args); #ifdef CONFIG_PLUGIN - /* detect non-plugin helpers */ - if (tcg_ctx->plugin_insn && unlikely(strncmp(info->name, "plugin_", 7))) { + /* flag helpers that are not internal to TCG */ + if (tcg_ctx->plugin_insn && + strncmp(info->name, "plugin_", 7) && + strcmp(info->name, "lookup_tb_ptr")) { tcg_ctx->plugin_insn->calls_helpers = true; } #endif From patchwork Sun Jan 8 16:51:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 13092591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9F0B9C54EBD for ; Sun, 8 Jan 2023 16:51:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pEYtL-0001rf-SA; Sun, 08 Jan 2023 11:51:27 -0500 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 1pEYtI-0001rU-6t for qemu-devel@nongnu.org; Sun, 08 Jan 2023 11:51:24 -0500 Received: from mail-qv1-xf35.google.com ([2607:f8b0:4864:20::f35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pEYtE-0001NE-VR for qemu-devel@nongnu.org; Sun, 08 Jan 2023 11:51:23 -0500 Received: by mail-qv1-xf35.google.com with SMTP id t17so4641964qvw.6 for ; Sun, 08 Jan 2023 08:51:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap-org.20210112.gappssmtp.com; s=20210112; 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=qdYBozkTmEnnxMe67YTmLz59tHO5RbfllBVv5dQ0Y3U=; b=4rt7y2byDKry2+p586uomYyFNjwAmFzcVrDWHeC4DA+tjQBH0bfYY/GNy5R/4LXWO0 vUPbaVLARibxnHjFaBFykHYash4kiN8cJWqnauAhivVj2IY2jVcj+BZ6dOV+MSuAXpRS oBsdpKDyWnOiFd2+bCaiOGae7gBm0Jukh8YgsYu0/O+Pw6Tf2KUMC38vf4Go0BI6fskJ MK0euWrsNM1xV395CYwehCYWgFEvQldJl/1ikPVdAzYdZg3FqxR01l4TDqy/fHpjGJo9 iy/VsNGWt66+7bCoUXSkKTZDRzxriggkjdzo0A/hsy+OD55zkLPiEWvByG00yp3mLGSO V5HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=qdYBozkTmEnnxMe67YTmLz59tHO5RbfllBVv5dQ0Y3U=; b=W5xu6xANTj5LvFr8dd57L0EfxOsdUQAePDc/iJeV6wD5EeiOP6AjrQ1Mr1dNVco7Qh BDEfGbQgoJ/SBsEWeU9EmDKZVODXEg2fMCXH/SQUN2keZdV28o3nWK8X5RluixQA4nBQ 2/zjhFUhjPurTl2XhfpZXV8WDWMhYylaFjF9SPU2KNVbO94q40thnxih0YvpGKJyhoNe aVpze1dBwwEItrIyVKblYMrS1ekDyZ+wcuHbYq0Fhph2GVcC2DCWjPftBdS0ixMCg4CH QHCgXaKgPNv2YHEcFhMQLi67S0VWD7mZIaBflAnWy+UwIkeKLCFV2Kh0hU4aZj3OZsIH X0Vg== X-Gm-Message-State: AFqh2krEuKO0dU734MZe7ZrjAE1lCMfSWbMOhRQHGvtdUtodxmVfo1Wk eCQTYaNOpRFJth0Bp3edHc8tYYgAlIEO/cRpGjv8JQ== X-Google-Smtp-Source: AMrXdXvDW0olP9LtmWJ8A315j3/Q/IzEUFGybO59puD5PzbAn5d9EepFa2dFtgVk0BkW8ian7AfRhA== X-Received: by 2002:a05:6214:1383:b0:531:a8f3:e8db with SMTP id pp3-20020a056214138300b00531a8f3e8dbmr45231241qvb.47.1673196678952; Sun, 08 Jan 2023 08:51:18 -0800 (PST) Received: from localhost ([185.156.46.146]) by smtp.gmail.com with ESMTPSA id u12-20020a05620a430c00b006ee949b8051sm3912447qko.51.2023.01.08.08.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 08:51:18 -0800 (PST) From: Emilio Cota To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson , Aaron Lindsay , Emilio Cota Subject: [PATCH 4/4] cpu-exec: assert that plugin_mem_cbs is NULL after execution Date: Sun, 8 Jan 2023 11:51:07 -0500 Message-Id: <20230108165107.62488-1-cota@braap.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230108164731.61469-1-cota@braap.org> References: <20230108164731.61469-1-cota@braap.org> MIME-Version: 1.0 Received-SPF: softfail client-ip=2607:f8b0:4864:20::f35; envelope-from=cota@braap.org; helo=mail-qv1-xf35.google.com X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Fixes: #1381 Signed-off-by: Emilio Cota --- accel/tcg/cpu-exec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 356fe348de..de4ba6e23c 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -504,6 +504,7 @@ static void cpu_exec_exit(CPUState *cpu) if (cc->tcg_ops->cpu_exec_exit) { cc->tcg_ops->cpu_exec_exit(cpu); } + g_assert(cpu->plugin_mem_cbs == NULL); } void cpu_exec_step_atomic(CPUState *cpu) @@ -1031,6 +1032,7 @@ int cpu_exec(CPUState *cpu) cpu_loop_exec_tb(cpu, tb, pc, &last_tb, &tb_exit); + g_assert(cpu->plugin_mem_cbs == NULL); /* Try to align the host and virtual clocks if the guest is in advance */ align_clocks(&sc, cpu);