From patchwork Thu Mar 12 19:42:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 184537 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp968154ile; Thu, 12 Mar 2020 13:01:40 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuBk5u5tTicIKSAYJp/4mx9zTWVDFPjLq1T7ktU1bHG0QyD+JgqZ8VlVhtJyt4kgFcfksry X-Received: by 2002:a0c:a998:: with SMTP id a24mr8928343qvb.141.1584043299857; Thu, 12 Mar 2020 13:01:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584043299; cv=none; d=google.com; s=arc-20160816; b=MmvyAezZHqTsCT4JK/MqUDnhLACaNNasEerQzgvIMO1bUjrV8/VzoPgx8lyAnkXVF2 2HgGZVAZbvMa0a6BMXF6fviDjcHg3smJOe34QiEIvca8hKxY7YX1H1KC6v3QzheiO86y k1Hgb5VPkbJL6NRoAAXRFXhortN8lDduIbmEvWm9ovUOC5+hOlCBw/Xh6cAnS+VSmZ30 M/12gh64vuzE4LXNtchUSJRRqbqQZ2DV8WpT5s6r2GlUQoNvXi/xUbymPp3rfpukIIu7 1lRKDCzi8nLDdH76ltnrzCXBNTDKtgwtg9h2zGKrl4AI1+6/U0m8dGMcXhJwDd+zbRd9 pbuQ== 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=D6dUTV6+AbmOvovc5B167VTVViwAF6biFLlOzA9HmSw=; b=NBkFfjhjCB5TZKqXyJ1w8BvH4j7Bb4ZCNPszSkJXFWTqpBmiAtTyhiUBeFEsubJTZi 9QVU/lB4X4wnw/5akIpqDnmMIZRZNjOi4zvCbDdIUDuFjIpZ7tRsnmdU4f3qJNmgMoOL fpRyo630vYumx5wfecV5mnB4iI4+EVA7qzD7WqibSLnbHh7uQUZqwNbX0fxUmZ7+G8JB mf+3womaW6JFSxNgfSufprImliyEkBGb6Gi09zdw5aG7kWaEZ9uZehoDl0zIoGCvqALX tE5PfsaNo6w2lJf88cC2X+sJ7mNWP649VdC2dfAnGbcuq35sAW1nzkuKv9oFKCqiH7PI YvQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e09oKrAd; 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 g7si591712qtr.388.2020.03.12.13.01.39 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Mar 2020 13:01: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=pass header.i=@linaro.org header.s=google header.b=e09oKrAd; 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]:49790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jCU1T-0003sR-CZ for patch@linaro.org; Thu, 12 Mar 2020 16:01:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46118) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jCTjk-00070x-Jf for qemu-devel@nongnu.org; Thu, 12 Mar 2020 15:43:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jCTjj-0002SM-4o for qemu-devel@nongnu.org; Thu, 12 Mar 2020 15:43:20 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:41421) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jCTji-0002Rv-Uq for qemu-devel@nongnu.org; Thu, 12 Mar 2020 15:43:19 -0400 Received: by mail-pl1-x643.google.com with SMTP id t14so3062851plr.8 for ; Thu, 12 Mar 2020 12:43:18 -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=D6dUTV6+AbmOvovc5B167VTVViwAF6biFLlOzA9HmSw=; b=e09oKrAdsRYr04MKQUlFO5Sqre3QYt0so/zB/TKS5uGXJhsG6oOYeV7w+jgh5Y62Lm I//ZEHwflheAWSAxD8k+NuOx8a2NbefPHvR1uQGSDQh9SPObQtbjp+osr2MIT3T73/4X kCg72AenLxeDqJ4LAMGUnnKpQA9LdegM2cAAuMHnW/3wi6bee2ocaZuhXVV6nK+GTtNm BqB4lzAmezWoeC/GAjhoGbblxnFeHnrZy1NjmKTtdJwKktoCcaFStfNgnapjKM9lpmd0 bRCJuzjeyPs+oyKiwfYbszRwc0ZT0iKX6Innswx5xCPMOd5b573cvaSCUHY/Ya957npe W05Q== 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=D6dUTV6+AbmOvovc5B167VTVViwAF6biFLlOzA9HmSw=; b=ujb3RzujdRBRk292qynfO9xHs5GZRWnpNNOaIQmfUIOlXOAQeN+Udpi7NNmK/Lqr6z d2Hj4bCUHu5zGSbVRhWKusc8pNmJ3Z1gz5nXd9MmxIKSeyH6aAZh/vT23ys2sv4e+Yp6 545ep9erOz98yCSU/Nta+K4DeDZLDrnWZWaijz3yKAR+uKUf8rVk4h4pjVcWdZTK6JET wNJDDKfdydjV+Wc5WqrcspH4wtnV07bj+/491ulq0XFX14+baAUEn0QEI5Y/yUgtMoIZ N+2PJreXN0nNa64sfRhgEqqTaF5cEpttYviE2glBCkwIwv2ChREy0mygX8dr0OpBrDGS oJ1g== X-Gm-Message-State: ANhLgQ0E2Q68pPheJ3YVIFbppi8/4dVlsdPCbxzzUYmaTMTeL1E7eyO8 96lNnfp922CONS3t9Vo9/ljHApyIm00= X-Received: by 2002:a17:902:8a88:: with SMTP id p8mr10026309plo.56.1584042197603; Thu, 12 Mar 2020 12:43:17 -0700 (PDT) Received: from localhost.localdomain (97-126-123-70.tukw.qwest.net. [97.126.123.70]) by smtp.gmail.com with ESMTPSA id g69sm6824842pje.34.2020.03.12.12.43.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 12:43:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v6 42/42] target/arm: Add allocation tag storage for system mode Date: Thu, 12 Mar 2020 12:42:19 -0700 Message-Id: <20200312194219.24406-43-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312194219.24406-1-richard.henderson@linaro.org> References: <20200312194219.24406-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::643 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Look up the physical address for the given virtual address, convert that to a tag physical address, and finally return the host address that backs it. Signed-off-by: Richard Henderson --- target/arm/mte_helper.c | 128 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) -- 2.20.1 diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c index c51f7f04f4..47db87a5a1 100644 --- a/target/arm/mte_helper.c +++ b/target/arm/mte_helper.c @@ -21,6 +21,7 @@ #include "cpu.h" #include "internals.h" #include "exec/exec-all.h" +#include "exec/ram_addr.h" #include "exec/cpu_ldst.h" #include "exec/helper-proto.h" @@ -74,8 +75,135 @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx, int ptr_size, MMUAccessType tag_access, int tag_size, uintptr_t ra) { +#ifdef CONFIG_USER_ONLY /* Tag storage not implemented. */ return NULL; +#else + uintptr_t index; + CPUIOTLBEntry *iotlbentry; + int in_page, flags; + ram_addr_t ptr_ra; + hwaddr ptr_paddr, tag_paddr, xlat; + MemoryRegion *mr; + ARMASIdx tag_asi; + AddressSpace *tag_as; + void *host; + + /* + * The caller must split calls to this function such that it will + * not access *tag* memory beyond the end of the page. + */ + in_page = -(ptr | -(TARGET_PAGE_SIZE >> (LOG2_TAG_GRANULE + 1))); + g_assert(tag_size <= in_page); + + /* + * Probe the first byte of the virtual address. This raises an + * exception for inaccessible pages, and resolves the virtual address + * into the softmmu tlb. + */ + flags = probe_access_flags(env, ptr, ptr_access, ptr_mmu_idx, + false, &host, ra); + + /* + * Find the iotlbentry for ptr. This *must* be present in the TLB + * because we just found the mapping. + * TODO: Perhaps there should be a cputlb helper that returns a + * matching tlb entry + iotlb entry. + */ + index = tlb_index(env, ptr_mmu_idx, ptr); +# ifdef CONFIG_DEBUG_TCG + { + CPUTLBEntry *entry = tlb_entry(env, ptr_mmu_idx, ptr); + target_ulong comparator = (ptr_access == MMU_DATA_LOAD + ? entry->addr_read + : tlb_addr_write(entry)); + g_assert(tlb_hit(comparator, ptr)); + } +# endif + iotlbentry = &env_tlb(env)->d[ptr_mmu_idx].iotlb[index]; + + /* If the virtual page MemAttr != Tagged, access unchecked. */ + if (!iotlbentry->attrs.target_tlb_bit1) { + return NULL; + } + + /* If not normal memory, tag storage is not implemented, access unchecked. */ + if (unlikely(flags & TLB_MMIO)) { + qemu_log_mask(LOG_GUEST_ERROR, + "Page @ 0x%" PRIx64 " indicates Tagged Normal memory " + "but is Device memory\n", ptr); + return NULL; + } + + /* + * The Normal memory access can extend to the next page. E.g. a single + * 8-byte access to the last byte of a page will check only the last + * tag on the first page. + * Any page access exception has priority over tag check exception. + */ + in_page = -(ptr | TARGET_PAGE_MASK); + if (unlikely(ptr_size > in_page)) { + void *ignore; + flags |= probe_access_flags(env, ptr + in_page, ptr_access, + ptr_mmu_idx, false, &ignore, ra); + } + + /* Any debug exception has priority over a tag check exception. */ + if (unlikely(flags & TLB_WATCHPOINT)) { + int wp = ptr_access == MMU_DATA_LOAD ? BP_MEM_READ : BP_MEM_WRITE; + cpu_check_watchpoint(env_cpu(env), ptr, ptr_size, + iotlbentry->attrs, wp, ra); + } + + /* + * Find the physical address within the normal mem space. + * The memory region lookup must succeed because TLB_MMIO was + * not set in the cputlb lookup above. + */ + mr = memory_region_from_host(host, &ptr_ra); + tcg_debug_assert(mr != NULL); + tcg_debug_assert(memory_region_is_ram(mr)); + ptr_paddr = ptr_ra; + do { + ptr_paddr += mr->addr; + mr = mr->container; + } while (mr); + + /* Convert to the physical address in tag space. */ + tag_paddr = ptr_paddr >> (LOG2_TAG_GRANULE + 1); + + /* Look up the address in tag space. */ + tag_asi = iotlbentry->attrs.secure ? ARMASIdx_TagS : ARMASIdx_TagNS; + tag_as = cpu_get_address_space(env_cpu(env), tag_asi); + mr = address_space_translate(tag_as, tag_paddr, &xlat, NULL, + tag_access == MMU_DATA_STORE, + iotlbentry->attrs); + + /* + * Note that @mr will never be NULL. If there is nothing in the address + * space at @tag_paddr, the translation will return the unallocated memory + * region. For our purposes, the result must be ram. + */ + if (unlikely(!memory_region_is_ram(mr))) { + /* ??? Failure is a board configuration error. */ + qemu_log_mask(LOG_UNIMP, + "Tag Memory @ 0x%" HWADDR_PRIx " not found for " + "Normal Memory @ 0x%" HWADDR_PRIx "\n", + tag_paddr, ptr_paddr); + return NULL; + } + + /* + * Ensure the tag memory is dirty on write, for migration. + * Tag memory can never contain code or display memory (vga). + */ + if (tag_access == MMU_DATA_STORE) { + ram_addr_t tag_ra = memory_region_get_ram_addr(mr) + xlat; + cpu_physical_memory_set_dirty_flag(tag_ra, DIRTY_MEMORY_MIGRATION); + } + + return memory_region_get_ram_ptr(mr) + xlat; +#endif } uint64_t HELPER(irg)(CPUARMState *env, uint64_t rn, uint64_t rm)