From patchwork Mon Jun 24 05:30:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 806996 Delivered-To: patch@linaro.org Received: by 2002:a5d:508d:0:b0:362:4979:7f74 with SMTP id a13csp1731782wrt; Sun, 23 Jun 2024 22:32:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVqk0DVwlxa4T7sRYqe0Koxl8xz37K3+v2su6R9Eu7GKgRIZaN2WgMp5xgi5wfY9HL0G9WyBiQPf03G8mI6z9FF X-Google-Smtp-Source: AGHT+IEXGDM6NRn2uu/h4wLAzf4679cdxD9YPqOYXl9biIaOvdbaRAdKjPdlSNeabZnJRkEv/hkE X-Received: by 2002:a67:b107:0:b0:48d:87f9:e529 with SMTP id ada2fe7eead31-48f4f0f8490mr2114734137.29.1719207125836; Sun, 23 Jun 2024 22:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719207125; cv=none; d=google.com; s=arc-20160816; b=zd7LgOy/DbRROBr4YssPwK/3/pAhb+7llUGhC3o7jVgepIQ1QiAXwNjFgZSxf/vSS0 iefBG4UaVMbb4VgpXi1Y6EALANHx5xqJW6gdDWeIqaKvFg0uKaj/3f1kOEwLjpgTVnyO E+jiQrTNsA+GC6v9nxvHbM10vadCL3WTaQDLbeZeCIeUu3KWqv+8NHhc+alR0ig/eajD ReHbzOhhRtzlB1Uf7HVIlFAP+w3mFXUn3+2q7zknb35d6N63cHXwW0aevVVQCYK+GVR0 askA/zkNgjEGpWtH1jpEhZgqPwWSsaSPNnb1rhOCBjHqXLEn26556fxaR6I4T8SUXgzb Sx2w== 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=8iJ/HuUc4gPL6Bek0vAIaSv9Lqxnq8U+8yqS5vGEFYg=; fh=b5q3cJgcc12gnKfUWQQbBLXKRqia4x4Q8oLG+cCF/wU=; b=gc+HCCHPYCmWC1TGER8g8a2LKa8Ziyeorau77r6lN4VX3Ympu/AwlYO8RcNs/dz4P/ WO9UAA0kKUekXUJRHmBOMNl8HiGG1q+RwGKwX0FJ2YBjcVpaNuUxvTunctytoodkAQCU qo3Rlw8kKBds+La8uZ6d+6aQNEKNw24XYhnt4aRV0pWOavWjuJZtiCyCJL90Eebv/DMd RPn6dVlx2jXaARRReirTxVhaDRmDorNhuzsT5mOKAgY61Bp3GewQmJN1bC3pPHHM5uLa zz+VBC172IcSAANMouXc+n9+K+mu1ToOkK8xKZX6iF1vvsWsRAzPDByzlaUdW02zx9GW oUmg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eYjMn2CW; 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-6b51ecfa402si73100556d6.67.2024.06.23.22.32.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 Jun 2024 22:32:05 -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=eYjMn2CW; 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 1sLcIe-00034k-16; Mon, 24 Jun 2024 01:31:32 -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 1sLcIY-00033V-Cr for qemu-devel@nongnu.org; Mon, 24 Jun 2024 01:31:27 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLcIW-0004b2-Ey for qemu-devel@nongnu.org; Mon, 24 Jun 2024 01:31:26 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-70671ecd334so876232b3a.0 for ; Sun, 23 Jun 2024 22:31:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719207082; x=1719811882; 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=8iJ/HuUc4gPL6Bek0vAIaSv9Lqxnq8U+8yqS5vGEFYg=; b=eYjMn2CWiLEcp4eQqYjzpDdl2xu0/w9XyDEs7XABnPfGq535BFJNkCNI72IO2wJZnY 04smpS67nJUqqdsPl7qV6fCSjt/j0JN7pffyf+D2GlsWNtLqceuAtl3dvL1l3XaURxCg AM0xAGwSAB5Dq6hwsZ5V9yqj8hpQ6qflADI06RxznkiIN/Iwyfrdhf20p3mwnCvTXJSn CH7kKTqV14QzdJ7WEHc1F4LiOx0WXDpJkCHXw8WS3sANFzGDniXlOduf5Rs20CY4hmU9 mKK+JJazKEfgjquVGDfPMj0MaN73aw8qPBJmkZovQNTZ9cXS86ggcKPxUWIBz62muEpJ Sz5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719207082; x=1719811882; 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=8iJ/HuUc4gPL6Bek0vAIaSv9Lqxnq8U+8yqS5vGEFYg=; b=QUn1DsTusL0HDFKv1WX2pgBtY3rmLZtTSHu8pDi07IgaArbWWrfS/NUe8M3nQSps+6 KfbIbaunt0gGiAm20wlcnEYCnIcgK9kMVmnx1UhsDhADYrmFSuz2Hrq1hMKEx7oPKTKc AnMLA8YojEGD5+mV41QWdG1c2wBrFyfWQHS7+H+tH/VD/cvTDPopAytrrk657Z4jLwf9 zily3o/T6inWTab+a6BEUWg9/Kmsxx/mg+19jC7+92ge5/L4GG0pkLB2S1Wc3PDKiRww mUmE0e1u2xMzKybph8NkG+izmF7ubhnJJYIBwcQmO/1k+pGevIcJLFM+l/m75RCEiu0y hsnQ== X-Gm-Message-State: AOJu0YyuFnBM6bDMsBBOq4RMYiBzyC7qMUTHNRHbqSirsi9MBkC+HJ6n mwyAfaQqj4gO7NpzXI/925m3YJNaSbqyxKecIhW0pxLc1cDKG1OKRz2g9zv2Sbb2GcVqs6p4fH2 1g4Q= X-Received: by 2002:a05:6a20:4da6:b0:1bc:f67f:604a with SMTP id adf61e73a8af0-1bcf67f7e5cmr3830998637.30.1719207082389; Sun, 23 Jun 2024 22:31:22 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:1758:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-716b4a73183sm3953601a12.39.2024.06.23.22.31.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jun 2024 22:31:21 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: philmd@linaro.org, peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v4 5/9] target/arm: Make some MTE helpers widely available Date: Mon, 24 Jun 2024 05:30:42 +0000 Message-Id: <20240624053046.221802-6-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240624053046.221802-1-gustavo.romero@linaro.org> References: <20240624053046.221802-1-gustavo.romero@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x42f.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 --- target/arm/tcg/mte_helper.c | 54 +++------------------------ target/arm/tcg/mte_helper.h | 74 +++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 49 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..da6bc72b9c 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,12 +256,6 @@ 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 ofs = extract32(ptr, LOG2_TAG_GRANULE, 1) * 4; - return extract32(*mem, ofs, 4); -} - uint64_t HELPER(ldg)(CPUARMState *env, uint64_t ptr, uint64_t xt) { int mmu_idx = arm_env_mmu_index(env); @@ -320,13 +283,6 @@ 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) -{ - int ofs = extract32(ptr, LOG2_TAG_GRANULE, 1) * 4; - *mem = deposit32(*mem, ofs, 4, tag); -} - /* For use in a parallel context, atomically store to the given nibble. */ static void store_tag1_parallel(uint64_t ptr, uint8_t *mem, int tag) { diff --git a/target/arm/tcg/mte_helper.h b/target/arm/tcg/mte_helper.h new file mode 100644 index 0000000000..6a82ff3403 --- /dev/null +++ b/target/arm/tcg/mte_helper.h @@ -0,0 +1,74 @@ +/* + * 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 + +/** + * 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) + */ +static inline int load_tag1(uint64_t ptr, uint8_t *mem) +{ + int ofs = extract32(ptr, LOG2_TAG_GRANULE, 1) * 4; + return extract32(*mem, ofs, 4); +} + +/** + * 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 + * + * For use in a non-parallel context, store to the given nibble. + */ +static inline 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); +} + +#endif /* TARGET_ARM_MTE_H */