* [PATCH v3 04/12] arch/arm: don't initialize kasan if it's disabled
[not found] <20250820053459.164825-1-bhe@redhat.com>
@ 2025-08-20 5:34 ` Baoquan He
2025-08-20 5:34 ` [PATCH v3 05/12] arch/arm64: " Baoquan He
1 sibling, 0 replies; 2+ messages in thread
From: Baoquan He @ 2025-08-20 5:34 UTC (permalink / raw)
To: linux-mm
Cc: ryabinin.a.a, andreyknvl, glider, dvyukov, vincenzo.frascino,
akpm, kasan-dev, linux-kernel, kexec, sj, lorenzo.stoakes, elver,
snovitoll, christophe.leroy, Baoquan He, linux-arm-kernel
And also add code to enable kasan_flag_enabled, this is for later
usage.
Here 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.
Signed-off-by: Baoquan He <bhe@redhat.com>
Cc: linux-arm-kernel@lists.infradead.org
---
arch/arm/kernel/setup.c | 6 ++++++
arch/arm/mm/kasan_init.c | 6 ++++++
2 files changed, 12 insertions(+)
diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index 0bfd66c7ada0..453a47a4c715 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -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
diff --git a/arch/arm/mm/kasan_init.c b/arch/arm/mm/kasan_init.c
index 111d4f703136..c764e1b9c9c5 100644
--- a/arch/arm/mm/kasan_init.c
+++ b/arch/arm/mm/kasan_init.c
@@ -212,6 +212,8 @@ void __init kasan_init(void)
phys_addr_t pa_start, pa_end;
u64 i;
+ if (kasan_arg_disabled)
+ return;
/*
* We are going to perform proper setup of shadow memory.
*
@@ -300,6 +302,10 @@ void __init kasan_init(void)
local_flush_tlb_all();
memset(kasan_early_shadow_page, 0, PAGE_SIZE);
+
+ /* KASAN is now initialized, enable it. */
+ static_branch_enable(&kasan_flag_enabled);
+
pr_info("Kernel address sanitizer initialized\n");
init_task.kasan_depth = 0;
}
--
2.41.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH v3 05/12] arch/arm64: don't initialize kasan if it's disabled
[not found] <20250820053459.164825-1-bhe@redhat.com>
2025-08-20 5:34 ` [PATCH v3 04/12] arch/arm: don't initialize kasan if it's disabled Baoquan He
@ 2025-08-20 5:34 ` Baoquan He
1 sibling, 0 replies; 2+ messages in thread
From: Baoquan He @ 2025-08-20 5:34 UTC (permalink / raw)
To: linux-mm
Cc: ryabinin.a.a, andreyknvl, glider, dvyukov, vincenzo.frascino,
akpm, kasan-dev, linux-kernel, kexec, sj, lorenzo.stoakes, elver,
snovitoll, christophe.leroy, Baoquan He, linux-arm-kernel
And also add code to enable kasan_flag_enabled, this is for later
usage.
And also need skip kasan_populate_early_vm_area_shadow() if kasan
is disabled.
Signed-off-by: Baoquan He <bhe@redhat.com>
Cc: linux-arm-kernel@lists.infradead.org
---
arch/arm64/mm/kasan_init.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c
index d541ce45daeb..0e4ffe3f5d0e 100644
--- a/arch/arm64/mm/kasan_init.c
+++ b/arch/arm64/mm/kasan_init.c
@@ -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,9 @@ void __init kasan_populate_early_vm_area_shadow(void *start, unsigned long size)
void __init kasan_init(void)
{
+ if (kasan_arg_disabled)
+ return;
+
kasan_init_shadow();
kasan_init_depth();
#if defined(CONFIG_KASAN_GENERIC)
@@ -405,6 +411,7 @@ void __init kasan_init(void)
* Software and Hardware Tag-Based modes still require
* kasan_init_sw_tags() and kasan_init_hw_tags() correspondingly.
*/
+ static_branch_enable(&kasan_flag_enabled);
pr_info("KernelAddressSanitizer initialized (generic)\n");
#endif
}
--
2.41.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-08-20 5:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20250820053459.164825-1-bhe@redhat.com>
2025-08-20 5:34 ` [PATCH v3 04/12] arch/arm: don't initialize kasan if it's disabled Baoquan He
2025-08-20 5:34 ` [PATCH v3 05/12] arch/arm64: " Baoquan He
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).