linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] support FEAT_MTE_STORE_ONLY feature
@ 2025-04-03 14:27 Yeoreum Yun
  2025-04-03 14:27 ` [PATCH 1/3] arm64/feature: add MTE_STORE_ONLY feature Yeoreum Yun
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Yeoreum Yun @ 2025-04-03 14:27 UTC (permalink / raw)
  To: catalin.marinas, will, broonie, anshuman.khandual, joey.gouly,
	maz, oliver.upton, frederic, james.morse, hardevsinh.palaniya,
	shameerali.kolothum.thodi, huangxiaojia2, mark.rutland,
	samuel.holland, palmer, charlie, thiago.bauermann, bgray, tglx,
	puranjay, david, yang, mbenes, joel.granados
  Cc: linux-arm-kernel, linux-kernel, nd, Yeoreum Yun

The FEAT_MTE_STORE_ONLY feature provides support for
tag check for store operation only. read operation is considered
as unchecked operation so it doesn't raise tag check fault.

NOTE:
  This patches based on https://lore.kernel.org/all/20250403141535.23496-1-yeoreum.yun@arm.com/

Yeoreum Yun (3):
  arm64/feature: add MTE_STORE_ONLY feature
  prtcl: introduce PR_MTE_STORE_ONLY
  arm64/kernel: support store-only mte tag check

 arch/arm64/include/asm/hwcap.h      |  1 +
 arch/arm64/include/asm/processor.h  |  2 ++
 arch/arm64/include/uapi/asm/hwcap.h |  1 +
 arch/arm64/kernel/cpufeature.c      |  9 +++++++++
 arch/arm64/kernel/cpuinfo.c         |  1 +
 arch/arm64/kernel/mte.c             | 11 ++++++++++-
 arch/arm64/kernel/process.c         |  6 +++++-
 arch/arm64/tools/cpucaps            |  1 +
 include/uapi/linux/prctl.h          |  2 ++
 9 files changed, 32 insertions(+), 2 deletions(-)

--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] arm64/feature: add MTE_STORE_ONLY feature
  2025-04-03 14:27 [PATCH 0/3] support FEAT_MTE_STORE_ONLY feature Yeoreum Yun
@ 2025-04-03 14:27 ` Yeoreum Yun
  2025-04-03 15:30   ` Mark Brown
  2025-04-03 14:27 ` [PATCH 2/3] prtcl: introduce PR_MTE_STORE_ONLY Yeoreum Yun
  2025-04-03 14:27 ` [PATCH 3/3] arm64/kernel: support store-only mte tag check Yeoreum Yun
  2 siblings, 1 reply; 6+ messages in thread
From: Yeoreum Yun @ 2025-04-03 14:27 UTC (permalink / raw)
  To: catalin.marinas, will, broonie, anshuman.khandual, joey.gouly,
	maz, oliver.upton, frederic, james.morse, hardevsinh.palaniya,
	shameerali.kolothum.thodi, huangxiaojia2, mark.rutland,
	samuel.holland, palmer, charlie, thiago.bauermann, bgray, tglx,
	puranjay, david, yang, mbenes, joel.granados
  Cc: linux-arm-kernel, linux-kernel, nd, Yeoreum Yun

add MTE_STORE_ONLY feature and HWCAP.

Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
 arch/arm64/include/asm/hwcap.h      | 1 +
 arch/arm64/include/uapi/asm/hwcap.h | 1 +
 arch/arm64/kernel/cpufeature.c      | 9 +++++++++
 arch/arm64/kernel/cpuinfo.c         | 1 +
 arch/arm64/tools/cpucaps            | 1 +
 5 files changed, 13 insertions(+)

diff --git a/arch/arm64/include/asm/hwcap.h b/arch/arm64/include/asm/hwcap.h
index 28dd1ac29ecc..13f94c8ddfc0 100644
--- a/arch/arm64/include/asm/hwcap.h
+++ b/arch/arm64/include/asm/hwcap.h
@@ -177,6 +177,7 @@
 
 #define __khwcap3_feature(x)		(const_ilog2(HWCAP3_ ## x) + 128)
 #define KERNEL_HWCAP_MTE_FAR		__khwcap3_feature(MTE_FAR)
+#define KERNEL_HWCAP_MTE_STORE_ONLY	__khwcap3_feature(MTE_STORE_ONLY)
 
 /*
  * This yields a mask that user programs can use to figure out what
diff --git a/arch/arm64/include/uapi/asm/hwcap.h b/arch/arm64/include/uapi/asm/hwcap.h
index 7d22527a7975..72c78468b806 100644
--- a/arch/arm64/include/uapi/asm/hwcap.h
+++ b/arch/arm64/include/uapi/asm/hwcap.h
@@ -144,5 +144,6 @@
  * HWCAP3 flags - for AT_HWCAP3
  */
 #define HWCAP3_MTE_FAR		(1UL << 0)
+#define HWCAP3_MTE_STORE_ONLY		(1UL << 1)
 
 #endif /* _UAPI__ASM_HWCAP_H */
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 183b4b7e3074..a2f25a8bed96 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -313,6 +313,7 @@ static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = {
 static const struct arm64_ftr_bits ftr_id_aa64pfr2[] = {
 	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR2_EL1_FPMR_SHIFT, 4, 0),
 	ARM64_FTR_BITS(FTR_VISIBLE, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64PFR2_EL1_MTEFAR_SHIFT, 4, ID_AA64PFR2_EL1_MTEFAR_NI),
+	ARM64_FTR_BITS(FTR_VISIBLE, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64PFR2_EL1_MTESTOREONLY_SHIFT, 4, ID_AA64PFR2_EL1_MTESTOREONLY_NI),
 	ARM64_FTR_END,
 };
 
@@ -2869,6 +2870,13 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
 		.matches = has_cpuid_feature,
 		ARM64_CPUID_FIELDS(ID_AA64PFR2_EL1, MTEFAR, IMP)
 	},
+	{
+		.desc = "Store Only MTE Tag Check",
+		.capability = ARM64_MTE_STORE_ONLY,
+		.type = ARM64_CPUCAP_SYSTEM_FEATURE,
+		.matches = has_cpuid_feature,
+		ARM64_CPUID_FIELDS(ID_AA64PFR2_EL1, MTESTOREONLY, IMP)
+	},
 #endif /* CONFIG_ARM64_MTE */
 	{
 		.desc = "RCpc load-acquire (LDAPR)",
@@ -3200,6 +3208,7 @@ static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = {
 	HWCAP_CAP(ID_AA64PFR1_EL1, MTE, MTE2, CAP_HWCAP, KERNEL_HWCAP_MTE),
 	HWCAP_CAP(ID_AA64PFR1_EL1, MTE, MTE3, CAP_HWCAP, KERNEL_HWCAP_MTE3),
 	HWCAP_CAP(ID_AA64PFR2_EL1, MTEFAR, IMP, CAP_HWCAP, KERNEL_HWCAP_MTE_FAR),
+	HWCAP_CAP(ID_AA64PFR2_EL1, MTESTOREONLY, IMP, CAP_HWCAP , KERNEL_HWCAP_MTE_STORE_ONLY),
 #endif /* CONFIG_ARM64_MTE */
 	HWCAP_CAP(ID_AA64MMFR0_EL1, ECV, IMP, CAP_HWCAP, KERNEL_HWCAP_ECV),
 	HWCAP_CAP(ID_AA64MMFR1_EL1, AFP, IMP, CAP_HWCAP, KERNEL_HWCAP_AFP),
diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c
index e2b13454e38a..40f85ec01fe4 100644
--- a/arch/arm64/kernel/cpuinfo.c
+++ b/arch/arm64/kernel/cpuinfo.c
@@ -161,6 +161,7 @@ static const char *const hwcap_str[] = {
 	[KERNEL_HWCAP_SME_STMOP]	= "smestmop",
 	[KERNEL_HWCAP_SME_SMOP4]	= "smesmop4",
 	[KERNEL_HWCAP_MTE_FAR]		= "mte_far",
+	[KERNEL_HWCAP_MTE_STORE_ONLY]	= "mte_store_only",
 };
 
 #ifdef CONFIG_COMPAT
diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps
index ef62ea04ba37..282a1dbb8bc9 100644
--- a/arch/arm64/tools/cpucaps
+++ b/arch/arm64/tools/cpucaps
@@ -68,6 +68,7 @@ MPAM_HCR
 MTE
 MTE_ASYMM
 MTE_FAR
+MTE_STORE_ONLY
 SME
 SME_FA64
 SME2
-- 
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] prtcl: introduce PR_MTE_STORE_ONLY
  2025-04-03 14:27 [PATCH 0/3] support FEAT_MTE_STORE_ONLY feature Yeoreum Yun
  2025-04-03 14:27 ` [PATCH 1/3] arm64/feature: add MTE_STORE_ONLY feature Yeoreum Yun
@ 2025-04-03 14:27 ` Yeoreum Yun
  2025-04-03 14:27 ` [PATCH 3/3] arm64/kernel: support store-only mte tag check Yeoreum Yun
  2 siblings, 0 replies; 6+ messages in thread
From: Yeoreum Yun @ 2025-04-03 14:27 UTC (permalink / raw)
  To: catalin.marinas, will, broonie, anshuman.khandual, joey.gouly,
	maz, oliver.upton, frederic, james.morse, hardevsinh.palaniya,
	shameerali.kolothum.thodi, huangxiaojia2, mark.rutland,
	samuel.holland, palmer, charlie, thiago.bauermann, bgray, tglx,
	puranjay, david, yang, mbenes, joel.granados
  Cc: linux-arm-kernel, linux-kernel, nd, Yeoreum Yun

PR_MTE_STORE_ONLY is used to restrict the MTE tag check for store
opeartion only.

Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
 include/uapi/linux/prctl.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h
index 15c18ef4eb11..83ac566251d8 100644
--- a/include/uapi/linux/prctl.h
+++ b/include/uapi/linux/prctl.h
@@ -244,6 +244,8 @@ struct prctl_mm_map {
 # define PR_MTE_TAG_MASK		(0xffffUL << PR_MTE_TAG_SHIFT)
 /* Unused; kept only for source compatibility */
 # define PR_MTE_TCF_SHIFT		1
+/* MTE tag check store only */
+# define PR_MTE_STORE_ONLY		(1UL << 19)
 /* RISC-V pointer masking tag length */
 # define PR_PMLEN_SHIFT			24
 # define PR_PMLEN_MASK			(0x7fUL << PR_PMLEN_SHIFT)
-- 
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] arm64/kernel: support store-only mte tag check
  2025-04-03 14:27 [PATCH 0/3] support FEAT_MTE_STORE_ONLY feature Yeoreum Yun
  2025-04-03 14:27 ` [PATCH 1/3] arm64/feature: add MTE_STORE_ONLY feature Yeoreum Yun
  2025-04-03 14:27 ` [PATCH 2/3] prtcl: introduce PR_MTE_STORE_ONLY Yeoreum Yun
@ 2025-04-03 14:27 ` Yeoreum Yun
  2 siblings, 0 replies; 6+ messages in thread
From: Yeoreum Yun @ 2025-04-03 14:27 UTC (permalink / raw)
  To: catalin.marinas, will, broonie, anshuman.khandual, joey.gouly,
	maz, oliver.upton, frederic, james.morse, hardevsinh.palaniya,
	shameerali.kolothum.thodi, huangxiaojia2, mark.rutland,
	samuel.holland, palmer, charlie, thiago.bauermann, bgray, tglx,
	puranjay, david, yang, mbenes, joel.granados
  Cc: linux-arm-kernel, linux-kernel, nd, Yeoreum Yun

Introduce new flag -- MTE_CTRL_STORE_ONLY used to set store-only tag check.
This flag isn't overrided by prefered tcf flag setting but set together
with prefered setting of way to report tag check fault.

Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
 arch/arm64/include/asm/processor.h |  2 ++
 arch/arm64/kernel/mte.c            | 11 ++++++++++-
 arch/arm64/kernel/process.c        |  6 +++++-
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h
index 1bf1a3b16e88..61d62bfd5a7b 100644
--- a/arch/arm64/include/asm/processor.h
+++ b/arch/arm64/include/asm/processor.h
@@ -23,6 +23,8 @@
 #define MTE_CTRL_TCF_ASYNC		(1UL << 17)
 #define MTE_CTRL_TCF_ASYMM		(1UL << 18)
 
+#define MTE_CTRL_STORE_ONLY		(1UL << 19)
+
 #ifndef __ASSEMBLY__
 
 #include <linux/build_bug.h>
diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c
index 2fbfd27ff5f2..e5e773844889 100644
--- a/arch/arm64/kernel/mte.c
+++ b/arch/arm64/kernel/mte.c
@@ -200,7 +200,7 @@ static void mte_update_sctlr_user(struct task_struct *task)
 	 * program requested values go with what was requested.
 	 */
 	resolved_mte_tcf = (mte_ctrl & pref) ? pref : mte_ctrl;
-	sctlr &= ~SCTLR_EL1_TCF0_MASK;
+	sctlr &= ~(SCTLR_EL1_TCF0_MASK | SCTLR_EL1_TCSO0_MASK);
 	/*
 	 * Pick an actual setting. The order in which we check for
 	 * set bits and map into register values determines our
@@ -212,6 +212,10 @@ static void mte_update_sctlr_user(struct task_struct *task)
 		sctlr |= SYS_FIELD_PREP_ENUM(SCTLR_EL1, TCF0, ASYNC);
 	else if (resolved_mte_tcf & MTE_CTRL_TCF_SYNC)
 		sctlr |= SYS_FIELD_PREP_ENUM(SCTLR_EL1, TCF0, SYNC);
+
+	if (mte_ctrl & MTE_CTRL_STORE_ONLY)
+		sctlr |= SYS_FIELD_PREP(SCTLR_EL1, TCSO0, 1);
+
 	task->thread.sctlr_user = sctlr;
 }
 
@@ -371,6 +375,9 @@ long set_mte_ctrl(struct task_struct *task, unsigned long arg)
 	    (arg & PR_MTE_TCF_SYNC))
 		mte_ctrl |= MTE_CTRL_TCF_ASYMM;
 
+	if (arg & PR_MTE_STORE_ONLY)
+		mte_ctrl |= MTE_CTRL_STORE_ONLY;
+
 	task->thread.mte_ctrl = mte_ctrl;
 	if (task == current) {
 		preempt_disable();
@@ -398,6 +405,8 @@ long get_mte_ctrl(struct task_struct *task)
 		ret |= PR_MTE_TCF_ASYNC;
 	if (mte_ctrl & MTE_CTRL_TCF_SYNC)
 		ret |= PR_MTE_TCF_SYNC;
+	if (mte_ctrl & MTE_CTRL_STORE_ONLY)
+		ret |= PR_MTE_STORE_ONLY;
 
 	return ret;
 }
diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 42faebb7b712..cea4a23a15de 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -815,10 +815,14 @@ long set_tagged_addr_ctrl(struct task_struct *task, unsigned long arg)
 	if (is_compat_thread(ti))
 		return -EINVAL;
 
-	if (system_supports_mte())
+	if (system_supports_mte()) {
 		valid_mask |= PR_MTE_TCF_SYNC | PR_MTE_TCF_ASYNC \
 			| PR_MTE_TAG_MASK;
 
+		if (cpus_have_cap(ARM64_MTE_STORE_ONLY))
+			valid_mask |= PR_MTE_STORE_ONLY;
+	}
+
 	if (arg & ~valid_mask)
 		return -EINVAL;
 
-- 
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] arm64/feature: add MTE_STORE_ONLY feature
  2025-04-03 14:27 ` [PATCH 1/3] arm64/feature: add MTE_STORE_ONLY feature Yeoreum Yun
@ 2025-04-03 15:30   ` Mark Brown
  2025-04-03 17:39     ` Yeoreum Yun
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Brown @ 2025-04-03 15:30 UTC (permalink / raw)
  To: Yeoreum Yun
  Cc: catalin.marinas, will, anshuman.khandual, joey.gouly, maz,
	oliver.upton, frederic, james.morse, hardevsinh.palaniya,
	shameerali.kolothum.thodi, huangxiaojia2, mark.rutland,
	samuel.holland, palmer, charlie, thiago.bauermann, bgray, tglx,
	puranjay, david, yang, mbenes, joel.granados, linux-arm-kernel,
	linux-kernel, nd

[-- Attachment #1: Type: text/plain, Size: 165 bytes --]

On Thu, Apr 03, 2025 at 03:27:05PM +0100, Yeoreum Yun wrote:
> add MTE_STORE_ONLY feature and HWCAP.

Please add this to the hwcaps selftest, and to elf_hwcaps.rst.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] arm64/feature: add MTE_STORE_ONLY feature
  2025-04-03 15:30   ` Mark Brown
@ 2025-04-03 17:39     ` Yeoreum Yun
  0 siblings, 0 replies; 6+ messages in thread
From: Yeoreum Yun @ 2025-04-03 17:39 UTC (permalink / raw)
  To: Mark Brown
  Cc: catalin.marinas, will, anshuman.khandual, joey.gouly, maz,
	oliver.upton, frederic, james.morse, hardevsinh.palaniya,
	shameerali.kolothum.thodi, huangxiaojia2, mark.rutland,
	samuel.holland, palmer, charlie, thiago.bauermann, bgray, tglx,
	puranjay, david, yang, mbenes, joel.granados, linux-arm-kernel,
	linux-kernel, nd

Hi Mark,

> On Thu, Apr 03, 2025 at 03:27:05PM +0100, Yeoreum Yun wrote:
> > add MTE_STORE_ONLY feature and HWCAP.
>
> Please add this to the hwcaps selftest, and to elf_hwcaps.rst.

Thanks. I'll add.

--
Sincerely,
Yeoreum Yun


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-04-03 17:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-03 14:27 [PATCH 0/3] support FEAT_MTE_STORE_ONLY feature Yeoreum Yun
2025-04-03 14:27 ` [PATCH 1/3] arm64/feature: add MTE_STORE_ONLY feature Yeoreum Yun
2025-04-03 15:30   ` Mark Brown
2025-04-03 17:39     ` Yeoreum Yun
2025-04-03 14:27 ` [PATCH 2/3] prtcl: introduce PR_MTE_STORE_ONLY Yeoreum Yun
2025-04-03 14:27 ` [PATCH 3/3] arm64/kernel: support store-only mte tag check Yeoreum Yun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).