From patchwork Tue Oct 26 10:22:26 2021 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: 516207 Delivered-To: patch@linaro.org Received: by 2002:ac0:c404:0:0:0:0:0 with SMTP id t4csp165606imj; Tue, 26 Oct 2021 04:00:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWVeDWieFdJyYlFB/wwDiciLV7p1h3/bhZEfaVEFYeDzVctEyjQihPuYjMh9rLGSkuXyXY X-Received: by 2002:a9d:17cd:: with SMTP id j71mr19359339otj.169.1635246039740; Tue, 26 Oct 2021 04:00:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635246039; cv=none; d=google.com; s=arc-20160816; b=UujzFd7xZqsbLQqr8TVRfE9ly2HYncRoEaVps302jR/vvmIzCEUHr+z9WHnMZFvRWk Ah2lko9z5IScqRWiYVNDNO+eDdHYBVAjmGlSmi1j8opJ69iQR31KdSiW5Vb23M5VCSUb b/wSsU4NT1h81uv1Q5BUOp0VVesWpiiX2GOsrYQD2vH9fhMn+rygJyua6NpFxOeiJw3s 5mJmsjKZQt0kjHq0SzpjIheB1Pnu/2BMpP9DOIqg5r0mTbxH/N+T9QwhVFJS6yFoB+bl RgYPNuZ7f7ZwiSVeXD2XVgLn2dUdBLKp/TRzl8iKmBmTbMV5klNisvgBw/hogCrHUm4g rMiA== 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=IQrJ14mdqhvYV5+ImzRfNnyvnL5jhONPouFr5OP3Q0g=; b=Um4I2RrTVEqDQLV+UzHmEUaggbKahZqUyYhxC1vC2nm29zHlQVAFQ9OO0EAWde5/pj N+Pgj848uBXy4W8u9Ftn67YhhR3MvIzvC5DZ2R6pcOVSO16eL/skHMp71zxx5ZvRNDDM 38/wIG771ejmeIwHqDYiL/21x+E2NkNO7YvjSgdIuey99TGQKuUh2hpeVRg8HPXDCtTB s7udBqeWCzeIgyfdqJsIS677Bx+ra9TbeZw1kqL20+6mDWJJ9khipyzjsne4Fv0a5FIr M4Mt+W0UAFYxP630v97XBAx9sc0CxdDXmO8CJ9oQj3UPXKN7woN73Duvpr2zxzvzMX+R hK3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RTbbwTtF; 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 m7si17296198otn.123.2021.10.26.04.00.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Oct 2021 04:00:39 -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=fail header.i=@linaro.org header.s=google header.b=RTbbwTtF; 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]:33990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfKC6-0001pZ-Ry for patch@linaro.org; Tue, 26 Oct 2021 07:00:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52958) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfJi9-0002ZZ-No for qemu-devel@nongnu.org; Tue, 26 Oct 2021 06:29:41 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:39659) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mfJi7-0004hG-MX for qemu-devel@nongnu.org; Tue, 26 Oct 2021 06:29:41 -0400 Received: by mail-wm1-x329.google.com with SMTP id y205-20020a1c7dd6000000b0032cc8c2800fso1657666wmc.4 for ; Tue, 26 Oct 2021 03:29:39 -0700 (PDT) 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=IQrJ14mdqhvYV5+ImzRfNnyvnL5jhONPouFr5OP3Q0g=; b=RTbbwTtFpfHshnfXcSscNDh1eDMdOy5eZ5ZGj/Sf5DGdw/dKHxnpW4ulX0VuG0hVgj 8ECZIH2ye5Q0xKlAPOr20KU580CKgFZKAMHqDUDlH4DObaorvOxG40YEp7U3rRg7KJjl FEeKJFkONVwtVqkBt+yqykB51E1948RgVP9Rcth5dlwzEd5ftGSWfHbZlig5wRKRTCma 8cS/VrVjNQ0FRHX5InoAcCBizxxuUqGaRUlDoQo6rgDNiYLutPmDnFkiPYTqnS2lFZNs 7oJ9Ou9YJMv6LxAzpq/yJG/1CKSEBwJ+Tkh2VeNLAQ1SyxruGx5K5jVaxqOZDP0s02I0 N9Eg== 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=IQrJ14mdqhvYV5+ImzRfNnyvnL5jhONPouFr5OP3Q0g=; b=QrIzt81x4rIHngOqgtgewFoMmuSWiTT6u2EDcz5VH1zyUdURsdCG+cXFkG9Q2I7QCk AiL3h55iAcmV9jQWKuebuSZPdpMhaL0zWb1Zd9QI1IDQxYIjh81HrrH0JVc/IkRRsrT6 twT2nrRndgl1k2VS4MUuJCDGHUF7n7sMPoPiueR9CSgYvVZsoN4FPTQQ7eE0QcmBeNiT nr2pXGInKjqQA4N2epCDRfc9bBA6R5FNUuIRVWLWj5c+dJGh8Vf6eUuifY5H4B6lXpDG 6c+ctC6wcJGvRZ0ngdDGm6O+2aWbc3rfPdsQfAQx/Yd8TGZuiwPi+h3Xj2bqhf+Guc+c e5bw== X-Gm-Message-State: AOAM532ELl8yPFLMIjYoaEYHjSSZ53jXyLbYS5bb71j52JipY5lY6eVK ig2jLbUzxqvAx3qVtKC8unBzGw== X-Received: by 2002:a05:600c:21c5:: with SMTP id x5mr18646500wmj.27.1635244178354; Tue, 26 Oct 2021 03:29:38 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id q14sm9155325wrv.55.2021.10.26.03.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 03:29:29 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 817FE1FFB5; Tue, 26 Oct 2021 11:22:36 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 20/28] plugins: try and make plugin_insn_append more ergonomic Date: Tue, 26 Oct 2021 11:22:26 +0100 Message-Id: <20211026102234.3961636-21-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211026102234.3961636-1-alex.bennee@linaro.org> References: <20211026102234.3961636-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x329.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, minyihh@uci.edu, berrange@redhat.com, kuhn.chenqun@huawei.com, Richard Henderson , f4bug@amsat.org, robhenry@microsoft.com, mahmoudabdalghany@outlook.com, aaron@os.amperecomputing.com, cota@braap.org, stefanha@redhat.com, crosa@redhat.com, pbonzini@redhat.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" Currently we make the assumption that the guest frontend loads all op code bytes sequentially. This mostly holds up for regular fixed encodings but some architectures like s390x like to re-read the instruction which causes weirdness to occur. Rather than changing the frontends make the plugin API a little more ergonomic and able to handle the re-read case. Stuff will still get strange if we read ahead of the opcode but so far no front ends have done that and this patch asserts the case so we can catch it early if they do. Signed-off-by: Alex Bennée Suggested-by: Richard Henderson --- include/exec/plugin-gen.h | 12 ++++++++++-- include/qemu/plugin.h | 7 +++++-- accel/tcg/plugin-gen.c | 3 +-- accel/tcg/translator.c | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) -- 2.30.2 Reviewed-by: Richard Henderson diff --git a/include/exec/plugin-gen.h b/include/exec/plugin-gen.h index b1b72b5d90..f92f169739 100644 --- a/include/exec/plugin-gen.h +++ b/include/exec/plugin-gen.h @@ -27,13 +27,21 @@ void plugin_gen_insn_end(void); void plugin_gen_disable_mem_helpers(void); void plugin_gen_empty_mem_callback(TCGv addr, uint32_t info); -static inline void plugin_insn_append(const void *from, size_t size) +static inline void plugin_insn_append(abi_ptr pc, const void *from, size_t size) { struct qemu_plugin_insn *insn = tcg_ctx->plugin_insn; + abi_ptr off; if (insn == NULL) { return; } + off = pc - insn->vaddr; + if (off < insn->data->len) { + g_byte_array_set_size(insn->data, off); + } else if (off > insn->data->len) { + /* we have an unexpected gap */ + g_assert_not_reached(); + } insn->data = g_byte_array_append(insn->data, from, size); } @@ -62,7 +70,7 @@ static inline void plugin_gen_disable_mem_helpers(void) static inline void plugin_gen_empty_mem_callback(TCGv addr, uint32_t info) { } -static inline void plugin_insn_append(const void *from, size_t size) +static inline void plugin_insn_append(abi_ptr pc, const void *from, size_t size) { } #endif /* CONFIG_PLUGIN */ diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index b3172b147f..145f8a221a 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -163,10 +163,12 @@ struct qemu_plugin_tb { /** * qemu_plugin_tb_insn_get(): get next plugin record for translation. - * + * @tb: the internal tb context + * @pc: address of instruction */ static inline -struct qemu_plugin_insn *qemu_plugin_tb_insn_get(struct qemu_plugin_tb *tb) +struct qemu_plugin_insn *qemu_plugin_tb_insn_get(struct qemu_plugin_tb *tb, + uint64_t pc) { struct qemu_plugin_insn *insn; int i, j; @@ -179,6 +181,7 @@ struct qemu_plugin_insn *qemu_plugin_tb_insn_get(struct qemu_plugin_tb *tb) g_byte_array_set_size(insn->data, 0); insn->calls_helpers = false; insn->mem_helper = false; + insn->vaddr = pc; for (i = 0; i < PLUGIN_N_CB_TYPES; i++) { for (j = 0; j < PLUGIN_N_CB_SUBTYPES; j++) { diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 61be64b78c..22d95fe1c3 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -876,9 +876,8 @@ void plugin_gen_insn_start(CPUState *cpu, const DisasContextBase *db) struct qemu_plugin_tb *ptb = tcg_ctx->plugin_tb; struct qemu_plugin_insn *pinsn; - pinsn = qemu_plugin_tb_insn_get(ptb); + pinsn = qemu_plugin_tb_insn_get(ptb, db->pc_next); tcg_ctx->plugin_insn = pinsn; - pinsn->vaddr = db->pc_next; plugin_gen_empty_callback(PLUGIN_GEN_FROM_INSN); /* diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index 390bd9db0a..f06c314266 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -169,7 +169,7 @@ static inline void translator_maybe_page_protect(DisasContextBase *dcbase, if (do_swap) { \ ret = swap_fn(ret); \ } \ - plugin_insn_append(&ret, sizeof(ret)); \ + plugin_insn_append(pc, &ret, sizeof(ret)); \ return ret; \ }