[PATCH 0/4] kasan: introduce page-granularity poisoning API

From: Pierre-Clément Tosi

Date: Tue Dec 01 2026 - 11:00:15 EST


(Based on mm-unstable at commit d2e5fd433042, with [1] cherry-picked)

This series aims to improve the performance of KASAN_HW_TAGS by taking
advantage of page-granularity tagging routines which arm64 must support
to service userspace MTE. It introduces the kasan_[un]poison_pages() API
analogous to the existing kasan_[un]poison() but which operates on page
aligned ranges, a common use-case in KASAN.

As *_pages() calls are backed by the pre-existing poisoning API when not
supported by the architecture (or outside of HW_TAGS), no functional
changes are expected outside of HW_TAGS+arm64 i.e. MTE.

For now, this series adds all of the necessary piping to enable KASAN to
use the MTE page tagging routines, but does not yet connect the two, as
the routines are being simultaneously introduce [2] and optimized [3] on
the arm64 side. A later commit will bridge this gap.

To motivate this change, here are the speedups I measure (see [3] for
methodology) when comparing tagging (and clearing) one warm page with
the optimized page tagging routines, compared to hw_set_mem_tag_range():

(cache=warm) kasan_poison*(init=false) kasan_poison*(init=true)
============== ========================== =============================
[SoC:CPU]Model DZP=0 DZP=1 DZP=0 DZP=1
============== ============ ============ ============ ===============
[G3:3]A510 1.17-1.22x 1.33x 1.14x 1.33x
[G4:3]A520 1.16x 1.58x 1.15x 1.40x
[G5:1]A520 1.12-1.15x 1.21-1.22x 1.08-1.13x 1.36-1.37x
[G3:7]A715 1.25-1.28x 4.17x 1.22-1.37x 4.17x
[G4:6]A720 1.29-1.37x 4.32x 1.36-1.57x 4.32x
[G5:4]A725 1.33-1.52x 4.27-4.31x 1.42-1.56x 4.26-4.30x
[G5:6]A725 1.42-1.57x 4.21-4.27x 1.43-1.49x 4.22-4.26x
[G6:1]C1-Pro 1.14-1.22x 3.63-3.93x 1.14-1.21x 3.79-3.95x
[G6:5]C1-Pro 1.21-1.24x 3.89-3.91x 1.13-1.20x 3.90-3.91x
[G3:8]X3 1.23-1.24x 4.20-4.25x 1.24-1.25x 4.20-4.22x
[G4:7]X4 1.26-1.30x 4.25x 1.36-1.37x 7.74x
[G5:7]X4 1.27-1.32x 4.23-4.25x 1.36-1.37x 7.73-7.74x
[G6:6]C1-Ultra 1.49-1.50x 26.66x 1.49-1.59x 26.65-26.66x
============== ============ ============ ============ ===============

As the page function are out-of-line (a branch being likely negligible
when poisoning a page or more), this also has the added side-effect of
shrinking the callers. Using bloat-o-meter on defconfig + KASAN_HW_TAGS:

================================== ============== ==============
Function Clang 21 GCC 15
================================== ============== ==============
__kasan_poison_pages 204->104 -49% 252->128 -49%
__kasan_poison_slab 304->208 -32% 348->196 -44%
__kasan_mempool_poison_pages 368->264 -28% 432->336 -22%
__kasan_mempool_poison_object 368->380 +3% 616->512 -17%
unpoison_page_alloc 332->280 -16% 416->280 -33%
__kasan_unpoison_vmalloc 772->920 +19% 916->1016 +11%
__kasan_unpoison_new_object +0% 156->172 +10%
__kasan_mempool_unpoison_object = +0% 680->688 +1%
kasan_poison (inlined) -
================================== ============== ==============

and unpoison_page_alloc gets inlined into __kasan_mempool_unpoison_pages
by Clang. The increase in *_vmalloc() is the result of the last commit
of this series, which adds a "fast path" for page-aligned allocations.

[1]: https://lore.kernel.org/linux-mm/20261201-fix-mempool-resample-v1-1-79bdf0278f68@xxxxxxxxxx
[2]: https://lore.kernel.org/linux-arm-kernel/20261201-mte-page-api-v1-0-5e38d19462ea@xxxxxxxxxx
[3]: https://lore.kernel.org/linux-arm-kernel/20261201-mte-page-optim-v1-0-322b9e4096c7@xxxxxxxxxx

Signed-off-by: Pierre-Clément Tosi <ptosi@xxxxxxxxxx>
---
Pierre-Clément Tosi (4):
kasan: rename kasan_[un]poison_pages() as hooks
kasan: add page-granularity (un)poison helpers
kasan: factor out __kasan_unpoison_vmalloc redzone
kasan: unpoison vmalloc with page-granularity

include/linux/kasan.h | 24 +++++++++++-----------
mm/kasan/common.c | 27 +++++++++++++------------
mm/kasan/hw_tags.c | 38 +++++++++++++++++++++++++---------
mm/kasan/kasan.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++
mm/page_alloc.c | 6 +++---
5 files changed, 113 insertions(+), 38 deletions(-)
---
base-commit: d2e5fd43304200927d92c50ffa8bbe8420753f88
change-id: 20261127-kasan-poison-pages-cf4b85cb7046
prerequisite-change-id: 20261127-fix-mempool-resample-ea561bae66ef:v1
prerequisite-patch-id: 8a69d42122d2f974d453d4c71dca7859b4a41c7c

Best regards,
--
Pierre-Clément Tosi <ptosi@xxxxxxxxxx>