arm64: Decouple MTE code from KASAN support
Get series with b4
b4 am [email protected] change-id 20261107-mte-kasan-split-3632e818f997Versions newest first
- v1 Latest24 patches 4 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/24 | arm64: Fix lazy TCO clear when enabling user MTEarch/ | +1 | 3 replies | |
| 2/24 | kselftest/arm64: Test lazy PSTATE.TCO handlingtools/ tools/ | +153 | 0 replies | |
| 3/24 | arm64: Fix volatility of IRG inline assemblyarch/ | +1 | 0 replies | |
| 4/24 | arm64: Skip TCO on privileged uaccess without kMTEarch/ arch/ | +19 | 0 replies | |
| 5/24 | arm64: Check MTE once per fault-handling sectionarch/ arch/ arch/ | +67 | 1 reply | |
| 6/24 | arm64: Harden is_ttbr1_addr() on tagged addressesarch/ arch/ | +4 | 0 replies | |
| 7/24 | arm64: Skip redundant TCO clear post-kernel entryarch/ | +5 | 0 replies | |
| 8/24 | arm64: Introduce mte_get_reset_tfsr() helpersarch/ arch/ | +32 | 0 replies | |
| 9/24 | kasan: rework hw_{force=>flush}_async_tag_fault()arch/ mm/ mm/ | +4 | 0 replies | |
| 10/24 | kasan: rework hw_{get=>set}_random_tag()arch/ arch/ mm/ | +13 | 0 replies | |
| 11/24 | kasan: provide empty stub for kasan_report_async()include/ | +2 | 0 replies | |
| 12/24 | kasan: drop mte-kasan.h from arch-agnostic headerarch/ mm/ | +6 | 0 replies | |
| 13/24 | arm64: Introduce set_pstate_tco() helper macroarch/ arch/ arch/ +2 more | +23 | 0 replies | |
| 14/24 | arm64: Add mte_{enter,exit}_*_{kernel,user}_mode()arch/ | +28 | 0 replies | |
| 15/24 | arm64: Refactor and remove mte_disable_tco_entry()arch/ arch/ arch/ +1 more | +31 | 0 replies | |
| 16/24 | arm64: Refactor KERNEL_GCR_EL1 out of <sysreg.h>arch/ arch/ arch/ +1 more | +21 | 0 replies | |
| 17/24 | arm64: Introduce MTE & KASAN tag handling helpersarch/ arch/ arch/ | +42 | 0 replies | |
| 18/24 | arm64: Inline and remove mte_check_tfsr_*()arch/ arch/ arch/ +1 more | +28 | 0 replies | |
| 19/24 | arm64: Rework static branches for kernel MTEarch/ arch/ arch/ +3 more | +59 | 0 replies | |
| 20/24 | arm64: Move MTE insn wrappers to <asm/mte-def.h>arch/ arch/ | +48 | 0 replies | |
| 21/24 | arm64: Introduce mte_tag[_and_zero]_range()arch/ arch/ | +53 | 0 replies | |
| 22/24 | arm64: Consolidate MTE-based KASAN in mte-kasan.harch/ arch/ arch/ | +36 | 0 replies | |
| 23/24 | arm64: Fold <asm/mte-kasan.h> into <asm/kasan.h>MAINTAINERS arch/ arch/ +2 more | +101 | 0 replies | |
| 24/24 | arm64: Introduce CONFIG_ARM64_MTE_KERNELarch/ arch/ arch/ +1 more | +13 | 0 replies |
Reviews trailers per patch
1 of 24 patches has a Reviewed-by or Acked-by.
| Patch | Catalin Marinas |
|---|---|
| 1/24 | R-b |
| 2/24 | |
| 3/24 | |
| 4/24 | |
| 5/24 | |
| 6/24 | |
| 7/24 | |
| 8/24 | |
| 9/24 | |
| 10/24 | |
| 11/24 | |
| 12/24 | |
| 13/24 | |
| 14/24 | |
| 15/24 | |
| 16/24 | |
| 17/24 | |
| 18/24 | |
| 19/24 | |
| 20/24 | |
| 21/24 | |
| 22/24 | |
| 23/24 | |
| 24/24 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH 00/24] arm64: Decouple MTE code from KASAN support
MTE is a hardware feature, KASAN is software infrastructure.
The direction of the dependency should be clear: KASAN uses MTE.
However, the code does not reflect this split: many mte_*() functions are actually only intended for HW_TAGS such that there is no way to make use of in-kernel MTE functionality without enabling KASAN. Furthermore, there is a lot of unnecessary indirection in those functions, causing duplication, code that is harder to follow than it should be, and making it easier for subtle inconsistencies to hide.
Instead, this series aims to untangle the two into a set of reusable, arch-level MTE functions and a thin wrapper around them that KASAN needs. For non-KASAN MTE-related code, instead of attempting to reuse KASAN functions, break out individual MTE primitives into KASAN-agnostic functions and use them where needed by aligning in style with how other features are supported e.g. during kernel entry/exit.
The result of this rework made some bugs and inefficiencies obvious so I ordered the patches into 3 sets: first, bug fixes, then, functional improvements, and finally the refactor. Specifically:
- patch 1 fixes a bug in the support for userspace MTE, with a kselftest reproducer in patch 2
- patch 3 fixes an unsound inline asm statement
- patches 4-7 address inefficiencies in PSTATE.TCO-guarded sections, TCO lazy clearing, and harden TTBR1 address categorization
- patches 9-12 rework MTE-specific code in arch-agnostic KASAN, with an arch-level early refactor in patch 8 to keep those minimal
- patches 13-23 then proceed with the methodical untangling of MTE from KASAN, leaving only a thin KASAN_HW_TAGS wrapper in <asm/kasan.h>
- patch 24 introduces a hidden Kconfig flag ARM64_MTE_KERNEL, to better document in the code when logic is required for EL1 MTE, as opposed to KASAN
This was tested on v7.4-rc1 and applies cleanly to arm64 for-next/core at commit f46be4da2cbb ("selftests/arm64: GCS must not leak on a failed clone3").
The following checkpatch.pl errors are consciously ignored:
- "WARNING: ... does MAINTAINERS need updating?" on patch 2 for the new kselftest but selftests/arm64/ is already properly maintained
- "WARNING: Macros with flow control statements should be avoided" on patch 5 but the new __raw_{get,put}_mem_tco() macros are intentionally consistent in style with the pre-existing __raw_{get,put}_mem()
while the other warnings/error are false-positives I fix in [1] and [2].
[1]: https://lore.kernel.org/r/20261107-checkpatch-asm-complex_macro-v1-1-9a7b3c69fc28@google.com
[2]: https://lore.kernel.org/r/20261107-checkpatch-file_path_changes-v1-1-8b11814560d8@google.com
---
Pierre-Clément Tosi (24):
arm64: Fix lazy TCO clear when enabling user MTE kselftest/arm64: Test lazy PSTATE.TCO handling
arm64: Fix volatility of IRG inline assembly
arm64: Skip TCO on privileged uaccess without kMTE
arm64: Check MTE once per fault-handling section
arm64: Harden is_ttbr1_addr() on tagged addresses
arm64: Skip redundant TCO clear post-kernel entry
arm64: Introduce mte_get_reset_tfsr() helpers
kasan: rework hw_{force=>flush}_async_tag_fault()
kasan: rework hw_{get=>set}_random_tag()
kasan: provide empty stub for kasan_report_async()
kasan: drop mte-kasan.h from arch-agnostic header
arm64: Introduce set_pstate_tco() helper macro
arm64: Add mte_{enter,exit}_*_{kernel,user}_mode()
arm64: Refactor and remove mte_disable_tco_entry()
arm64: Refactor KERNEL_GCR_EL1 out of <sysreg.h>
arm64: Introduce MTE & KASAN tag handling helpers
arm64: Inline and remove mte_check_tfsr_*()
arm64: Rework static branches for kernel MTE
arm64: Move MTE insn wrappers to <asm/mte-def.h>
arm64: Introduce mte_tag[_and_zero]_range()
arm64: Consolidate MTE-based KASAN in mte-kasan.h
arm64: Fold <asm/mte-kasan.h> into <asm/kasan.h>
arm64: Introduce CONFIG_ARM64_MTE_KERNEL
MAINTAINERS | 2 +- arch/arm64/Kconfig | 8 + arch/arm64/include/asm/kasan.h | 103 +++++++- arch/arm64/include/asm/memory.h | 14 -- arch/arm64/include/asm/mte-def.h | 65 +++++ arch/arm64/include/asm/mte-kasan.h | 266 --------------------- arch/arm64/include/asm/mte.h | 189 ++++++++++----- arch/arm64/include/asm/processor.h | 6 +- arch/arm64/include/asm/sysreg.h | 17 +- arch/arm64/include/asm/uaccess.h | 106 +++++--- arch/arm64/include/asm/word-at-a-time.h | 22 +- arch/arm64/kernel/entry-common.c | 58 ++++- arch/arm64/kernel/entry.S | 3 +- arch/arm64/kernel/mte.c | 72 +++--- arch/arm64/lib/strlen.S | 4 +- arch/arm64/mm/copypage.c | 1 + arch/arm64/mm/fault.c | 2 +- include/linux/kasan.h | 8 +- mm/kasan/hw_tags.c | 3 +- mm/kasan/kasan.h | 14 +- tools/testing/selftests/arm64/mte/.gitignore | 1 + tools/testing/selftests/arm64/mte/check_lazy_tco.c | 152 ++++++++++++ 22 files changed, 649 insertions(+), 467 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261107-mte-kasan-split-3632e818f997
Best regards,
Signature · 1 line
Pierre-Clément Tosi <[email protected]>