From patchwork Fri Jun 28 12:42:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 808252 Delivered-To: patch@linaro.org Received: by 2002:adf:fe0a:0:b0:362:4979:7f74 with SMTP id n10csp341470wrr; Fri, 28 Jun 2024 05:44:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUfazcWGFmps4Uf1f+SDUqHd+X+3HYUnymVjeQTsFIBmOioeMc9oZx783Jg/tQ0vJhcubcdBgSRFXcLOoeASDb6 X-Google-Smtp-Source: AGHT+IHWptmz5ceLNSi7IgA0Vw0PXR8e+9RrS+6ij+F4a3uH4WwyWGekJjOINJPfA81PA+bQeT3P X-Received: by 2002:a0c:d993:0:b0:6b0:92ac:8193 with SMTP id 6a1803df08f44-6b540afb101mr166129126d6.54.1719578692560; Fri, 28 Jun 2024 05:44:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719578692; cv=none; d=google.com; s=arc-20160816; b=o7UTioG3+GewrL5qqpZj0Wb1qVokxQ66Yv8NcOScStUVOWmlKqSSDtI4RwmpGBj+UU qLR5PAqm/I4FNr+F6ec4FCT8LgPiaDrXZa2WvG87X/R2ySh7ZdH7sU9vnSLjbRkUYNOy DuM/RWsTyWdBA0/x2UVcYpxiCkGEzkXpUzQ/7JbJNateiMpXYAsFJZOzAcKkio/iAT5/ UsEz24PfMbsD6dRw8HzcrAWtv09n5Mqm+mO2W+swFcE8ziPKiCHC+vWarIzwHEdrn35P Q1nexIqA+bDyQs+jSzCQTDyfd1hrFS5hf7vv//cL1yR457kulYJel37oibCWjSS2KXdW h0Tw== 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=U6hurhQTjp832TOlAx+LCodgHfvL9JAd0ZCjMoFRr6I=; fh=f05/u3L8SxnQJOoOR/DeDiZV5idUwgWurHbJB0fL01s=; b=iLkXn+v7Co7B8XRxC8/TNZ0Jcip+ervwnojR7bkiJs6piQb3fKHhyu2rf10tnI03xy W2Mq32tM6KL8hj0E0JvPgrOSejwuC5L2uorErJhyF41E181iIJxlI+z0DogImu9VPtuu kR8Ikn25ce7W5lHczno6AudUS9dM2GDofqCVRZzoKQy9whebv7Ubpbbt8tXALkuqw9wV 2/7YSVkUykoDO2DBAfRsFhdcFq/YHbJwgA5RbPQ0Vn+WEQkIWaao7pTyDMLDAgEOeALs 8cDSDXsqzQWoz1M5jjePF7y7geuw2ffQ22WX+sDvStYiT87YFzAJe8d3fPe+UvVZ9EBH 76bw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q0zNADPh; 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-6b59e613188si19492916d6.529.2024.06.28.05.44.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Jun 2024 05:44:52 -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=q0zNADPh; 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 1sNAxb-0006GX-Ri; Fri, 28 Jun 2024 08:44:19 -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 1sNAwm-0004vh-1P for qemu-devel@nongnu.org; Fri, 28 Jun 2024 08:43:26 -0400 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sNAwh-0005ks-Em for qemu-devel@nongnu.org; Fri, 28 Jun 2024 08:43:23 -0400 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-57d2fc03740so699143a12.0 for ; Fri, 28 Jun 2024 05:43:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719578595; x=1720183395; 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=q0zNADPhH1koDKGnbXnUbkXJuEG/38kXy+faKAqtya8NFtxLE/ltAL3IXr/IB/MqNl l6LGN1c9mWqOO7ySzctRh1H9ExXdm7gaX7VBiz+u4FOAu8XBYybJpZ9xf50vP03FTlLE SoDhZ5Vifolw9RvM+1vsVbtpXF71TQauHDqQ1QaMT7qOnQIAtoyyQmWwg2TjcTINLOj/ 9kBMbUr2/KD1qNe3c6+12iK4RK+f5zmb86myu9Zalw6O9mE404jkzKmoiTgJbD0IyZd9 +s1hHLulWmW4r/MWZQ2841LO8F4PF8nEq40wNaXYBQt1Yk7kxWO3pAeq7eNF88v0cz8A 2x2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719578595; x=1720183395; 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=Rvzz0DSZIoKkmsqsVZQoLgmzx0cwoX3Il6g+Obn0EsjG5vfuvQLT2F9Qob4a6lT5o9 7RYO33pchnqHwq7eXspW9+kBMzvxOB0GX9U6SE1ivtH1C+8n0t/bP7iD2nzJBIc5r/mf lnIN1eGu3s0L5bOCs1UW2lGualiBin2qe+wz8OMmz4mcFwyPEZMLiGJ96WziIeHDQb/K SH8r1ssRPaomS2tWizu+dr8fk45PzPA3uW3LxBzBI25daKD/FLGrjJXP5ENqYmglWAiM WcyyjLnrOr16D2ZjE9W6sg8jNCH6Jqj1I3AK0mGmj+B98WoInpn87yOjzFAUcuSUg8BU xT2Q== X-Gm-Message-State: AOJu0YxAgSr7480AhUKeLdbvd49LAasqE8VDTRQShWIV3AuFE4bqNK5J 73xM4VvGtBWJ7Mh/b97jYUuDQSyPBzRGK2xP9ZPo+Mn4KKNOQQMRpTpjJmLpDmA= X-Received: by 2002:a50:d75c:0:b0:57c:74fb:6e31 with SMTP id 4fb4d7f45d1cf-57d7007bab6mr7487330a12.35.1719578594689; Fri, 28 Jun 2024 05:43:14 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-58612c835dfsm980078a12.20.2024.06.28.05.43.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 05:43:11 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id B909E5FA3E; Fri, 28 Jun 2024 13:43:00 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: David Hildenbrand , Beraldo Leal , Eduardo Habkost , =?utf-8?q?Alex_Benn=C3=A9e?= , Wainer dos Santos Moschetta , qemu-arm@nongnu.org, Peter Xu , Mads Ynddal , Mahmoud Mandour , Pierrick Bouvier , Laurent Vivier , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Alexandre Iooss , Stefan Hajnoczi , Peter Maydell , Richard Henderson , Thomas Huth , Gustavo Romero Subject: [PATCH 18/23] target/arm: Factor out code for setting MTE TCF0 field Date: Fri, 28 Jun 2024 13:42:53 +0100 Message-Id: <20240628124258.832466-19-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240628124258.832466-1-alex.bennee@linaro.org> References: <20240628124258.832466-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52b; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x52b.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 autolearn=unavailable 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 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ée --- 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 #include "target/arm/cpu-features.h" +#include "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/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 = 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); +} 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, abi_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 = gen_vdso.process('vdso-le.so', extra_args: ['-r', '__kernel_rt_sigreturn']) linux_user_ss.add(when: 'TARGET_AARCH64', if_true: [vdso_be_inc, vdso_le_inc]) + +linux_user_ss.add(when: 'TARGET_AARCH64', if_true: [files('mte_user_helper.c')])