[PATCH 12/24] kasan: drop mte-kasan.h from arch-agnostic header

From: Pierre-Clément Tosi

Date: Sat Nov 07 2026 - 10:57:27 EST


The inclusion of <asm/mte-kasan.h> (only defined by arm64) is based on
the brittle assumption that KASAN_HW_TAGS is equivalent to MTE, which
will break as soon as another architecture supports it. Furthermore,
exposing the header's contents to common KASAN_HW_TAGS code risks
spreading this wrong assumption further.

Allow KASAN_GRANULE_SIZE to be arch-defined, with a fallback.

Define KASAN_GRANULE_SIZE in arm64's KASAN header when KASAN_HW_TAGS.

Remove the #include, which is now unused as a result.

Cc: Alexander Potapenko <glider@xxxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Andrey Konovalov <andreyknvl@xxxxxxxxx>
Cc: Andrey Ryabinin <ryabinin.a.a@xxxxxxxxx>
Cc: Dmitry Vyukov <dvyukov@xxxxxxxxxx>
Cc: kasan-dev@xxxxxxxxxxxxxxxx
Cc: linux-mm@xxxxxxxxx
Signed-off-by: Pierre-Clément Tosi <ptosi@xxxxxxxxxx>
---
arch/arm64/include/asm/kasan.h | 5 +++++
mm/kasan/kasan.h | 5 +----
2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/include/asm/kasan.h b/arch/arm64/include/asm/kasan.h
index b167e9d3da91..3106a2271781 100644
--- a/arch/arm64/include/asm/kasan.h
+++ b/arch/arm64/include/asm/kasan.h
@@ -6,6 +6,7 @@

#include <linux/linkage.h>
#include <asm/memory.h>
+#include <asm/mte-def.h>
#include <asm/mte-kasan.h>
#include <asm/pgtable-types.h>

@@ -22,5 +23,9 @@ void kasan_init(void);
static inline void kasan_init(void) { }
#endif

+#ifdef CONFIG_KASAN_HW_TAGS
+#define KASAN_GRANULE_SIZE MTE_GRANULE_SIZE
+#endif /* CONFIG_KASAN_HW_TAGS */
+
#endif
#endif
diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
index 0df7daee1864..52c2e7dca739 100644
--- a/mm/kasan/kasan.h
+++ b/mm/kasan/kasan.h
@@ -128,11 +128,8 @@ static inline bool kasan_requires_meta(void)

#endif /* CONFIG_KASAN_GENERIC */

-#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
+#ifndef KASAN_GRANULE_SIZE
#define KASAN_GRANULE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT)
-#else
-#include <asm/mte-kasan.h>
-#define KASAN_GRANULE_SIZE MTE_GRANULE_SIZE
#endif

#define KASAN_GRANULE_MASK (KASAN_GRANULE_SIZE - 1)

--
2.56.0.455.g6c5a503b38-goog