[PATCH v4 12/12] mm/kasan: make kasan=on|off take effect for all three modes

Baoquan He posted 12 patches 2 months, 1 week ago
[PATCH v4 12/12] mm/kasan: make kasan=on|off take effect for all three modes
Posted by Baoquan He 2 months, 1 week ago
Now everything is ready, set kasan=off can disable kasan for all
three modes.

Signed-off-by: Baoquan He <bhe@redhat.com>
---
 include/linux/kasan-enabled.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/kasan-enabled.h b/include/linux/kasan-enabled.h
index b05ec6329fbe..b33c92cc6bd8 100644
--- a/include/linux/kasan-enabled.h
+++ b/include/linux/kasan-enabled.h
@@ -4,6 +4,7 @@
 
 #include <linux/static_key.h>
 
+#ifdef CONFIG_KASAN
 extern bool kasan_arg_disabled;
 
 /*
@@ -12,7 +13,6 @@ extern bool kasan_arg_disabled;
  */
 DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled);
 
-#if defined(CONFIG_ARCH_DEFER_KASAN) || defined(CONFIG_KASAN_HW_TAGS)
 /*
  * Runtime control for shadow memory initialization or HW_TAGS mode.
  * Uses static key for architectures that need deferred KASAN or HW_TAGS.
@@ -30,7 +30,7 @@ static inline void kasan_enable(void)
 /* 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) {}
-- 
2.41.0
Re: [PATCH v4 12/12] mm/kasan: make kasan=on|off take effect for all three modes
Posted by Andrey Konovalov 2 months ago
On Fri, Nov 28, 2025 at 4:35 AM 'Baoquan He' via kasan-dev
<kasan-dev@googlegroups.com> wrote:
>
> Now everything is ready, set kasan=off can disable kasan for all
> three modes.
>
> Signed-off-by: Baoquan He <bhe@redhat.com>
> ---
>  include/linux/kasan-enabled.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/kasan-enabled.h b/include/linux/kasan-enabled.h
> index b05ec6329fbe..b33c92cc6bd8 100644
> --- a/include/linux/kasan-enabled.h
> +++ b/include/linux/kasan-enabled.h
> @@ -4,6 +4,7 @@
>
>  #include <linux/static_key.h>
>
> +#ifdef CONFIG_KASAN
>  extern bool kasan_arg_disabled;
>
>  /*
> @@ -12,7 +13,6 @@ extern bool kasan_arg_disabled;
>   */
>  DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled);
>
> -#if defined(CONFIG_ARCH_DEFER_KASAN) || defined(CONFIG_KASAN_HW_TAGS)

So do we still need CONFIG_ARCH_DEFER_KASAN? If not, it needs to be removed.

But if we only allow kasan=off for x86/arm64 after all (see my comment
to the cover letter), I believe we need to keep it.


>  /*
>   * Runtime control for shadow memory initialization or HW_TAGS mode.
>   * Uses static key for architectures that need deferred KASAN or HW_TAGS.
> @@ -30,7 +30,7 @@ static inline void kasan_enable(void)
>  /* 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) {}
> --
> 2.41.0
>
> --
> You received this message because you are subscribed to the Google Groups "kasan-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/kasan-dev/20251128033320.1349620-13-bhe%40redhat.com.
Re: [PATCH v4 12/12] mm/kasan: make kasan=on|off take effect for all three modes
Posted by Alexander Potapenko 2 months, 1 week ago
> @@ -30,7 +30,7 @@ static inline void kasan_enable(void)
>  /* For architectures that can enable KASAN early, use compile-time check. */
I think the behavior of kasan_enabled() is inconsistent with this comment now.
>  static __always_inline bool kasan_enabled(void)
>  {
> -       return IS_ENABLED(CONFIG_KASAN);
> +       return false;
>  }
Re: [PATCH v4 12/12] mm/kasan: make kasan=on|off take effect for all three modes
Posted by Baoquan He 2 months, 1 week ago
On 11/28/25 at 04:50pm, Alexander Potapenko wrote:
> > @@ -30,7 +30,7 @@ static inline void kasan_enable(void)
> >  /* For architectures that can enable KASAN early, use compile-time check. */
> I think the behavior of kasan_enabled() is inconsistent with this comment now.

You are right, that line should be removed. Thanks for careful checking.

> >  static __always_inline bool kasan_enabled(void)
> >  {
> > -       return IS_ENABLED(CONFIG_KASAN);
> > +       return false;
> >  }
>