From patchwork Wed Feb 9 14:15:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 541102 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp1408960imo; Wed, 9 Feb 2022 06:57:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJyiU4M1aAnwHhFgZLuvrBPcx6pTkW3Yh01uv7yvuVdufG0ArX4aSe4pPBRKvxUf6wSXjCmo X-Received: by 2002:a25:b90f:: with SMTP id x15mr2263636ybj.423.1644418655182; Wed, 09 Feb 2022 06:57:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644418655; cv=none; d=google.com; s=arc-20160816; b=Iqbt7Wp2q7OEnj3C9yIKhNdCOvs3RmQBSizQewEView4e9K4v5V+/I8NSvzJsGUruL USjJc+zFaE80QYl7mTTe8w51nfFd8fsfhJcWK0ERMSDICTqSdAxDm4T5nG+HdP3udiNi Kjh5ti3Sb5lRAJjZrVpfgIkYONKntwzDkxUnrPr8Yd8ITiU4RI9BvLL83L35JeF59h10 bd7/R01eHdw6+gR5/WbiuTVHxV4JFRQmiSDBz15V4Hbh409c1tv70ghg8KxsLf1IUL0x ubNRm84U9O4+yIRFXaOVGbIhE5DDpxyMEYwKREY4DoLnHg02fOB5UWPs0jHthgNQJ4ie DkNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from :dkim-signature; bh=XggHg/DQ8QhJtcx6aM9YPetrL2sQVDLzuBfvyJu1Zn0=; b=iVyJIMcU1QO453fJqM9VTDRxR4LqwNM2KKmCIH5yXnq8d3wzYBgYlLYw3DFSLHT8aq xj2EKhMazCGKEVQdAg6Rc+dTV8LJdGmYOjr4D2c1Rbp1OWEnp243SpdI2m/IQXAreKjF Yj6nS66Roh+YwDLB6zGNps6rYXnxA/KXPE8UiJBcicfzC3mchW+Bu1F3Cmi8sIevIbGN e/qodZD3aGQIrhi7yNEl0rEK8TGchAVneRdkNizr8jL7qKP046GVKOyqLJwNrZJtGjE7 lhle6TdUOR9EvhR1BRINRYezys1X2zaAOp82FYEKJwjYyLZJZFiI/96hO8N7ETM38cVb B8mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="aIpTCKE/"; 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=fail (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 k7si13055142ywb.4.2022.02.09.06.57.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 Feb 2022 06:57:35 -0800 (PST) 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=fail header.i=@linaro.org header.s=google header.b="aIpTCKE/"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:44644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHoPW-0005WD-Mn for patch@linaro.org; Wed, 09 Feb 2022 09:57:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHnty-0000L9-2Z for qemu-devel@nongnu.org; Wed, 09 Feb 2022 09:24:58 -0500 Received: from [2a00:1450:4864:20::42c] (port=39757 helo=mail-wr1-x42c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHntw-0001LD-CO for qemu-devel@nongnu.org; Wed, 09 Feb 2022 09:24:57 -0500 Received: by mail-wr1-x42c.google.com with SMTP id d27so4356242wrc.6 for ; Wed, 09 Feb 2022 06:24:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XggHg/DQ8QhJtcx6aM9YPetrL2sQVDLzuBfvyJu1Zn0=; b=aIpTCKE/V3kV8ZxRfMOHBwLIFNITUdlQquFH/oL1lgvRguf9gkT9Fl5muFyU9Dy/lw iMJuoNrmhHUEilVQlbHvNFLOZCf+YdRdEMtiDyhqT/4eeDJcDRxH2n3sXDwcp6SYXTvd GigR3sfWTCAfDd1D7r+V+Hn66jnRlHaMSbrqD3ob1pGVC6PHH1vqvg1+2vAkyycJGj7V eZxjMjhppIxr6LUzX/uXf49Oe51l0nBd5yLjf4gVU3PYjIiNkjB/V12dtuoMuUN2LDBA KKwDuTr3xzL2Xv3dzPZ4RkMZt+jtaaxEx2SCY2kSYKxO5QZd/Z3i4VkETVRwKBNTINi2 5wyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XggHg/DQ8QhJtcx6aM9YPetrL2sQVDLzuBfvyJu1Zn0=; b=LPOjW8QnFv/AkqTx60o5jPcdFDNesVt2d2dEQ0U6p8psKEMCxjTsw1gMTjK60h5XLp psHYIzfEDu6wvsnK/5c97PwHZx6Rao3Pb4kGjK3mXbTKiHAlk6LcVqxyz7BNwN3IGlHX YTO6iRrWqlDKAoh2lH2/VmbM0foNY0Vl2FgNP0Gq6Btvu5j8rUsX+23QMYFLdVLPQuuG UELHHQj0djYn0i7rnH7hd6JTGuj+muZe0W1vDeICV0beIC+QSaKC+BrfjiNPwstYaYkW S+9YpB+O7yg3kq7uQswyADpdp2Fz7K8SMetDO7qrEA7s/PMo8jWcllneWc/YeBU7qQdR cSjQ== X-Gm-Message-State: AOAM530tkS4I4rqnmO2y7PHlIofoR9aNSEJ7uUu3ByzJuCxGgDKv+XPQ VMzY8w0VcPQk+4C4XOFKpwWIwA== X-Received: by 2002:a05:6000:15c4:: with SMTP id y4mr2346168wry.522.1644416695025; Wed, 09 Feb 2022 06:24:55 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id r11sm7428925wrt.28.2022.02.09.06.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 06:24:49 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 99FD41FFD1; Wed, 9 Feb 2022 14:15:31 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL 26/28] plugins: move reset of plugin data to tb_start Date: Wed, 9 Feb 2022 14:15:27 +0000 Message-Id: <20220209141529.3418384-27-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220209141529.3418384-1-alex.bennee@linaro.org> References: <20220209141529.3418384-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42c (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42c.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We can't always guarantee we get to the end of a translator loop. Although this can happen for a variety of reasons it does happen more often on x86 system emulation when an instruction spans across to an un-faulted page. This caused confusion of the instruction tracking data resulting in apparent reverse execution (at least from the plugins point of view). Fix this by moving the reset code to plugin_gen_tb_start so we always start with a clean slate. We unconditionally reset tcg_ctx->plugin_insn as the plugin_insn_append code uses this as a proxy for knowing if plugins are enabled for the current instruction. Otherwise we can hit a race where a previously instrumented thread leaves a stale value after the main thread exits and disables instrumentation. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/824 Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20220204204335.1689602-27-alex.bennee@linaro.org> diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 22d95fe1c3..3d0b101e34 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -854,10 +854,20 @@ static void plugin_gen_inject(const struct qemu_plugin_tb *plugin_tb) bool plugin_gen_tb_start(CPUState *cpu, const TranslationBlock *tb, bool mem_only) { - struct qemu_plugin_tb *ptb = tcg_ctx->plugin_tb; bool ret = false; if (test_bit(QEMU_PLUGIN_EV_VCPU_TB_TRANS, cpu->plugin_mask)) { + struct qemu_plugin_tb *ptb = tcg_ctx->plugin_tb; + int i; + + /* reset callbacks */ + for (i = 0; i < PLUGIN_N_CB_SUBTYPES; i++) { + if (ptb->cbs[i]) { + g_array_set_size(ptb->cbs[i], 0); + } + } + ptb->n = 0; + ret = true; ptb->vaddr = tb->pc; @@ -868,6 +878,9 @@ bool plugin_gen_tb_start(CPUState *cpu, const TranslationBlock *tb, bool mem_onl plugin_gen_empty_callback(PLUGIN_GEN_FROM_TB); } + + tcg_ctx->plugin_insn = NULL; + return ret; } @@ -904,23 +917,19 @@ void plugin_gen_insn_end(void) plugin_gen_empty_callback(PLUGIN_GEN_AFTER_INSN); } +/* + * There are cases where we never get to finalise a translation - for + * example a page fault during translation. As a result we shouldn't + * do any clean-up here and make sure things are reset in + * plugin_gen_tb_start. + */ void plugin_gen_tb_end(CPUState *cpu) { struct qemu_plugin_tb *ptb = tcg_ctx->plugin_tb; - int i; /* collect instrumentation requests */ qemu_plugin_tb_trans_cb(cpu, ptb); /* inject the instrumentation at the appropriate places */ plugin_gen_inject(ptb); - - /* clean up */ - for (i = 0; i < PLUGIN_N_CB_SUBTYPES; i++) { - if (ptb->cbs[i]) { - g_array_set_size(ptb->cbs[i], 0); - } - } - ptb->n = 0; - tcg_ctx->plugin_insn = NULL; }