[PATCH v3 03/12] mm/kasan/sw_tags: don't initialize kasan if it's disabled

Baoquan He
2025-08-20T05:35:49Z

And also add code to enable kasan_flag_enabled, this is for later
usage.

Signed-off-by: Baoquan He <bhe@redhat.com>
---
mm/kasan/sw_tags.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c
index 01f19bc4a326..dd963ba4d143 100644
--- a/mm/kasan/sw_tags.c
+++ b/mm/kasan/sw_tags.c
@@ -40,11 +40,17 @@ void __init kasan_init_sw_tags(void)
{
int cpu;

+ if (kasan_arg_disabled)
+ return;
+
for_each_possible_cpu(cpu)
per_cpu(prng_state, cpu) = (u32)get_cycles();

kasan_init_tags();

+ /* KASAN is now initialized, enable it. */
+ static_branch_enable(&kasan_flag_enabled);
+
pr_info("KernelAddressSanitizer initialized (sw-tags, stacktrace=%s)\n",
str_on_off(kasan_stack_collection_enabled()));
}
--
2.41.0