From patchwork Wed May 15 07:52:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796886 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp2854067wra; Wed, 15 May 2024 00:55:27 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVp2sbg3vPwA6b0m7hlu1SyRckXQxZwHjLzM4Z9WRbFP5WHgqqAO8xc5muFVIxSYUC0e0rxPzo48Sbfb979CDfD X-Google-Smtp-Source: AGHT+IG9cW3M3+AsObPAG161Bovd9F7tv23Jk+lfPUzxHQaoGgQB9lecqCSfZ4dDkSkdtV5YT/mj X-Received: by 2002:a05:6214:4412:b0:696:4086:5e1 with SMTP id 6a1803df08f44-6a16790406fmr233982196d6.2.1715759727104; Wed, 15 May 2024 00:55:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715759727; cv=none; d=google.com; s=arc-20160816; b=MnmiAfMZY8zsP2ydtdXMnow7BWU1b6luEe8Pnj0N3jtOp500fxfVXIj0+T33S2W2pj 4NPGaKKf1dvSFY4qX94sw+2x/OSIQw1vXNefLB3adF4RttVnLya3wrWc0rd22rpl/WEJ WXpIiIqMDIef8iIxkuYp9rH59K+u4r7Q/UHqCsE3CRojuUnHtzWSACQ0diDwUsV8r6FP SjUr9gIlMPiMCc+q0t4X+AnXPoj6CImAVE3j+GI/F+lQfXRjB1/Xfr2caKYBw3ke2Ld/ UPe0cwY91k/hXj8yGsXMPLU+ZJKrhah0nWg8nabykOMtK/arp32We7ZDAg4UJyR/ZpHA scfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=NHmxyaHJvfTQV6eJCp+0w5/I7rCSGxf4lZPvvgw/PM4=; fh=vm85eyWrvOAHduw3sqEA+cYBqvHB7M0MHFcRJg7VWOo=; b=rGvFy/I3so3duVkx5V+x5MyPI2VA76rNQp85Jg+8k51tFbZF4RS1ADzvvteZOxdy/H h+cbvl1n5ttFwp8Fcnp8c4wWbmtGVmPoi9KY0tfMinSvWqQr8YrWUmgL6fOcXDmbtBm3 uoRs0ZkkR1DRRNUo7qZDjcRGjcfRHf+7FEyAgq1L/iO13yfSnrwpK6FVRj+4hGnMlShm 5cSzSdm04fdcCMyVctFLxYb62Re4C8cT/10Wzb0Fkwtp23LchRG2CM3Z1MU0v5JL/2jx 8lojiZhAcDe4OmfU0IXdLxeasxwhwFIyX9Pr587XS4JLtfMjmPCBaDdJ+FIm/bpzCyhi LuFw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=c1fFZEoZ; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-43df566f8d3si132852041cf.280.2024.05.15.00.55.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 00:55:27 -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=c1fFZEoZ; 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 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s79Ri-00048u-75; Wed, 15 May 2024 03:53:06 -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 1s79Rd-00046Y-Op for qemu-devel@nongnu.org; Wed, 15 May 2024 03:53:01 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s79Rb-0001Zq-DK for qemu-devel@nongnu.org; Wed, 15 May 2024 03:53:01 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-41ffad2426eso48854145e9.3 for ; Wed, 15 May 2024 00:52:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715759578; x=1716364378; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NHmxyaHJvfTQV6eJCp+0w5/I7rCSGxf4lZPvvgw/PM4=; b=c1fFZEoZQE131nGH/6H3/4+xJj0Dc750RMzM+AWRkM16s13X0mTdrDCPT/sGHLFXx4 n7H3vvEBpV/yw4XYbbSPrdImo93O/DawUW4vbkyyHsCQEnPm1JHWPobNsu4kLhN+Yu1F RW+R2hxNWTi/5JeuMCMXCtiCnzbNtOpl38rdNiqfma5m0+8yT3EubfY7CPSROb9GWlOy FlxhWI26pVUVn9xlZCsiKc3Gd+jFAJdz/kBrU9q4Bvgevm1a+fKYX00rO72p1q8S4nff M8O4MWdRYjphvR3EVuYl3dv75hxN6G3ErRfBwXRQH5tr70EO/+FoISofilpUbUb30gYz 4F1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715759578; x=1716364378; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NHmxyaHJvfTQV6eJCp+0w5/I7rCSGxf4lZPvvgw/PM4=; b=c6P07/8CmWKg7ZzfVawyx/lcBBudUzYSVIJVtR+7TcdqYfQcgxs/eSNelNXutKMWCR /ya4QhLqdsOgv7iP7qrjPiTQKyZDG10DbuWcj+8Sy5/tmtY1YiDQO1II+3kJLTgtAuxO 2xx35pSNR6C/a2dvXclI+v7tvfNRRjOdOpuefmCoFckME1Fm1Yua87jpwHqS6tNSKbrZ WExp59LddwiRkG5GWfDiYfhpFQNBNe/1SzeYWY4Wq1/71z15vuR1UZnw7Mii0uT14G0j ujh7awnIChxq3MgtBwRGyOB9XWsA9nuLLPhE6U5tKHrwcdnG9ATdxzxOwNW5Uu4RsRaj r58w== X-Gm-Message-State: AOJu0YwooE6fsqyfd9eelaMA65Ub3J/ZrEcPP+Arjqog5Mi3iIWq2ZCm 1aXTwj3vuqW13JCwRlg9+Rd4vxwRbeVYJID3haAXgX3HpIgJQUPWbRB7Yrza/H8tOvOgznRke44 UYKE= X-Received: by 2002:a05:600c:3548:b0:41a:6edd:6c1d with SMTP id 5b1f17b1804b1-41feac55e10mr130103785e9.32.1715759578121; Wed, 15 May 2024 00:52:58 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41fccee9292sm222611855e9.37.2024.05.15.00.52.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 00:52:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier Subject: [PULL 13/34] plugins: Use DisasContextBase for qemu_plugin_insn_haddr Date: Wed, 15 May 2024 09:52:26 +0200 Message-Id: <20240515075247.68024-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240515075247.68024-1-richard.henderson@linaro.org> References: <20240515075247.68024-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32d.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 We can delay the computation of haddr until the plugin actually requests it. Reviewed-by: Pierrick Bouvier Signed-off-by: Richard Henderson --- include/qemu/plugin.h | 4 ---- accel/tcg/plugin-gen.c | 20 -------------------- plugins/api.c | 25 ++++++++++++++++++++++++- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index c28d0ca31c..da0f37e269 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -99,7 +99,6 @@ struct qemu_plugin_dyn_cb { /* Internal context for instrumenting an instruction */ struct qemu_plugin_insn { uint64_t vaddr; - void *haddr; GArray *insn_cbs; GArray *mem_cbs; uint8_t len; @@ -120,9 +119,6 @@ struct qemu_plugin_tb { GPtrArray *insns; size_t n; uint64_t vaddr; - uint64_t vaddr2; - void *haddr1; - void *haddr2; /* if set, the TB calls helpers that might access guest memory */ bool mem_helper; diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 2aa1e08c17..c36632e8df 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -319,9 +319,6 @@ bool plugin_gen_tb_start(CPUState *cpu, const DisasContextBase *db) ret = true; ptb->vaddr = db->pc_first; - ptb->vaddr2 = -1; - ptb->haddr1 = db->host_addr[0]; - ptb->haddr2 = NULL; ptb->mem_helper = false; tcg_gen_plugin_cb(PLUGIN_GEN_FROM_TB); @@ -363,23 +360,6 @@ void plugin_gen_insn_start(CPUState *cpu, const DisasContextBase *db) pc = db->pc_next; insn->vaddr = pc; - /* - * Detect page crossing to get the new host address. - * Note that we skip this when haddr1 == NULL, e.g. when we're - * fetching instructions from a region not backed by RAM. - */ - if (ptb->haddr1 == NULL) { - insn->haddr = NULL; - } else if (is_same_page(db, db->pc_next)) { - insn->haddr = ptb->haddr1 + pc - ptb->vaddr; - } else { - if (ptb->vaddr2 == -1) { - ptb->vaddr2 = TARGET_PAGE_ALIGN(db->pc_first); - get_page_addr_code_hostp(cpu_env(cpu), ptb->vaddr2, &ptb->haddr2); - } - insn->haddr = ptb->haddr2 + pc - ptb->vaddr2; - } - tcg_gen_plugin_cb(PLUGIN_GEN_FROM_INSN); } diff --git a/plugins/api.c b/plugins/api.c index 9e4aa9d2d9..0ae19774df 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -242,7 +242,30 @@ uint64_t qemu_plugin_insn_vaddr(const struct qemu_plugin_insn *insn) void *qemu_plugin_insn_haddr(const struct qemu_plugin_insn *insn) { - return insn->haddr; + const DisasContextBase *db = tcg_ctx->plugin_db; + vaddr page0_last = db->pc_first | ~TARGET_PAGE_MASK; + + if (db->fake_insn) { + return NULL; + } + + /* + * ??? The return value is not intended for use of host memory, + * but as a proxy for address space and physical address. + * Thus we are only interested in the first byte and do not + * care about spanning pages. + */ + if (insn->vaddr <= page0_last) { + if (db->host_addr[0] == NULL) { + return NULL; + } + return db->host_addr[0] + insn->vaddr - db->pc_first; + } else { + if (db->host_addr[1] == NULL) { + return NULL; + } + return db->host_addr[1] + insn->vaddr - (page0_last + 1); + } } char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn)