From: Gabriel Brookman <brookmangabriel@gmail.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Gustavo Romero <gustavo.romero@linaro.org>,
qemu-arm@nongnu.org,
Gabriel Brookman <brookmangabriel@gmail.com>
Subject: [PATCH RFC v2 06/10] target/arm: add canonical and no-address tag logic
Date: Sun, 16 Nov 2025 20:40:23 -0500 [thread overview]
Message-ID: <20251116-feat-mte4-v2-6-9a7122b7fa76@gmail.com> (raw)
In-Reply-To: <20251116-feat-mte4-v2-0-9a7122b7fa76@gmail.com>
This feature causes tag checks to compare logical address tags against
their canonical form rather than against allocation tags. Described in
the ARM ARM section "Logical Address Tagging".
Signed-off-by: Gabriel Brookman <brookmangabriel@gmail.com>
---
target/arm/internals.h | 40 ++++++++++++++++++++++++++++++++++++++++
target/arm/tcg/mte_helper.c | 12 ++++++++++++
2 files changed, 52 insertions(+)
diff --git a/target/arm/internals.h b/target/arm/internals.h
index 75677945af..5f0bcdaaac 100644
--- a/target/arm/internals.h
+++ b/target/arm/internals.h
@@ -1633,6 +1633,46 @@ static inline bool tcma_check(uint32_t desc, int bit55, int ptr_tag)
return tcma && match;
}
+/* Return whether or not the second nibble of a VA matches bit 55. */
+static inline bool tag_is_canonical(int ptr_tag, int bit55)
+{
+ return ((ptr_tag + bit55) & 0xf) == 0;
+}
+
+/* Return true if mtx bits mean that the access is canonically checked. */
+static inline bool mtx_check(CPUARMState *env, bool bit55)
+{
+ /*
+ * the MTX bits used in EL0 are those used in whichever EL is used
+ * for the supervisor. The EL that contains the supervisor uses
+ * bits 60 and 61 (MTX0 and MTX1), while the other ELs that aren't
+ * used by the supervisor.
+ */
+ int el = arm_current_el(env);
+ if (el == 0) {
+ if (HCR_E2H & env->cp15.hcr_el2) {
+ return (1l << (60 + bit55)) & env->cp15.tcr_el[2];
+ } else {
+ return (1l << (60 + bit55)) & env->cp15.tcr_el[1];
+ }
+ } else if (el == 1) {
+ if (HCR_E2H & env->cp15.hcr_el2) {
+ g_assert_not_reached();
+ } else {
+ return (1l << (60 + bit55)) & env->cp15.tcr_el[1];
+ }
+ } else if (el == 2) {
+ if (HCR_E2H & env->cp15.hcr_el2) {
+ return (1l << (60 + bit55)) & env->cp15.tcr_el[2];
+ } else {
+ return (1l << 33) & env->cp15.tcr_el[2];
+ }
+ } else if (el == 3) {
+ return (1l << 33) & env->cp15.tcr_el[3];
+ }
+ return false;
+}
+
/*
* For TBI, ideally, we would do nothing. Proper behaviour on fault is
* for the tag to be present in the FAR_ELx register. But for user-only
diff --git a/target/arm/tcg/mte_helper.c b/target/arm/tcg/mte_helper.c
index f9fd6fd408..513ee8d6a1 100644
--- a/target/arm/tcg/mte_helper.c
+++ b/target/arm/tcg/mte_helper.c
@@ -799,6 +799,10 @@ static int mte_probe_int(CPUARMState *env, uint32_t desc, uint64_t ptr,
return 1;
}
+ if (mtx_check(env, bit55)) {
+ return tag_is_canonical(ptr_tag, bit55);
+ }
+
mmu_idx = FIELD_EX32(desc, MTEDESC, MIDX);
type = FIELD_EX32(desc, MTEDESC, WRITE) ? MMU_DATA_STORE : MMU_DATA_LOAD;
sizem1 = FIELD_EX32(desc, MTEDESC, SIZEM1);
@@ -962,6 +966,14 @@ uint64_t HELPER(mte_check_zva)(CPUARMState *env, uint32_t desc, uint64_t ptr)
goto done;
}
+ if (mtx_check(env, bit55)) {
+ if (tag_is_canonical(ptr_tag, bit55)) {
+ goto done;
+ }
+ mte_check_fail(env, desc, ptr, ra);
+ }
+
+
/*
* In arm_cpu_realizefn, we asserted that dcz > LOG2_TAG_GRANULE+1,
* i.e. 32 bytes, which is an unreasonably small dcz anyway, to make
--
2.51.2
next prev parent reply other threads:[~2025-11-17 1:42 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-17 1:40 [PATCH RFC v2 00/10] target/arm: add support for MTE4 Gabriel Brookman
2025-11-17 1:40 ` [PATCH RFC v2 01/10] target/arm: explicitly disable MTE4 for max Gabriel Brookman
2025-11-17 9:48 ` Richard Henderson
2025-11-17 1:40 ` [PATCH RFC v2 02/10] tests/tcg: added test for MTE FAR Gabriel Brookman
2025-11-17 9:51 ` Richard Henderson
2025-11-17 1:40 ` [PATCH RFC v2 03/10] target/arm: add TCSO bitmasks to SCTLR Gabriel Brookman
2025-11-17 15:14 ` Richard Henderson
2025-11-17 1:40 ` [PATCH RFC v2 04/10] target/arm: add FEAT_MTE_STORE_ONLY logic Gabriel Brookman
2025-11-17 15:26 ` Richard Henderson
2025-11-17 1:40 ` [PATCH RFC v2 05/10] tests/tcg: added test for MTE write-only Gabriel Brookman
2025-11-17 15:39 ` Richard Henderson
2025-11-17 1:40 ` Gabriel Brookman [this message]
2025-11-17 16:18 ` [PATCH RFC v2 06/10] target/arm: add canonical and no-address tag logic Richard Henderson
2025-11-17 1:40 ` [PATCH RFC v2 07/10] target/arm: ldg on canonical tag loads the tag Gabriel Brookman
2025-11-17 16:26 ` Richard Henderson
2025-11-18 17:31 ` brookmangabriel
2025-11-17 1:40 ` [PATCH RFC v2 08/10] target/arm: storing to canonical tags faults Gabriel Brookman
2025-11-19 7:48 ` Richard Henderson
2025-11-17 1:40 ` [PATCH RFC v2 09/10] tests/tcg: added test for MTE canonical and NAT Gabriel Brookman
2025-11-19 7:49 ` Richard Henderson
2025-11-17 1:40 ` [PATCH RFC v2 10/10] docs: added MTE4 features to docs Gabriel Brookman
2025-11-19 7:51 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251116-feat-mte4-v2-6-9a7122b7fa76@gmail.com \
--to=brookmangabriel@gmail.com \
--cc=gustavo.romero@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).