From patchwork Thu Jun 13 17:21:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 803876 Delivered-To: patch@linaro.org Received: by 2002:a5d:58c5:0:b0:35b:5a80:51b4 with SMTP id o5csp426023wrf; Thu, 13 Jun 2024 10:23:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXMmBL+k2Cx3+ZW0Jpvz9jNHwvg5DU1F6wFUfsfDuTr3jmWYVPm6ZXPBgWdTNp6CYsK/1qA/xpuaLy5SEWggm92 X-Google-Smtp-Source: AGHT+IHERCUTjfLZDlSjzaQDJkJGf2eJ1VBFPhD411q6Nr4f//OTBZLxw2XZ4b/N1Yyf/E1KSM8r X-Received: by 2002:a25:295:0:b0:dfb:814:6ebe with SMTP id 3f1490d57ef6-dff153adc88mr137180276.30.1718299398363; Thu, 13 Jun 2024 10:23:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718299398; cv=none; d=google.com; s=arc-20160816; b=e8dpGjf3eq+qM3zKwrC/meUOhF5013YqK3fk87L6W4ovy1RnBSWmS5cgiRcXe5rvNh QjbZ2eFm1lc34Rf+xYA1HdP3o+lI4Yg6SBS+4I8CNCmc7nQ7FWJroGAFFkLAdqAn00uJ uqAzzOGPmdS+a3+4NZsIyth0Tz0luqoV7MgY9hvS4JoeQjeDT2KJAAeT44Bnk7jEuHPS yQ4rFTuUSkIdDI2cH1jY7SODQpTDfemXcxb6HCcl0FcRlwfT4qqbY5fsUR8E2bVBIvC5 zeoNz3nJg59d+u+PtEFHDHc904rjGMEK7L5f0vMqqU8dOXDZAOGHR3oEHdpIYAwwD1Jh m3vg== 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=I8/Wixo704I9fR54FMLOa8feLRsS1yC83cftMeEAmA4=; fh=ZLVo7h1WCYX+mCQET83n+8bPmyNFw4pMQxFlbH8xyms=; b=0z0I5bTMt98oVFoypddQsv4Yfayzz144TT2fOdDwmU/6HWDlgTAW8uoqt7/1MFwgxm gll5XXLphW3GDY/9TABPV3I45HN4gbVTX0T+oI8pabcw2aNqI4DKpZlg4kiyibmmjtBr C5/dVb1NjvrmnblTIsh2pu33NqTGoNC2wUFzOUd65ATap9vJ1UFek0G7OTzeTYpb3UwM Se0Emf+1teFwu666hLfXLgXr9IaMUfwFzCuMyCszWwRJH4WVBS2RfI4R5GiebF5/QNfP VGh2dff8EBgPmIVtah4+zPTimX1Tvj/oRfcl0jXryKvssT3tFXpkN+B6AlAs9maBWeRq rQPg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QK+caPCX; 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-6b2a5b8982dsi18814896d6.560.2024.06.13.10.23.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jun 2024 10:23:18 -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=QK+caPCX; 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 1sHo8x-0000il-2v; Thu, 13 Jun 2024 13:21:47 -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 1sHo8t-0000hF-5w for qemu-devel@nongnu.org; Thu, 13 Jun 2024 13:21:44 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sHo8r-0005r4-CX for qemu-devel@nongnu.org; Thu, 13 Jun 2024 13:21:42 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-70436ac8882so1014415b3a.2 for ; Thu, 13 Jun 2024 10:21:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718299299; x=1718904099; 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=I8/Wixo704I9fR54FMLOa8feLRsS1yC83cftMeEAmA4=; b=QK+caPCXRkJWlBoyioiglzI5J5SsC/RwbDX8loSj3BTUc4Z5yE/BsK7RNfD/2LKJfz QognfbRa+4Q1aHq3z81JeyCP15/51JIk4mI1l4yGmEggUeZJ4wu3Ea7PuDFfqKYzgwJM hJDUedd78jNoKLL9w5gEGMb2IzPeDXZEHY8iqSxKGMdmjxAeaGgDqkOYVCZ0O1cBBBdO BeFsorCx6ywsiloYNDzeEbohacJhyOX9Z4jO15nsUdv9VhGUjS4nMPk2ywMkAV9tycCT oKo2xy2EfaNaPBFxLzDrFxAM5yWVS0w/r9dgsVLFIYFZCoPN4qSspS9JF5ueMnyMlY8x V91g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718299299; x=1718904099; 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=I8/Wixo704I9fR54FMLOa8feLRsS1yC83cftMeEAmA4=; b=NZxvRsXPWx5/M1otsouAbRqZD5XR8wHINOChRVloCU3gH1Z3BtfUQ0fpykpaL5Gvt6 /4BP+bMgn2oqy1iyo0MtqVbcILg8mRlesekcRuEw/A5qG5GzHFdxsF/O0seziXgNWdwy 4zYkEe27y5qw6HdIqVHZdq76bu93ctj+0C5SAMRLNpdh07cZiK3gE8tr/WOjiP8B+GHq wmzmovkK+cNxdd7PE7l0rD7ARF3MSYuf4m/HQcoz1gwABwMHmZvPP3RBvNEiltPiBIae 1ZFBxbly/EUOGATvtT62MuCBdM/AqdYV8n6rUBgzdg0w4r0Xl/PhYIA3ah7QCsN8wf2U y+wg== X-Gm-Message-State: AOJu0YzCo2IbOLsNHR9h6HsmJySUYuO4cCrXYty+/iiwviGA4dJ3QjrZ Y/FXcT2GwDPUUjP8mmdhq9jYtt5YXaldrIhdOkRGXoy3BP7ri836uKojhCcULfacqJcRuUDMOhW d X-Received: by 2002:a05:6a20:9499:b0:1b8:1be8:7ff5 with SMTP id adf61e73a8af0-1bae82900a0mr393960637.50.1718299299592; Thu, 13 Jun 2024 10:21:39 -0700 (PDT) Received: from amd.. ([2804:7f0:b400:8dcb:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855e5b85bsm16443885ad.32.2024.06.13.10.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 10:21:39 -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 v2 6/9] target/arm: Factor out code for setting MTE TCF0 field Date: Thu, 13 Jun 2024 17:21:00 +0000 Message-Id: <20240613172103.2987519-7-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240613172103.2987519-1-gustavo.romero@linaro.org> References: <20240613172103.2987519-1-gustavo.romero@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x434.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/mte.h | 53 +++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 target/arm/mte.h diff --git a/linux-user/aarch64/target_prctl.h b/linux-user/aarch64/target_prctl.h index aa8e203c15..8a11404222 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/mte.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); + set_mte_tcf0(env, arg2); /* * Write PR_MTE_TAG to GCR_EL1[Exclude]. diff --git a/target/arm/mte.h b/target/arm/mte.h new file mode 100644 index 0000000000..89712aad70 --- /dev/null +++ b/target/arm/mte.h @@ -0,0 +1,53 @@ +/* + * ARM MemTag convenience functions. + * + * Copyright (c) 2024 Linaro, Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef MTE_H +#define MTE_H + +#ifdef CONFIG_TCG +#ifdef CONFIG_USER_ONLY +#include "sys/prctl.h" + +static void 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 /* CONFIG_TCG */ + +#endif /* MTE_H */