[PATCH 2/4] arm64: Introduce <asm/mte-tagging.h>

From: Pierre-Clément Tosi

Date: Tue Dec 01 2026 - 09:50:28 EST


Since mte.h is included by multiple low-level headers such as pgtable.h
or uaccess.h, it is hard to extend it without falling into circular
dependency traps. This is specifically relevant since upcoming patches
will need to call linux/mm.h macros, which would break the build as-is.

One way to get around this issue would be to add new code in *.c files,
like commit da9f24dc4336 ("arm64: mte: Add mte_clear_folio_tags()") had
to do but that isn't ideal for simple helpers which the compiler should
ideally be able to inline.

A cleaner alternative is to split up mte.h into more fundamental headers
and untangle the different clients. For example, pgtable.h only needs
mte.h for swap logic while uaccess.h uses it for TCO-guarded sections.

Therefore, introduce a dedicated header for tagging functions, mostly
intended to be included from *.c files and such that it itself can
include headers such as linux/mm.h without triggering circular includes.

For now, include it from all callers of mte_[zero_]clear_page_tags() and
limit the header to including mte.h. Future commits will build on that.

Signed-off-by: Pierre-Clément Tosi <ptosi@xxxxxxxxxx>
---
arch/arm64/include/asm/mte-tagging.h | 13 +++++++++++++
arch/arm64/kernel/cpufeature.c | 1 +
arch/arm64/kernel/mte.c | 1 +
arch/arm64/kvm/guest.c | 1 +
arch/arm64/kvm/mmu.c | 1 +
arch/arm64/mm/fault.c | 1 +
6 files changed, 18 insertions(+)

diff --git a/arch/arm64/include/asm/mte-tagging.h b/arch/arm64/include/asm/mte-tagging.h
new file mode 100644
index 000000000000..5da9c6433fb8
--- /dev/null
+++ b/arch/arm64/include/asm/mte-tagging.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * MTE tagging helpers.
+ *
+ * Header dedicated to tagging functions, pulled out of <asm/mte.h> to simplify
+ * the header dependency graph and intended to mostly be included from .c files.
+ */
+#ifndef __ASM_MTE_TAGGING_H
+#define __ASM_MTE_TAGGING_H
+
+#include <asm/mte.h>
+
+#endif /* __ASM_MTE_TAGGING_H */
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 8265803357c1..e817d49037a6 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -88,6 +88,7 @@
#include <asm/mmu.h>
#include <asm/mmu_context.h>
#include <asm/mpam.h>
+#include <asm/mte-tagging.h>
#include <asm/mte.h>
#include <asm/hypervisor.h>
#include <asm/processor.h>
diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c
index 850bcee21e77..0aadaabbe31e 100644
--- a/arch/arm64/kernel/mte.c
+++ b/arch/arm64/kernel/mte.c
@@ -21,6 +21,7 @@

#include <asm/barrier.h>
#include <asm/cpufeature.h>
+#include <asm/mte-tagging.h>
#include <asm/mte.h>
#include <asm/ptrace.h>
#include <asm/sysreg.h>
diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c
index b7d36c2abfdf..fc6d067b97ef 100644
--- a/arch/arm64/kvm/guest.c
+++ b/arch/arm64/kvm/guest.c
@@ -25,6 +25,7 @@
#include <asm/kvm.h>
#include <asm/kvm_emulate.h>
#include <asm/kvm_nested.h>
+#include <asm/mte-tagging.h>
#include <asm/sigcontext.h>

#include "trace.h"
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index a0d4981ebb99..0ae2e19d0bc6 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -22,6 +22,7 @@
#include <asm/kvm_pkvm.h>
#include <asm/kvm_asm.h>
#include <asm/kvm_emulate.h>
+#include <asm/mte-tagging.h>
#include <asm/virt.h>

#include "trace.h"
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index cf855aa1c30f..e093e8473b5e 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -39,6 +39,7 @@
#include <asm/debug-monitors.h>
#include <asm/esr.h>
#include <asm/kprobes.h>
+#include <asm/mte-tagging.h>
#include <asm/mte.h>
#include <asm/processor.h>
#include <asm/sysreg.h>

--
2.56.1.839.g22a8290db9-goog