From: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
To: hca@linux.ibm.com, christophe.leroy@csgroup.eu,
andreyknvl@gmail.com, agordeev@linux.ibm.com,
akpm@linux-foundation.org
Cc: ryabinin.a.a@gmail.com, glider@google.com, dvyukov@google.com,
kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org,
loongarch@lists.linux.dev, linuxppc-dev@lists.ozlabs.org,
linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org,
linux-um@lists.infradead.org, linux-mm@kvack.org,
snovitoll@gmail.com
Subject: [PATCH v3 03/12] kasan/powerpc: select ARCH_DEFER_KASAN and call kasan_init_generic
Date: Thu, 17 Jul 2025 19:27:23 +0500 [thread overview]
Message-ID: <20250717142732.292822-4-snovitoll@gmail.com> (raw)
In-Reply-To: <20250717142732.292822-1-snovitoll@gmail.com>
PowerPC with radix MMU is the primary architecture that needs deferred
KASAN initialization, as it requires complex shadow memory setup before
KASAN can be safely enabled.
Select ARCH_DEFER_KASAN for PPC_RADIX_MMU to enable the static key
mechanism for runtime KASAN control. Other PowerPC configurations
(like book3e and 32-bit) can enable KASAN early and will use
compile-time constants instead.
Also call kasan_init_generic() which handles Generic KASAN initialization.
For PowerPC radix MMU (which selects ARCH_DEFER_KASAN), this enables
the static key. For other PowerPC variants, kasan_enable() is a no-op
and kasan_enabled() returns IS_ENABLED(CONFIG_KASAN).
Remove the PowerPC-specific static key and kasan_arch_is_ready()
implementation in favor of the unified interface.
This ensures that:
- PowerPC radix gets the runtime control it needs
- Other PowerPC variants get optimal compile-time behavior
- No unnecessary overhead is added where not needed
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217049
Fixes: 55d77bae7342 ("kasan: fix Oops due to missing calls to kasan_arch_is_ready()")
Signed-off-by: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
---
Changes in v3:
- Added CONFIG_ARCH_DEFER_KASAN selection for PPC_RADIX_MMU only
- Kept ARCH_DISABLE_KASAN_INLINE selection since it's needed independently
---
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 +-----
5 files changed, 4 insertions(+), 19 deletions(-)
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index c3e0cc83f12..e5a6aae6a77 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -123,6 +123,7 @@ config PPC
#
select ARCH_32BIT_OFF_T if PPC32
select ARCH_DISABLE_KASAN_INLINE if PPC_RADIX_MMU
+ select ARCH_DEFER_KASAN if PPC_RADIX_MMU
select ARCH_DMA_DEFAULT_COHERENT if !NOT_COHERENT_CACHE
select ARCH_ENABLE_MEMORY_HOTPLUG
select ARCH_ENABLE_MEMORY_HOTREMOVE
diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h
index b5bbb94c51f..957a57c1db5 100644
--- a/arch/powerpc/include/asm/kasan.h
+++ b/arch/powerpc/include/asm/kasan.h
@@ -53,18 +53,6 @@
#endif
#ifdef CONFIG_KASAN
-#ifdef CONFIG_PPC_BOOK3S_64
-DECLARE_STATIC_KEY_FALSE(powerpc_kasan_enabled_key);
-
-static __always_inline bool kasan_arch_is_ready(void)
-{
- if (static_branch_likely(&powerpc_kasan_enabled_key))
- return true;
- return false;
-}
-
-#define kasan_arch_is_ready kasan_arch_is_ready
-#endif
void kasan_early_init(void);
void kasan_mmu_init(void);
diff --git a/arch/powerpc/mm/kasan/init_32.c b/arch/powerpc/mm/kasan/init_32.c
index 03666d790a5..1d083597464 100644
--- a/arch/powerpc/mm/kasan/init_32.c
+++ b/arch/powerpc/mm/kasan/init_32.c
@@ -165,7 +165,7 @@ void __init kasan_init(void)
/* At this point kasan is fully initialized. Enable error messages */
init_task.kasan_depth = 0;
- pr_info("KASAN init done\n");
+ kasan_init_generic();
}
void __init kasan_late_init(void)
diff --git a/arch/powerpc/mm/kasan/init_book3e_64.c b/arch/powerpc/mm/kasan/init_book3e_64.c
index 60c78aac0f6..0d3a73d6d4b 100644
--- a/arch/powerpc/mm/kasan/init_book3e_64.c
+++ b/arch/powerpc/mm/kasan/init_book3e_64.c
@@ -127,7 +127,7 @@ void __init kasan_init(void)
/* Enable error messages */
init_task.kasan_depth = 0;
- pr_info("KASAN init done\n");
+ kasan_init_generic();
}
void __init kasan_late_init(void) { }
diff --git a/arch/powerpc/mm/kasan/init_book3s_64.c b/arch/powerpc/mm/kasan/init_book3s_64.c
index 7d959544c07..dcafa641804 100644
--- a/arch/powerpc/mm/kasan/init_book3s_64.c
+++ b/arch/powerpc/mm/kasan/init_book3s_64.c
@@ -19,8 +19,6 @@
#include <linux/memblock.h>
#include <asm/pgalloc.h>
-DEFINE_STATIC_KEY_FALSE(powerpc_kasan_enabled_key);
-
static void __init kasan_init_phys_region(void *start, void *end)
{
unsigned long k_start, k_end, k_cur;
@@ -92,11 +90,9 @@ void __init kasan_init(void)
*/
memset(kasan_early_shadow_page, 0, PAGE_SIZE);
- static_branch_inc(&powerpc_kasan_enabled_key);
-
/* Enable error messages */
init_task.kasan_depth = 0;
- pr_info("KASAN init done\n");
+ kasan_init_generic();
}
void __init kasan_early_init(void) { }
--
2.34.1
next prev parent reply other threads:[~2025-07-17 15:03 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-17 14:27 [PATCH v3 00/12] kasan: unify kasan_arch_is_ready() and remove arch-specific implementations Sabyrzhan Tasbolatov
2025-07-17 14:27 ` [PATCH v3 01/12] lib/kasan: introduce CONFIG_ARCH_DEFER_KASAN option Sabyrzhan Tasbolatov
2025-07-17 22:10 ` Andrew Morton
2025-07-18 8:05 ` Sabyrzhan Tasbolatov
2025-07-21 23:18 ` Andrey Ryabinin
2025-07-22 0:35 ` Andrew Morton
2025-07-18 12:38 ` Alexander Gordeev
2025-07-21 22:59 ` Andrey Ryabinin
2025-07-17 14:27 ` [PATCH v3 02/12] kasan: unify static kasan_flag_enabled across modes Sabyrzhan Tasbolatov
2025-07-21 22:59 ` Andrey Ryabinin
2025-07-17 14:27 ` Sabyrzhan Tasbolatov [this message]
2025-07-17 14:27 ` [PATCH v3 04/12] kasan/arm64: call kasan_init_generic in kasan_init Sabyrzhan Tasbolatov
2025-07-17 14:27 ` [PATCH v3 05/12] kasan/arm: " Sabyrzhan Tasbolatov
2025-07-17 14:27 ` [PATCH v3 06/12] kasan/xtensa: " Sabyrzhan Tasbolatov
2025-07-17 14:27 ` [PATCH v3 07/12] kasan/loongarch: select ARCH_DEFER_KASAN and call kasan_init_generic Sabyrzhan Tasbolatov
2025-07-21 22:59 ` Andrey Ryabinin
2025-07-22 14:09 ` Sabyrzhan Tasbolatov
2025-07-17 14:27 ` [PATCH v3 08/12] kasan/um: " Sabyrzhan Tasbolatov
2025-07-21 23:00 ` Andrey Ryabinin
2025-07-22 14:17 ` Sabyrzhan Tasbolatov
2025-07-23 17:10 ` Andrey Ryabinin
2025-07-17 14:27 ` [PATCH v3 09/12] kasan/x86: call kasan_init_generic in kasan_init Sabyrzhan Tasbolatov
2025-07-17 14:27 ` [PATCH v3 10/12] kasan/s390: " Sabyrzhan Tasbolatov
2025-07-18 12:38 ` Alexander Gordeev
2025-07-17 14:27 ` [PATCH v3 11/12] kasan/riscv: " Sabyrzhan Tasbolatov
2025-07-17 14:27 ` [PATCH v3 12/12] kasan: add shadow checks to wrappers and rename kasan_arch_is_ready Sabyrzhan Tasbolatov
2025-07-21 22:59 ` [PATCH v3 00/12] kasan: unify kasan_arch_is_ready() and remove arch-specific implementations Andrey Ryabinin
2025-07-22 18:21 ` Sabyrzhan Tasbolatov
2025-07-23 17:32 ` Andrey Ryabinin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250717142732.292822-4-snovitoll@gmail.com \
--to=snovitoll@gmail.com \
--cc=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=christophe.leroy@csgroup.eu \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=hca@linux.ibm.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=loongarch@lists.linux.dev \
--cc=ryabinin.a.a@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).