From patchwork Wed Jul 31 16:06:49 2019 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: 170189 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp4238694ile; Wed, 31 Jul 2019 09:31:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqxcvOziz2XTq6ImHqimsCYoM4l2CVDckpiF0chVncuZM1WHQcnoCTN7Ht+74xM946kLFFUN X-Received: by 2002:a17:906:edcb:: with SMTP id sb11mr95646559ejb.260.1564590700427; Wed, 31 Jul 2019 09:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564590700; cv=none; d=google.com; s=arc-20160816; b=RZP6fitrOFEoCMVDKh29KLrtyUe4YjxIZuoATbol0kuqjSps5pxQ0Gk1Kb40PgLn/X i/1M1F9nWyxcFChK6MjnPcfC2m1du6c/eF7Gh/51JhiSTTWdA2T4dz5i8XwdIkE6MIIF mIPSpbgGLyLg8C6BrnjuzP4IYD4apivf71IARzXvIWREj1GJZtQP2K2+Zj11P4fl1PGz PmVxsvhV7zsohj4+HiiforYpgKFoIyyJkqiFPLLlqFUhU4yunTLK3PGr0Vv7XvmR5Vlu UwPNpbgA17l/Im0Hv9WEx9Pu9+vWWVIrBBBz09BMioq5WWG6wD7HBz0EsE1THXlxfY0r dDcw== 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:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=nwwivd4l04F9lotguBi5Pm9ljTTEntqAZyI9oEyrjH8=; b=csrGw0mxbiCYwyYACWv+hYLWv8K+9gMHXCcuq0xicsSgMOjWehaslee2RVE1FQo9Re 5/Cv6eG/vlc0HqbJj+8m9ro+Q9dCSHevtheFp24GOZ/KRZsRz9fgGdkUzPmUtOe2GNjG 9cJ4eYA6GfszZvA8x7xu3niNPDYVEulYkXJCICJBqObLjmY9G400EDzTmmtznA+RCd4X 8XnApCIk5gJWEOPrBQHSwkekoo5pLbHQN1OpBq7RktzPWoI6muIphkss0UahItbLwBuT jaeSqeOSYkndbF3MLb8RlWQsWwgG0rklZZ5pMPvqyOO4jaiWeRO0T3IMME03KKGV/dD+ rTmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=sDO1fhpF; 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 x48si22175453edm.225.2019.07.31.09.31.40 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Jul 2019 09:31:40 -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=sDO1fhpF; 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]:42814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrVr-0001zW-FM for patch@linaro.org; Wed, 31 Jul 2019 12:31:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45205) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPn-00051s-GW for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPm-0000MS-0K for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:23 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:35107) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPl-0000Ly-QB for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:21 -0400 Received: by mail-wr1-x444.google.com with SMTP id y4so70383126wrm.2 for ; Wed, 31 Jul 2019 09:25:21 -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=nwwivd4l04F9lotguBi5Pm9ljTTEntqAZyI9oEyrjH8=; b=sDO1fhpFlvG0YQoaMXLyUECDLb92YEL+YNc8Ll9Tqnl1Yyu8fW78x/hEpRuRewSQpX hKc4+mvpSE8YHZej0UNrw8gFlTvIUhHpjoLPs5yX8EJfr+wg+mFt4NVUe74rhrcjHCnG s5FtNIHTCGfPI/bCv1nt7tLymIyDKlDHz2WkhROZBnFx7vGyUhIufL8S0/CayDobrSyr d2zkcuHbdnV50XuTtjAqnTdm3dmEnf2ABd9y2Zldyc85F3mh7eankudz99l1ZwRAOZ0d PEGAYA5oQg11E9M1xTv+0xy74GPIG3Y/hR5PGV41Pw3L7H9QeTS1gUG9ZDzNTe4J3Hhu /CIA== 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=nwwivd4l04F9lotguBi5Pm9ljTTEntqAZyI9oEyrjH8=; b=boqW/XHOSZS0uXx2ibGaJ33ZBfiguKDm977hUsDZ4CHmRdhe8zqE2CCo3HtbBrQYaz WeNmT7oMG785at19xmMbPQe/uojJTwxTsVqf/CTqo3iraU8auRN2Ax02Jd0n6k0nzYDz PLUR/SNbbaGJ/rkdvScBuh/BF6+a/tT+qWFgB89EHchIAcHG5QczfHSoVUA55259F/j2 ikspq/AXL8pg04BCd+Xcjsf3CodFRdddWfqcZBVkZ98aYNyh2mohhz1RGnMEBYkG1ro2 4OqSpo7ob2uzwh8upxRIx9ycsiSMzNSmXXsGJC6LPDdF6SG1V/TIptoNfmDTg37bNqUT BqSg== X-Gm-Message-State: APjAAAXLfeDYnzLjjPwkNMkehSRLFUfm0yNEL9HKgknCnA4qAD5k3Na+ TCmsyP9zaA+rFUYIJYe3HcTL0IVuTpM= X-Received: by 2002:a5d:6144:: with SMTP id y4mr5708897wrt.84.1564590320731; Wed, 31 Jul 2019 09:25:20 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id j17sm113934938wrb.35.2019.07.31.09.25.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:16 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C480D1FF8C; Wed, 31 Jul 2019 17:07:21 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:49 +0100 Message-Id: <20190731160719.11396-25-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH v4 24/54] plugins: implement helpers for resolving hwaddr 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@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= , Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We need to keep a local per-cpu copy of the data as other threads may be running. We use a automatically growing array and re-use the space for subsequent queries. Signed-off-by: Alex Bennée --- accel/tcg/cputlb.c | 32 ++++++++++++++++++++++++++ include/exec/exec-all.h | 17 ++++++++++++++ include/qemu/plugin.h | 6 +++++ plugins/api.c | 50 +++++++++++++++++++++++++++++++++-------- 4 files changed, 96 insertions(+), 9 deletions(-) -- 2.20.1 diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index f7c0290639c..f37e89c806d 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1130,6 +1130,38 @@ void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr, return (void *)((uintptr_t)addr + entry->addend); } + +#ifdef CONFIG_PLUGIN +/* + * Perform a TLB lookup and populate the qemu_plugin_hwaddr structure. + * This should be a hot path as we will have just looked this path up + * in the softmmu lookup code (or helper). We don't handle re-fills or + * checking the victim table. This is purely informational. + */ + +bool tlb_plugin_lookup(CPUState *cpu, target_ulong addr, int mmu_idx, + bool is_store, struct qemu_plugin_hwaddr *data) +{ + CPUArchState *env = cpu->env_ptr; + CPUTLBEntry *tlbe = tlb_entry(env, mmu_idx, addr); + target_ulong tlb_addr = is_store ? tlb_addr_write(tlbe) : tlbe->addr_read; + + if (tlb_hit(tlb_addr, addr)) { + if (tlb_addr & TLB_MMIO) { + data->hostaddr = 0; + data->is_io = true; + /* XXX: lookup device */ + } else { + data->hostaddr = addr + tlbe->addend; + data->is_io = false; + } + return true; + } + return false; +} + +#endif + /* Probe for a read-modify-write atomic operation. Do not allow unaligned * operations, or io operations to proceed. Return the host address. */ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr, diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 90045e77c1f..c42626e35b1 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -262,6 +262,17 @@ void tlb_set_page(CPUState *cpu, target_ulong vaddr, int mmu_idx, target_ulong size); void probe_write(CPUArchState *env, target_ulong addr, int size, int mmu_idx, uintptr_t retaddr); + +/** + * tlb_plugin_lookup: query last TLB lookup + * @cpu: cpu environment + * + * This function can be used directly after a memory operation to + * query information about the access. It is used by the plugin + * infrastructure to expose more information about the address. + */ +bool tlb_plugin_lookup(CPUState *cpu, target_ulong addr, int mmu_idx, + bool is_store, struct qemu_plugin_hwaddr *data); #else static inline void tlb_init(CPUState *cpu) { @@ -311,6 +322,12 @@ static inline void tlb_flush_by_mmuidx_all_cpus_synced(CPUState *cpu, uint16_t idxmap) { } +static inline bool tlb_plugin_lookup(CPUState *cpu, target_ulong addr, + int mmu_idx, bool is_store, + struct qemu_plugin_hwaddr *data) +{ + return false; +} #endif #define CODE_GEN_ALIGN 16 /* must be >= of the size of a icache line */ diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 3c46a241669..657345df60c 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -182,6 +182,12 @@ struct qemu_plugin_insn *qemu_plugin_tb_insn_get(struct qemu_plugin_tb *tb) return insn; } +struct qemu_plugin_hwaddr { + uint64_t hostaddr; + bool is_io; +}; + + #ifdef CONFIG_PLUGIN void qemu_plugin_vcpu_init_hook(CPUState *cpu); diff --git a/plugins/api.c b/plugins/api.c index 586bb8789f1..4b3ac9e31fb 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -39,7 +39,7 @@ #include "cpu.h" #include "sysemu/sysemu.h" #include "tcg/tcg.h" -#include "trace/mem-internal.h" /* mem_info macros */ +#include "exec/exec-all.h" #include "plugin.h" #ifndef CONFIG_USER_ONLY #include "hw/boards.h" @@ -240,11 +240,42 @@ bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info) * Virtual Memory queries */ +#ifdef CONFIG_SOFTMMU +static GArray *hwaddr_refs; + +struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info, + uint64_t vaddr) +{ + CPUState *cpu = current_cpu; + unsigned int mmu_idx = info >> TRACE_MEM_MMU_SHIFT; + struct qemu_plugin_hwaddr *hwaddr; + + /* Ensure we have memory allocated for this work */ + if (!hwaddr_refs) { + hwaddr_refs = g_array_sized_new(false, true, + sizeof(struct qemu_plugin_hwaddr), + cpu->cpu_index + 1); + } else if (cpu->cpu_index >= hwaddr_refs->len) { + hwaddr_refs = g_array_set_size(hwaddr_refs, cpu->cpu_index + 1); + } + + hwaddr = &g_array_index(hwaddr_refs, struct qemu_plugin_hwaddr, + cpu->cpu_index); + + if (!tlb_plugin_lookup(cpu, vaddr, mmu_idx, + info & TRACE_MEM_ST, hwaddr)) { + return NULL; + } + + return hwaddr; +} +#else struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info, uint64_t vaddr) { return NULL; } +#endif bool qemu_plugin_hwaddr_is_io(struct qemu_plugin_hwaddr *hwaddr) { @@ -253,14 +284,15 @@ bool qemu_plugin_hwaddr_is_io(struct qemu_plugin_hwaddr *hwaddr) uint64_t qemu_plugin_hwaddr_to_raddr(const struct qemu_plugin_hwaddr *haddr) { -#if 0 /* XXX FIXME should be SOFTMMU */ - ram_addr_t ram_addr; - - g_assert(haddr); - ram_addr = qemu_ram_addr_from_host(haddr); - if (ram_addr == RAM_ADDR_INVALID) { - error_report("Bad ram pointer %p", haddr); - abort(); +#ifdef CONFIG_SOFTMMU + ram_addr_t ram_addr = 0; + + if (haddr && !haddr->is_io) { + ram_addr = qemu_ram_addr_from_host((void *) haddr->hostaddr); + if (ram_addr == RAM_ADDR_INVALID) { + error_report("Bad ram pointer %"PRIx64"", haddr->hostaddr); + abort(); + } } return ram_addr; #else