* [PATCH RFC 1/5] target/arm: explicitly disable MTE4 for max
2025-11-12 0:50 [PATCH RFC 0/5] target/arm: add support for MTE4 Gabriel Brookman
@ 2025-11-12 0:50 ` Gabriel Brookman
2025-11-12 0:50 ` [PATCH RFC 2/5] tests/tcg: added test for MTE FAR Gabriel Brookman
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Gabriel Brookman @ 2025-11-12 0:50 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Gustavo Romero, qemu-arm, Gabriel Brookman
Previously, the bits used to advertise the various MTE4 features were
not explicitly set for -cpu max. This commit calls out these bits and
explicitly unsets them. At the end of the patch series, a second commit
will explicitly set all of them.
Signed-off-by: Gabriel Brookman <brookmangabriel@gmail.com>
---
target/arm/tcg/cpu64.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c
index 6871956382..6688b78bb8 100644
--- a/target/arm/tcg/cpu64.c
+++ b/target/arm/tcg/cpu64.c
@@ -1281,8 +1281,16 @@ void aarch64_max_tcg_initfn(Object *obj)
t = FIELD_DP64(t, ID_AA64PFR1, CSV2_FRAC, 0); /* FEAT_CSV2_3 */
t = FIELD_DP64(t, ID_AA64PFR1, NMI, 1); /* FEAT_NMI */
t = FIELD_DP64(t, ID_AA64PFR1, GCS, 1); /* FEAT_GCS */
+ t = FIELD_DP64(t, ID_AA64PFR1,
+ MTEX, 0); /* FEAT_MTE_NO_ADDRESS_TAGS + FEAT_MTE_CANONICAL_TAGS */
SET_IDREG(isar, ID_AA64PFR1, t);
+ t = GET_IDREG(isar, ID_AA64PFR2);
+ t = FIELD_DP64(t, ID_AA64PFR2, MTEFAR, 0); /* FEAT_MTE_TAGGED_FAR */
+ t = FIELD_DP64(t, ID_AA64PFR2, MTESTOREONLY, 0); /* FEAT_MTE_STORE_ONLY */
+ t = FIELD_DP64(t, ID_AA64PFR2, MTEPERM, 0); /* FEAT_MTE_PERM */
+ SET_IDREG(isar, ID_AA64PFR2, t);
+
t = GET_IDREG(isar, ID_AA64MMFR0);
t = FIELD_DP64(t, ID_AA64MMFR0, PARANGE, 6); /* FEAT_LPA: 52 bits */
t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN16, 1); /* 16k pages supported */
--
2.51.2
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH RFC 2/5] tests/tcg: added test for MTE FAR
2025-11-12 0:50 [PATCH RFC 0/5] target/arm: add support for MTE4 Gabriel Brookman
2025-11-12 0:50 ` [PATCH RFC 1/5] target/arm: explicitly disable MTE4 for max Gabriel Brookman
@ 2025-11-12 0:50 ` Gabriel Brookman
2025-11-12 0:50 ` [PATCH RFC 3/5] target/arm: add TCSO bitmasks to SCTLR Gabriel Brookman
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Gabriel Brookman @ 2025-11-12 0:50 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Gustavo Romero, qemu-arm, Gabriel Brookman
This functionality was previously enabled but not advertised or tested.
This commit adds a new test, mte-9, that tests the code for proper
full-address reporting.
Signed-off-by: Gabriel Brookman <brookmangabriel@gmail.com>
---
tests/tcg/aarch64/Makefile.target | 2 +-
tests/tcg/aarch64/mte-9.c | 48 +++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
index 9fa8687453..b491cfb5e1 100644
--- a/tests/tcg/aarch64/Makefile.target
+++ b/tests/tcg/aarch64/Makefile.target
@@ -64,7 +64,7 @@ AARCH64_TESTS += bti-2
# MTE Tests
ifneq ($(CROSS_CC_HAS_ARMV8_MTE),)
-AARCH64_TESTS += mte-1 mte-2 mte-3 mte-4 mte-5 mte-6 mte-7 mte-8
+AARCH64_TESTS += mte-1 mte-2 mte-3 mte-4 mte-5 mte-6 mte-7 mte-8 mte-9
mte-%: CFLAGS += $(CROSS_CC_HAS_ARMV8_MTE)
endif
diff --git a/tests/tcg/aarch64/mte-9.c b/tests/tcg/aarch64/mte-9.c
new file mode 100644
index 0000000000..9626a90c13
--- /dev/null
+++ b/tests/tcg/aarch64/mte-9.c
@@ -0,0 +1,48 @@
+/*
+ * Memory tagging, full-address reporting.
+ *
+ * Copyright (c) 2021 Linaro Ltd
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "mte.h"
+
+static void *faulting_ptr;
+
+void pass(int sig, siginfo_t *info, void *uc)
+{
+ assert(faulting_ptr == info->si_addr);
+ exit(0);
+}
+
+int main(int ac, char **av)
+{
+ struct sigaction sa;
+ int *p0, *p1, *p2;
+ long excl = 1;
+
+ enable_mte(PR_MTE_TCF_SYNC);
+ p0 = alloc_mte_mem(sizeof(*p0));
+
+ /* Create two differently tagged pointers. */
+ asm("irg %0,%1,%2" : "=r"(p1) : "r"(p0), "r"(excl));
+ asm("gmi %0,%1,%0" : "+r"(excl) : "r" (p1));
+ assert(excl != 1);
+ asm("irg %0,%1,%2" : "=r"(p2) : "r"(p0), "r"(excl));
+ assert(p1 != p2);
+
+ /* Store the tag from the first pointer. */
+ asm("stg %0, [%0]" : : "r"(p1));
+
+ *p1 = 0;
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_sigaction = pass;
+ sa.sa_flags = SA_SIGINFO;
+ sigaction(SIGSEGV, &sa, NULL);
+
+ faulting_ptr = p2;
+ *p2 = 0;
+
+ abort();
+}
--
2.51.2
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH RFC 3/5] target/arm: add TCSO bitmasks to SCTLR
2025-11-12 0:50 [PATCH RFC 0/5] target/arm: add support for MTE4 Gabriel Brookman
2025-11-12 0:50 ` [PATCH RFC 1/5] target/arm: explicitly disable MTE4 for max Gabriel Brookman
2025-11-12 0:50 ` [PATCH RFC 2/5] tests/tcg: added test for MTE FAR Gabriel Brookman
@ 2025-11-12 0:50 ` Gabriel Brookman
2025-11-12 0:50 ` [PATCH RFC 4/5] target/arm: add FEAT_MTE_STORE_ONLY logic Gabriel Brookman
2025-11-12 0:50 ` [PATCH RFC 5/5] docs: added MTE4 features to docs Gabriel Brookman
4 siblings, 0 replies; 6+ messages in thread
From: Gabriel Brookman @ 2025-11-12 0:50 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Gustavo Romero, qemu-arm, Gabriel Brookman
These are the bitmasks used to control the FEAT_MTE_STORE_ONLY feature.
They are now named and setting these fields of SCTLR is ignored if MTE
is disabled, as per convention.
Signed-off-by: Gabriel Brookman <brookmangabriel@gmail.com>
---
target/arm/cpu.h | 2 ++
target/arm/helper.c | 4 ++--
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 39f2b2e54d..2c7c76777f 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -1424,6 +1424,8 @@ void pmu_init(ARMCPU *cpu);
#define SCTLR_EnAS0 (1ULL << 55) /* FEAT_LS64_ACCDATA */
#define SCTLR_EnALS (1ULL << 56) /* FEAT_LS64 */
#define SCTLR_EPAN (1ULL << 57) /* FEAT_PAN3 */
+#define SCTLR_TSCO0 (1ULL << 58) /* FEAT_MTE_STORE_ONLY */
+#define SCTLR_TSCO (1ULL << 59) /* FEAT_MTE_STORE_ONLY */
#define SCTLR_EnTP2 (1ULL << 60) /* FEAT_SME */
#define SCTLR_NMI (1ULL << 61) /* FEAT_NMI */
#define SCTLR_SPINTMASK (1ULL << 62) /* FEAT_NMI */
diff --git a/target/arm/helper.c b/target/arm/helper.c
index 27ebc6f29b..32fbb2e25d 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -3364,10 +3364,10 @@ static void sctlr_write(CPUARMState *env, const ARMCPRegInfo *ri,
if (ri->state == ARM_CP_STATE_AA64 && !cpu_isar_feature(aa64_mte, cpu)) {
if (ri->opc1 == 6) { /* SCTLR_EL3 */
- value &= ~(SCTLR_ITFSB | SCTLR_TCF | SCTLR_ATA);
+ value &= ~(SCTLR_ITFSB | SCTLR_TCF | SCTLR_ATA | SCTLR_TSCO);
} else {
value &= ~(SCTLR_ITFSB | SCTLR_TCF0 | SCTLR_TCF |
- SCTLR_ATA0 | SCTLR_ATA);
+ SCTLR_ATA0 | SCTLR_ATA | SCTLR_TSCO | SCTLR_TSCO0);
}
}
--
2.51.2
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH RFC 4/5] target/arm: add FEAT_MTE_STORE_ONLY logic
2025-11-12 0:50 [PATCH RFC 0/5] target/arm: add support for MTE4 Gabriel Brookman
` (2 preceding siblings ...)
2025-11-12 0:50 ` [PATCH RFC 3/5] target/arm: add TCSO bitmasks to SCTLR Gabriel Brookman
@ 2025-11-12 0:50 ` Gabriel Brookman
2025-11-12 0:50 ` [PATCH RFC 5/5] docs: added MTE4 features to docs Gabriel Brookman
4 siblings, 0 replies; 6+ messages in thread
From: Gabriel Brookman @ 2025-11-12 0:50 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Gustavo Romero, qemu-arm, Gabriel Brookman
This feature automatically succeeds tag checks on load instructions when
the appropriate SCTLR_TCSO register for the current exception level is
set.
Signed-off-by: Gabriel Brookman <brookmangabriel@gmail.com>
---
target/arm/tcg/mte_helper.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/target/arm/tcg/mte_helper.c b/target/arm/tcg/mte_helper.c
index bb48fe359b..3f7e89f436 100644
--- a/target/arm/tcg/mte_helper.c
+++ b/target/arm/tcg/mte_helper.c
@@ -865,8 +865,30 @@ static int mte_probe_int(CPUARMState *env, uint32_t desc, uint64_t ptr,
return 0;
}
+static bool mte_store_only_active(CPUARMState *env)
+{
+ int el = arm_current_el(env);
+ if (el) {
+ if (SCTLR_TSCO & env->cp15.sctlr_el[el]) {
+ return true;
+ }
+ } else {
+ if ((HCR_E2H & env->cp15.hcr_el2) &&
+ (SCTLR_TSCO0 & env->cp15.sctlr_el[2])) {
+ return true;
+ } else if (SCTLR_TSCO0 & env->cp15.sctlr_el[1]) {
+ return true;
+ }
+ }
+ return false;
+}
+
uint64_t mte_check(CPUARMState *env, uint32_t desc, uint64_t ptr, uintptr_t ra)
{
+ if (!FIELD_EX32(desc, MTEDESC, WRITE) && mte_store_only_active(env)) {
+ return useronly_clean_ptr(ptr);
+ }
+
uint64_t fault;
int ret = mte_probe_int(env, desc, ptr, ra, &fault);
--
2.51.2
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH RFC 5/5] docs: added MTE4 features to docs
2025-11-12 0:50 [PATCH RFC 0/5] target/arm: add support for MTE4 Gabriel Brookman
` (3 preceding siblings ...)
2025-11-12 0:50 ` [PATCH RFC 4/5] target/arm: add FEAT_MTE_STORE_ONLY logic Gabriel Brookman
@ 2025-11-12 0:50 ` Gabriel Brookman
4 siblings, 0 replies; 6+ messages in thread
From: Gabriel Brookman @ 2025-11-12 0:50 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Gustavo Romero, qemu-arm, Gabriel Brookman
The implemented MTE4 features are now present in
docs/system/arm/emulation.rst
Signed-off-by: Gabriel Brookman <brookmangabriel@gmail.com>
---
docs/system/arm/emulation.rst | 2 ++
1 file changed, 2 insertions(+)
diff --git a/docs/system/arm/emulation.rst b/docs/system/arm/emulation.rst
index 31a5878a8f..1bf99c77bb 100644
--- a/docs/system/arm/emulation.rst
+++ b/docs/system/arm/emulation.rst
@@ -106,6 +106,8 @@ the following architecture extensions:
- FEAT_MTE3 (MTE Asymmetric Fault Handling)
- FEAT_MTE_ASYM_FAULT (Memory tagging asymmetric faults)
- FEAT_MTE_ASYNC (Asynchronous reporting of Tag Check Fault)
+- FEAT_MTE_TAGGED_FAR (Full address reporting of Tag Check Fault)
+- FEAT_MTE_STORE_ONLY (Store-only tag checking)
- FEAT_NMI (Non-maskable Interrupt)
- FEAT_NV (Nested Virtualization)
- FEAT_NV2 (Enhanced nested virtualization support)
--
2.51.2
^ permalink raw reply related [flat|nested] 6+ messages in thread