From patchwork Mon Jan 24 20:16:08 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: 534524 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp3148491imr; Mon, 24 Jan 2022 12:33:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJxxNxJl2z1BCUMD+cbl5rmuQXytIFi9lGnSkYBrt6NAtI4ruBjMTHAS9idTOPCu9uEX4JIl X-Received: by 2002:a05:6902:692:: with SMTP id i18mr24145811ybt.410.1643056428926; Mon, 24 Jan 2022 12:33:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643056428; cv=none; d=google.com; s=arc-20160816; b=HL0BOQ6/a2RnUviBvzwNbrCow5ifO8Qq/q2l6Lmi33pBHRvbjztcLu/7A0L8zhzAyp Epv2KeXNP2oux3lfOUz7xMKSfzAARXVYNHNKYiDwbI8chMObg75DtHYLL4ZIBQEyY4ST +99GYzBOGl0/TdwUfIZb3/Njti/rUkjixVUf/m21bi7jTkBzoD0s9yCDPfTEGjxkjQpW 87WVJtHkwnnwFQQeMiDyzCpe2Oge2GgfNBUWDijh1BzR0bfLc15CWEGUlsE3vODPyFwV M+tv4+478u+ag8PVhrHzQGSdNic+zK1iHheLmfwhD3CJhiHAcCV08Pm+1rYEAkSIA8b9 3ezw== 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=MRNIvDYLPOqN3WM8XDKQNxj/+D1kLnUW2Ll6/NI+3fM=; b=dfjeNUUeOTHST6OA/aAS3O5OMwDp5Dfe2ibkQ/TZ3GGyL5zAjCieteazUBsbtnbMlL KrtyJepAe7qXUMKNRAhy5zU4HuXYCg+CpuISWh3OsgMAEvYqoiUbUWMZnH393BZkm+Xa BxjxpzSk6WjXmKNlinb+bjVNwBf/GC3nqnZqUKA0JzUVo86QiuKoXMh22p99bA268FFb Q/mIm6LaScxCTyb7tgGq+CQhcczrGt419LuloIsCEgJMMK+v9mUCoFwkgRiJCgQAfud1 vCbVcdbm05u3nY6OxeO0NY7o5yZqecprW72LV/2KTerQFoFpfq9RDFQVr6ckAsLmZZf5 I92w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QRFR7hTp; 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 r12si11690948ybu.177.2022.01.24.12.33.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 Jan 2022 12:33:48 -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=QRFR7hTp; 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]:51970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nC628-0004pF-5K for patch@linaro.org; Mon, 24 Jan 2022 15:33:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nC5rs-0005It-Em for qemu-devel@nongnu.org; Mon, 24 Jan 2022 15:23:12 -0500 Received: from [2a00:1450:4864:20::536] (port=39613 helo=mail-ed1-x536.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nC5rq-0004K5-IZ for qemu-devel@nongnu.org; Mon, 24 Jan 2022 15:23:11 -0500 Received: by mail-ed1-x536.google.com with SMTP id u18so44385689edt.6 for ; Mon, 24 Jan 2022 12:23:10 -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=MRNIvDYLPOqN3WM8XDKQNxj/+D1kLnUW2Ll6/NI+3fM=; b=QRFR7hTp3ynUvvtF4cEGPxHNn3k3pueplETmOTePGSolhCEq7ksTAiZv2u/uafb+au 0nhs+II+0tsOSMQJAsHpizqIxN91BM94p3UXH4tC+QACnIWnPNnmhK7qJyuDwDmrn+Fa JeO9VvimZSHnJxVODc2sTkF8LcqFkkI54jNR7pWKjp1y95rUe28QkH2eLdy7kN9g/4ym f8QofCdLpLgi30M3YqUINpsyzPiJstdf5dwlMQCnRMs16wVf1I5sceSkibxYv1z5jiVE flb2bCCF8Bkt8rsMAMcQFKfv8zBIhkGxlvjyagopBIvImc1kh+/O0rVRE9GYoR+E+4se XHtA== 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=MRNIvDYLPOqN3WM8XDKQNxj/+D1kLnUW2Ll6/NI+3fM=; b=OPA3vXnPVBgFphsxuEtsGrzu2zNVUA3pXRszywNIix/olBLo3dHkXSyJ4PzOxLG63p Mc05pRyoHEeD8s1XurTWfbEnr+JJ6jljGuAoKSwb4eUvFx4LeRCofSdvZUuG7RxX8HJU 52tSWZbSeaDBFIDjkNUSecT/SDmEGKUAMTnuhfAEXoleBRSLFOKjrjMDx7QIUYOGTJsj pCd8iu3UohTuKi9rEKNnPFv+lWbTVW4Blu6YqpfTfzKAf2qR8n+k/iVgceA27WIl65g4 syVwCbsTySzL2pzQo72DwWN55uxwvL5AxY11wyA5ehjNtHqdzsSGwD5mZGiBn2hQCI+u 6OeQ== X-Gm-Message-State: AOAM530x0pj7dWkPYIfUoFPdAgmf5tSeQzheG38PEtm+yp89DHLRzC7c gaF+nlszx807Gf0WvyUzzlc4zQ== X-Received: by 2002:a05:6402:4383:: with SMTP id o3mr5045113edc.353.1643055789055; Mon, 24 Jan 2022 12:23:09 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id w22sm5279874ejj.64.2022.01.24.12.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 12:23:07 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C62831FFCD; Mon, 24 Jan 2022 20:16:10 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 22/22] plugins: move reset of plugin data to tb_start Date: Mon, 24 Jan 2022 20:16:08 +0000 Message-Id: <20220124201608.604599-23-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220124201608.604599-1-alex.bennee@linaro.org> References: <20220124201608.604599-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::536 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::536; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x536.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 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 , aaron@os.amperecomputing.com, robhenry@microsoft.com, mahmoudabdalghany@outlook.com, minyihh@uci.edu, cota@braap.org, Luke.Craig@ll.mit.edu, Paolo Bonzini , kuhn.chenqun@huawei.com, ma.mandourr@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= 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 --- 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; }