Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 74AB6CD4F54 for ; Fri, 29 May 2026 19:54:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT3Gl-0005cH-SL; Fri, 29 May 2026 15:53:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wT3GU-0004zM-AS for qemu-arm@nongnu.org; Fri, 29 May 2026 15:53:07 -0400 Received: from mail-oo1-xc2a.google.com ([2607:f8b0:4864:20::c2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wT3GR-0005Xg-2p for qemu-arm@nongnu.org; Fri, 29 May 2026 15:53:05 -0400 Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-69dead44101so1962371eaf.3 for ; Fri, 29 May 2026 12:53:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780084382; x=1780689182; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=KO7Mq8JRuwohDcM/67cxG4Kl5R8QIg4FU/azGfOw7c8=; b=L38I8+LQb0m3yp00jhSy3NKGrGovLPSnuLP3XNld/VQHwMzgH9uC3VerI5XmCn1op6 15Olt/tLGl3ZvE+5aRbBXfywwLFejDyqMChwyk5E7Lc7JBj9j5tWHUKITVJ65pUOt2ge gj0yhJ4KGqev+5fHIW+t0aFrWsAvQBUKlSiwyaZWU+/O308HjnsCzSFBZwYzk85ndP1a el0ZsPr2dTx8mbMhqBeHsLamnpZolyu/tK/91fzIntBcFbwG8NQpaeIeu37Wy0B/2aO6 lGAEvu5E37c/bqT/0c2YRXuXWMhys6gj1eHI7/qPJKPals6HsFqdYwEWto9XAMBUGkOp hahw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780084382; x=1780689182; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=KO7Mq8JRuwohDcM/67cxG4Kl5R8QIg4FU/azGfOw7c8=; b=PML7pvP0dTvczqfv5ltMVtROl+soDv5L5EGQQ0lUuBMYQZONERzmfgpmoNK4Wq+Vm3 JK0Ct4ePxVGGu+QU7QhtjkH+HCPZ3RyORbDNYEgGztYvCckBzhllGPhFOkvNLgyt/NCE wpPXWCu6PHq/z+bBhuKMI2MRwxhDNSSJZZ/9inARyN7oe1VzZgqjL9wqrcZulchy8Dzj DgAr1qE5BtQfs/R9RWMZXCN4mZgaP2ohasL82jJaTjHSdHfKaFIpZJkucFE84VmDdMYf e0/Ojt4W01e37XbP448LxOMD9i3MnYBvHPD+QHUnz1po5IWjEe//MneFKN22agSweL8D 56Yg== X-Forwarded-Encrypted: i=1; AFNElJ/n7RNvbDdOkn9Oy/wukXAx91fr/VQ8YCAerHIbXB3kxO+C19XpSEuG4gciDCIGUCRo8YAre+zm1w==@nongnu.org X-Gm-Message-State: AOJu0YywqEV2d5kD8ug9SeVrO/LE03gNWkqieCQUorzqnp3IXeB1uAkD T2tzR48Soz75BsAyCoWlJtK9xkU+yPAYsDlUlbGiThztl6ZcjfK56BWmiPKW6zRm X-Gm-Gg: Acq92OE5JnOYJfHJEoRc0UMn25EljGnmLOqb4usLQydJBOEo81F0V698UM/+xx+pKE1 mb67QGyizn62ovX0Z002bJGsk9RNmkfQTP/LWM8hHz6bhC0MQ7BuwPdBbueZI2hmk5LmXcFKYsO GqRP+xNm4stwJmrGzRTuvE+k0I2GTItXw7VdS2IeIElVa2GodVDGqOxwc9/ZtgctHoSjUs43+u5 /8ttaIFwOhJCSQYHkt0o5ak5GWqu2LBiR+tJw4AVtzJXLnWQmVIBQE2ajwSx/cQa8xCPhlcZ5mT qhER/7yUkJd9V+7YHmmYCuDE6T5llEZrJVhkcdMQD0iBam4jgY8IWRYMMj/fuy8EtnQtu65DsIi oYR/0MC3pAGFfKhtlWgHUYq8hkmd0XDFgfTh5dX7nZ7IznFZVu0XnSciBIZY49PMacvTCquKBnE FBEZp33XXEGH/QCt2m3NlMDCVycBlTRJTGdqAgwSUIggc= X-Received: by 2002:a05:6820:1621:b0:694:8c67:5cb6 with SMTP id 006d021491bc7-69e1056f72cmr407587eaf.41.1780084381780; Fri, 29 May 2026 12:53:01 -0700 (PDT) Received: from [10.21.163.79] ([146.74.94.63]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-69e06587eecsm1626692eaf.0.2026.05.29.12.53.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 12:53:01 -0700 (PDT) From: Gabriel Brookman Date: Fri, 29 May 2026 12:52:44 -0700 Subject: [PATCH v7 04/15] linux-user: add MTE_STORE_ONLY to prctl MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260529-feat-mte4-v7-4-ccbd3c14eb3c@gmail.com> References: <20260529-feat-mte4-v7-0-ccbd3c14eb3c@gmail.com> In-Reply-To: <20260529-feat-mte4-v7-0-ccbd3c14eb3c@gmail.com> To: qemu-devel@nongnu.org Cc: Peter Maydell , Gustavo Romero , Richard Henderson , qemu-arm@nongnu.org, Laurent Vivier , Gabriel Brookman , Helge Deller , Pierrick Bouvier , Pierrick Bouvier X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1780084373; l=4942; i=brookmangabriel@gmail.com; s=20251009; h=from:subject:message-id; bh=3NUHlDKCw8l8rqmAwbaWm0eM8fht4yd8LR/eAfpLXkM=; b=uoYIV86MDp6ZmD6M18GW4FynMVQVea2hopTLoocsSdrtpHP6Gp4PbAq3W79RqN3qQWzzIjA7Q uZ+/1njRRJ3BzT0SN7qIlQSXI2xxVIVaPCz1zetYvUTEOZTtpXZcUD8 X-Developer-Key: i=brookmangabriel@gmail.com; a=ed25519; pk=m9TtPDal6WzoHNnQiHHKf8dTrv3DUCPUUTujuo8vNrw= Received-SPF: pass client-ip=2607:f8b0:4864:20::c2a; envelope-from=brookmangabriel@gmail.com; helo=mail-oo1-xc2a.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@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-arm-bounces+qemu-arm=archiver.kernel.org@nongnu.org Sender: qemu-arm-bounces+qemu-arm=archiver.kernel.org@nongnu.org Linux-user processes can now control whether MTE_STORE_ONLY is enabled using the prctl syscall. Signed-off-by: Gabriel Brookman Reviewed-by: Richard Henderson --- linux-user/aarch64/mte_user_helper.c | 11 ++++++++++- linux-user/aarch64/mte_user_helper.h | 14 +++++++++----- linux-user/aarch64/target_prctl.h | 6 +++++- target/arm/gdbstub64.c | 2 +- tests/tcg/aarch64/mte.h | 3 +++ 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/linux-user/aarch64/mte_user_helper.c b/linux-user/aarch64/mte_user_helper.c index a5b1c8503b..b5c4dafcda 100644 --- a/linux-user/aarch64/mte_user_helper.c +++ b/linux-user/aarch64/mte_user_helper.c @@ -10,7 +10,7 @@ #include "qemu.h" #include "mte_user_helper.h" -void arm_set_mte_tcf0(CPUArchState *env, abi_long value) +void arm_set_tagged_addr_ctrl(CPUArchState *env, abi_long value) { /* * Write PR_MTE_TCF to SCTLR_EL1[TCF0]. @@ -32,4 +32,13 @@ void arm_set_mte_tcf0(CPUArchState *env, abi_long value) tcf = 2; } env->cp15.sctlr_el[1] = deposit64(env->cp15.sctlr_el[1], 38, 2, tcf); + + /* + * If MTE_STORE_ONLY is enabled, set the corresponding sctlr_el1 bit + */ + if (value & PR_MTE_STORE_ONLY) { + env->cp15.sctlr_el[1] |= SCTLR_TCSO0; + } else { + env->cp15.sctlr_el[1] &= ~SCTLR_TCSO0; + } } diff --git a/linux-user/aarch64/mte_user_helper.h b/linux-user/aarch64/mte_user_helper.h index 0c53abda22..8a46f743f4 100644 --- a/linux-user/aarch64/mte_user_helper.h +++ b/linux-user/aarch64/mte_user_helper.h @@ -20,15 +20,19 @@ # define PR_MTE_TAG_SHIFT 3 # define PR_MTE_TAG_MASK (0xffffUL << PR_MTE_TAG_SHIFT) #endif +#ifndef PR_MTE_STORE_ONLY +# define PR_MTE_STORE_ONLY (1UL << 19) +#endif /** - * arm_set_mte_tcf0 - Set TCF0 field in SCTLR_EL1 register + * arm_set_tagged_addr_ctrl - Set TCF0 and TCSO0 fields in SCTLR_EL1 register * @env: The CPU environment - * @value: The value to be set for the Tag Check Fault in EL0 field. + * @value: The value to be set for the Tag Check Fault and Tag Check Store Only + * in EL0 field. * - * Only SYNC and ASYNC modes can be selected. If ASYMM mode is given, the SYNC - * mode is selected instead. So, there is no way to set the ASYMM mode. + * Only SYNC and ASYNC modes can be selected for TCF0. If ASYMM mode is given, + * the SYNC mode is selected instead. So, there is no way to set the ASYMM mode. */ -void arm_set_mte_tcf0(CPUArchState *env, abi_long value); +void arm_set_tagged_addr_ctrl(CPUArchState *env, abi_long value); #endif /* AARCH64_MTE_USER_HELPER_H */ diff --git a/linux-user/aarch64/target_prctl.h b/linux-user/aarch64/target_prctl.h index 621be5727f..d91e75d60d 100644 --- a/linux-user/aarch64/target_prctl.h +++ b/linux-user/aarch64/target_prctl.h @@ -168,6 +168,9 @@ static abi_long do_prctl_set_tagged_addr_ctrl(CPUArchState *env, abi_long arg2) if (cpu_isar_feature(aa64_mte, cpu)) { valid_mask |= PR_MTE_TCF_MASK; valid_mask |= PR_MTE_TAG_MASK; + if (cpu_isar_feature(aa64_mte_store_only, cpu)) { + valid_mask |= PR_MTE_STORE_ONLY; + } } if (arg2 & ~valid_mask) { @@ -176,7 +179,7 @@ static abi_long do_prctl_set_tagged_addr_ctrl(CPUArchState *env, abi_long arg2) env->tagged_addr_enable = arg2 & PR_TAGGED_ADDR_ENABLE; if (cpu_isar_feature(aa64_mte, cpu)) { - arm_set_mte_tcf0(env, arg2); + arm_set_tagged_addr_ctrl(env, arg2); /* * Write PR_MTE_TAG to GCR_EL1[Exclude]. @@ -185,6 +188,7 @@ static abi_long do_prctl_set_tagged_addr_ctrl(CPUArchState *env, abi_long arg2) */ env->cp15.gcr_el1 = deposit64(env->cp15.gcr_el1, 0, 16, ~arg2 >> PR_MTE_TAG_SHIFT); + arm_rebuild_hflags(env); } return 0; diff --git a/target/arm/gdbstub64.c b/target/arm/gdbstub64.c index a4fa740caf..0c3e5b30bd 100644 --- a/target/arm/gdbstub64.c +++ b/target/arm/gdbstub64.c @@ -684,7 +684,7 @@ int aarch64_gdb_set_tag_ctl_reg(CPUState *cs, uint8_t *buf, int reg) * expose options regarding the type of MTE fault that can be controlled at * runtime. */ - arm_set_mte_tcf0(env, tcf); + arm_set_tagged_addr_ctrl(env, tcf); return 1; #else diff --git a/tests/tcg/aarch64/mte.h b/tests/tcg/aarch64/mte.h index 0805676b11..17b932f3f1 100644 --- a/tests/tcg/aarch64/mte.h +++ b/tests/tcg/aarch64/mte.h @@ -20,6 +20,9 @@ #ifndef PR_TAGGED_ADDR_ENABLE # define PR_TAGGED_ADDR_ENABLE (1UL << 0) #endif +#ifndef PR_MTE_STORE_ONLY +# define PR_MTE_STORE_ONLY (1UL << 19) +#endif #ifndef PR_MTE_TCF_SHIFT # define PR_MTE_TCF_SHIFT 1 # define PR_MTE_TCF_NONE (0UL << PR_MTE_TCF_SHIFT) -- 2.54.0