From patchwork Wed Mar 17 07:22:04 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: 403035 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp231816jai; Wed, 17 Mar 2021 00:27:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnaPXGNwgSzYuzCd/LrQrwkApwFhwqd1LAcIVdqhCJuCSToiTPaW+2PSUeJeOc2XwkNgJt X-Received: by 2002:a25:d911:: with SMTP id q17mr2872118ybg.468.1615966028384; Wed, 17 Mar 2021 00:27:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615966028; cv=none; d=google.com; s=arc-20160816; b=bCWxaNwarATkbzUEWrTJmChhhJ/AbaxU6fbYG9C9b9FDRowUfLQdXLQ53yHIWKolDh m+9joZulk/w6VuMB8tHZMVCXC5sTBms8wt1NozvUST90TLjb4LyvJBvcxmys3/Rm/lCG 0O40VoQ9RwSQ1MWsKYnvM8N2qNd9ECgfIPc+Ct2UNxcDePy/X8ZXliq1j542vZu3jyl1 B4xHRTXUg5lI/TlS+Siq+KIUanhbuwc2OpsmQ+Te6EOAyuFiVKkOWr/5tsNXoKhzPtMA Etc+4z1fq/LghHrm+IPtHdaXBMHffsGvLv3tKtUxCMnmCZKHcyHBbIGoorNhyVqvuoeo I1Eg== 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=frvWeWkE0HLi8OnAGFQ6yFN2uwXNepdq5oonZmdE2hY=; b=w447V0w3RQnmlf3zxkMNra7aqI9gft7WqlYel8f/fY45no66Qy7Ile0htmxB2fxpIW Z1xAyCfBpvENeajfGkeHp4Qw2fF57Phs+W578hi3XbJY6fKfE/PO8vOeDeKmfEFWgvgo i0zQSajCl/IHOs9tNG20/G/mIiFc4wRkD3c99kQqe66AviIdY5WH1ghtpNLb4a10+nwz mvRP3y8CH3tKsjcaYyVnURo/zfu91J9HDh6esRQf8ucA2Efb8ZzHu6XGTUT5WHNgQWxq P6Jjq6oe3or5LFDG79YBfnZoFr0fNAJcScRWw6e9pYIJpF0E2SsgcEuzwv9I+i5F+aZa T39w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="T/VeUJEt"; 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 i83si21038853ybb.244.2021.03.17.00.27.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Mar 2021 00:27:08 -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="T/VeUJEt"; 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]:41438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMQaB-0001p5-Q1 for patch@linaro.org; Wed, 17 Mar 2021 03:27:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMQVd-0003Uv-Jt for qemu-devel@nongnu.org; Wed, 17 Mar 2021 03:22:25 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]:45378) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lMQVb-0007sY-NR for qemu-devel@nongnu.org; Wed, 17 Mar 2021 03:22:25 -0400 Received: by mail-ej1-x62f.google.com with SMTP id mm21so887769ejb.12 for ; Wed, 17 Mar 2021 00:22:23 -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=frvWeWkE0HLi8OnAGFQ6yFN2uwXNepdq5oonZmdE2hY=; b=T/VeUJEtbH5PdGg0JgO38rtGO2jSFFCinL6WZDb8gfGbA4bzGqaHnF+suGcgDMI83H zFpuu0s0PdgHeKGnHclucn+m3FWwzWqgEXrL3+XEAzXuICU1c1O3ojszmd6kSOQTQbl9 bquriywD8XTmT9aL+KGldITXdwZXmr89GmssLviHwWnLp2ZxOw4ZdjEGkyjVYVx+Boc9 mElEXO5Ema59lKJx7q/ESSI7vzq01V2OU5GZg1mQptJVE8xTQ4OC3cXvvJfMJ/hg1Ux/ 8f9qHzPQNaBGk+ESmIvUuJxkxzVMJcEVWEJdrgeR1MvEKNppAbxRFhONIgSctDKu0OpM 0hHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=frvWeWkE0HLi8OnAGFQ6yFN2uwXNepdq5oonZmdE2hY=; b=k2Gaf6MlsFUEaeImRLeuSBvUquDN8S6Apd2CQh8OMYKX2u57olx1PHBhC12/CieFy3 z4u3UJ1hre9c7NUs3bSghwSekYr0kcFaFIIqzCqnZM5LQkgQ+QAXEOYVHQwJ7qKfLMKc YUcKfnTASwIFHHnbKw4O3qnYwHADdnl3tVS3uLGT76lIEiohELJ99XiupulTVaFzlwOF gilE/P8cDVdcCyIiP3VzF+4964DWhHVOJUKM5Yby6/9lNKZvP407LGP96gP7+E5Xok5w yhDtw1yq6MWG6PKs2WbQaEGFZ5Gh0qlMXzLMXpofhW75rnzBlDanGzHFxn7/Ko7gjeh+ jZqw== X-Gm-Message-State: AOAM531K9OATj+o7/1Y9PMs6YUEc5D59iRWDX+MFBv4MSeJglBXD0BJ9 U0QguB9AMKAVcR1amqx8VpACVg== X-Received: by 2002:a17:906:b0d8:: with SMTP id bk24mr34718162ejb.252.1615965742426; Wed, 17 Mar 2021 00:22:22 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id c10sm11718549edt.64.2021.03.17.00.22.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 00:22:20 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id F03EF1FF8F; Wed, 17 Mar 2021 07:22:16 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL v2 03/15] plugins: Expose physical addresses instead of device offsets Date: Wed, 17 Mar 2021 07:22:04 +0000 Message-Id: <20210317072216.16316-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210317072216.16316-1-alex.bennee@linaro.org> References: <20210317072216.16316-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62f.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: Aaron Lindsay , =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Aaron Lindsay This allows plugins to query for full virtual-to-physical address translation for a given `qemu_plugin_hwaddr` and stops exposing the offset within the device itself. As this change breaks the API, QEMU_PLUGIN_VERSION is incremented. Signed-off-by: Aaron Lindsay Signed-off-by: Alex Bennée Message-Id: <20210309202802.211756-1-aaron@os.amperecomputing.com> Message-Id: <20210312172821.31647-3-alex.bennee@linaro.org> -- 2.20.1 diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index c66507fe8f..3303dce862 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -47,7 +47,7 @@ typedef uint64_t qemu_plugin_id_t; extern QEMU_PLUGIN_EXPORT int qemu_plugin_version; -#define QEMU_PLUGIN_VERSION 0 +#define QEMU_PLUGIN_VERSION 1 typedef struct { /* string describing architecture */ @@ -307,8 +307,8 @@ bool qemu_plugin_mem_is_sign_extended(qemu_plugin_meminfo_t info); bool qemu_plugin_mem_is_big_endian(qemu_plugin_meminfo_t info); bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info); -/* - * qemu_plugin_get_hwaddr(): +/** + * qemu_plugin_get_hwaddr() - return handle for memory operation * @vaddr: the virtual address of the memory operation * * For system emulation returns a qemu_plugin_hwaddr handle to query @@ -323,12 +323,30 @@ struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info, uint64_t vaddr); /* - * The following additional queries can be run on the hwaddr structure - * to return information about it. For non-IO accesses the device - * offset will be into the appropriate block of RAM. + * The following additional queries can be run on the hwaddr structure to + * return information about it - namely whether it is for an IO access and the + * physical address associated with the access. + */ + +/** + * qemu_plugin_hwaddr_is_io() - query whether memory operation is IO + * @haddr: address handle from qemu_plugin_get_hwaddr() + * + * Returns true if the handle's memory operation is to memory-mapped IO, or + * false if it is to RAM */ bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr); -uint64_t qemu_plugin_hwaddr_device_offset(const struct qemu_plugin_hwaddr *haddr); + +/** + * qemu_plugin_hwaddr_phys_addr() - query physical address for memory operation + * @haddr: address handle from qemu_plugin_get_hwaddr() + * + * Returns the physical address associated with the memory operation + * + * Note that the returned physical address may not be unique if you are dealing + * with multiple address spaces. + */ +uint64_t qemu_plugin_hwaddr_phys_addr(const struct qemu_plugin_hwaddr *haddr); /* * Returns a string representing the device. The string is valid for diff --git a/contrib/plugins/hotpages.c b/contrib/plugins/hotpages.c index eacc678eac..bf53267532 100644 --- a/contrib/plugins/hotpages.c +++ b/contrib/plugins/hotpages.c @@ -122,7 +122,7 @@ static void vcpu_haddr(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, } } else { if (hwaddr && !qemu_plugin_hwaddr_is_io(hwaddr)) { - page = (uint64_t) qemu_plugin_hwaddr_device_offset(hwaddr); + page = (uint64_t) qemu_plugin_hwaddr_phys_addr(hwaddr); } else { page = vaddr; } diff --git a/contrib/plugins/hwprofile.c b/contrib/plugins/hwprofile.c index 6dac1d5f85..faf216ac00 100644 --- a/contrib/plugins/hwprofile.c +++ b/contrib/plugins/hwprofile.c @@ -201,7 +201,7 @@ static void vcpu_haddr(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, return; } else { const char *name = qemu_plugin_hwaddr_device_name(hwaddr); - uint64_t off = qemu_plugin_hwaddr_device_offset(hwaddr); + uint64_t off = qemu_plugin_hwaddr_phys_addr(hwaddr); bool is_write = qemu_plugin_mem_is_store(meminfo); DeviceCounts *counts; diff --git a/plugins/api.c b/plugins/api.c index 0b04380d57..3c7dc406e3 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -40,6 +40,7 @@ #include "sysemu/sysemu.h" #include "tcg/tcg.h" #include "exec/exec-all.h" +#include "exec/ram_addr.h" #include "disas/disas.h" #include "plugin.h" #ifndef CONFIG_USER_ONLY @@ -298,19 +299,25 @@ bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr) #endif } -uint64_t qemu_plugin_hwaddr_device_offset(const struct qemu_plugin_hwaddr *haddr) +uint64_t qemu_plugin_hwaddr_phys_addr(const struct qemu_plugin_hwaddr *haddr) { #ifdef CONFIG_SOFTMMU if (haddr) { if (!haddr->is_io) { - ram_addr_t ram_addr = qemu_ram_addr_from_host((void *) haddr->v.ram.hostaddr); - if (ram_addr == RAM_ADDR_INVALID) { + RAMBlock *block; + ram_addr_t offset; + void *hostaddr = (void *) haddr->v.ram.hostaddr; + + block = qemu_ram_block_from_host(hostaddr, false, &offset); + if (!block) { error_report("Bad ram pointer %"PRIx64"", haddr->v.ram.hostaddr); abort(); } - return ram_addr; + + return block->offset + offset + block->mr->addr; } else { - return haddr->v.io.offset; + MemoryRegionSection *mrs = haddr->v.io.section; + return haddr->v.io.offset + mrs->mr->addr; } } #endif