From patchwork Tue Feb 1 18:20:50 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: 538978 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp1126625imr; Tue, 1 Feb 2022 14:44:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJxlJwRL6LKws2k9fU/dSrepBcg/Nrgpa1nZQgbmAu1Ks1x2l2vHFmCXPwMHoDiTz0XNmpJb X-Received: by 2002:a25:552:: with SMTP id 79mr41687951ybf.392.1643755494111; Tue, 01 Feb 2022 14:44:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643755494; cv=none; d=google.com; s=arc-20160816; b=Dk66IHY7N9LjXXsVynPVxYN4eZHMzZvBACKqNb0+OVQmCG79hRGM385qVXBrKar9jo ZwK8tHAy8FYVlY5M23y/5Wi+gmswCPwXOh5gIesdcxGdEJtTMTzAfuyRS7t3Lb0rvfnN Iz08DxZPqkghTWzqPphqFnwq90dJIqc7RQuQmqfE4NS3G7JAoX8Eo8jekCD5eH0He3mp 5KhRSIrDq7soTUMR8IX7v2vXCvPYYzO2uiqHagBQFYQ/v6pFDOpTX9NnuPtLKLhWCYd0 zDyrDrzqGNxgXW/Pbl6rU5HfJiNGYaQ55CRUmaG6bADrz+rU6id5VnzN6R2ZTqVt76+7 PjyA== 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=EhmXOO/6q9XmPV09312oaXBgVpi24xyzc4IO4oCe4TQ=; b=hlVdrHgw1Hm+fAkPKR3ETpMi+wf7/CuUZBRB3qeALb5F219vgxpQVjrqv/plsm8sBB v7MN10V3XMUldM0dgGGdew5G3mzWllBZ7B3ul+sfW14bz0AMQBBqcTXSY4MKpTQNYkMe yICu72NcNkrcQ32yqZisgjijeaTFik8VTh0dZUmVbPeDVgN09Q4T/Ti/qPKWzcXiFXzx QBVxrnURefeHUP9yqj51JrfSrezWULE1HSHmarXoHZmPcVg8BwbiPTjDlm0//Ay0DUfx LGiMRSrYZAo4nvgXC7kwMiu0LEojXMd36JoK8GGDY+tWIuewWSvSbK5GeWv+lBqGNZ9L gLmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=FGjGSEwR; 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 k199si34828415ybk.732.2022.02.01.14.44.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 01 Feb 2022 14:44:54 -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=FGjGSEwR; 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]:33966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nF1tN-0000He-Gm for patch@linaro.org; Tue, 01 Feb 2022 17:44:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nExnX-0008Cx-6V for qemu-devel@nongnu.org; Tue, 01 Feb 2022 13:22:36 -0500 Received: from [2a00:1450:4864:20::62a] (port=41506 helo=mail-ej1-x62a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nExmY-0000fA-U7 for qemu-devel@nongnu.org; Tue, 01 Feb 2022 13:21:36 -0500 Received: by mail-ej1-x62a.google.com with SMTP id a8so56641389ejc.8 for ; Tue, 01 Feb 2022 10:21:13 -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=EhmXOO/6q9XmPV09312oaXBgVpi24xyzc4IO4oCe4TQ=; b=FGjGSEwRA1Ne87wtvz84S0Rjl1HDNlOM+Bj29reXxtQFIJZ5npsQsG1jevq8jd+vUG tZWWL717PAfB3pXProq7nNg/2h4ysF7XtWV8WKq2egbUhqhUikcuePb6beaY3Cr5SJVV 92LJxZ/2bnc0lfNN+oRqT46ZmCAXONOgVJKLt2azwQBKAnPUvLS8QwlZyooE0US6xDSV hK5/hZaQRAuVpiAKgUmHAGp+PnbXuMcj2y8sWEdIrTNgf3acF6wIO/De6tG3+dA/D/zV 8oIUFLj65Y03R6ij0CVU9mAngYhIZJUxTp1nfQr2suLZsx0QJwrHFCbCCuacnZDT6NfS qxhw== 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=EhmXOO/6q9XmPV09312oaXBgVpi24xyzc4IO4oCe4TQ=; b=v+puPUNOtnclcyhJb0KpsCd7TZ2NkvWa5WGLFR7q2Zzyk2e3layKM7g1d8KgBI4iHr R50CGb3+zVptq0a42A2GnmGLPnebgC/KRfu1Y7qux0kDJTBMrKa+WPZoSIOwnKsICqaB c3x/0pdy1YceFNC90plT0upDOa00p8GUHS6fAHUkvl4jiOIgYSegunZSjJtPFP+oEehg bJQ+il9JHhgEvVrNrpjdnhIsgLOBAexYSLBV4NMp6HSr2QcAL+aaiut6z5Elkjxo1eO7 5rUtb/TyABmVhe5H/QWrQpGWBmgqnYyy8kujsEKc6qJEPCzd4u4/V+g7XwyBYg4ZrtG1 xqnw== X-Gm-Message-State: AOAM533ii5Mj4eycVg4pT6Ys31PbCP8o16UXqJPtr1uDK8Ii8SOrFSXc RSMIFg0MrboQtg0aatICn752RQ== X-Received: by 2002:a17:906:a250:: with SMTP id bi16mr22474672ejb.732.1643739672770; Tue, 01 Feb 2022 10:21:12 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id c14sm19901454edy.66.2022.02.01.10.20.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 10:21:08 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 1F2121FFD0; Tue, 1 Feb 2022 18:20:53 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 25/25] plugins: move reset of plugin data to tb_start Date: Tue, 1 Feb 2022 18:20:50 +0000 Message-Id: <20220201182050.15087-26-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220201182050.15087-1-alex.bennee@linaro.org> References: <20220201182050.15087-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::62a (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62a.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: fam@euphon.net, berrange@redhat.com, stefanha@redhat.com, crosa@redhat.com, Richard Henderson , aaron@os.amperecomputing.com, robhenry@microsoft.com, f4bug@amsat.org, mahmoudabdalghany@outlook.com, minyihh@uci.edu, cota@braap.org, Luke.Craig@ll.mit.edu, pbonzini@redhat.com, kuhn.chenqun@huawei.com, ma.mandourr@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , aurelien@aurel32.net 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. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/824 Signed-off-by: Alex Bennée Message-Id: <20220124201608.604599-23-alex.bennee@linaro.org> --- accel/tcg/plugin-gen.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 22d95fe1c3..ae70e4a5b0 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -854,10 +854,21 @@ 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; + tcg_ctx->plugin_insn = NULL; + ret = true; ptb->vaddr = tb->pc; @@ -904,23 +915,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; }