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 08/10] target/arm: storing to canonical tags faults
Date: Sun, 16 Nov 2025 20:40:25 -0500 [thread overview]
Message-ID: <20251116-feat-mte4-v2-8-9a7122b7fa76@gmail.com> (raw)
In-Reply-To: <20251116-feat-mte4-v2-0-9a7122b7fa76@gmail.com>
According to ARM ARM, section "Memory region tagging types", tag-store
instructions targeting canonically tagged regions cause a stage 1
permission fault.
Signed-off-by: Gabriel Brookman <brookmangabriel@gmail.com>
---
target/arm/tcg/mte_helper.c | 47 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/target/arm/tcg/mte_helper.c b/target/arm/tcg/mte_helper.c
index ddb68e11fc..9eb3777fe2 100644
--- a/target/arm/tcg/mte_helper.c
+++ b/target/arm/tcg/mte_helper.c
@@ -196,6 +196,23 @@ uint8_t *allocation_tag_mem_probe(CPUARMState *env, int ptr_mmu_idx,
#endif
}
+static void canonical_tag_write_fail(CPUARMState *env,
+ uint64_t dirty_ptr, uintptr_t ra)
+{
+ uint64_t syn;
+
+ env->exception.vaddress = dirty_ptr;
+
+ /* bit 42 is TnD */
+ syn = (1l << 42) | syn_data_abort_no_iss(arm_current_el(env) != 0,
+ 0, 0, 0, 0, 1, 0b1110);
+ raise_exception_ra(env, EXCP_DATA_ABORT, syn, exception_target_el(env), ra);
+ g_assert_not_reached();
+
+}
+
+
+
static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx,
uint64_t ptr, MMUAccessType ptr_access,
int ptr_size, MMUAccessType tag_access,
@@ -332,6 +349,11 @@ static inline void do_stg(CPUARMState *env, uint64_t ptr, uint64_t xt,
int mmu_idx = arm_env_mmu_index(env);
uint8_t *mem;
+ if (mtx_check(env, 1 & (ptr >> 55))) {
+ canonical_tag_write_fail(env, ptr, ra);
+ return;
+ }
+
check_tag_aligned(env, ptr, ra);
/* Trap if accessing an invalid page. */
@@ -359,6 +381,11 @@ void HELPER(stg_stub)(CPUARMState *env, uint64_t ptr)
int mmu_idx = arm_env_mmu_index(env);
uintptr_t ra = GETPC();
+ if (mtx_check(env, 1 & (ptr >> 55))) {
+ canonical_tag_write_fail(env, ptr, ra);
+ return;
+ }
+
check_tag_aligned(env, ptr, ra);
probe_write(env, ptr, TAG_GRANULE, mmu_idx, ra);
}
@@ -370,6 +397,11 @@ static inline void do_st2g(CPUARMState *env, uint64_t ptr, uint64_t xt,
int tag = allocation_tag_from_addr(xt);
uint8_t *mem1, *mem2;
+ if (mtx_check(env, 1 & (ptr >> 55))) {
+ canonical_tag_write_fail(env, ptr, ra);
+ return;
+ }
+
check_tag_aligned(env, ptr, ra);
/*
@@ -418,6 +450,11 @@ void HELPER(st2g_stub)(CPUARMState *env, uint64_t ptr)
uintptr_t ra = GETPC();
int in_page = -(ptr | TARGET_PAGE_MASK);
+ if (mtx_check(env, 1 & (ptr >> 55))) {
+ canonical_tag_write_fail(env, ptr, ra);
+ return;
+ }
+
check_tag_aligned(env, ptr, ra);
if (likely(in_page >= 2 * TAG_GRANULE)) {
@@ -504,6 +541,11 @@ void HELPER(stgm)(CPUARMState *env, uint64_t ptr, uint64_t val)
ptr = QEMU_ALIGN_DOWN(ptr, gm_bs_bytes);
+ if (mtx_check(env, 1 & (ptr >> 55))) {
+ canonical_tag_write_fail(env, ptr, ra);
+ return;
+ }
+
/* Trap if accessing an invalid page. */
tag_mem = allocation_tag_mem(env, mmu_idx, ptr, MMU_DATA_STORE,
gm_bs_bytes, MMU_DATA_LOAD, ra);
@@ -550,6 +592,11 @@ void HELPER(stzgm_tags)(CPUARMState *env, uint64_t ptr, uint64_t val)
intptr_t dcz_bytes, tag_bytes;
uint8_t *mem;
+ if (mtx_check(env, 1 & (ptr >> 55))) {
+ canonical_tag_write_fail(env, ptr, ra);
+ return;
+ }
+
/*
* In arm_cpu_realizefn, we assert that dcz > LOG2_TAG_GRANULE+1,
* i.e. 32 bytes, which is an unreasonably small dcz anyway,
--
2.51.2
next prev parent reply other threads:[~2025-11-17 1:41 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 ` [PATCH RFC v2 06/10] target/arm: add canonical and no-address tag logic Gabriel Brookman
2025-11-17 16:18 ` 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 ` Gabriel Brookman [this message]
2025-11-19 7:48 ` [PATCH RFC v2 08/10] target/arm: storing to canonical tags faults 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-8-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).