Skip to content

kasan: unify kasan_enabled() and remove arch-specific implementations

Sabyrzhan Tasbolatov linux-arm-kernel linux-mm linux-riscv linux-s390 linux-um linuxppc-dev lkml loongarch 4 versions – Applied

Status from this message: This series was applied to riscv/linux.git (for-next)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v6 Latest2 patches 9 repliesApplied 2/2
  2. v52 patches 10 repliesSuperseded
  3. v49 patches 9 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v312 patches19 repliesSuperseded

Changes in v6 from the cover letter

- Call kasan_init_generic() in arch/riscv _after_ local_flush_tlb_all()
- Added more details in git commit message
- Fixed commenting format per coding style in UML (Christophe Leroy)
- Changed exporting to GPL for kasan_flag_enabled (Christophe Leroy)
- Converted ARCH_DEFER_KASAN to def_bool depending on KASAN to avoid arch users to have if KASAN condition (Christophe Leroy)
- Forgot to add __init for kasan_init in UML

Patches in v6 All 2 applied

#Subject and filesSizeRepliesApplied
1/2kasan: introduce ARCH_DEFER_KASAN and unify static key across modesarch/loongarch/Kconfig arch/loongarch/include/asm/kasan.h arch/loongarch/mm/kasan_init.c +18 more+106 -708 repliesApplied
2/2kasan: call kasan_init_generic in kasan_initarch/arm/mm/kasan_init.c arch/arm64/mm/kasan_init.c arch/riscv/mm/kasan_init.c +3 more+7 -71 replyApplied

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchAlexandre GhitiAlexander GordeevChristophe LeroyRitesh Harjani (IBM)
1/2R-b R-b
2/2T-b A-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v6 thread

Cover letter [PATCH v6 0/2] kasan: unify kasan_enabled() and remove arch-specific implementations

This patch series addresses the fragmentation in KASAN initialization across architectures by introducing a unified approach that eliminates duplicate static keys and arch-specific kasan_arch_is_ready() implementations.

The core issue is that different architectures have inconsistent approaches to KASAN readiness tracking:
- PowerPC, LoongArch, and UML arch, each implement own kasan_arch_is_ready()
- Only HW_TAGS mode had a unified static key (kasan_flag_enabled)
- Generic and SW_TAGS modes relied on arch-specific solutions
or always-on behavior

Changes in v6:
- Call kasan_init_generic() in arch/riscv _after_ local_flush_tlb_all()
- Added more details in git commit message
- Fixed commenting format per coding style in UML (Christophe Leroy)
- Changed exporting to GPL for kasan_flag_enabled (Christophe Leroy)
- Converted ARCH_DEFER_KASAN to def_bool depending on KASAN to avoid arch users to have if KASAN condition (Christophe Leroy)
- Forgot to add __init for kasan_init in UML

Changes in v5:
- Unified patches where arch (powerpc, UML, loongarch) selects ARCH_DEFER_KASAN in the first patch not to break bisectability. So in v5 we have 2 patches now in the series instead of 9.
- Removed kasan_arch_is_ready completely as there is no user
- Removed __wrappers in v4, left only those where it's necessary due to different implementations

Tested on:
- powerpc - selects ARCH_DEFER_KASAN
Built ppc64_defconfig (PPC_BOOK3S_64) - OK
Booted via qemu-system-ppc64 - OK

I have not tested in v4 powerpc without KASAN enabled.

In v4 arch/powerpc/Kconfig it was:
select ARCH_DEFER_KASAN if PPC_RADIX_MMU

and compiling with ppc64_defconfig caused:
lib/stackdepot.o:(__jump_table+0x8): undefined reference to `kasan_flag_enabled'

I have fixed it in v5 via adding KASAN condition:

	select ARCH_DEFER_KASAN			if KASAN && PPC_RADIX_MMU

- um - selects ARCH_DEFER_KASAN

KASAN_GENERIC && KASAN_INLINE && STATIC_LINK
Before:
In file included from mm/kasan/common.c:32:
mm/kasan/kasan.h:550:2: error: #error kasan_arch_is_ready only works in KASAN generic outline mode! 550 | #error kasan_arch_is_ready only works in KASAN generic outline mode

After (with auto-selected ARCH_DEFER_KASAN):
./arch/um/include/asm/kasan.h:29:2: error: #error UML does not work in KASAN_INLINE mode with STATIC_LINK enabled! 29 | #error UML does not work in KASAN_INLINE mode with STATIC_LINK enabled!

KASAN_GENERIC && KASAN_OUTLINE && STATIC_LINK &&
Before:
./linux boots.

After (with auto-selected ARCH_DEFER_KASAN):
./linux boots.

KASAN_GENERIC && KASAN_OUTLINE && !STATIC_LINK
Before:
./linux boots

After (with auto-disabled !ARCH_DEFER_KASAN):
./linux boots

- loongarch - selects ARCH_DEFER_KASAN
Built defconfig with KASAN_GENERIC - OK
Haven't tested the boot. Asking Loongarch developers to verify - N/A But should be good, since Loongarch does not have specific "kasan_init()" call like UML does. It selects ARCH_DEFER_KASAN and calls kasan_init() in the end of setup_arch() after jump_label_init().

Previous v5 thread: https://lore.kernel.org/all/[email protected]/
Previous v4 thread: https://lore.kernel.org/all/[email protected]/
Previous v3 thread: https://lore.kernel.org/all/[email protected]/
Previous v2 thread: https://lore.kernel.org/all/[email protected]/

Sabyrzhan Tasbolatov (2):
kasan: introduce ARCH_DEFER_KASAN and unify static key across modes
kasan: call kasan_init_generic in kasan_init

 arch/arm/mm/kasan_init.c               |  2 +-
 arch/arm64/mm/kasan_init.c             |  4 +---
 arch/loongarch/Kconfig                 |  1 +
 arch/loongarch/include/asm/kasan.h     |  7 ------
 arch/loongarch/mm/kasan_init.c         |  8 +++----
 arch/powerpc/Kconfig                   |  1 +
 arch/powerpc/include/asm/kasan.h       | 12 ----------
 arch/powerpc/mm/kasan/init_32.c        |  2 +-
 arch/powerpc/mm/kasan/init_book3e_64.c |  2 +-
 arch/powerpc/mm/kasan/init_book3s_64.c |  6 +----
 arch/riscv/mm/kasan_init.c             |  1 +
 arch/s390/kernel/early.c               |  3 ++-
 arch/um/Kconfig                        |  1 +
 arch/um/include/asm/kasan.h            |  5 ++--
 arch/um/kernel/mem.c                   | 13 ++++++++---
 arch/x86/mm/kasan_init_64.c            |  2 +-
 arch/xtensa/mm/kasan_init.c            |  2 +-
 include/linux/kasan-enabled.h          | 32 ++++++++++++++++++--------
 include/linux/kasan.h                  |  6 +++++
 lib/Kconfig.kasan                      | 12 ++++++++++
 mm/kasan/common.c                      | 17 ++++++++++----
 mm/kasan/generic.c                     | 19 +++++++++++----
 mm/kasan/hw_tags.c                     |  9 +-------
 mm/kasan/kasan.h                       |  8 ++++++-
 mm/kasan/shadow.c                      | 12 +++++-----
 mm/kasan/sw_tags.c                     |  1 +
 mm/kasan/tags.c                        |  2 +-
 27 files changed, 113 insertions(+), 77 deletions(-)
Signature · 1 line
2.34.1