[PATCH 08/24] arm64: Introduce mte_get_reset_tfsr() helpers
From: Pierre-Clément Tosi
Date: Sat Nov 07 2026 - 13:47:42 EST
In an effort to untangle MTE from KASAN, split a reusable MTE helper out
of mte_check_tfsr_el1(), providing two variants, to accommodate the
contexts under which it gets called: one synchronising TFx before
reading it and another delegating that responsibility to the caller.
Name the helpers similarly to __dsu_pmu_get_reset_overflow().
This prepares for a rework of the KASAN API to simplify circular header
dependencies, as KASAN calls into mte_check_tfsr_el1(), which calls back
into a kasan_*() function.
Signed-off-by: Pierre-Clément Tosi <ptosi@xxxxxxxxxx>
---
arch/arm64/include/asm/mte.h | 31 +++++++++++++++++++++++++++++++
arch/arm64/kernel/mte.c | 12 +-----------
2 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h
index 1d6113ae786f..614fff7dc35f 100644
--- a/arch/arm64/include/asm/mte.h
+++ b/arch/arm64/include/asm/mte.h
@@ -17,7 +17,9 @@
#include <linux/sched.h>
#include <linux/types.h>
+#include <asm/barrier.h>
#include <asm/pgtable-types.h>
+#include <asm/sysreg.h>
void mte_clear_page_tags(void *addr);
unsigned long mte_copy_tags_from_user(void *to, const void __user *from,
@@ -31,6 +33,35 @@ void mte_invalidate_tags_area(int type);
void *mte_allocate_tag_storage(void);
void mte_free_tag_storage(char *storage);
+static __always_inline bool __mte_get_reset_tfsr(void)
+{
+ u64 tfsr_el1 = read_sysreg_s(SYS_TFSR_EL1);
+
+ if (likely(!(tfsr_el1 & SYS_TFSR_EL1_TF1)))
+ return false;
+
+ /*
+ * Note: isb() is not required after this direct write
+ * because there is no indirect read subsequent to it
+ * (per ARM DDI 0487F.c table D13-1).
+ */
+ write_sysreg_s(0, SYS_TFSR_EL1);
+
+ return true;
+}
+
+static __always_inline bool mte_get_reset_tfsr(void)
+{
+ /*
+ * The barriers are required to guarantee that the indirect writes
+ * to TFSR_EL1 are synchronized before we report the state.
+ */
+ dsb(nsh);
+ isb();
+
+ return __mte_get_reset_tfsr();
+}
+
#ifdef CONFIG_ARM64_MTE
/* track which pages have valid allocation tags */
diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c
index 8025ee1f7fdb..47432c9c4de0 100644
--- a/arch/arm64/kernel/mte.c
+++ b/arch/arm64/kernel/mte.c
@@ -182,18 +182,8 @@ int mte_enable_kernel_store_only(void)
#ifdef CONFIG_KASAN_HW_TAGS
void mte_check_tfsr_el1(void)
{
- u64 tfsr_el1 = read_sysreg_s(SYS_TFSR_EL1);
-
- if (unlikely(tfsr_el1 & SYS_TFSR_EL1_TF1)) {
- /*
- * Note: isb() is not required after this direct write
- * because there is no indirect read subsequent to it
- * (per ARM DDI 0487F.c table D13-1).
- */
- write_sysreg_s(0, SYS_TFSR_EL1);
-
+ if (__mte_get_reset_tfsr())
kasan_report_async();
- }
}
#endif
--
2.56.0.455.g6c5a503b38-goog