Skip to contentSkip to conversation

mm/kasan: make kasan=on|off work for all three modes

PATCH In review Baoquan He 4 participants 23 messages Feb 25 – Mar 17

Subsystems (15)
lore
Share & tools
lore

Baoquan He

author
#0 lore raw

v5 cover mm/kasan: make kasan=on|off work for all three modes

Currently only hw_tags mode of kasan can be enabled or disabled with kernel parameter kasan=on|off for built kernel. For kasan generic and sw_tags mode, there's no way to disable them once kernel is built.

This is not convenient sometime, e.g in system kdump is configured. When the 1st kernel has KASAN enabled and crash triggered to switch to kdump kernel, the generic or sw_tags mode will cost much extra memory while in fact it's meaningless to have kasan in kdump kernel

There are two parts of big amount of memory requiring for kasan enabed kernel. One is the direct memory mapping shadow of kasan, which is 1/8 of system RAM in generic mode and 1/16 of system RAM in sw_tags mode; the other is the shadow meomry for vmalloc which causes big meomry usage in kdump kernel because of lazy vmap freeing. By introducing "kasan=off|on", if we specify 'kasan=off', the former is avoided by skipping the kasan_init(), and the latter is avoided by not building the vmalloc shadow for vmalloc.

So this patchset moves the kasan=on|off out of hw_tags scope and into common code to make it visible in generic and sw_tags mode too. Then we can add kasan=off in kdump kernel to reduce the unneeded meomry cost for kasan.

Note that this hasn't been supported on s390 since I am not familiar with s390 code. Hope s390 developer will make it work.

Testing:
========
Testing is done on upstream kernel 6.19.0+:

- For generic mode, testing is taken on below systems and passed.
- x86_64 baremetal system
- aarch64 baremetal system
- ppc64le baremetal system (Model 9183-22X)
- risc-v kvm guest

- For sw_tags mode, testing is taken on below system and passed.
- aarch64 baremetal system

- For hw_tags mode, testing is taken on below system and passed.
- aarch64 kvm guest with "-machine virt,mte=on -cpu max" qemu command.

Changelog:
====
v4->v5:
- Add helper __kasan_cache_shrink() in mm/kasan/generic.c so that the kasan_enabled() checking done in kasan_cache_shrink() which is in include/linux/kasan.h. This change is made in patch 1.
- Carve out the change of renaming 'kasan_arg' to 'kasan_arg_disabled' into a separate patch from the old patch 2.
- put the old patch 12 to earlier place as patch 4 in this sereis so that the ifdeffery scope embracing kasan_flag_enabled definition is meaningful and understandable.
- Remove the stale and incorrect comment above kasan_enabled() in the old patch 12.
- Add comment 'If KASAN is disabled via command line, don't initialize it.' to all places where kasan is initialized and kasan_arg_disabled is checked.
- Add document in kernel-parameters.txt to note kasan=on|off.
- Remove unneeded ARCH_DEFER_KASAN and kasan_arch_is_ready().
- All these changes are made according to reviewers' suggestion in v4, thanks to Andrey Konovalov, Andrey Ryabinin and Alexander Potapenko.

v3->v4:
- Rebase code to the latest linux-next/master to make the whole patchset set on top of
[PATCH 0/2] kasan: cleanups for kasan_enabled() checks
[PATCH v6 0/2] kasan: unify kasan_enabled() and remove arch-specific implementations

v2->v3:
- Fix a building error on UML ARCH when CONFIG_KASAN is not set. The change of fixing is appended into patch patch 11. This is reported by LKP, thanks to them.

v1->v2:
- Add __ro_after_init for kasan_arg_disabled, and remove redundant blank lines in mm/kasan/common.c. Thanks to Marco.
- Fix a code bug in <linux/kasan-enabled.h> when CONFIG_KASAN is unset, this is found out by SeongJae and Lorenzo, and also reported by LKP report, thanks to them.
- Add a missing kasan_enabled() checking in kasan_report(). This will cause a KASAN report info even though kasan=off is set:
- Add jump_label_init() calling before kasan_init() in setup_arch() in these
architectures: xtensa, arm. Because they currenly rely on jump_label_init() in main() which is a little late. Then the early static key kasan_flag_enabled in kasan_init() won't work.
- In UML architecture, change to enable kasan_flag_enabled in arch_mm_preinit() because kasan_init() is enabled before main(), there's no chance to operate on static key in kasan_init().

Baoquan He (15):
mm/kasan: add conditional checks in functions to return directly if
kasan is disabled
mm/kasan: rename 'kasan_arg' to 'kasan_arg_disabled' mm/kasan: mm/kasan: move kasan= code to common place mm/kasan: make kasan=on|off take effect for all three modes mm/kasan/sw_tags: don't initialize kasan if it's disabled arch/arm: don't initialize kasan if it's disabled arch/arm64: don't initialize kasan if it's disabled arch/loongarch: don't initialize kasan if it's disabled arch/powerpc: don't initialize kasan if it's disabled arch/riscv: don't initialize kasan if it's disabled arch/x86: don't initialize kasan if it's disabled arch/xtensa: don't initialize kasan if it's disabled arch/um: don't initialize kasan if it's disabled mm/kasan: add document into kernel-parameters.txt mm/kasan: clean up unneeded ARCH_DEFER_KASAN and kasan_arch_is_ready

 .../admin-guide/kernel-parameters.txt         |  4 +++
 Documentation/dev-tools/kasan.rst             |  2 --
 arch/arm/kernel/setup.c                       |  6 ++++
 arch/arm/mm/kasan_init.c                      |  3 ++
 arch/arm64/mm/kasan_init.c                    |  7 +++++
 arch/loongarch/Kconfig                        |  1 -
 arch/loongarch/mm/kasan_init.c                |  3 ++
 arch/powerpc/Kconfig                          |  1 -
 arch/powerpc/mm/kasan/init_32.c               |  6 +++-
 arch/powerpc/mm/kasan/init_book3e_64.c        |  4 +++
 arch/powerpc/mm/kasan/init_book3s_64.c        |  4 +++
 arch/riscv/mm/kasan_init.c                    |  4 +++
 arch/um/Kconfig                               |  1 -
 arch/um/kernel/mem.c                          |  5 +++-
 arch/x86/mm/kasan_init_64.c                   |  4 +++
 arch/xtensa/kernel/setup.c                    |  1 +
 arch/xtensa/mm/kasan_init.c                   |  4 +++
 include/linux/kasan-enabled.h                 | 10 +++----
 include/linux/kasan.h                         |  7 ++++-
 lib/Kconfig.kasan                             | 12 --------
 mm/kasan/common.c                             | 21 ++++++++++++--
 mm/kasan/generic.c                            | 16 +++++++++--
 mm/kasan/hw_tags.c                            | 28 ++-----------------
 mm/kasan/init.c                               |  6 ++++
 mm/kasan/kasan.h                              |  6 ----
 mm/kasan/quarantine.c                         |  3 ++
 mm/kasan/report.c                             |  4 ++-
 mm/kasan/shadow.c                             | 11 +++++++-
 mm/kasan/sw_tags.c                            |  7 +++++
 29 files changed, 128 insertions(+), 63 deletions(-)
Signature · 1 line
2.52.0
author
#1 lore raw

PATCH v5 1/15 mm/kasan: add conditional checks in functions to return directly if kasan is disabled

The current codes only check if kasan is disabled for hw_tags mode. Here add the conditional checks for functional functions of generic mode and sw_tags mode.

And also add a helper __kasan_cache_shrink() in mm/kasan/generic.c so that the conditional check is done in include/linux/kasan.h.

This is prepared for later adding kernel parameter kasan=on|off for all three kasan modes.

---
 include/linux/kasan.h |  7 ++++++-
 mm/kasan/generic.c    | 16 ++++++++++++++--
 mm/kasan/init.c       |  6 ++++++
 mm/kasan/quarantine.c |  3 +++
 mm/kasan/report.c     |  4 +++-
 mm/kasan/shadow.c     | 11 ++++++++++-
 mm/kasan/sw_tags.c    |  3 +++
 7 files changed, 45 insertions(+), 5 deletions(-)
include/linux/kasan.h +6 -1
index 338a1921a50a..a9b8d58d8699 100644
@@ -492,7 +492,12 @@ size_t kasan_metadata_size(struct kmem_cache *cache, bool in_object);
 void kasan_cache_create(struct kmem_cache *cache, unsigned int *size,
 			slab_flags_t *flags);
 
-void kasan_cache_shrink(struct kmem_cache *cache);
+void __kasan_cache_shrink(struct kmem_cache *cache);
+static inline void kasan_cache_shrink(struct kmem_cache *cache)
+{
+	if (kasan_enabled())
+		__kasan_cache_shrink(cache);
+}
 void kasan_cache_shutdown(struct kmem_cache *cache);
 void kasan_record_aux_stack(void *ptr);
 
mm/kasan/generic.c +14 -2
index 2b8e73f5f6a7..25850e7c2e00 100644
@@ -212,14 +212,14 @@ bool kasan_byte_accessible(const void *addr)
 	return shadow_byte >= 0 && shadow_byte < KASAN_GRANULE_SIZE;
 }
 
-void kasan_cache_shrink(struct kmem_cache *cache)
+void __kasan_cache_shrink(struct kmem_cache *cache)
 {
 	kasan_quarantine_remove_cache(cache);
 }
 
 void kasan_cache_shutdown(struct kmem_cache *cache)
 {
-	if (!__kmem_cache_empty(cache))
+	if (kasan_enabled() && !__kmem_cache_empty(cache))
 		kasan_quarantine_remove_cache(cache);
 }
 
@@ -239,6 +239,9 @@ void __asan_register_globals(void *ptr, ssize_t size)
 	int i;
 	struct kasan_global *globals = ptr;
 
+	if (!kasan_enabled())
+		return;
+
 	for (i = 0; i < size; i++)
 		register_global(&globals[i]);
 }
@@ -369,6 +372,9 @@ void kasan_cache_create(struct kmem_cache *cache, unsigned int *size,
 	unsigned int rem_free_meta_size;
 	unsigned int orig_alloc_meta_offset;
 
+	if (!kasan_enabled())
+		return;
+
 	if (!kasan_requires_meta())
 		return;
 
@@ -518,6 +524,9 @@ size_t kasan_metadata_size(struct kmem_cache *cache, bool in_object)
 {
 	struct kasan_cache *info = &cache->kasan_info;
 
+	if (!kasan_enabled())
+		return 0;
+
 	if (!kasan_requires_meta())
 		return 0;
 
@@ -543,6 +552,9 @@ void kasan_record_aux_stack(void *addr)
 	struct kasan_alloc_meta *alloc_meta;
 	void *object;
 
+	if (!kasan_enabled())
+		return;
+
 	if (is_kfence_address(addr) || !slab)
 		return;
 
mm/kasan/init.c +6 -0
index f084e7a5df1e..c78d77ed47bc 100644
@@ -447,6 +447,9 @@ void kasan_remove_zero_shadow(void *start, unsigned long size)
 	unsigned long addr, end, next;
 	pgd_t *pgd;
 
+	if (!kasan_enabled())
+		return;
+
 	addr = (unsigned long)kasan_mem_to_shadow(start);
 	end = addr + (size >> KASAN_SHADOW_SCALE_SHIFT);
 
@@ -482,6 +485,9 @@ int kasan_add_zero_shadow(void *start, unsigned long size)
 	int ret;
 	void *shadow_start, *shadow_end;
 
+	if (!kasan_enabled())
+		return 0;
+
 	shadow_start = kasan_mem_to_shadow(start);
 	shadow_end = shadow_start + (size >> KASAN_SHADOW_SCALE_SHIFT);
 
mm/kasan/quarantine.c +3 -0
index 6958aa713c67..a6dc2c3d8a15 100644
@@ -405,6 +405,9 @@ static int __init kasan_cpu_quarantine_init(void)
 {
 	int ret = 0;
 
+	if (!kasan_enabled())
+		return 0;
+
 	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mm/kasan:online",
 				kasan_cpu_online, kasan_cpu_offline);
 	if (ret < 0)
mm/kasan/report.c +3 -1
index 27efb78eb32d..1a39b3f62c57 100644
@@ -576,7 +576,9 @@ bool kasan_report(const void *addr, size_t size, bool is_write,
 	unsigned long irq_flags;
 	struct kasan_report_info info;
 
-	if (unlikely(report_suppressed_sw()) || unlikely(!report_enabled())) {
+	if (unlikely(report_suppressed_sw()) ||
+	    unlikely(!report_enabled()) ||
+	    !kasan_enabled()) {
 		ret = false;
 		goto out;
 	}
mm/kasan/shadow.c +10 -1
index d286e0a04543..87f517b76d6e 100644
@@ -164,6 +164,8 @@ void kasan_unpoison(const void *addr, size_t size, bool init)
 {
 	u8 tag = get_tag(addr);
 
+	if (!kasan_enabled())
+		return;
 	/*
 	 * Perform shadow offset calculation based on untagged address, as
 	 * some of the callers (e.g. kasan_unpoison_new_object) pass tagged
@@ -277,7 +279,8 @@ static int __meminit kasan_mem_notifier(struct notifier_block *nb,
 
 static int __init kasan_memhotplug_init(void)
 {
-	hotplug_memory_notifier(kasan_mem_notifier, DEFAULT_CALLBACK_PRI);
+	if (kasan_enabled())
+		hotplug_memory_notifier(kasan_mem_notifier, DEFAULT_CALLBACK_PRI);
 
 	return 0;
 }
@@ -660,6 +663,9 @@ int kasan_alloc_module_shadow(void *addr, size_t size, gfp_t gfp_mask)
 	size_t shadow_size;
 	unsigned long shadow_start;
 
+	if (!kasan_enabled())
+		return 0;
+
 	shadow_start = (unsigned long)kasan_mem_to_shadow(addr);
 	scaled_size = (size + KASAN_GRANULE_SIZE - 1) >>
 				KASAN_SHADOW_SCALE_SHIFT;
@@ -696,6 +702,9 @@ int kasan_alloc_module_shadow(void *addr, size_t size, gfp_t gfp_mask)
 
 void kasan_free_module_shadow(const struct vm_struct *vm)
 {
+	if (!kasan_enabled())
+		return;
+
 	if (IS_ENABLED(CONFIG_UML))
 		return;
 
mm/kasan/sw_tags.c +3 -0
index c75741a74602..6c1caec4261a 100644
@@ -79,6 +79,9 @@ bool kasan_check_range(const void *addr, size_t size, bool write,
 	u8 *shadow_first, *shadow_last, *shadow;
 	void *untagged_addr;
 
+	if (!kasan_enabled())
+		return true;
+
 	if (unlikely(size == 0))
 		return true;
 
Signature · 1 line
2.52.0
author
#2 lore raw

PATCH v5 2/15 mm/kasan: rename 'kasan_arg' to 'kasan_arg_disabled'

In reply to Baoquan He

And change it to be a bool variable. This is prepared for later usage.

---
 mm/kasan/hw_tags.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
mm/kasan/hw_tags.c +5 -11
index cbef5e450954..26a69f0d822c 100644
@@ -22,12 +22,6 @@
 
 #include "kasan.h"
 
-enum kasan_arg {
-	KASAN_ARG_DEFAULT,
-	KASAN_ARG_OFF,
-	KASAN_ARG_ON,
-};
-
 enum kasan_arg_mode {
 	KASAN_ARG_MODE_DEFAULT,
 	KASAN_ARG_MODE_SYNC,
@@ -41,7 +35,7 @@ enum kasan_arg_vmalloc {
 	KASAN_ARG_VMALLOC_ON,
 };
 
-static enum kasan_arg kasan_arg __ro_after_init;
+bool kasan_arg_disabled __ro_after_init;
 static enum kasan_arg_mode kasan_arg_mode __ro_after_init;
 static enum kasan_arg_vmalloc kasan_arg_vmalloc __initdata;
 
@@ -88,9 +82,9 @@ static int __init early_kasan_flag(char *arg)
 		return -EINVAL;
 
 	if (!strcmp(arg, "off"))
-		kasan_arg = KASAN_ARG_OFF;
+		kasan_arg_disabled = true;
 	else if (!strcmp(arg, "on"))
-		kasan_arg = KASAN_ARG_ON;
+		kasan_arg_disabled = false;
 	else
 		return -EINVAL;
 
@@ -222,7 +216,7 @@ void kasan_init_hw_tags_cpu(void)
 	 * When this function is called, kasan_flag_enabled is not yet
 	 * set by kasan_init_hw_tags(). Thus, check kasan_arg instead.
 	 */
-	if (kasan_arg == KASAN_ARG_OFF)
+	if (kasan_arg_disabled)
 		return;
 
 	/*
@@ -240,7 +234,7 @@ void __init kasan_init_hw_tags(void)
 		return;
 
 	/* If KASAN is disabled via command line, don't initialize it. */
-	if (kasan_arg == KASAN_ARG_OFF)
+	if (kasan_arg_disabled)
 		return;
 
 	switch (kasan_arg_mode) {
Signature · 1 line
2.52.0
author
#3 lore raw

PATCH v5 3/15 mm/kasan: mm/kasan: move kasan= code to common place

In reply to Baoquan He

This allows generic and sw_tags to be set in kernel cmdline too.

---
 include/linux/kasan-enabled.h |  2 ++
 mm/kasan/common.c             | 21 +++++++++++++++++++++
 mm/kasan/hw_tags.c            | 18 ------------------
 3 files changed, 23 insertions(+), 18 deletions(-)
include/linux/kasan-enabled.h +2 -0
index 9eca967d8526..b7cb906825ca 100644
@@ -35,6 +35,8 @@ static inline void kasan_enable(void) {}
 #endif /* CONFIG_ARCH_DEFER_KASAN || CONFIG_KASAN_HW_TAGS */
 
 #ifdef CONFIG_KASAN_HW_TAGS
+extern bool kasan_arg_disabled;
+
 static inline bool kasan_hw_tags_enabled(void)
 {
 	return kasan_enabled();
mm/kasan/common.c +21 -0
index b7d05c2a6d93..0d788a468e96 100644
@@ -42,6 +42,27 @@ DEFINE_STATIC_KEY_FALSE(kasan_flag_enabled);
 EXPORT_SYMBOL_GPL(kasan_flag_enabled);
 #endif
 
+#ifdef CONFIG_KASAN_HW_TAGS
+bool kasan_arg_disabled __ro_after_init;
+
+/* kasan=off/on */
+static int __init early_kasan_flag(char *arg)
+{
+	if (!arg)
+		return -EINVAL;
+
+	if (!strcmp(arg, "off"))
+		kasan_arg_disabled = true;
+	else if (!strcmp(arg, "on"))
+		kasan_arg_disabled = false;
+	else
+		return -EINVAL;
+
+	return 0;
+}
+early_param("kasan", early_kasan_flag);
+#endif
+
 struct slab *kasan_addr_to_slab(const void *addr)
 {
 	if (virt_addr_valid(addr))
mm/kasan/hw_tags.c +0 -18
index 26a69f0d822c..9602ea4861e2 100644
@@ -35,7 +35,6 @@ enum kasan_arg_vmalloc {
 	KASAN_ARG_VMALLOC_ON,
 };
 
-bool kasan_arg_disabled __ro_after_init;
 static enum kasan_arg_mode kasan_arg_mode __ro_after_init;
 static enum kasan_arg_vmalloc kasan_arg_vmalloc __initdata;
 
@@ -75,23 +74,6 @@ unsigned int kasan_page_alloc_sample_order = PAGE_ALLOC_SAMPLE_ORDER_DEFAULT;
 
 DEFINE_PER_CPU(long, kasan_page_alloc_skip);
 
-/* kasan=off/on */
-static int __init early_kasan_flag(char *arg)
-{
-	if (!arg)
-		return -EINVAL;
-
-	if (!strcmp(arg, "off"))
-		kasan_arg_disabled = true;
-	else if (!strcmp(arg, "on"))
-		kasan_arg_disabled = false;
-	else
-		return -EINVAL;
-
-	return 0;
-}
-early_param("kasan", early_kasan_flag);
-
 /* kasan.mode=sync/async/asymm */
 static int __init early_kasan_mode(char *arg)
 {
Signature · 1 line
2.52.0
author
#4 lore raw

PATCH v5 4/15 mm/kasan: make kasan=on|off take effect for all three modes

In reply to Baoquan He

Now everything is ready, setting kasan=off can disable kasan for all three modes.

---
 include/linux/kasan-enabled.h | 12 +++++-------
 mm/kasan/common.c             |  4 ----
 2 files changed, 5 insertions(+), 11 deletions(-)
include/linux/kasan-enabled.h +5 -7
index b7cb906825ca..cec21a08446e 100644
@@ -4,10 +4,11 @@
 
 #include <linux/static_key.h>
 
-#if defined(CONFIG_ARCH_DEFER_KASAN) || defined(CONFIG_KASAN_HW_TAGS)
+#ifdef CONFIG_KASAN
+extern bool kasan_arg_disabled;
+
 /*
  * Global runtime flag for KASAN modes that need runtime control.
- * Used by ARCH_DEFER_KASAN architectures and HW_TAGS mode.
  */
 DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled);
 
@@ -25,18 +26,15 @@ static inline void kasan_enable(void)
 	static_branch_enable(&kasan_flag_enabled);
 }
 #else
-/* For architectures that can enable KASAN early, use compile-time check. */
 static __always_inline bool kasan_enabled(void)
 {
-	return IS_ENABLED(CONFIG_KASAN);
+	return false;
 }
 
 static inline void kasan_enable(void) {}
-#endif /* CONFIG_ARCH_DEFER_KASAN || CONFIG_KASAN_HW_TAGS */
+#endif
 
 #ifdef CONFIG_KASAN_HW_TAGS
-extern bool kasan_arg_disabled;
-
 static inline bool kasan_hw_tags_enabled(void)
 {
 	return kasan_enabled();
mm/kasan/common.c +0 -4
index 0d788a468e96..fc6513fa5795 100644
@@ -33,16 +33,13 @@
 #include "kasan.h"
 #include "../slab.h"
 
-#if defined(CONFIG_ARCH_DEFER_KASAN) || defined(CONFIG_KASAN_HW_TAGS)
 /*
  * Definition of the unified static key declared in kasan-enabled.h.
  * This provides consistent runtime enable/disable across KASAN modes.
  */
 DEFINE_STATIC_KEY_FALSE(kasan_flag_enabled);
 EXPORT_SYMBOL_GPL(kasan_flag_enabled);
-#endif
 
-#ifdef CONFIG_KASAN_HW_TAGS
 bool kasan_arg_disabled __ro_after_init;
 
 /* kasan=off/on */
@@ -61,7 +58,6 @@ static int __init early_kasan_flag(char *arg)
 	return 0;
 }
 early_param("kasan", early_kasan_flag);
-#endif
 
 struct slab *kasan_addr_to_slab(const void *addr)
 {
Signature · 1 line
2.52.0
author
#5 lore raw

PATCH v5 5/15 mm/kasan/sw_tags: don't initialize kasan if it's disabled

In reply to Baoquan He

Here, kasan is disabled if specified 'kasan=off' in kernel cmdline.

---
 mm/kasan/sw_tags.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/kasan/sw_tags.c +4 -0
index 6c1caec4261a..7757b69b1c86 100644
@@ -40,6 +40,10 @@ void __init kasan_init_sw_tags(void)
 {
 	int cpu;
 
+	/* If KASAN is disabled via command line, don't initialize it. */
+	if (kasan_arg_disabled)
+		return;
+
 	for_each_possible_cpu(cpu)
 		per_cpu(prng_state, cpu) = (u32)get_cycles();
 
Signature · 1 line
2.52.0
author
#6 lore raw

PATCH v5 6/15 arch/arm: don't initialize kasan if it's disabled

In reply to Baoquan He

Here, kasan is disabled if specified 'kasan=off' in kernel cmdline.

And also call jump_label_init() early in setup_arch() so that later kasan_init() can enable static key kasan_flag_enabled. Put jump_label_init() beofre parse_early_param() as other architectures do.

---
 arch/arm/kernel/setup.c  | 6 ++++++
 arch/arm/mm/kasan_init.c | 3 +++
 2 files changed, 9 insertions(+)
arch/arm/kernel/setup.c +6 -0
index 0bfd66c7ada0..453a47a4c715 100644
@@ -1135,6 +1135,12 @@ void __init setup_arch(char **cmdline_p)
 	early_fixmap_init();
 	early_ioremap_init();
 
+	/*
+	 * Initialise the static keys early as they may be enabled by the
+	 * kasan_init() or early parameters.
+	 */
+	jump_label_init();
+
 	parse_early_param();
 
 #ifdef CONFIG_MMU
arch/arm/mm/kasan_init.c +3 -0
index c6625e808bf8..82ec043c891f 100644
@@ -212,6 +212,9 @@ void __init kasan_init(void)
 	phys_addr_t pa_start, pa_end;
 	u64 i;
 
+	/* If KASAN is disabled via command line, don't initialize it. */
+	if (kasan_arg_disabled)
+		return;
 	/*
 	 * We are going to perform proper setup of shadow memory.
 	 *
Signature · 1 line
2.52.0
author
#7 lore raw

PATCH v5 7/15 arch/arm64: don't initialize kasan if it's disabled

In reply to Baoquan He

Here, kasan is disabled if specified 'kasan=off' in kernel cmdline.

And also need skip kasan_populate_early_vm_area_shadow() if kasan is disabled.

---
 arch/arm64/mm/kasan_init.c | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm64/mm/kasan_init.c +7 -0
index abeb81bf6ebd..4a58e609c81b 100644
@@ -384,6 +384,9 @@ void __init kasan_populate_early_vm_area_shadow(void *start, unsigned long size)
 {
 	unsigned long shadow_start, shadow_end;
 
+	if (!kasan_enabled())
+		return;
+
 	if (!is_vmalloc_or_module_addr(start))
 		return;
 
@@ -397,6 +400,10 @@ void __init kasan_populate_early_vm_area_shadow(void *start, unsigned long size)
 
 void __init kasan_init(void)
 {
+	/* If KASAN is disabled via command line, don't initialize it. */
+	if (kasan_arg_disabled)
+		return;
+
 	kasan_init_shadow();
 	kasan_init_depth();
 	kasan_init_generic();
Signature · 1 line
2.52.0
author
#8 lore raw

PATCH v5 8/15 arch/loongarch: don't initialize kasan if it's disabled

In reply to Baoquan He

Here, kasan is disabled if specified 'kasan=off' in kernel cmdline.

---
 arch/loongarch/mm/kasan_init.c | 3 +++
 1 file changed, 3 insertions(+)
arch/loongarch/mm/kasan_init.c +3 -0
index 0fc02ca06457..047a059544e1 100644
@@ -269,6 +269,9 @@ void __init kasan_init(void)
 	u64 i;
 	phys_addr_t pa_start, pa_end;
 
+	/* If KASAN is disabled via command line, don't initialize it. */
+	if (kasan_arg_disabled)
+		return;
 	/*
 	 * If PGDIR_SIZE is too large for cpu_vabits, KASAN_SHADOW_END will
 	 * overflow UINTPTR_MAX and then looks like a user space address.
Signature · 1 line
2.52.0
author
#9 lore raw

PATCH v5 9/15 arch/powerpc: don't initialize kasan if it's disabled

In reply to Baoquan He

Here, kasan is disabled if specified 'kasan=off' in kernel cmdline.

This includes 32bit, book3s/64 and book3e/64.

---
 arch/powerpc/mm/kasan/init_32.c        | 6 +++++-
 arch/powerpc/mm/kasan/init_book3e_64.c | 4 ++++
 arch/powerpc/mm/kasan/init_book3s_64.c | 4 ++++
 3 files changed, 13 insertions(+), 1 deletion(-)
arch/powerpc/mm/kasan/init_32.c +5 -1
index 1d083597464f..0ea2a636c992 100644
@@ -141,6 +141,10 @@ void __init kasan_init(void)
 	u64 i;
 	int ret;
 
+	/* If KASAN is disabled via command line, don't initialize it. */
+	if (kasan_arg_disabled)
+		return;
+
 	for_each_mem_range(i, &base, &end) {
 		phys_addr_t top = min(end, total_lowmem);
 
@@ -170,7 +174,7 @@ void __init kasan_init(void)
 
 void __init kasan_late_init(void)
 {
-	if (IS_ENABLED(CONFIG_KASAN_VMALLOC))
+	if (IS_ENABLED(CONFIG_KASAN_VMALLOC) && kasan_enabled())
 		kasan_unmap_early_shadow_vmalloc();
 }
 
arch/powerpc/mm/kasan/init_book3e_64.c +4 -0
index 0d3a73d6d4b0..fbe4c9a7e460 100644
@@ -111,6 +111,10 @@ void __init kasan_init(void)
 	u64 i;
 	pte_t zero_pte = pfn_pte(virt_to_pfn(kasan_early_shadow_page), PAGE_KERNEL_RO);
 
+	/* If KASAN is disabled via command line, don't initialize it. */
+	if (kasan_arg_disabled)
+		return;
+
 	for_each_mem_range(i, &start, &end)
 		kasan_init_phys_region(phys_to_virt(start), phys_to_virt(end));
 
arch/powerpc/mm/kasan/init_book3s_64.c +4 -0
index dcafa641804c..f7906f9ef9be 100644
@@ -54,6 +54,10 @@ void __init kasan_init(void)
 	u64 i;
 	pte_t zero_pte = pfn_pte(virt_to_pfn(kasan_early_shadow_page), PAGE_KERNEL);
 
+	/* If KASAN is disabled via command line, don't initialize it. */
+	if (kasan_arg_disabled)
+		return;
+
 	if (!early_radix_enabled()) {
 		pr_warn("KASAN not enabled as it requires radix!");
 		return;
Signature · 1 line
2.52.0
Tested-by on v5 9/15
#10 lore raw

Re: [PATCH v5 09/15] arch/powerpc: don't initialize kasan if it's disabled

Quoted 56 lines · Baoquan He

Here, kasan is disabled if specified 'kasan=off' in kernel cmdline.

This includes 32bit, book3s/64 and book3e/64.

---
  arch/powerpc/mm/kasan/init_32.c        | 6 +++++-
  arch/powerpc/mm/kasan/init_book3e_64.c | 4 ++++
  arch/powerpc/mm/kasan/init_book3s_64.c | 4 ++++
  3 files changed, 13 insertions(+), 1 deletion(-)
arch/powerpc/mm/kasan/init_32.c +5 -1
index 1d083597464f..0ea2a636c992 100644
@@ -141,6 +141,10 @@ void __init kasan_init(void)
  	u64 i;
  	int ret;
 
+	/* If KASAN is disabled via command line, don't initialize it. */
+	if (kasan_arg_disabled)
+		return;
+
  	for_each_mem_range(i, &base, &end) {
  		phys_addr_t top = min(end, total_lowmem);
 
@@ -170,7 +174,7 @@ void __init kasan_init(void)
 
  void __init kasan_late_init(void)
  {
-	if (IS_ENABLED(CONFIG_KASAN_VMALLOC))
+	if (IS_ENABLED(CONFIG_KASAN_VMALLOC) && kasan_enabled())
  		kasan_unmap_early_shadow_vmalloc();
  }
 
arch/powerpc/mm/kasan/init_book3e_64.c +4 -0
index 0d3a73d6d4b0..fbe4c9a7e460 100644
@@ -111,6 +111,10 @@ void __init kasan_init(void)
  	u64 i;
  	pte_t zero_pte = pfn_pte(virt_to_pfn(kasan_early_shadow_page), PAGE_KERNEL_RO);
 
+	/* If KASAN is disabled via command line, don't initialize it. */
+	if (kasan_arg_disabled)
+		return;
+
  	for_each_mem_range(i, &start, &end)
  		kasan_init_phys_region(phys_to_virt(start), phys_to_virt(end));
 
arch/powerpc/mm/kasan/init_book3s_64.c +0 -0
index dcafa641804c..f7906f9ef9be 100644

arch/powerpc/mm/kasan/init_book3s_64.c void __init kasan_init(void) · line 63

Quoted 10 lines
arch/powerpc/mm/kasan/init_book3s_64.c +4 -0
@@ -54,6 +54,10 @@ void __init kasan_init(void)
  	u64 i;
  	pte_t zero_pte = pfn_pte(virt_to_pfn(kasan_early_shadow_page), PAGE_KERNEL);
 
+	/* If KASAN is disabled via command line, don't initialize it. */
+	if (kasan_arg_disabled)
+		return;
+
  	if (!early_radix_enabled()) {
  		pr_warn("KASAN not enabled as it requires radix!");
  		return;

Should we log in the kernel log buffer that KASAN is disabled?

Right now, I don't see the kernel advertising the same.

$ dmesg | grep -i kasan
[    0.000000] Kernel command line: BOOT_IMAGE=(ieee1275//vdevice/v-scsi@30000070/disk@8100000000000000,msdos2)/vmlinuz-7.0.0-rc3+ crashkernel=2G kasan=off

Tested this series on powerpc Pseries platform.
So feel free to add:

- Sourabh Jain

#11 lore raw

Re: [PATCH v5 09/15] arch/powerpc: don't initialize kasan if it's disabled

Le 12/03/2026 à 12:12, Sourabh Jain a écrit :

Quoted 65 lines · Baoquan He
Quoted 50 lines

Here, kasan is disabled if specified 'kasan=off' in kernel cmdline.

This includes 32bit, book3s/64 and book3e/64.

---
  arch/powerpc/mm/kasan/init_32.c        | 6 +++++- arch/powerpc/mm/kasan/init_book3e_64.c | 4 ++++ arch/powerpc/mm/kasan/init_book3s_64.c | 4 ++++

  3 files changed, 13 insertions(+), 1 deletion(-)
arch/powerpc/mm/kasan/init_32.c +5 -1
index 1d083597464f..0ea2a636c992 100644
@@ -141,6 +141,10 @@ void __init kasan_init(void)
       u64 i;
       int ret;
+    /* If KASAN is disabled via command line, don't initialize it. */
+    if (kasan_arg_disabled)
+        return;
+
       for_each_mem_range(i, &base, &end) {
           phys_addr_t top = min(end, total_lowmem);
@@ -170,7 +174,7 @@ void __init kasan_init(void)
   void __init kasan_late_init(void)
   {
-    if (IS_ENABLED(CONFIG_KASAN_VMALLOC))
+    if (IS_ENABLED(CONFIG_KASAN_VMALLOC) && kasan_enabled())
           kasan_unmap_early_shadow_vmalloc();
   }
arch/powerpc/mm/kasan/init_book3e_64.c +4 -0
index 0d3a73d6d4b0..fbe4c9a7e460 100644
@@ -111,6 +111,10 @@ void __init kasan_init(void)
       u64 i;
       pte_t zero_pte = pfn_pte(virt_to_pfn(kasan_early_shadow_page), PAGE_KERNEL_RO);
+    /* If KASAN is disabled via command line, don't initialize it. */
+    if (kasan_arg_disabled)
+        return;
+
       for_each_mem_range(i, &start, &end)
           kasan_init_phys_region(phys_to_virt(start), phys_to_virt(end));
arch/powerpc/mm/kasan/init_book3s_64.c +0 -0
index dcafa641804c..f7906f9ef9be 100644

arch/powerpc/mm/kasan/init_book3s_64.c void __init kasan_init(void) · line 62

Quoted 9 lines
arch/powerpc/mm/kasan/init_book3s_64.c +4 -0
@@ -54,6 +54,10 @@ void __init kasan_init(void)
       u64 i;
       pte_t zero_pte = pfn_pte(virt_to_pfn(kasan_early_shadow_page), PAGE_KERNEL);
+    /* If KASAN is disabled via command line, don't initialize it. */
+    if (kasan_arg_disabled)
+        return;
+
       if (!early_radix_enabled()) {
           pr_warn("KASAN not enabled as it requires radix!");
           return;

Should we log in the kernel log buffer that KASAN is disabled?

Quoted 1 line

Right now, I don't see the kernel advertising the same.

When KASAN is enabled it is advertised with:

	pr_info("KernelAddressSanitizer initialized (generic)\n");

Isn't the absence of that message enough to understand KASAN is not there ?

Quoted 10 lines
$ dmesg | grep -i kasan
[    0.000000] Kernel command line: BOOT_IMAGE=(ieee1275//vdevice/v- scsi@30000070/disk@8100000000000000,msdos2)/vmlinuz-7.0.0-rc3+ crashkernel=2G kasan=off

Tested this series on powerpc Pseries platform.
So feel free to add:

- Sourabh Jain

author
#12 lore raw

Re: [PATCH v5 09/15] arch/powerpc: don't initialize kasan if it's disabled

Quoted 73 lines · Christophe Leroy (CS GROUP)

Le 12/03/2026 à 12:12, Sourabh Jain a écrit :

Quoted 70 lines · Baoquan He
Quoted 54 lines

Here, kasan is disabled if specified 'kasan=off' in kernel cmdline.

This includes 32bit, book3s/64 and book3e/64.

---
  arch/powerpc/mm/kasan/init_32.c        | 6 +++++- arch/powerpc/mm/kasan/init_book3e_64.c | 4 ++++ arch/powerpc/mm/kasan/init_book3s_64.c | 4 ++++

  3 files changed, 13 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/arch/powerpc/mm/kasan/ init_32.c
index 1d083597464f..0ea2a636c992 100644

arch/powerpc/mm/kasan/init_32.c +5 -1
@@ -141,6 +141,10 @@ void __init kasan_init(void)
       u64 i;
       int ret;
+    /* If KASAN is disabled via command line, don't initialize it. */
+    if (kasan_arg_disabled)
+        return;
+
       for_each_mem_range(i, &base, &end) {
           phys_addr_t top = min(end, total_lowmem);
@@ -170,7 +174,7 @@ void __init kasan_init(void)
   void __init kasan_late_init(void)
   {
-    if (IS_ENABLED(CONFIG_KASAN_VMALLOC))
+    if (IS_ENABLED(CONFIG_KASAN_VMALLOC) && kasan_enabled())
           kasan_unmap_early_shadow_vmalloc();
   }
(quoted diff) +0 -0

b/arch/powerpc/mm/ kasan/init_book3e_64.c
index 0d3a73d6d4b0..fbe4c9a7e460 100644

arch/powerpc/mm/kasan/init_book3e_64.c +4 -0
@@ -111,6 +111,10 @@ void __init kasan_init(void)
       u64 i;
       pte_t zero_pte = pfn_pte(virt_to_pfn(kasan_early_shadow_page),
 PAGE_KERNEL_RO);
+    /* If KASAN is disabled via command line, don't initialize it. */
+    if (kasan_arg_disabled)
+        return;
+
       for_each_mem_range(i, &start, &end)
           kasan_init_phys_region(phys_to_virt(start), phys_to_virt(end));
(quoted diff) +0 -0

b/arch/powerpc/mm/ kasan/init_book3s_64.c
index dcafa641804c..f7906f9ef9be 100644

arch/powerpc/mm/kasan/init_book3s_64.c void __init kasan_init(void) · line 63

Quoted 10 lines
arch/powerpc/mm/kasan/init_book3s_64.c +4 -0
@@ -54,6 +54,10 @@ void __init kasan_init(void)
       u64 i;
       pte_t zero_pte = pfn_pte(virt_to_pfn(kasan_early_shadow_page),
 PAGE_KERNEL);
+    /* If KASAN is disabled via command line, don't initialize it. */
+    if (kasan_arg_disabled)
+        return;
+
       if (!early_radix_enabled()) {
           pr_warn("KASAN not enabled as it requires radix!");
           return;

Should we log in the kernel log buffer that KASAN is disabled?

Quoted 7 lines
Quoted 1 line

Right now, I don't see the kernel advertising the same.

When KASAN is enabled it is advertised with:

	pr_info("KernelAddressSanitizer initialized (generic)\n");

Isn't the absence of that message enough to understand KASAN is not there ?

Right, that's the way I took when I tested it.

Quoted 10 lines
Quoted 10 lines

$ dmesg | grep -i kasan
[    0.000000] Kernel command line: BOOT_IMAGE=(ieee1275//vdevice/v-
scsi@30000070/disk@8100000000000000,msdos2)/vmlinuz-7.0.0-rc3+
crashkernel=2G kasan=off

Tested this series on powerpc Pseries platform.
So feel free to add:

Thanks for testing.

#13 lore raw

Re: [PATCH v5 09/15] arch/powerpc: don't initialize kasan if it's disabled

In reply to Christophe Leroy (CS GROUP)
Quoted 68 lines · Christophe Leroy (CS GROUP)

Le 12/03/2026 à 12:12, Sourabh Jain a écrit :

Quoted 65 lines · Baoquan He
Quoted 50 lines

Here, kasan is disabled if specified 'kasan=off' in kernel cmdline.

This includes 32bit, book3s/64 and book3e/64.

---
  arch/powerpc/mm/kasan/init_32.c        | 6 +++++- arch/powerpc/mm/kasan/init_book3e_64.c | 4 ++++ arch/powerpc/mm/kasan/init_book3s_64.c | 4 ++++

  3 files changed, 13 insertions(+), 1 deletion(-)
arch/powerpc/mm/kasan/init_32.c +5 -1
index 1d083597464f..0ea2a636c992 100644
@@ -141,6 +141,10 @@ void __init kasan_init(void)
       u64 i;
       int ret;
+    /* If KASAN is disabled via command line, don't initialize it. */
+    if (kasan_arg_disabled)
+        return;
+
       for_each_mem_range(i, &base, &end) {
           phys_addr_t top = min(end, total_lowmem);
@@ -170,7 +174,7 @@ void __init kasan_init(void)
   void __init kasan_late_init(void)
   {
-    if (IS_ENABLED(CONFIG_KASAN_VMALLOC))
+    if (IS_ENABLED(CONFIG_KASAN_VMALLOC) && kasan_enabled())
           kasan_unmap_early_shadow_vmalloc();
   }
arch/powerpc/mm/kasan/init_book3e_64.c +4 -0
index 0d3a73d6d4b0..fbe4c9a7e460 100644
@@ -111,6 +111,10 @@ void __init kasan_init(void)
       u64 i;
       pte_t zero_pte = pfn_pte(virt_to_pfn(kasan_early_shadow_page), PAGE_KERNEL_RO);
+    /* If KASAN is disabled via command line, don't initialize it. */
+    if (kasan_arg_disabled)
+        return;
+
       for_each_mem_range(i, &start, &end)
           kasan_init_phys_region(phys_to_virt(start), phys_to_virt(end));
arch/powerpc/mm/kasan/init_book3s_64.c +0 -0
index dcafa641804c..f7906f9ef9be 100644

arch/powerpc/mm/kasan/init_book3s_64.c void __init kasan_init(void) · line 62

Quoted 9 lines
arch/powerpc/mm/kasan/init_book3s_64.c +4 -0
@@ -54,6 +54,10 @@ void __init kasan_init(void)
       u64 i;
       pte_t zero_pte = pfn_pte(virt_to_pfn(kasan_early_shadow_page), PAGE_KERNEL);
+    /* If KASAN is disabled via command line, don't initialize it. */
+    if (kasan_arg_disabled)
+        return;
+
       if (!early_radix_enabled()) {
           pr_warn("KASAN not enabled as it requires radix!");
           return;

Should we log in the kernel log buffer that KASAN is disabled?

Quoted 7 lines
Quoted 1 line

Right now, I don't see the kernel advertising the same.

When KASAN is enabled it is advertised with:

    pr_info("KernelAddressSanitizer initialized (generic)\n");

Isn't the absence of that message enough to understand KASAN is not there ?

Yes this should work. Thanks.

- Sourabh Jain

Quoted 12 lines
Quoted 11 lines

$ dmesg | grep -i kasan
[    0.000000] Kernel command line: BOOT_IMAGE=(ieee1275//vdevice/v- scsi@30000070/disk@8100000000000000,msdos2)/vmlinuz-7.0.0-rc3+ crashkernel=2G kasan=off

Tested this series on powerpc Pseries platform.
So feel free to add:

- Sourabh Jain

author
#14 lore raw

PATCH v5 10/15 arch/riscv: don't initialize kasan if it's disabled

In reply to Baoquan He

Here, kasan is disabled if specified 'kasan=off' in kernel cmdline.

---
 arch/riscv/mm/kasan_init.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/riscv/mm/kasan_init.c +4 -0
index c4a2a9e5586e..dc7cc0dcc7eb 100644
@@ -485,6 +485,10 @@ void __init kasan_init(void)
 	phys_addr_t p_start, p_end;
 	u64 i;
 
+	/* If KASAN is disabled via command line, don't initialize it. */
+	if (kasan_arg_disabled)
+		return;
+
 	create_tmp_mapping();
 	csr_write(CSR_SATP, PFN_DOWN(__pa(tmp_pg_dir)) | satp_mode);
 
Signature · 1 line
2.52.0
author
#15 lore raw

PATCH v5 11/15 arch/x86: don't initialize kasan if it's disabled

In reply to Baoquan He

Here, kasan is disabled if specified 'kasan=off' in kernel cmdline.

---
 arch/x86/mm/kasan_init_64.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/mm/kasan_init_64.c +4 -0
index 998b6010d6d3..5ebf2850c77d 100644
@@ -343,6 +343,10 @@ void __init kasan_init(void)
 	unsigned long shadow_cea_begin, shadow_cea_per_cpu_begin, shadow_cea_end;
 	int i;
 
+	/* If KASAN is disabled via command line, don't initialize it. */
+	if (kasan_arg_disabled)
+		return;
+
 	memcpy(early_top_pgt, init_top_pgt, sizeof(early_top_pgt));
 
 	/*
Signature · 1 line
2.52.0
author
#16 lore raw

PATCH v5 12/15 arch/xtensa: don't initialize kasan if it's disabled

In reply to Baoquan He

Here, kasan is disabled if specified 'kasan=off' in kernel cmdline.

And also call jump_label_init() early in setup_arch() so that later kasan_init() can enable static key kasan_flag_enabled. Put jump_label_init() beofre parse_early_param() as other architectures do.

Cc Chris Zankel <[email protected]>
Cc Max Filippov <[email protected]>
---
 arch/xtensa/kernel/setup.c  | 1 +
 arch/xtensa/mm/kasan_init.c | 4 ++++
 2 files changed, 5 insertions(+)
arch/xtensa/kernel/setup.c +1 -0
index f72e280363be..aabeb23f41fa 100644
@@ -352,6 +352,7 @@ void __init setup_arch(char **cmdline_p)
 	mem_reserve(__pa(_SecondaryResetVector_text_start),
 		    __pa(_SecondaryResetVector_text_end));
 #endif
+	jump_label_init();
 	parse_early_param();
 	bootmem_init();
 	kasan_init();
arch/xtensa/mm/kasan_init.c +4 -0
index 0524b9ed5e63..eb367b801218 100644
@@ -70,6 +70,10 @@ void __init kasan_init(void)
 {
 	int i;
 
+	/* If KASAN is disabled via command line, don't initialize it. */
+	if (kasan_arg_disabled)
+		return;
+
 	BUILD_BUG_ON(KASAN_SHADOW_OFFSET != KASAN_SHADOW_START -
 		     (KASAN_START_VADDR >> KASAN_SHADOW_SCALE_SHIFT));
 	BUILD_BUG_ON(VMALLOC_START < KASAN_START_VADDR);
Signature · 1 line
2.52.0
author
#17 lore raw

PATCH v5 13/15 arch/um: don't initialize kasan if it's disabled

In reply to Baoquan He

Here, kasan is disabled if specified 'kasan=off' in kernel cmdline.

And also wrap up the kasan code into CONFIG_KASAN ifdeffery scope.

---
 arch/um/kernel/mem.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/um/kernel/mem.c +4 -1
index 89c8c8b94a79..2bf858ab35b5 100644
@@ -62,8 +62,11 @@ static unsigned long brk_end;
 
 void __init arch_mm_preinit(void)
 {
+#ifdef CONFIG_KASAN
 	/* Safe to call after jump_label_init(). Enables KASAN. */
-	kasan_init_generic();
+	if (!kasan_arg_disabled)
+		kasan_init_generic();
+#endif
 
 	/* clear the zero-page */
 	memset(empty_zero_page, 0, PAGE_SIZE);
Signature · 1 line
2.52.0
author
#18 lore raw

PATCH v5 14/15 mm/kasan: add document into kernel-parameters.txt

In reply to Baoquan He

And also remove the relevant description in dev-tools/kasan.rst which is hw_tags specificially.

---
 Documentation/admin-guide/kernel-parameters.txt | 4 ++++
 Documentation/dev-tools/kasan.rst               | 2 --
 2 files changed, 4 insertions(+), 2 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +4 -0
index cb850e5290c2..e0115fad9e60 100644
@@ -2899,6 +2899,10 @@ Kernel parameters
 	js=		[HW,JOY] Analog joystick
 			See Documentation/input/joydev/joystick.rst.
 
+	kasan=		[KNL] controls whether KASAN is enabled.
+			Format: off | on
+			default: on
+
 	kasan_multi_shot
 			[KNL] Enforce KASAN (Kernel Address Sanitizer) to print
 			report on every invalid memory access. Without this
Documentation/dev-tools/kasan.rst +0 -2
index a034700da7c4..eaae83fcb5e4 100644
@@ -129,8 +129,6 @@ Hardware Tag-Based KASAN mode is intended for use in production as a security
 mitigation. Therefore, it supports additional boot parameters that allow
 disabling KASAN altogether or controlling its features:
 
-- ``kasan=off`` or ``=on`` controls whether KASAN is enabled (default: ``on``).
-
 - ``kasan.mode=sync``, ``=async`` or ``=asymm`` controls whether KASAN
   is configured in synchronous, asynchronous or asymmetric mode of
   execution (default: ``sync``).
Signature · 1 line
2.52.0
#19 lore raw

Re: [PATCH v5 14/15] mm/kasan: add document into kernel-parameters.txt

Hi Baoquan,

Quoted 29 lines · Baoquan He

And also remove the relevant description in dev-tools/kasan.rst which is hw_tags specificially.

---
 Documentation/admin-guide/kernel-parameters.txt | 4 ++++
 Documentation/dev-tools/kasan.rst               | 2 --
 2 files changed, 4 insertions(+), 2 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +4 -0
index cb850e5290c2..e0115fad9e60 100644
@@ -2899,6 +2899,10 @@ Kernel parameters
 	js=		[HW,JOY] Analog joystick
 			See Documentation/input/joydev/joystick.rst.
 
+	kasan=		[KNL] controls whether KASAN is enabled.
+			Format: off | on
+			default: on
+
 	kasan_multi_shot
 			[KNL] Enforce KASAN (Kernel Address Sanitizer) to print
 			report on every invalid memory access. Without this
Documentation/dev-tools/kasan.rst +0 -0
index a034700da7c4..eaae83fcb5e4 100644

Documentation/dev-tools/kasan.rst Hardware Tag-Based KASAN mode is intended for use in production as a security · line 130

Quoted 2 lines
Documentation/dev-tools/kasan.rst +0 -0
@@ -129,8 +129,6 @@ Hardware Tag-Based KASAN mode is intended for use in production as a security
 mitigation. Therefore, it supports additional boot parameters that allow
 disabling KASAN altogether or controlling its features:

The sentence above is now incorrect as well. I would recommend documenting the parameter earlier in the "Boot parameters" section instead of removing it from this document entirely.

Regards,
Samuel

Quoted 6 lines
Documentation/dev-tools/kasan.rst +0 -2
-- ``kasan=off`` or ``=on`` controls whether KASAN is enabled (default: ``on``).
-
 - ``kasan.mode=sync``, ``=async`` or ``=asymm`` controls whether KASAN
   is configured in synchronous, asynchronous or asymmetric mode of
   execution (default: ``sync``).
author
#20 lore raw

Re: [PATCH v5 14/15] mm/kasan: add document into kernel-parameters.txt

Quoted 30 lines · Samuel Holland

Hi Baoquan,

Quoted 27 lines · Baoquan He

And also remove the relevant description in dev-tools/kasan.rst which is hw_tags specificially.

---
 Documentation/admin-guide/kernel-parameters.txt | 4 ++++
 Documentation/dev-tools/kasan.rst               | 2 --
 2 files changed, 4 insertions(+), 2 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +4 -0
index cb850e5290c2..e0115fad9e60 100644
@@ -2899,6 +2899,10 @@ Kernel parameters
 	js=		[HW,JOY] Analog joystick
 			See Documentation/input/joydev/joystick.rst.
 
+	kasan=		[KNL] controls whether KASAN is enabled.
+			Format: off | on
+			default: on
+
 	kasan_multi_shot
 			[KNL] Enforce KASAN (Kernel Address Sanitizer) to print
 			report on every invalid memory access. Without this
Documentation/dev-tools/kasan.rst +0 -1
index a034700da7c4..eaae83fcb5e4 100644
--- a/Documentation/dev-tools/kasan.rst
Quoted 8 lines

Documentation/dev-tools/kasan.rst Hardware Tag-Based KASAN mode is intended for use in production as a security · line 130

Quoted 4 lines

+++ b/Documentation/dev-tools/kasan.rst

Documentation/dev-tools/kasan.rst +0 -0
@@ -129,8 +129,6 @@ Hardware Tag-Based KASAN mode is intended for use in production as a security
 mitigation. Therefore, it supports additional boot parameters that allow
 disabling KASAN altogether or controlling its features:

The sentence above is now incorrect as well. I would recommend documenting the parameter earlier in the "Boot parameters" section instead of removing it from this document entirely.

Good catch and the suggestion is good to me. Thanks.

Is below change OK to you?

From 317be48b9c1bf9d33b8d8fff5e401e3155531d81 Mon Sep 17 00:00:00 2001
From: Baoquan He <[email protected]>
Date: Tue, 17 Mar 2026 11:28:39 +0800
Subject: [PATCH] mm/kasan: adjust documentation
Content-type: text/plain

To reflect the change of kasan=on|off.

---
 Documentation/dev-tools/kasan.rst | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
Documentation/dev-tools/kasan.rst +4 -3
index a034700da7c4..8e65bc04dbcd 100644
@@ -103,6 +103,9 @@ Boot parameters
 KASAN is affected by the generic ``panic_on_warn`` command line parameter.
 When it is enabled, KASAN panics the kernel after printing a bug report.
 
+The generic ``kasan=off`` or ``=on`` command line parameter controls
+whether KASAN is enabled (default: ``on``).
+
 By default, KASAN prints a bug report only for the first invalid memory access.
 With ``kasan_multi_shot``, KASAN prints a report on every invalid access. This
 effectively disables ``panic_on_warn`` for KASAN reports.
@@ -127,9 +130,7 @@ modes below) support altering stack trace collection behavior:
 
 Hardware Tag-Based KASAN mode is intended for use in production as a security
 mitigation. Therefore, it supports additional boot parameters that allow
-disabling KASAN altogether or controlling its features:
-
-- ``kasan=off`` or ``=on`` controls whether KASAN is enabled (default: ``on``).
+controlling its features:
 
 - ``kasan.mode=sync``, ``=async`` or ``=asymm`` controls whether KASAN
   is configured in synchronous, asynchronous or asymmetric mode of
Signature · 1 line
2.52.0
Reviewed-by
#21 lore raw

Re: [PATCH v5 14/15] mm/kasan: add document into kernel-parameters.txt

Quoted 42 lines · Baoquan He
Quoted 30 lines · Samuel Holland

Hi Baoquan,

Quoted 27 lines · Baoquan He

And also remove the relevant description in dev-tools/kasan.rst which is hw_tags specificially.

---
 Documentation/admin-guide/kernel-parameters.txt | 4 ++++
 Documentation/dev-tools/kasan.rst               | 2 --
 2 files changed, 4 insertions(+), 2 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +4 -0
index cb850e5290c2..e0115fad9e60 100644
@@ -2899,6 +2899,10 @@ Kernel parameters
 	js=		[HW,JOY] Analog joystick
 			See Documentation/input/joydev/joystick.rst.
 
+	kasan=		[KNL] controls whether KASAN is enabled.
+			Format: off | on
+			default: on
+
 	kasan_multi_shot
 			[KNL] Enforce KASAN (Kernel Address Sanitizer) to print
 			report on every invalid memory access. Without this
Documentation/dev-tools/kasan.rst +0 -1
index a034700da7c4..eaae83fcb5e4 100644
--- a/Documentation/dev-tools/kasan.rst
Quoted 8 lines

Documentation/dev-tools/kasan.rst Hardware Tag-Based KASAN mode is intended for use in production as a security · line 130

Quoted 4 lines

+++ b/Documentation/dev-tools/kasan.rst

Documentation/dev-tools/kasan.rst +0 -0
@@ -129,8 +129,6 @@ Hardware Tag-Based KASAN mode is intended for use in production as a security
 mitigation. Therefore, it supports additional boot parameters that allow
 disabling KASAN altogether or controlling its features:

The sentence above is now incorrect as well. I would recommend documenting the parameter earlier in the "Boot parameters" section instead of removing it from this document entirely.

Good catch and the suggestion is good to me. Thanks.

Quoted 7 lines

Is below change OK to you?

From 317be48b9c1bf9d33b8d8fff5e401e3155531d81 Mon Sep 17 00:00:00 2001
From: Baoquan He <[email protected]>
Date: Tue, 17 Mar 2026 11:28:39 +0800
Subject: [PATCH] mm/kasan: adjust documentation

I'd suggest something a bit more specific, maybe like "mm/kasan: document kasan= for all modes".

Quoted 14 lines

Content-type: text/plain

To reflect the change of kasan=on|off.

---
 Documentation/dev-tools/kasan.rst | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
Documentation/dev-tools/kasan.rst +0 -0
index a034700da7c4..8e65bc04dbcd 100644

Documentation/dev-tools/kasan.rst Boot parameters · line 108

Quoted 6 lines
Documentation/dev-tools/kasan.rst +3 -0
@@ -103,6 +103,9 @@ Boot parameters
 KASAN is affected by the generic ``panic_on_warn`` command line parameter.
 When it is enabled, KASAN panics the kernel after printing a bug report.
 
+The generic ``kasan=off`` or ``=on`` command line parameter controls
+whether KASAN is enabled (default: ``on``).
+

This is in the middle of paragraphs describing the fault reporting options. I'd suggest to move it to the beginning of the section.

With those fixes, you can add

Quoted 14 lines
Documentation/dev-tools/kasan.rst +1 -3
 By default, KASAN prints a bug report only for the first invalid memory access.
 With ``kasan_multi_shot``, KASAN prints a report on every invalid access. This
 effectively disables ``panic_on_warn`` for KASAN reports.
@@ -127,9 +130,7 @@ modes below) support altering stack trace collection behavior:
 
 Hardware Tag-Based KASAN mode is intended for use in production as a security
 mitigation. Therefore, it supports additional boot parameters that allow
-disabling KASAN altogether or controlling its features:
-
-- ``kasan=off`` or ``=on`` controls whether KASAN is enabled (default: ``on``).
+controlling its features:
 
 - ``kasan.mode=sync``, ``=async`` or ``=asymm`` controls whether KASAN
   is configured in synchronous, asynchronous or asymmetric mode of
author
#22 lore raw

PATCH v5 15/15 mm/kasan: clean up unneeded ARCH_DEFER_KASAN and kasan_arch_is_ready

In reply to Baoquan He

Since commit 1e338f4d99e6 ("kasan: introduce ARCH_DEFER_KASAN and unify static key across modes"), kasan_arch_is_ready() has been dead code. And up to now, ARCH_DEFER_KASAN is useless too because of code change for 'kasan=on|off'.

Here clean them up.

---
 arch/loongarch/Kconfig |  1 -
 arch/powerpc/Kconfig   |  1 -
 arch/um/Kconfig        |  1 -
 lib/Kconfig.kasan      | 12 ------------
 mm/kasan/kasan.h       |  6 ------
 5 files changed, 21 deletions(-)
arch/loongarch/Kconfig +0 -1
index d211c6572b0a..4b7802d02911 100644
@@ -9,7 +9,6 @@ config LOONGARCH
 	select ACPI_PPTT if ACPI
 	select ACPI_SYSTEM_POWER_STATES_SUPPORT	if ACPI
 	select ARCH_BINFMT_ELF_STATE
-	select ARCH_NEEDS_DEFER_KASAN
 	select ARCH_DISABLE_KASAN_INLINE
 	select ARCH_ENABLE_MEMORY_HOTPLUG
 	select ARCH_ENABLE_MEMORY_HOTREMOVE
arch/powerpc/Kconfig +0 -1
index ad7a2fe63a2a..b51fbc25bdc9 100644
@@ -122,7 +122,6 @@ config PPC
 	# Please keep this list sorted alphabetically.
 	#
 	select ARCH_32BIT_OFF_T if PPC32
-	select ARCH_NEEDS_DEFER_KASAN		if PPC_RADIX_MMU
 	select ARCH_DISABLE_KASAN_INLINE	if PPC_RADIX_MMU
 	select ARCH_DMA_DEFAULT_COHERENT	if !NOT_COHERENT_CACHE
 	select ARCH_ENABLE_MEMORY_HOTPLUG
arch/um/Kconfig +0 -1
index 098cda44db22..fd0bedd2c696 100644
@@ -6,7 +6,6 @@ config UML
 	bool
 	default y
 	select ARCH_DISABLE_KASAN_INLINE if STATIC_LINK
-	select ARCH_NEEDS_DEFER_KASAN if STATIC_LINK
 	select ARCH_WANTS_DYNAMIC_TASK_STRUCT
 	select ARCH_HAS_CACHE_LINE_SIZE
 	select ARCH_HAS_CPU_FINALIZE_INIT
lib/Kconfig.kasan +0 -12
index a4bb610a7a6f..f82889a830fa 100644
@@ -19,18 +19,6 @@ config ARCH_DISABLE_KASAN_INLINE
 	  Disables both inline and stack instrumentation. Selected by
 	  architectures that do not support these instrumentation types.
 
-config ARCH_NEEDS_DEFER_KASAN
-	bool
-
-config ARCH_DEFER_KASAN
-	def_bool y
-	depends on KASAN && ARCH_NEEDS_DEFER_KASAN
-	help
-	  Architectures should select this if they need to defer KASAN
-	  initialization until shadow memory is properly set up. This
-	  enables runtime control via static keys. Otherwise, KASAN uses
-	  compile-time constants for better performance.
-
 config CC_HAS_KASAN_GENERIC
 	def_bool $(cc-option, -fsanitize=kernel-address)
 
mm/kasan/kasan.h +0 -6
index fc9169a54766..f08f7f75c285 100644
@@ -552,12 +552,6 @@ static inline void kasan_poison_last_granule(const void *address, size_t size) {
 
 #endif /* CONFIG_KASAN_GENERIC */
 
-#ifndef kasan_arch_is_ready
-static inline bool kasan_arch_is_ready(void)	{ return true; }
-#elif !defined(CONFIG_KASAN_GENERIC) || !defined(CONFIG_KASAN_OUTLINE)
-#error kasan_arch_is_ready only works in KASAN generic outline mode!
-#endif
-
 #if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST)
 
 void kasan_kunit_test_suite_start(void);
Signature · 1 line
2.52.0