linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
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 08/12] kasan/um: select ARCH_DEFER_KASAN and call kasan_init_generic
Date: Thu, 17 Jul 2025 19:27:28 +0500	[thread overview]
Message-ID: <20250717142732.292822-9-snovitoll@gmail.com> (raw)
In-Reply-To: <20250717142732.292822-1-snovitoll@gmail.com>

UserMode Linux needs deferred KASAN initialization as it has a custom
kasan_arch_is_ready() implementation that tracks shadow memory readiness
via the kasan_um_is_ready flag.

Select ARCH_DEFER_KASAN to enable the unified static key mechanism
for runtime KASAN control. Call kasan_init_generic() which handles
Generic KASAN initialization and enables the static key.

Delete the key kasan_um_is_ready in favor of the unified kasan_enabled()
interface.

Note that kasan_init_generic has __init macro, which is called by
kasan_init() which is not marked with __init in arch/um code.

Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217049
Signed-off-by: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
---
Changes in v3:
- Added CONFIG_ARCH_DEFER_KASAN selection for proper runtime control
---
 arch/um/Kconfig             | 1 +
 arch/um/include/asm/kasan.h | 5 -----
 arch/um/kernel/mem.c        | 4 ++--
 3 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/arch/um/Kconfig b/arch/um/Kconfig
index f08e8a7fac9..fd6d78bba52 100644
--- a/arch/um/Kconfig
+++ b/arch/um/Kconfig
@@ -8,6 +8,7 @@ config UML
 	select ARCH_WANTS_DYNAMIC_TASK_STRUCT
 	select ARCH_HAS_CPU_FINALIZE_INIT
 	select ARCH_HAS_FORTIFY_SOURCE
+	select ARCH_DEFER_KASAN
 	select ARCH_HAS_GCOV_PROFILE_ALL
 	select ARCH_HAS_KCOV
 	select ARCH_HAS_STRNCPY_FROM_USER
diff --git a/arch/um/include/asm/kasan.h b/arch/um/include/asm/kasan.h
index f97bb1f7b85..81bcdc0f962 100644
--- a/arch/um/include/asm/kasan.h
+++ b/arch/um/include/asm/kasan.h
@@ -24,11 +24,6 @@
 
 #ifdef CONFIG_KASAN
 void kasan_init(void);
-extern int kasan_um_is_ready;
-
-#ifdef CONFIG_STATIC_LINK
-#define kasan_arch_is_ready() (kasan_um_is_ready)
-#endif
 #else
 static inline void kasan_init(void) { }
 #endif /* CONFIG_KASAN */
diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c
index 76bec7de81b..058cb70e330 100644
--- a/arch/um/kernel/mem.c
+++ b/arch/um/kernel/mem.c
@@ -21,9 +21,9 @@
 #include <os.h>
 #include <um_malloc.h>
 #include <linux/sched/task.h>
+#include <linux/kasan.h>
 
 #ifdef CONFIG_KASAN
-int kasan_um_is_ready;
 void kasan_init(void)
 {
 	/*
@@ -32,7 +32,7 @@ void kasan_init(void)
 	 */
 	kasan_map_memory((void *)KASAN_SHADOW_START, KASAN_SHADOW_SIZE);
 	init_task.kasan_depth = 0;
-	kasan_um_is_ready = true;
+	kasan_init_generic();
 }
 
 static void (*kasan_init_ptr)(void)
-- 
2.34.1



  parent reply	other threads:[~2025-07-17 14:28 UTC|newest]

Thread overview: 32+ 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 ` [PATCH v3 03/12] kasan/powerpc: select ARCH_DEFER_KASAN and call kasan_init_generic Sabyrzhan Tasbolatov
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 ` Sabyrzhan Tasbolatov [this message]
2025-07-21 23:00   ` [PATCH v3 08/12] kasan/um: " 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
2025-08-03 19:27       ` Sabyrzhan Tasbolatov
2025-08-04 12:04         ` Christophe Leroy
2025-08-04 13:21           ` Sabyrzhan Tasbolatov

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-9-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