From patchwork Mon Jun 17 06:28:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 804835 Delivered-To: patch@linaro.org Received: by 2002:adf:fb90:0:b0:360:93e7:1765 with SMTP id a16csp423825wrr; Sun, 16 Jun 2024 23:30:42 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWEkUbRKgZAS836gLdbkdqrNcrL22Nan+nfuCN3Vos2J2JpCkPFWieyw8w8fDJQLGVzN0Iv2u4w3JpJbccs7t9N X-Google-Smtp-Source: AGHT+IHACfweH+T/Vsyw6SGayFKuj1lS0bwmjARRWvSh8onuZ3STOmEgtY3G2NYsY1dApJupjZ9t X-Received: by 2002:a05:620a:2585:b0:794:f60e:c050 with SMTP id af79cd13be357-798d26a468bmr951937485a.71.1718605842050; Sun, 16 Jun 2024 23:30:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718605842; cv=none; d=google.com; s=arc-20160816; b=Yw1gKAEYYOWA1ZJJEcIP9F/1bsLcligmzoBYBgTW7aaLBD4sRUVm1C2kNO1UGZR9aN WxQm2wmuPSwkv4LM4M0t0g/B0YndKo4MfnSIGV2f3wf2KrGcqxK1599GYEUi3k6bjMDA oEDVJY0ED9ddYMmiVcP5YXB4firIN7+ZW0rCFi8TQtZue4a3gZzRTy53xKsDIR3HE9hS MNFtY9m5G005fgxi7pBe//GMUe8EN7z6+fgdzmRStH9wfIgMUs09cMWfQeTEnyCoD/m6 +C++K9V1w5oAwDJaK/311+MjlC79n2MsHkwLMrXGZooIaXxGFFfvdGvfGmK1Hx0iSepA eA3Q== 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=nd0arIutfBDSvvt+flGv2i8x1ts6dfIDGNUcyWMohdI=; fh=ZLVo7h1WCYX+mCQET83n+8bPmyNFw4pMQxFlbH8xyms=; b=EVbVTADLncnpGdz2LwLH2+sWpqeL+XjytEp5W+Zgv/gdT2Lrg3ayYtHShMN4syyMo4 FXCNobbxC8IXPFa3Y6zUZYMYDc/DH1MzNWSE28UVvtiLQOlZOGtdiC9LUvMAZ+SeeHvx Gc2c1qe8Mju3olk7wUu0UODD3+wB1aDzB47SZa3/JKAP9bD98aET/k7IihdDg0xGRXnL 5qzfItCabNL8d2L/AnrLT9TzukVjoimFbbv2n6Fs725rkooAipazl2Ff/7/PqdwG7gUi 5hEfRZD6lP/1dn/3PE86TkF1+uExbUWaQzRt2zEiuQxsr5a/Fo53HF3T2CjrGlGmgECv L1Ww==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="VxGMxv/O"; 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 d75a77b69052e-4421ad8efb3si68853831cf.55.2024.06.16.23.30.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 16 Jun 2024 23:30:42 -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="VxGMxv/O"; 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 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 #include "target/arm/cpu-features.h" +#include "target/arm/tcg/mte_user_helper.h" static abi_long do_prctl_sve_get_vl(CPUArchState *env) { @@ -173,26 +174,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)) { - /* - * 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 = 0; - if (arg2 & PR_MTE_TCF_SYNC) { - tcf = 1; - } else if (arg2 & PR_MTE_TCF_ASYNC) { - tcf = 2; - } - env->cp15.sctlr_el[1] = deposit64(env->cp15.sctlr_el[1], 38, 2, tcf); + arm_set_mte_tcf0(env, arg2); /* * Write PR_MTE_TAG to GCR_EL1[Exclude]. diff --git a/target/arm/tcg/mte_user_helper.h b/target/arm/tcg/mte_user_helper.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 = 0; + if (value & PR_MTE_TCF_SYNC) { + tcf = 1; + } else if (value & PR_MTE_TCF_ASYNC) { + tcf = 2; + } + env->cp15.sctlr_el[1] = deposit64(env->cp15.sctlr_el[1], 38, 2, tcf); +} +#endif /* CONFIG_USER_ONLY */ + +#endif /* MTE_H */