From patchwork Fri Jun 28 05:08:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 808140 Delivered-To: patch@linaro.org Received: by 2002:adf:fe0a:0:b0:362:4979:7f74 with SMTP id n10csp194941wrr; Thu, 27 Jun 2024 22:22:16 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUlxry9d5a/gSnmBDJ+vk4/2fLuDHvS+wR3+DDWrNzTJGGlvumn7rmDa9m/m1g80F0QkWgPA0VREhqUkbUv2P6t X-Google-Smtp-Source: AGHT+IESb+LZn4tOH7Z3ZpPJ1EdapsSvsVQW4DrB/z3U8ztu5TJecDAJCcf87+daEnYrHOfJSxQg X-Received: by 2002:ad4:4105:0:b0:6b5:4aee:1077 with SMTP id 6a1803df08f44-6b54aee13afmr136074736d6.47.1719552136542; Thu, 27 Jun 2024 22:22:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719552136; cv=none; d=google.com; s=arc-20160816; b=VvXTj6wKH37iH8/BPCro1XPk9eK+cqpNgfW8UjAjddRhF/HmSC9v2CCeNHZdI6eTzh wCL51tyJJ9e7dn18f7XsnqoaSfk5Y55dqY31R0xO9ZCrNmUgCf2qzOFqLM9tsnYAqyWY o2mOrYjwwSmlRDUhB+l4IwyD1de5zTkAnaY4oQbx8VrpHCJT3B1m2VO4pcDTxEYQkzNZ V7QsCXA+iLGoQVcqY8+VavENSJSXUBrJr5ACW0I+JwmoVtwD5hu1IS2ii9yVZ4t8wkZy 0cVE7RaUums4dXuu5zUih23e/7G6yS+lPcgS2xmbA0TwDyxQRSfGOEmaGRqRIySkPbLt YH/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=iNGHLZ6SUmkXQCpzg0N2HSo1zlyebo9gy5r+WIIkQrU=; fh=fQSRkfw+DkTHa5KQssXieneufL+rl3wPoA2jkVIsZpk=; b=QBHml3fcON+FEPCbRGXQrUATNjTsdpBCFEC9MaHI2/t7TP1aP/9ERaddm2EFHGOD6O 5Z+emZ+peYEqf9US8jrrBwpp30jQxsis3z73rDtJGnunc84ZSkflnzp4k5CN8B1QsBmg ePgiQ8Y6YTMSH7eFr8d14BObHX31aUX5Nfdh6rqBuRCi/Nqu68lUpsnnt2rDgcDlYyF4 GhkAeW4cmsJ8q5MK/+5z9ebW62WPbqabSIurUPUNOlWhG3y/YXHtFX38PU4FpnxKSIot WhnaWRimqCZ7rVqStL9q1Y/JCGNLdYr/a43HdFdljtuEUBiIvTSXtcWHB2zRaoMflwtv DOkA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WLqVvAUD; 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 6a1803df08f44-6b59e3637dasi12390486d6.94.2024.06.27.22.22.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Jun 2024 22:22:16 -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=WLqVvAUD; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sN42s-0003Hl-H5; Fri, 28 Jun 2024 01:21:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sN42q-0003HB-Td for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:12 -0400 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN42o-0008DW-Tf for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:12 -0400 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-701f9fb9483so140353a34.1 for ; Thu, 27 Jun 2024 22:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719552069; x=1720156869; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iNGHLZ6SUmkXQCpzg0N2HSo1zlyebo9gy5r+WIIkQrU=; b=WLqVvAUD6sBfoVE7YMegGq8BsoFUW11o0aW9w1WdPXnrrj1QHfHE9Lea8gfnxiosKu AYB98uy3GUV/KyUDQRlmgumSePeh78NAByGQYIkh5H9Ddb9bgqQR6cqacFiu0hOf3s9I RzwtLh5WbT7eVIQewTbCBS5L1vhQ02BvNEfCkICVhEpczc4gM/oykQ1kHb5xbbhfFZES ubdRB01/taIgpdU6+yGXkVP+gYQJCNAI5lEnWLlaHhh+dNimaIvbjuX4qk64oYpo7NI/ 99oI5MYnjzLxj4Di5b9HsuaQdVXlNCc7ZieU5bRLqHgYnvBKNdTQGZAELMnwu3Ot7Vit +uuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719552069; x=1720156869; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iNGHLZ6SUmkXQCpzg0N2HSo1zlyebo9gy5r+WIIkQrU=; b=UbrOZ9pf2GEfOzvRpzkLE521p7eBUUwGlwC4fdpnr+GSdSXH0qUF2EVcbJwmFZnr2d mMeG28UF5aultIbr5j9AhsMBfwAQQ70yf25gFK5NhCrJAbkoHA0dyK5vvaK/JgX6VCd5 pMh5xKuzCpPtnuzHJ4RrIS62OHRo1Sx9of6EidIAYUkwobSuxCUGYI/Lp45prJq8lPbv WQA7Ky5x9YHAaeIlsXlwXof96XDCfr6Yk3vnk0QMZPyJBJiO/2TdZFFPDwomox57dOhP 3pU3/FR5idhkxubEE0t7HZ/iPU6d0iCBLPeE4b4gd3gO3AM/ZEgZCEPoHwgk9LiQ3PkJ Jr+g== X-Gm-Message-State: AOJu0YwIXuvTuRH9nKF6Ur6lTVJCeS1bvjWKP1fqmqp0Pmq/Vn1s2KVQ xzvSAOV5+BJjOYjq0mKdtBnfgTOXfYUokTIIXZ+d6/vTziaEfOoyEiUd0GiT1snvscQ97IjA2hx 9 X-Received: by 2002:a05:6870:c1d2:b0:254:a8ec:306f with SMTP id 586e51a60fabf-25d0191bef2mr15450620fac.43.1719552068490; Thu, 27 Jun 2024 22:21:08 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:391e:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-72c6b2a16cdsm423932a12.46.2024.06.27.22.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 22:21:07 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, philmd@linaro.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v6 05/11] target/arm: Make some MTE helpers widely available Date: Fri, 28 Jun 2024 05:08:44 +0000 Message-Id: <20240628050850.536447-6-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628050850.536447-1-gustavo.romero@linaro.org> References: <20240628050850.536447-1-gustavo.romero@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::330; envelope-from=gustavo.romero@linaro.org; helo=mail-ot1-x330.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Make the MTE helpers allocation_tag_mem_probe, load_tag1, and store_tag1 available to other subsystems. Signed-off-by: Gustavo Romero Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- target/arm/tcg/mte_helper.c | 45 ++++--------------------- target/arm/tcg/mte_helper.h | 66 +++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 38 deletions(-) create mode 100644 target/arm/tcg/mte_helper.h diff --git a/target/arm/tcg/mte_helper.c b/target/arm/tcg/mte_helper.c index a50d576294..9d2ba287ee 100644 --- a/target/arm/tcg/mte_helper.c +++ b/target/arm/tcg/mte_helper.c @@ -29,6 +29,7 @@ #include "hw/core/tcg-cpu-ops.h" #include "qapi/error.h" #include "qemu/guest-random.h" +#include "mte_helper.h" static int choose_nonexcluded_tag(int tag, int offset, uint16_t exclude) @@ -50,42 +51,10 @@ static int choose_nonexcluded_tag(int tag, int offset, uint16_t exclude) return tag; } -/** - * allocation_tag_mem_probe: - * @env: the cpu environment - * @ptr_mmu_idx: the addressing regime to use for the virtual address - * @ptr: the virtual address for which to look up tag memory - * @ptr_access: the access to use for the virtual address - * @ptr_size: the number of bytes in the normal memory access - * @tag_access: the access to use for the tag memory - * @probe: true to merely probe, never taking an exception - * @ra: the return address for exception handling - * - * Our tag memory is formatted as a sequence of little-endian nibbles. - * That is, the byte at (addr >> (LOG2_TAG_GRANULE + 1)) contains two - * tags, with the tag at [3:0] for the lower addr and the tag at [7:4] - * for the higher addr. - * - * Here, resolve the physical address from the virtual address, and return - * a pointer to the corresponding tag byte. - * - * If there is no tag storage corresponding to @ptr, return NULL. - * - * If the page is inaccessible for @ptr_access, or has a watchpoint, there are - * three options: - * (1) probe = true, ra = 0 : pure probe -- we return NULL if the page is not - * accessible, and do not take watchpoint traps. The calling code must - * handle those cases in the right priority compared to MTE traps. - * (2) probe = false, ra = 0 : probe, no fault expected -- the caller guarantees - * that the page is going to be accessible. We will take watchpoint traps. - * (3) probe = false, ra != 0 : non-probe -- we will take both memory access - * traps and watchpoint traps. - * (probe = true, ra != 0 is invalid and will assert.) - */ -static uint8_t *allocation_tag_mem_probe(CPUARMState *env, int ptr_mmu_idx, - uint64_t ptr, MMUAccessType ptr_access, - int ptr_size, MMUAccessType tag_access, - bool probe, uintptr_t ra) +uint8_t *allocation_tag_mem_probe(CPUARMState *env, int ptr_mmu_idx, + uint64_t ptr, MMUAccessType ptr_access, + int ptr_size, MMUAccessType tag_access, + bool probe, uintptr_t ra) { #ifdef CONFIG_USER_ONLY uint64_t clean_ptr = useronly_clean_ptr(ptr); @@ -287,7 +256,7 @@ uint64_t HELPER(addsubg)(CPUARMState *env, uint64_t ptr, return address_with_allocation_tag(ptr + offset, rtag); } -static int load_tag1(uint64_t ptr, uint8_t *mem) +int load_tag1(uint64_t ptr, uint8_t *mem) { int ofs = extract32(ptr, LOG2_TAG_GRANULE, 1) * 4; return extract32(*mem, ofs, 4); @@ -321,7 +290,7 @@ static void check_tag_aligned(CPUARMState *env, uint64_t ptr, uintptr_t ra) } /* For use in a non-parallel context, store to the given nibble. */ -static void store_tag1(uint64_t ptr, uint8_t *mem, int tag) +void store_tag1(uint64_t ptr, uint8_t *mem, int tag) { int ofs = extract32(ptr, LOG2_TAG_GRANULE, 1) * 4; *mem = deposit32(*mem, ofs, 4, tag); diff --git a/target/arm/tcg/mte_helper.h b/target/arm/tcg/mte_helper.h new file mode 100644 index 0000000000..1f471fb69b --- /dev/null +++ b/target/arm/tcg/mte_helper.h @@ -0,0 +1,66 @@ +/* + * ARM MemTag operation helpers. + * + * This code is licensed under the GNU GPL v2 or later. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#ifndef TARGET_ARM_MTE_H +#define TARGET_ARM_MTE_H + +#include "exec/mmu-access-type.h" + +/** + * allocation_tag_mem_probe: + * @env: the cpu environment + * @ptr_mmu_idx: the addressing regime to use for the virtual address + * @ptr: the virtual address for which to look up tag memory + * @ptr_access: the access to use for the virtual address + * @ptr_size: the number of bytes in the normal memory access + * @tag_access: the access to use for the tag memory + * @probe: true to merely probe, never taking an exception + * @ra: the return address for exception handling + * + * Our tag memory is formatted as a sequence of little-endian nibbles. + * That is, the byte at (addr >> (LOG2_TAG_GRANULE + 1)) contains two + * tags, with the tag at [3:0] for the lower addr and the tag at [7:4] + * for the higher addr. + * + * Here, resolve the physical address from the virtual address, and return + * a pointer to the corresponding tag byte. + * + * If there is no tag storage corresponding to @ptr, return NULL. + * + * If the page is inaccessible for @ptr_access, or has a watchpoint, there are + * three options: + * (1) probe = true, ra = 0 : pure probe -- we return NULL if the page is not + * accessible, and do not take watchpoint traps. The calling code must + * handle those cases in the right priority compared to MTE traps. + * (2) probe = false, ra = 0 : probe, no fault expected -- the caller guarantees + * that the page is going to be accessible. We will take watchpoint traps. + * (3) probe = false, ra != 0 : non-probe -- we will take both memory access + * traps and watchpoint traps. + * (probe = true, ra != 0 is invalid and will assert.) + */ +uint8_t *allocation_tag_mem_probe(CPUARMState *env, int ptr_mmu_idx, + uint64_t ptr, MMUAccessType ptr_access, + int ptr_size, MMUAccessType tag_access, + bool probe, uintptr_t ra); + +/** + * load_tag1 - Load 1 tag (nibble) from byte + * @ptr: The tagged address + * @mem: The tag address (packed, 2 tags in byte) + */ +int load_tag1(uint64_t ptr, uint8_t *mem); + +/** + * store_tag1 - Store 1 tag (nibble) into byte + * @ptr: The tagged address + * @mem: The tag address (packed, 2 tags in byte) + * @tag: The tag to be stored in the nibble + */ +void store_tag1(uint64_t ptr, uint8_t *mem, int tag); + +#endif /* TARGET_ARM_MTE_H */