[PATCH 0/7] kasan: Add KUnit config and fix missing instrumentation in load_unaligned_zeropad()

From: Bill Wendling

Date: Fri Sep 11 2026 - 03:13:25 EST


This series makes the KASAN KUnit test suite easy to run via kunit.py
and fixes a real detection gap it uncovered along the way.

Patch 1 adds mm/kasan/.kunitconfig so the suite can be run with:

./tools/testing/kunit/kunit.py run --arch=x86_64 --kunitconfig mm/kasan

Getting CONFIG_KASAN_KUNIT_TEST to actually build required pulling in
CONFIG_SCHED_TRACER (CONFIG_FTRACE alone doesn't select the invisible
TRACEPOINTS symbol it depends on), plus a larger CONFIG_LOG_BUF_SHIFT
to stop KASAN's verbose reports from overflowing the printk buffer
under QEMU.

The migration from read_word_at_a_time() to load_unaligned_zeropad() lost
instrumentation, because the load_unaligned_zeropad() functions are
implemented as inline asm with an exception table entry on every
architecture, so the compiler never sees the memory access and can't
instrument it for KASAN/KCSAN. This meant sized_strscpy() silently
bypassed KASAN when reading its source buffer word-at-a-time, and the
same gap turned out to be open at every other call site in the tree.

Rather than patching each call site individually, patch 2 renames
x86's load_unaligned_zeropad() to arch_load_unaligned_zeropad() and
adds a single common, always-inlined wrapper that instruments the read
before calling through.

Patches 3-7 convert the remaining architectures (arm64, arm, riscv,
s390, powerpc) that implement load_unaligned_zeropad() to the same
pattern, so each can be reviewed independently by its arch maintainer.

Verified via objdump that the wrapper adds no calls or relocations
when KASAN and KCSAN are both disabled.

Bill Wendling (7):
kasan: Add .kunitconfig for KUnit tests
x86/word-at-a-time: Instrument load_unaligned_zeropad()
arm64/word-at-a-time: Instrument load_unaligned_zeropad()
arm/word-at-a-time: Instrument load_unaligned_zeropad()
riscv/word-at-a-time: Instrument load_unaligned_zeropad()
s390/word-at-a-time: Instrument load_unaligned_zeropad()
powerpc/word-at-a-time: Instrument load_unaligned_zeropad()

arch/arm/include/asm/word-at-a-time.h | 4 ++-
arch/arm64/include/asm/word-at-a-time.h | 4 ++-
arch/powerpc/include/asm/word-at-a-time.h | 4 ++-
arch/riscv/include/asm/word-at-a-time.h | 4 ++-
arch/s390/include/asm/word-at-a-time.h | 4 ++-
arch/x86/include/asm/word-at-a-time.h | 4 ++-
.../asm-generic/word-at-a-time-instrumented.h | 25 +++++++++++++++++++
mm/kasan/.kunitconfig | 15 +++++++++++
8 files changed, 58 insertions(+), 6 deletions(-)
create mode 100644 include/asm-generic/word-at-a-time-instrumented.h
create mode 100644 mm/kasan/.kunitconfig

--
2.47.3