From nobody Mon Nov 25 04:46:36 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=1718605842; cv=none; d=zohomail.com; s=zohoarc; b=LQj/tD5SPWs+L3vsUqvMfrqQx0aXBftXEUrEsUgNaBeC5mXEuve/3r4PHDnC3vGFQGVBDE7njuH3OxDXeUXTmkJqLJBhb0wBUIW2wtQezt5pTnls3ciDgJJbnQJnQHStItqvYZc59NvuVaFS7WBEG30rUgPeHvPOC+rJzKFi3Xs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718605842; h=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=nd0arIutfBDSvvt+flGv2i8x1ts6dfIDGNUcyWMohdI=; b=K5aIeGPcBN0QOGsxxbkJoNXoxUzCw9RQVBVwlntNIlsxKZjM8T6/uJMyRN+zMvseJuJcyzHCAgTmine45XgzY5VFl6lOcbLBVP9YXqSMCa25VZamUJllaH7cgOLMUPukTbcpHq+xWiSKWbvg8FIhdOoXef0DGEwEkQqJe5q+0iA= 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 1718605842226883.0089309195793; Sun, 16 Jun 2024 23:30:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJ5rv-0003oE-2T; Mon, 17 Jun 2024 02:29:31 -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 1sJ5rt-0003nY-E9 for qemu-devel@nongnu.org; Mon, 17 Jun 2024 02:29:29 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sJ5rr-0003TY-Nr for qemu-devel@nongnu.org; Mon, 17 Jun 2024 02:29:29 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-70599522368so2779728b3a.2 for ; Sun, 16 Jun 2024 23:29:27 -0700 (PDT) Received: from amd.. ([2804:7f0:b400:8dcb:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c4a75ed69csm10641863a91.14.2024.06.16.23.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 23:29:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718605766; x=1719210566; 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=nd0arIutfBDSvvt+flGv2i8x1ts6dfIDGNUcyWMohdI=; b=VxGMxv/OYpdnzES8/scfNCxztBPMY6UP+TpvFDEVskSJ1Yqg3j4CEb/XH8bshZLKqm iuK3jiVl+FOmNc949PNPyfpS+IgutBBVZoO0/a/yr58b+xMqFhWxjxv1pvGTjgTaRIiv u536P27OYChLagKFPXIvt/zqjIL3xI7HwqeSk0R8lS3gDuqvWkaVUpQF+9P0tYVl/K1T YGnvvIkoWHE0Dqn3dHVgZ2awg6kJBmXOIFhhy3KOX7KeqkGmr31F+sGaQmAsL6EYtKAd 7CeEZ2PCiDzfm5UQnBfv4KExh9wE7tvq2fB+zuj9iV4YTySiDpb6on1jmWNeQK/x23qd Q7ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718605766; x=1719210566; 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=nd0arIutfBDSvvt+flGv2i8x1ts6dfIDGNUcyWMohdI=; b=KXZUhbaGemDN1fqVpMUXpQqB8X4p9yYU0EpjhWZ0PghztzVLhF1ybTwlfH5FWsSI/i RrqPZkmxgT/LpPsvElA3V9mS57Y+7fmLP606XYWSMeRkrtGIryXnind6PvJlrP0BnOuQ 847A5/BWRJWC8LkdZu7Ik8/aU2TY5kALiMcazjfwANsC0Z5RJnqpb4XNeAzz7cxNxvPL QTnqSQiYdo1uIIfeQxOk5dhmoMvAYlc1l6nazWZlUTMbciT8HKWxScdTL/kqSFimyOO0 sBGs3leD8aX0m9x4WqKXT2EUsji7QGqpawtsdXhbrxUVhGPIz3gv3Io3T1rOdd0liTtn 5uxA== X-Gm-Message-State: AOJu0YwN9KTEompBbVYQOmKExFP2zIBGPLYq0CIY5gU8RjFsDF8em1AF JUsEZrYf794D6XRCZM4PC8Kw+J7BgWOsWuOrIBWn1mdQqPxMEEgtOukNQB97q5a+DOKzbl1xxDd E X-Google-Smtp-Source: AGHT+IH5+tMe2owX2I5fIBlGuAW8LRb8XyhMJ2ynclYImrcNiWsJY+QlI7n5Zg1qixFwH7VjnNoOkw== X-Received: by 2002:a05:6a20:6f8e:b0:1b5:d36a:5d6e with SMTP id adf61e73a8af0-1bae8214a4amr8881310637.43.1718605765907; Sun, 16 Jun 2024 23:29:25 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, philmd@linaro.org, peter.maydell@linaro.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: gustavo.romero@linaro.org Subject: [PATCH v3 6/9] target/arm: Factor out code for setting MTE TCF0 field Date: Mon, 17 Jun 2024 06:28:46 +0000 Message-Id: <20240617062849.3531745-7-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617062849.3531745-1-gustavo.romero@linaro.org> References: <20240617062849.3531745-1-gustavo.romero@linaro.org> MIME-Version: 1.0 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=2607:f8b0:4864:20::42c; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x42c.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1718605843338100006 Content-Type: text/plain; charset="utf-8" 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 --- linux-user/aarch64/target_prctl.h | 22 ++--------------- target/arm/tcg/mte_user_helper.h | 40 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 20 deletions(-) create mode 100644 target/arm/tcg/mte_user_helper.h diff --git a/linux-user/aarch64/target_prctl.h b/linux-user/aarch64/target_= prctl.h index aa8e203c15..cfc8567eac 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 "target/arm/tcg/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/target/arm/tcg/mte_user_helper.h b/target/arm/tcg/mte_user_hel= per.h new file mode 100644 index 0000000000..dee74d0923 --- /dev/null +++ b/target/arm/tcg/mte_user_helper.h @@ -0,0 +1,40 @@ +/* + * ARM MemTag convenience functions. + * + * This code is licensed under the GNU GPL v2 or later. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#ifndef MTE_H +#define MTE_H + +#ifdef CONFIG_USER_ONLY +#include "sys/prctl.h" + +static inline 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); +} +#endif /* CONFIG_USER_ONLY */ + +#endif /* MTE_H */ --=20 2.34.1