From nobody Tue Feb 10 19:48:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549847876614651.8826059507046; Sun, 10 Feb 2019 17:17:56 -0800 (PST) Received: from localhost ([127.0.0.1]:42191 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gt0EL-0004B6-IN for importer@patchew.org; Sun, 10 Feb 2019 20:17:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gt05w-0005yH-Oo for qemu-devel@nongnu.org; Sun, 10 Feb 2019 20:09:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gt05s-00008Z-EZ for qemu-devel@nongnu.org; Sun, 10 Feb 2019 20:09:12 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:38628) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gt05s-0008T0-1d for qemu-devel@nongnu.org; Sun, 10 Feb 2019 20:09:08 -0500 Received: by mail-pl1-x644.google.com with SMTP id e5so4510889plb.5 for ; Sun, 10 Feb 2019 17:09:04 -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 g14sm17177630pfg.27.2019.02.10.17.09.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 10 Feb 2019 17:09:02 -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=MvaIKsOMPQ7hbRMjemvvtwhP7sBFQA2Gv3Y/7+kAWX0=; b=OeNmJRWYjbAAGxeF8eAGRyomWMZYqMo+HpCnjZC8mVnI1fk6ZT++0jvc1JfCTJtr7M 132XkFBNjBWB8ebtPsHJGt7ZZlua+eH7poE9WcjF16J+I027dpq3TnOYd1m5J02oz7KR zxaKtDgpCdxK9auAw3o6eKA2F/OwKi3n/+0loEh90XOyITjSQ6Z3Qel/8tvNMuCLo1EK 2Ne1JHa2YenYpceDkhH1ynZ4O+MdGLQ6gKbTfI80ym4ZKe+G85YQqqH6jN1gxZd3FH1c KUew5QOI+/nYCPOj4Iyj90udM56Cfs5f3oh3lCkuA6AtwXexzeRq1FDBiVYu2B/OC5Xp lcoA== 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=MvaIKsOMPQ7hbRMjemvvtwhP7sBFQA2Gv3Y/7+kAWX0=; b=Sr3Sw5TMdyidxyydsFujINVAJ8NyjzdSb2YcLPrDN7lLr5NKDgk8l2KFzNrUpj7/jY LyED8JImwVaXqbnBKnKC64rH4Vfxod/jdFc6JbdUFcpsJXRE82toOzjnnzXJTee3Y6tV ifSqcmJ7w10C9K4vTiQysAvTRh//5T+Fu+/itBMbJ8mY4vuOXFkygML3wDB/sNenC+fu dEv1tjRG0Wq/8/aa8P7DMG5TsYFyCOpkSwFUfAl4TbghVmVPBA0guk4JW0MNB4+5OKHz e7hua+jnD7hZLE0EVgMXnJXunl1jlM3xx3z5DgeyeExVHOScP2w8pFN8/QC4d/OzGTfb 7GDA== X-Gm-Message-State: AHQUAuaeZpWKTc0GdRyr085s2+RaENp3tA5ea8mhzwv7aOqXZ0G2QHWx V8PqpTeOzuC927XfyEJQei1svBuiVok= X-Google-Smtp-Source: AHgI3Ib/VKFIeXTGy37mTlIPaMVnJcOS2AptLvtyfjpKIZoNA5lzE/nzfMk+WU5OWzFG/WOT74INDQ== X-Received: by 2002:a17:902:7608:: with SMTP id k8mr29078056pll.245.1549847342745; Sun, 10 Feb 2019 17:09:02 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 10 Feb 2019 17:08:27 -0800 Message-Id: <20190211010829.29869-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190211010829.29869-1-richard.henderson@linaro.org> References: <20190211010829.29869-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::644 Subject: [Qemu-devel] [PATCH v2 24/26] 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/mte_helper.c | 96 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 87 insertions(+), 9 deletions(-) diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c index ad2902472d..3abed62018 100644 --- a/target/arm/mte_helper.c +++ b/target/arm/mte_helper.c @@ -53,19 +53,19 @@ static uint64_t strip_tbi(CPUARMState *env, uint64_t pt= r) static uint8_t *allocation_tag_mem(CPUARMState *env, uint64_t ptr, bool write, uintptr_t ra) { -#ifdef CONFIG_USER_ONLY ARMCPU *cpu =3D arm_env_get_cpu(env); + CPUState *cs =3D CPU(cpu); uint64_t clean_ptr =3D strip_tbi(env, ptr); uint8_t *tags; uintptr_t index; - int flags; =20 - flags =3D page_get_flags(clean_ptr); +#ifdef CONFIG_USER_ONLY + int flags =3D page_get_flags(clean_ptr); =20 if (!(flags & PAGE_VALID) || !(flags & (write ? PAGE_WRITE : PAGE_READ= ))) { /* SIGSEGV */ env->exception.vaddress =3D ptr; - cpu_restore_state(CPU(cpu), ra, true); + cpu_restore_state(cs, ra, true); raise_exception(env, EXCP_DATA_ABORT, 0, 1); } =20 @@ -82,16 +82,94 @@ static uint8_t *allocation_tag_mem(CPUARMState *env, ui= nt64_t ptr, if (tags =3D=3D NULL) { size_t alloc_size =3D TARGET_PAGE_SIZE >> (LOG2_TAG_GRANULE + 1); tags =3D page_alloc_target_data(clean_ptr, alloc_size); - assert(tags !=3D 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 =3D cpu_mmu_index(env, false); + index =3D tlb_index(env, mmu_idx, clean_ptr); + te =3D tlb_entry(env, mmu_idx, clean_ptr); + if (!tlb_hit(write ? tlb_addr_write(te) : te->addr_read, clean_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 =3D tlb_index(env, mmu_idx, clean_ptr); + te =3D tlb_entry(env, mmu_idx, clean_ptr); } =20 + /* If the virtual page MemAttr !=3D Tagged, nothing to do. */ + iotlbentry =3D &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 =3D cpu_get_address_space(cs, ARMASIdx_TAG); + if (!as) { + return NULL; + } + + /* Find the physical address for the virtual access. */ + section =3D iotlb_to_section(cs, iotlbentry->addr, iotlbentry->attrs); + physaddr =3D ((iotlbentry->addr & TARGET_PAGE_MASK) + clean_ptr + + section->offset_within_address_space + - section->offset_within_region); + + /* Convert to the physical address in tag space. */ + tag_physaddr =3D physaddr >> (LOG2_TAG_GRANULE + 1); + tag_len =3D 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 =3D address_space_to_flatview(as); + mr =3D 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", + clean_ptr, physaddr); + return NULL; + } + rcu_read_unlock(); + + /* The board should have created tag ram sized correctly. */ + assert(tag_len =3D=3D TARGET_PAGE_SIZE >> (LOG2_TAG_GRANULE + 1)); + + /* FIXME: Mark the tag page dirty for migration. */ + + tags =3D qemu_map_ram_ptr(mr->ram_block, xlat); +#endif + + assert(tags !=3D NULL); index =3D extract32(clean_ptr, LOG2_TAG_GRANULE + 1, TARGET_PAGE_BITS - LOG2_TAG_GRANULE - 1); return tags + index; -#else - /* Tag storage not implemented. */ - return NULL; -#endif } =20 static int get_allocation_tag(CPUARMState *env, uint64_t ptr, uintptr_t ra) --=20 2.17.2