From patchwork Tue Oct 15 00:38:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 835402 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c8f:0:b0:37d:45d0:187 with SMTP id z15csp50wrs; Mon, 14 Oct 2024 17:39:29 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVhb7/MbHRqQlhIagDtF2AZlB05PIAJUzsdkWZj44PR8a0Oqm8abFrv2RgRzhdWlniAHHvBqg==@linaro.org X-Google-Smtp-Source: AGHT+IGX30zJ6ziwh1NfoYmDIU7JcFbCdR/GhpfFlbcyD5je7M92dTLafeE4xjWP5jLPIk92bsJA X-Received: by 2002:ac8:5f12:0:b0:458:217d:be48 with SMTP id d75a77b69052e-460583fc582mr182126721cf.14.1728952769391; Mon, 14 Oct 2024 17:39:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728952769; cv=none; d=google.com; s=arc-20240605; b=YPdTvNF9p/sG3XxkWmn1liwQ+z76aAedW7c0CAbRtL44vG187z0aTv9gGbhl6Gml1j E8wBa5QgDmFr0xdkfSx5l2qSEK1bsmWfSy50NjgINVnzB1fIYbP7BEPv2qYqJ5KeMs4P whT0+POkVG3+OOkkl/5fWTigXIkFdR+Y6uw0imlplm9h+DhKuurTYpA2h65joxl2JcqY pXM/98RERetlkb84GvWhiHP2JugfEDzw25ad8vqqiRmpyxyx+9bmFzTDmphigbuNeSWJ +dmgvp+T6DMz0pJ7UT7TAnoIRfGFlx2rYN49MAAuYCpTaGJd+5eb97gZODY/jWSiG9Zg qQRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=sKdTmWQZMuc+B9+0ZkccinXkQqU8Wb8KTqtA56Nb0ww=; fh=dv+oXJeazpvil0yFWljkv1Q/sIi6LFwp1XcA9k9d5AE=; b=T8jzJ6wrTi8J8r+tk4vbQz+R3veVrD0QC0CgUs44Y/asG+gpovIJe04UnuTlDPlsKK zxk4AO6ca8X3jxVBots85Edi16/kqiHnbq7m9+d+UH6k7I+FEiLxbfI75EbFo4E2urzz WBL2f9tKw0zOcCxemEPDg6d1nOfVwXHJJAfBuUPaYpiG0KIeQbX1tPNjPZeodhOOfHwZ WlVUwyoxMjfGui8gZqngTIMQZgxw5Di3MWRPhhEQepTPQ1RkQaB2xhFkTXxyvVHPyQVK oTiyoAN/1QFsm7TPm0VQUTEeFornbR8CE08Un2iWRSmze+4DZWBy8fT6Lkgzed8mA16r T41w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gU5GreiV; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-4607b4c963csi2757141cf.588.2024.10.14.17.39.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Oct 2024 17:39:29 -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=gU5GreiV; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0Va1-00022L-05; Mon, 14 Oct 2024 20:38:29 -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 1t0VZz-00021x-Sj for qemu-devel@nongnu.org; Mon, 14 Oct 2024 20:38:27 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t0VZx-0006BX-O9 for qemu-devel@nongnu.org; Mon, 14 Oct 2024 20:38:27 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-20c70abba48so31165765ad.0 for ; Mon, 14 Oct 2024 17:38:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728952704; x=1729557504; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=sKdTmWQZMuc+B9+0ZkccinXkQqU8Wb8KTqtA56Nb0ww=; b=gU5GreiVKkb7eQjWUok7okLqF0JwJa33WbKI7JU3uBx+QoJgh81TUWGfnE1h9riPxB dupkgbrP7X3iQSFUhE6kVPFgDxuuqAY9wI2UV7trK7vFM6NM8m/jhqhkdlvGSuRn+Gq0 GzZFHm87ukM4S6sl1XGdkF1wtrun6jc5w5ob6Q/Totqfgetj57FMmiU03RV+U/uZlwcy Fqac14IJ2QeEJH8EPJahRJHHchTITQ0Y3+wchtYGjBIBeD8CTbE1AUV1k4+5m4Fb8aNJ BfsNKhYmYx5TNUacZzzUOd6Xrm38ZU+7oQyzO/utPxYuDqD9a2q3JLHQpF/87KLcagLP 9Hxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728952704; x=1729557504; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sKdTmWQZMuc+B9+0ZkccinXkQqU8Wb8KTqtA56Nb0ww=; b=Zl+lwCJb4tNqiIr0Rm985YrK+/r4vRVmZX4MApqyQEZSgtJ3dxwHIQgxpus4cSV0i3 +DBQDVGe4BLbPU6zpQUuAICWzHOC6uaWFRKIpy0KJ4q81auoTpRqUbFLGiJRqUICvWuQ ku4Bu+gp+EsoulS0KroouZeRYj+F2XR6sCRp9ntXYATe3wpf34Po/9izMHmvd4jC3FG5 vN/MEeLjvJlyGBgUsGRvRVgwUsBvERfGfGmMdbgIfPBKSyVqXfghusIWuEYxzgesO/X7 NT+TRLu2jG7Bu77VqM6OV0aZ3AcdLaB7f6G7HfY0Qnwspq/DoOylxrI7EkIzvOxZBc0k TWvQ== X-Gm-Message-State: AOJu0Yy79paAtFKtvNfnUnUyVlEQwYejYHAljwer8fJGmlbgMWjDeOEX 6mCpjtNgEX+/KsG1vhM6kxx5abfmt7zo5aqGIqBkRSMSLsrreGEm7Ck725dGup+utfU41pY2v3J QeI2+nw== X-Received: by 2002:a17:903:41c1:b0:20c:6392:1a7b with SMTP id d9443c01a7336-20cbb18355dmr181925455ad.2.1728952703750; Mon, 14 Oct 2024 17:38:23 -0700 (PDT) Received: from linaro.. (216-180-64-156.dyn.novuscom.net. [216.180.64.156]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20d1804b716sm1287345ad.202.2024.10.14.17.38.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 17:38:23 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Paolo Bonzini , alex.bennee@linaro.org, Richard Henderson , Pierrick Bouvier Subject: [PATCH v2] plugins: fix qemu_plugin_reset Date: Mon, 14 Oct 2024 17:38:19 -0700 Message-Id: <20241015003819.984601-1-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62e.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 34e5e1 refactored the plugin context initialization. After this change, tcg_ctx->plugin_insn is not reset inconditionnally anymore, but only if one plugin at least is active. When uninstalling the last plugin active, we stopped reinitializing tcg_ctx->plugin_insn, which leads to memory callbacks being emitted. This results in an error as they don't appear in a plugin op sequence as expected. The correct fix is to make sure we reset plugin translation variables after current block translation ends. This way, we can catch any potential misuse of those after a given block, in more than fixing the current bug. v2: do not reset tcg_ctx->plugin_tb as it gets reused between translations. Fixes: https://gitlab.com/qemu-project/qemu/-/issues/2570 Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Tested-by: Robbin Ehn --- accel/tcg/plugin-gen.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 2ee4c22befd..0f47bfbb489 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -467,4 +467,8 @@ void plugin_gen_tb_end(CPUState *cpu, size_t num_insns) /* inject the instrumentation at the appropriate places */ plugin_gen_inject(ptb); + + /* reset plugin translation state (plugin_tb is reused between blocks) */ + tcg_ctx->plugin_db = NULL; + tcg_ctx->plugin_insn = NULL; }