From patchwork Mon Feb 11 23:52:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 158061 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3220268jaa; Mon, 11 Feb 2019 16:19:47 -0800 (PST) X-Google-Smtp-Source: AHgI3IbRC+NmBD7f9VwR8rF0j7Y+Kfpmc1NUClURbsEdK9xtOzA/6ntrAoB/VLnd3IhuMbqxOhZl X-Received: by 2002:a0d:ff85:: with SMTP id p127mr689586ywf.371.1549930787922; Mon, 11 Feb 2019 16:19:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549930787; cv=none; d=google.com; s=arc-20160816; b=ppAUDgpA/uQxJQY+dTaXxf1UnJ2nldLgNo7qnQ/WzAnqdOLUmzn5tnSzQgCt9EQugU lYPAlAHIYYWhXDjih074VvXtKvDBZ1XqZ4BXj4S3Ttkvyb3NuMh7o/zTEBW6D9cnjzPQ Y/72CLkcdr/9hdkobxPPKo+BKF4a5AX0LO8iGoqcNeCP5KxQC9WuhdGYXoD75thEYlYl DqfWENm3z68K1UGQKpc+y+WyFPKcTrEPQN6KKkpjYAAcHasAF6lwrPCCQNXxvydF16Zt DjeI74qkffWM8gY5CaRXH2TzPBZNLxaR4MbZ9HroXz9lioG/K1XMFxYD4WrglBwIzw0J bVPQ== 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:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=Ju0kTjI209UCLXJK9JoNZjkA22NnBtRT7DAuiRVZe0I=; b=B/INGqTdqTrI7X7D8kh92/vTP1LfIsGrr3lySxEhHCSyQKI0qz2+80uv+NjM+pYKbl y4aDG6PuPhbXdZihb4qVwZC8or6bbKa7KjrLUey/8g52ip+xq+9/KeN3px2bZ11U9M/w 3/DDgccpkcJ/WuvrbPoklljUXccG3zbzxOjPkRXRFQo49A8/tM9qn5xcHIIeKE4ukPy0 RYB7WNJnYNwHiw1GLEUIZ9DzJvGSI7cYbf6UiljWcZXtUoVnru2ZqzW5LdH/3lxqPwcn KlPQPlvMJCUL3JFRRmpcM8FJ34zXAEagcSgU8//uC6yB8plMxwX4Pj3n9reap2G3c65J +dPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=eM3Ut9Q8; 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 a2si6912827ybh.176.2019.02.11.16.19.47 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 11 Feb 2019 16:19:47 -0800 (PST) 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=eM3Ut9Q8; 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 ([127.0.0.1]:58569 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtLnf-0000iQ-EJ for patch@linaro.org; Mon, 11 Feb 2019 19:19:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38736) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtLOj-0005uE-F7 for qemu-devel@nongnu.org; Mon, 11 Feb 2019 18:54:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtLOf-00052i-VY for qemu-devel@nongnu.org; Mon, 11 Feb 2019 18:54:01 -0500 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:44535) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gtLOf-0004iu-9x for qemu-devel@nongnu.org; Mon, 11 Feb 2019 18:53:57 -0500 Received: by mail-pg1-x541.google.com with SMTP id y1so306475pgk.11 for ; Mon, 11 Feb 2019 15:53:36 -0800 (PST) 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; bh=Ju0kTjI209UCLXJK9JoNZjkA22NnBtRT7DAuiRVZe0I=; b=eM3Ut9Q8OhHf/eHwpTKfKXuR4n3UxEo0v3fKALx4rnCNGvNsCyChNUJk9M4shOWu2y v8o+idtV1ZR7V0xmQa/7/U6/7IAoSNTzxfrrnOgRERvg3OZ5sN+1Ttoo7UrSQUdZ+80N jym1TYVkP+2z9RayUAKeiVf41Iwn7bGi1Nel8eC+SCkJTaTPg53+lMWzY3HqeUg8zDdY 977BRlcLpE0W243Sz2j8SHb+pAywtQPJu3/c+ogWhslMLup8RPlPwFOqE/mUXBgqGfb8 DSOtO7DlTBlYWIv+vXkZ6EYkCsZtE2wDjYNU+bWqaj/SWp8rGuTqkxaPK4hbtScQnGvp K/lQ== 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; bh=Ju0kTjI209UCLXJK9JoNZjkA22NnBtRT7DAuiRVZe0I=; b=kEIv57Zs/bt9PdNVAWSY/FbNpN3u6GimNrlX2gDw1XwZzK77biWxpaoGhBlVeKSzr6 BG1Zdx73/Z8cAirkcby9H8F1NYhrcfrLk6nnyBeIl4zT/TFWO1jh2Ex7IJt7r0EqKNPT aA+t39cI11/WhiO+n1WxWEKPIqqMgf6uH/s2MMzTrwQIBPf5QEubheOQOyiU/uc3EBe8 ROH8T24hTyNSICuZxOU6bRiVW0wJKyhA3m7nYMqoE0ErEmLI0nqlkUMG9yyva+Mgx/v1 jQLGfWE6rm/eDOEHLNfTtu8PUfJlttYFLrdyh4DBHzb0g/yTXb7As79KXdCDzyZNGhN6 2gtQ== X-Gm-Message-State: AHQUAua+ZMp2YzDVzH/xLejgBlsigm9EpJbObGZBizKUbgGcEvU3ZrZm LlCD3Cxup9JNHCYe8HBgTMf+z1CRAq0= X-Received: by 2002:aa7:8802:: with SMTP id c2mr938329pfo.20.1549929215416; Mon, 11 Feb 2019 15:53:35 -0800 (PST) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id c4sm11861031pgq.85.2019.02.11.15.53.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Feb 2019 15:53:34 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 11 Feb 2019 15:52:56 -0800 Message-Id: <20190211235258.542-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190211235258.542-1-richard.henderson@linaro.org> References: <20190211235258.542-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::541 Subject: [Qemu-devel] [PATCH v3 26/28] target/arm: Add allocation tag storage for system mode X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- target/arm/mte_helper.c | 96 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 87 insertions(+), 9 deletions(-) -- 2.17.2 diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c index 09c387e2c7..53c3ed862e 100644 --- a/target/arm/mte_helper.c +++ b/target/arm/mte_helper.c @@ -28,18 +28,18 @@ static uint8_t *allocation_tag_mem(CPUARMState *env, uint64_t ptr, bool write, uintptr_t ra) { -#ifdef CONFIG_USER_ONLY ARMCPU *cpu = arm_env_get_cpu(env); + CPUState *cs = CPU(cpu); uint8_t *tags; uintptr_t index; - int flags; - flags = page_get_flags(ptr); +#ifdef CONFIG_USER_ONLY + int flags = page_get_flags(ptr); if (!(flags & PAGE_VALID) || !(flags & (write ? PAGE_WRITE : PAGE_READ))) { /* SIGSEGV */ env->exception.vaddress = ptr; - cpu_restore_state(CPU(cpu), ra, true); + cpu_restore_state(cs, ra, true); raise_exception(env, EXCP_DATA_ABORT, 0, 1); } @@ -56,16 +56,94 @@ static uint8_t *allocation_tag_mem(CPUARMState *env, uint64_t ptr, if (tags == NULL) { size_t alloc_size = TARGET_PAGE_SIZE >> (LOG2_TAG_GRANULE + 1); tags = page_alloc_target_data(ptr, alloc_size); - assert(tags != NULL); + } +#else + int mmu_idx; + AddressSpace *as; + CPUTLBEntry *te; + CPUIOTLBEntry *iotlbentry; + MemoryRegionSection *section; + MemoryRegion *mr; + FlatView *fv; + hwaddr physaddr, tag_physaddr, tag_len, xlat; + + /* + * Find the TLB entry for this access. + * As a side effect, this also raises an exception for invalid access. + */ + mmu_idx = cpu_mmu_index(env, false); + index = tlb_index(env, mmu_idx, ptr); + te = tlb_entry(env, mmu_idx, ptr); + if (!tlb_hit(write ? tlb_addr_write(te) : te->addr_read, ptr)) { + /* ??? Expose VICTIM_TLB_HIT from accel/tcg/cputlb.c. */ + tlb_fill(cs, ptr, 16, write ? MMU_DATA_STORE : MMU_DATA_LOAD, + mmu_idx, ra); + index = tlb_index(env, mmu_idx, ptr); + te = tlb_entry(env, mmu_idx, ptr); } + /* If the virtual page MemAttr != Tagged, nothing to do. */ + iotlbentry = &env->iotlb[mmu_idx][index]; + if (!iotlbentry->attrs.target_tlb_bit1) { + return NULL; + } + + /* If the board did not allocate tag memory, nothing to do. */ + as = cpu_get_address_space(cs, ARMASIdx_TAG); + if (!as) { + return NULL; + } + + /* Find the physical address for the virtual access. */ + section = iotlb_to_section(cs, iotlbentry->addr, iotlbentry->attrs); + physaddr = ((iotlbentry->addr & TARGET_PAGE_MASK) + ptr + + section->offset_within_address_space + - section->offset_within_region); + + /* Convert to the physical address in tag space. */ + tag_physaddr = physaddr >> (LOG2_TAG_GRANULE + 1); + tag_len = TARGET_PAGE_SIZE >> (LOG2_TAG_GRANULE + 1); + + /* + * Find the tag physical address within the tag address space. + * + * ??? Create a new mmu_idx to cache the rest of this. + * + * ??? If we were assured of exactly one block of normal ram, + * and thus exactly one block of tag ram, then we could validate + * section->mr as ram, use the section offset vs cpu->tag_memory, + * and finish with memory_region_get_ram_ptr. + */ + rcu_read_lock(); + fv = address_space_to_flatview(as); + mr = flatview_translate(fv, tag_physaddr, &xlat, &tag_len, + write, MEMTXATTRS_UNSPECIFIED); + if (!memory_access_is_direct(mr, write)) { + /* + * This would seem to imply that the guest has marked a + * virtual page as Tagged when the physical page is not RAM. + * Should this raise some sort of bus error? + */ + rcu_read_unlock(); + qemu_log_mask(LOG_GUEST_ERROR, "Tagged virtual page 0x%" PRIx64 + " maps to physical page 0x%" PRIx64 " without RAM\n", + ptr, physaddr); + return NULL; + } + rcu_read_unlock(); + + /* The board should have created tag ram sized correctly. */ + assert(tag_len == TARGET_PAGE_SIZE >> (LOG2_TAG_GRANULE + 1)); + + /* FIXME: Mark the tag page dirty for migration. */ + + tags = qemu_map_ram_ptr(mr->ram_block, xlat); +#endif + + assert(tags != NULL); index = extract32(ptr, LOG2_TAG_GRANULE + 1, TARGET_PAGE_BITS - LOG2_TAG_GRANULE - 1); return tags + index; -#else - /* Tag storage not implemented. */ - return NULL; -#endif } static int get_allocation_tag(CPUARMState *env, uint64_t ptr, uintptr_t ra)