From nobody Thu Sep 19 01:50:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1720169270; cv=none; d=zohomail.com; s=zohoarc; b=NwcHrCSLvgkJA6KphVkx81OCDqWsC+HWczRMsTiROfQ51UV3WuvK524rddv2JKR1RjOHxbgzPd/ml//sN+B3cicpW5we7oZfi5vTXo7doPR1yLADiK1eQudV4/zBGjMFOBuBZKEOQQ2qJdzACYHcZiWK+WylPIc4ZABd99+V/cw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720169270; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=U6hurhQTjp832TOlAx+LCodgHfvL9JAd0ZCjMoFRr6I=; b=fPM/wM7pMij8+wKOXe2lHl2ywkke+Lu76jp8mAG2VUoD0iMJjbf9MaxBywlUOhclDihrw30eNgoreMZ5sPZPRRSTW4kS3+YGYHvSmgDuxNn1gF63oLNCA0T2TPMY7PITMhIL6j2hK5RsKfOw5EvxMfL9xnEoL6PVeqVvwT3xWlk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720169270121448.7862187389753; Fri, 5 Jul 2024 01:47:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sPebT-00010a-8T; Fri, 05 Jul 2024 04:47:40 -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 1sPebE-0000tP-PY for qemu-devel@nongnu.org; Fri, 05 Jul 2024 04:47:27 -0400 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sPeb2-0004AU-RS for qemu-devel@nongnu.org; Fri, 05 Jul 2024 04:47:24 -0400 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a7541fad560so157277566b.0 for ; Fri, 05 Jul 2024 01:47:12 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a77cd9637f4sm30271366b.57.2024.07.05.01.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 01:47:10 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 2244A62176; Fri, 5 Jul 2024 09:40:51 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720169231; x=1720774031; 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=U6hurhQTjp832TOlAx+LCodgHfvL9JAd0ZCjMoFRr6I=; b=tloXcRzD/TdeBgMvGcAJw7duetYDQWUVFysuCIMfYrG9Kjeku+naNCo53+rdsr/w2r 7u2rotExWPqrDmprKCDnG+sUIDvAIW37KUO8tNcTFndzYBnGm0gLeAW0MPsX5C3kv8ep yOnu5fkhvPMjc+t5C8R7LLdep/AcnU1xu9DO8td8iCSYKYXhM18QSx9JO7JQF1b5pZZt cgru0a8gGyMwUfm87Q7SgSLozGRhgnX32sSK1WKREX0u3YF5X3W/ICD0Q7iSa5RFilaB KWjEatUVAWxbvj/SRm8GTnoySSFpPF+i1lptDyZ+/17sTAZQxH1r9JRnibk6IxDbqlJK coVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720169231; x=1720774031; 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=U6hurhQTjp832TOlAx+LCodgHfvL9JAd0ZCjMoFRr6I=; b=hjOr/kfLvTJSRQWEzm6dXEEukvn02Z2bv31/UtwSYuE68hseAOz7DDojKVxZDwaSnc aWLoD79jiev+CFxxHqxas+fXOQOmMu/BOVW36IYgWKN03DXmfs1aBBKpRhMIIkwtIWlZ 4JJPcfLjJWvsauUuFoEoebZO454v5gE64uytE4UCwVqlhLDKT4sYC2N3B+U6WE238ze+ Zz+DC2ACQjYRZEKV8kRc913cm7pbwcodPqlqczzQmRzwccJGGclEyzbLBqMm+8soWahc BGsLsERkRko3FBeGoW5jDdzkCaFIwY21FeYuCEKjDfvYjK08ztScIe8Ft+kUxd1xMwIE 8qDw== X-Gm-Message-State: AOJu0YwmKu+xTB8rM5utbBxkvmiFLcWCnu+810IYQWgaZLsEV2u87eJo c9NB9fCFjsYB/aCO5aR/tPpb47n7bbG4TmnqJ/ThDCH/2rnUZv417FZYx+aWsi4= X-Google-Smtp-Source: AGHT+IEubJGY+NDAKB0/iFr5NUae5zedXOgoBWbSGzbBjmJUi4vwkha4pOXNA4h47JqROyILcck8cg== X-Received: by 2002:a17:907:97c8:b0:a77:a58f:7f6a with SMTP id a640c23a62f3a-a77ba70e417mr395665766b.38.1720169230781; Fri, 05 Jul 2024 01:47:10 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Wainer dos Santos Moschetta , Beraldo Leal , David Hildenbrand , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Alexandre Iooss , Thomas Huth , Mahmoud Mandour , Peter Maydell , qemu-arm@nongnu.org, Aleksandar Rikalo , Mads Ynddal , Yanan Wang , Eduardo Habkost , Peter Xu , Richard Henderson , Marcel Apfelbaum , Paul Burton , Stefan Hajnoczi , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Laurent Vivier , Gustavo Romero Subject: [PATCH v2 35/40] target/arm: Factor out code for setting MTE TCF0 field Date: Fri, 5 Jul 2024 09:40:42 +0100 Message-Id: <20240705084047.857176-36-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240705084047.857176-1-alex.bennee@linaro.org> References: <20240705084047.857176-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a00:1450:4864:20::634; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x634.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1720169271935100001 From: Gustavo Romero Factor out the code used for setting the MTE TCF0 field from the prctl code into a convenient function. Other subsystems, like gdbstub, need to set this field as well, so keep it as a separate function to avoid duplication and ensure consistency in how this field is set across the board. Signed-off-by: Gustavo Romero Message-Id: <20240628050850.536447-7-gustavo.romero@linaro.org> [AJB: clean-up includes, move MTE defines] Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Manos Pitsidianakis --- vAJB: - clean-up includes, move MTE defines --- linux-user/aarch64/mte_user_helper.h | 32 +++++++++++++++++++++++++ linux-user/aarch64/target_prctl.h | 22 ++--------------- linux-user/aarch64/mte_user_helper.c | 35 ++++++++++++++++++++++++++++ linux-user/syscall.c | 9 ------- linux-user/aarch64/meson.build | 2 ++ 5 files changed, 71 insertions(+), 29 deletions(-) create mode 100644 linux-user/aarch64/mte_user_helper.h create mode 100644 linux-user/aarch64/mte_user_helper.c diff --git a/linux-user/aarch64/mte_user_helper.h b/linux-user/aarch64/mte_= user_helper.h new file mode 100644 index 0000000000..8685e5175a --- /dev/null +++ b/linux-user/aarch64/mte_user_helper.h @@ -0,0 +1,32 @@ +/* + * ARM MemTag convenience functions. + * + * This code is licensed under the GNU GPL v2 or later. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#ifndef AARCH64_MTE_USER_HELPER_H +#define AARCH64_MTE USER_HELPER_H + +#ifndef PR_MTE_TCF_SHIFT +# define PR_MTE_TCF_SHIFT 1 +# define PR_MTE_TCF_NONE (0UL << PR_MTE_TCF_SHIFT) +# define PR_MTE_TCF_SYNC (1UL << PR_MTE_TCF_SHIFT) +# define PR_MTE_TCF_ASYNC (2UL << PR_MTE_TCF_SHIFT) +# define PR_MTE_TCF_MASK (3UL << PR_MTE_TCF_SHIFT) +# define PR_MTE_TAG_SHIFT 3 +# define PR_MTE_TAG_MASK (0xffffUL << PR_MTE_TAG_SHIFT) +#endif + +/** + * arm_set_mte_tcf0 - Set TCF0 field in SCTLR_EL1 register + * @env: The CPU environment + * @value: The value to be set for the Tag Check Fault 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. + */ +void arm_set_mte_tcf0(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 aa8e203c15..ed75b9e4b5 100644 --- a/linux-user/aarch64/target_prctl.h +++ b/linux-user/aarch64/target_prctl.h @@ -7,6 +7,7 @@ #define AARCH64_TARGET_PRCTL_H =20 #include "target/arm/cpu-features.h" +#include "mte_user_helper.h" =20 static abi_long do_prctl_sve_get_vl(CPUArchState *env) { @@ -173,26 +174,7 @@ static abi_long do_prctl_set_tagged_addr_ctrl(CPUArchS= tate *env, abi_long arg2) env->tagged_addr_enable =3D arg2 & PR_TAGGED_ADDR_ENABLE; =20 if (cpu_isar_feature(aa64_mte, cpu)) { - /* - * Write PR_MTE_TCF to SCTLR_EL1[TCF0]. - * - * The kernel has a per-cpu configuration for the sysadmin, - * /sys/devices/system/cpu/cpu/mte_tcf_preferred, - * which qemu does not implement. - * - * Because there is no performance difference between the modes, a= nd - * because SYNC is most useful for debugging MTE errors, choose SY= NC - * as the preferred mode. With this preference, and the way the A= PI - * uses only two bits, there is no way for the program to select - * ASYMM mode. - */ - unsigned tcf =3D 0; - if (arg2 & PR_MTE_TCF_SYNC) { - tcf =3D 1; - } else if (arg2 & PR_MTE_TCF_ASYNC) { - tcf =3D 2; - } - env->cp15.sctlr_el[1] =3D deposit64(env->cp15.sctlr_el[1], 38, 2, = tcf); + arm_set_mte_tcf0(env, arg2); =20 /* * Write PR_MTE_TAG to GCR_EL1[Exclude]. diff --git a/linux-user/aarch64/mte_user_helper.c b/linux-user/aarch64/mte_= user_helper.c new file mode 100644 index 0000000000..a5b1c8503b --- /dev/null +++ b/linux-user/aarch64/mte_user_helper.c @@ -0,0 +1,35 @@ +/* + * ARM MemTag convenience functions. + * + * This code is licensed under the GNU GPL v2 or later. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "mte_user_helper.h" + +void arm_set_mte_tcf0(CPUArchState *env, abi_long value) +{ + /* + * Write PR_MTE_TCF to SCTLR_EL1[TCF0]. + * + * The kernel has a per-cpu configuration for the sysadmin, + * /sys/devices/system/cpu/cpu/mte_tcf_preferred, + * which qemu does not implement. + * + * Because there is no performance difference between the modes, and + * because SYNC is most useful for debugging MTE errors, choose SYNC + * as the preferred mode. With this preference, and the way the API + * uses only two bits, there is no way for the program to select + * ASYMM mode. + */ + unsigned tcf =3D 0; + if (value & PR_MTE_TCF_SYNC) { + tcf =3D 1; + } else if (value & PR_MTE_TCF_ASYNC) { + tcf =3D 2; + } + env->cp15.sctlr_el[1] =3D deposit64(env->cp15.sctlr_el[1], 38, 2, tcf); +} diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e2804312fc..b8c278b91d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6281,15 +6281,6 @@ abi_long do_arch_prctl(CPUX86State *env, int code, a= bi_ulong addr) # define PR_GET_TAGGED_ADDR_CTRL 56 # define PR_TAGGED_ADDR_ENABLE (1UL << 0) #endif -#ifndef PR_MTE_TCF_SHIFT -# define PR_MTE_TCF_SHIFT 1 -# define PR_MTE_TCF_NONE (0UL << PR_MTE_TCF_SHIFT) -# define PR_MTE_TCF_SYNC (1UL << PR_MTE_TCF_SHIFT) -# define PR_MTE_TCF_ASYNC (2UL << PR_MTE_TCF_SHIFT) -# define PR_MTE_TCF_MASK (3UL << PR_MTE_TCF_SHIFT) -# define PR_MTE_TAG_SHIFT 3 -# define PR_MTE_TAG_MASK (0xffffUL << PR_MTE_TAG_SHIFT) -#endif #ifndef PR_SET_IO_FLUSHER # define PR_SET_IO_FLUSHER 57 # define PR_GET_IO_FLUSHER 58 diff --git a/linux-user/aarch64/meson.build b/linux-user/aarch64/meson.build index 248c578d15..f75bb3cd75 100644 --- a/linux-user/aarch64/meson.build +++ b/linux-user/aarch64/meson.build @@ -9,3 +9,5 @@ vdso_le_inc =3D gen_vdso.process('vdso-le.so', extra_args: ['-r', '__kernel_rt_sigreturn']) =20 linux_user_ss.add(when: 'TARGET_AARCH64', if_true: [vdso_be_inc, vdso_le_i= nc]) + +linux_user_ss.add(when: 'TARGET_AARCH64', if_true: [files('mte_user_helper= .c')]) --=20 2.39.2