linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/9] kasan: unify kasan_arch_is_ready with kasan_enabled
@ 2025-06-25  9:52 Sabyrzhan Tasbolatov
  2025-06-25  9:52 ` [PATCH 1/9] kasan: unify static kasan_flag_enabled across modes Sabyrzhan Tasbolatov
                   ` (8 more replies)
  0 siblings, 9 replies; 21+ messages in thread
From: Sabyrzhan Tasbolatov @ 2025-06-25  9:52 UTC (permalink / raw)
  To: ryabinin.a.a, glider, andreyknvl, dvyukov, vincenzo.frascino,
	catalin.marinas, will, chenhuacai, kernel, maddy, mpe, npiggin,
	christophe.leroy, hca, gor, agordeev, borntraeger, svens, richard,
	anton.ivanov, johannes, dave.hansen, luto, peterz, tglx, mingo,
	bp, x86, hpa, chris, jcmvbkbc, akpm
  Cc: guoweikang.kernel, geert, rppt, tiwei.btw, richard.weiyang,
	benjamin.berg, kevin.brodsky, kasan-dev, linux-arm-kernel,
	linux-kernel, loongarch, linuxppc-dev, linux-s390, linux-um,
	linux-mm, snovitoll

This patch series unifies the kasan_arch_is_ready() and kasan_enabled()
interfaces by extending the existing kasan_enabled() infrastructure to
work consistently across all KASAN modes (Generic, SW_TAGS, HW_TAGS).

Currently, kasan_enabled() only works for HW_TAGS mode using a static key,
while other modes either return IS_ENABLED(CONFIG_KASAN) (compile-time
constant) or rely on architecture-specific kasan_arch_is_ready()
implementations with custom static keys and global variables.

This leads to:
- Code duplication across architectures  
- Inconsistent runtime behavior between KASAN modes
- Architecture-specific readiness tracking

After this series:
- All KASAN modes use the same kasan_flag_enabled static key
- Consistent runtime enable/disable behavior across modes
- Simplified architecture code with unified kasan_init_generic() calls
- Elimination of arch specific kasan_arch_is_ready() implementations
- Unified vmalloc integration using kasan_enabled() checks

This addresses the bugzilla issue [1] about making
kasan_flag_enabled and kasan_enabled() work for Generic mode,
and extends it to provide true unification across all modes.

[1] https://bugzilla.kernel.org/show_bug.cgi?id=217049

=== Current mainline KUnit status

To see if there is any regression, I've tested first on the following
commit 739a6c93cc75 ("Merge tag 'nfsd-6.16-1' of
git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux").

Tested via compiling a kernel with CONFIG_KASAN_KUNIT_TEST and running
QEMU VM. There are failing tests in SW_TAGS and GENERIC modes in arm64:

arm64 CONFIG_KASAN_HW_TAGS:
	# kasan: pass:62 fail:0 skip:13 total:75
	# Totals: pass:62 fail:0 skip:13 total:75
	ok 1 kasan

arm64 CONFIG_KASAN_SW_TAGS=y:
	# kasan: pass:65 fail:1 skip:9 total:75
	# Totals: pass:65 fail:1 skip:9 total:75
	not ok 1 kasan
	# kasan_strings: EXPECTATION FAILED at mm/kasan/kasan_test_c.c:1598
	KASAN failure expected in "strscpy(ptr, src + KASAN_GRANULE_SIZE, KASAN_GRANULE_SIZE)", but none occurred

arm64 CONFIG_KASAN_GENERIC=y, CONFIG_KASAN_OUTLINE=y:
	# kasan: pass:61 fail:1 skip:13 total:75
	# Totals: pass:61 fail:1 skip:13 total:75
	not ok 1 kasan
	# same failure as above

x86_64 CONFIG_KASAN_GENERIC=y:
	# kasan: pass:58 fail:0 skip:17 total:75
	# Totals: pass:58 fail:0 skip:17 total:75
	ok 1 kasan

=== Testing with the patches:

* arm64  (GENERIC, HW_TAGS, SW_TAGS): no regression, same above results.
* x86_64 (GENERIC): no regression, no errors

=== NB

I haven't tested on the following arch. due to the absence of qemu-system-
support on those arch on my machine. So I defer this to relevant arch
people to test KASAN initialization:
- loongarch
- s390
- um
- xtensa
- powerpc

Sabyrzhan Tasbolatov (9):
  kasan: unify static kasan_flag_enabled across modes
  kasan: replace kasan_arch_is_ready with kasan_enabled
  kasan/arm64: call kasan_init_generic in kasan_init
  kasan/xtensa: call kasan_init_generic in kasan_init
  kasan/loongarch: call kasan_init_generic in kasan_init
  kasan/um: call kasan_init_generic in kasan_init
  kasan/x86: call kasan_init_generic in kasan_init
  kasan/s390: call kasan_init_generic in kasan_init
  kasan/powerpc: call kasan_init_generic in kasan_init

 arch/arm64/mm/kasan_init.c             |  4 +---
 arch/loongarch/include/asm/kasan.h     |  7 -------
 arch/loongarch/mm/kasan_init.c         |  7 ++-----
 arch/powerpc/include/asm/kasan.h       | 14 --------------
 arch/powerpc/mm/kasan/init_book3s_64.c |  6 +-----
 arch/s390/kernel/early.c               |  2 +-
 arch/um/include/asm/kasan.h            |  5 -----
 arch/um/kernel/mem.c                   |  4 ++--
 arch/x86/mm/kasan_init_64.c            |  2 +-
 arch/xtensa/mm/kasan_init.c            |  2 +-
 include/linux/kasan-enabled.h          | 22 ++++++++++++++++------
 include/linux/kasan.h                  |  6 ++++++
 mm/kasan/common.c                      | 15 +++++++++++----
 mm/kasan/generic.c                     | 17 ++++++++++++++---
 mm/kasan/hw_tags.c                     |  7 -------
 mm/kasan/kasan.h                       |  6 ------
 mm/kasan/shadow.c                      | 15 +++------------
 mm/kasan/sw_tags.c                     |  2 ++
 18 files changed, 61 insertions(+), 82 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2025-06-26 13:53 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-25  9:52 [PATCH 0/9] kasan: unify kasan_arch_is_ready with kasan_enabled Sabyrzhan Tasbolatov
2025-06-25  9:52 ` [PATCH 1/9] kasan: unify static kasan_flag_enabled across modes Sabyrzhan Tasbolatov
2025-06-25 10:35   ` Christophe Leroy
2025-06-26  9:31     ` Sabyrzhan Tasbolatov
2025-06-25  9:52 ` [PATCH 2/9] kasan: replace kasan_arch_is_ready with kasan_enabled Sabyrzhan Tasbolatov
2025-06-25 10:27   ` Christophe Leroy
2025-06-25 12:23     ` Johannes Berg
2025-06-25 12:50       ` Sabyrzhan Tasbolatov
2025-06-25  9:52 ` [PATCH 3/9] kasan/arm64: call kasan_init_generic in kasan_init Sabyrzhan Tasbolatov
2025-06-25  9:52 ` [PATCH 4/9] kasan/xtensa: " Sabyrzhan Tasbolatov
2025-06-25  9:52 ` [PATCH 5/9] kasan/loongarch: " Sabyrzhan Tasbolatov
2025-06-26 13:29   ` Peter Zijlstra
2025-06-26 13:52     ` Sabyrzhan Tasbolatov
2025-06-25  9:52 ` [PATCH 6/9] kasan/um: " Sabyrzhan Tasbolatov
2025-06-25 12:20   ` Johannes Berg
2025-06-25  9:52 ` [PATCH 7/9] kasan/x86: " Sabyrzhan Tasbolatov
2025-06-25  9:52 ` [PATCH 8/9] kasan/s390: " Sabyrzhan Tasbolatov
2025-06-25  9:52 ` [PATCH 9/9] kasan/powerpc: " Sabyrzhan Tasbolatov
2025-06-25 10:33   ` Christophe Leroy
2025-06-25 12:45     ` Sabyrzhan Tasbolatov
2025-06-26 10:52   ` Christophe Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).