From: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
To: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: ryabinin.a.a@gmail.com, bhe@redhat.com, hca@linux.ibm.com,
andreyknvl@gmail.com, akpm@linux-foundation.org,
zhangqing@loongson.cn, chenhuacai@loongson.cn,
davidgow@google.co, glider@google.com, dvyukov@google.com,
alex@ghiti.fr, agordeev@linux.ibm.com,
vincenzo.frascino@arm.com, elver@google.com,
kasan-dev@googlegroups.com,
linux-arm-kernel@lists.infradead.org,
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
Subject: Re: [PATCH v5 1/2] kasan: introduce ARCH_DEFER_KASAN and unify static key across modes
Date: Sun, 10 Aug 2025 12:20:31 +0500 [thread overview]
Message-ID: <CACzwLxjr+Z+xUj-936rcWDSqEwfUP7bRB1xcqZQKGE7ux-gEXQ@mail.gmail.com> (raw)
In-Reply-To: <af677847-e625-43d7-8750-b2ce4ba9626c@csgroup.eu>
On Fri, Aug 8, 2025 at 10:03 PM Christophe Leroy
<christophe.leroy@csgroup.eu> wrote:
>
>
>
> Le 08/08/2025 à 17:33, Sabyrzhan Tasbolatov a écrit :
> > On Fri, Aug 8, 2025 at 10:03 AM Christophe Leroy
> > <christophe.leroy@csgroup.eu> wrote:
> >>
> >>
> >>
> >> Le 07/08/2025 à 21:40, Sabyrzhan Tasbolatov a écrit :
> >>> Introduce CONFIG_ARCH_DEFER_KASAN to identify architectures [1] that need
> >>> to defer KASAN initialization until shadow memory is properly set up,
> >>> and unify the static key infrastructure across all KASAN modes.
> >>
> >> That probably desserves more details, maybe copy in informations from
> >> the top of cover letter.
> >>
> >> I think there should also be some exeplanations about
> >> kasan_arch_is_ready() becoming kasan_enabled(), and also why
> >> kasan_arch_is_ready() completely disappear from mm/kasan/common.c
> >> without being replaced by kasan_enabled().
> >>
> >>>
> >>> [1] PowerPC, UML, LoongArch selects ARCH_DEFER_KASAN.
> >>>
> >>> Closes: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.kernel.org%2Fshow_bug.cgi%3Fid%3D217049&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Cfe4f5a759ad6452b047408ddd691024a%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638902640503259176%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=UM4uvQihJdeWwcC6DIiJXbn4wGsrijjRcHc55uCMErI%3D&reserved=0
> >>> Signed-off-by: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
> >>> ---
> >>> Changes in v5:
> >>> - Unified patches where arch (powerpc, UML, loongarch) selects
> >>> ARCH_DEFER_KASAN in the first patch not to break
> >>> bisectability
> >>> - Removed kasan_arch_is_ready completely as there is no user
> >>> - Removed __wrappers in v4, left only those where it's necessary
> >>> due to different implementations
> >>>
> >>> Changes in v4:
> >>> - Fixed HW_TAGS static key functionality (was broken in v3)
> >>> - Merged configuration and implementation for atomicity
> >>> ---
> >>> arch/loongarch/Kconfig | 1 +
> >>> arch/loongarch/include/asm/kasan.h | 7 ------
> >>> arch/loongarch/mm/kasan_init.c | 8 +++----
> >>> 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 +----
> >>> arch/um/Kconfig | 1 +
> >>> arch/um/include/asm/kasan.h | 5 ++--
> >>> arch/um/kernel/mem.c | 10 ++++++--
> >>> include/linux/kasan-enabled.h | 32 ++++++++++++++++++--------
> >>> include/linux/kasan.h | 6 +++++
> >>> lib/Kconfig.kasan | 8 +++++++
> >>> mm/kasan/common.c | 17 ++++++++++----
> >>> mm/kasan/generic.c | 19 +++++++++++----
> >>> mm/kasan/hw_tags.c | 9 +-------
> >>> mm/kasan/kasan.h | 8 ++++++-
> >>> mm/kasan/shadow.c | 12 +++++-----
> >>> mm/kasan/sw_tags.c | 1 +
> >>> mm/kasan/tags.c | 2 +-
> >>> 21 files changed, 100 insertions(+), 69 deletions(-)
> >>>
> >>> diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
> >>> index f0abc38c40a..cd64b2bc12d 100644
> >>> --- a/arch/loongarch/Kconfig
> >>> +++ b/arch/loongarch/Kconfig
> >>> @@ -9,6 +9,7 @@ config LOONGARCH
> >>> select ACPI_PPTT if ACPI
> >>> select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI
> >>> select ARCH_BINFMT_ELF_STATE
> >>> + select ARCH_DEFER_KASAN if KASAN
> >>
> >> Instead of adding 'if KASAN' in all users, you could do in two steps:
> >>
> >> Add a symbol ARCH_NEEDS_DEFER_KASAN.
> >>
> >> +config ARCH_NEEDS_DEFER_KASAN
> >> + bool
> >>
> >> And then:
> >>
> >> +config ARCH_DEFER_KASAN
> >> + def_bool
> >> + depends on KASAN
> >> + depends on ARCH_DEFER_KASAN
> >> + help
> >> + Architectures should select this if they need to defer KASAN
> >> + initialization until shadow memory is properly set up. This
> >> + enables runtime control via static keys. Otherwise, KASAN uses
> >> + compile-time constants for better performance.
> >>
> >
> > Actually, I don't see the benefits from this option. Sorry, have just
> > revisited this again.
> > With the new symbol, arch (PowerPC, UML, LoongArch) still needs select
> > 2 options:
> >
> > select ARCH_NEEDS_DEFER_KASAN
> > select ARCH_DEFER_KASAN
>
> Sorry, my mistake, ARCH_DEFER_KASAN has to be 'def_bool y'. Missing the
> 'y'. That way it is automatically set to 'y' as long as KASAN and
> ARCH_NEEDS_DEFER_KASAN are selected. Should be:
>
> config ARCH_DEFER_KASAN
> def_bool y
> depends on KASAN
> depends on ARCH_NEEDS_DEFER_KASAN
>
>
> >
> > and the oneline with `if` condition is cleaner.
> > select ARCH_DEFER_KASAN if KASAN
Hello,
Have just had a chance to test this.
lib/Kconfig.kasan:
config ARCH_NEEDS_DEFER_KASAN
bool
config ARCH_DEFER_KASAN
def_bool y
depends on KASAN
depends on ARCH_NEEDS_DEFER_KASAN
It works for UML defconfig where arch/um/Kconfig is:
config UML
bool
default y
select ARCH_NEEDS_DEFER_KASAN
select ARCH_DEFER_KASAN if STATIC_LINK
But it prints warnings for PowerPC, LoongArch:
config LOONGARCH
bool
...
select ARCH_NEEDS_DEFER_KASAN
select ARCH_DEFER_KASAN
$ make defconfig ARCH=loongarch
*** Default configuration is based on 'loongson3_defconfig'
WARNING: unmet direct dependencies detected for ARCH_DEFER_KASAN
Depends on [n]: KASAN [=n] && ARCH_NEEDS_DEFER_KASAN [=y]
Selected by [y]:
- LOONGARCH [=y]
config PPC
bool
default y
select ARCH_DEFER_KASAN if PPC_RADIX_MMU
select ARCH_NEEDS_DEFER_KASAN
$ make ppc64_defconfig
WARNING: unmet direct dependencies detected for ARCH_DEFER_KASAN
Depends on [n]: KASAN [=n] && ARCH_NEEDS_DEFER_KASAN [=y]
Selected by [y]:
- PPC [=y] && PPC_RADIX_MMU [=y]
> >
>
> I don't think so because it requires all architectures to add 'if KASAN'
> which is not convenient.
>
> Christophe
next prev parent reply other threads:[~2025-08-10 7:20 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-07 19:40 [PATCH v5 0/2] kasan: unify kasan_enabled() and remove arch-specific implementations Sabyrzhan Tasbolatov
2025-08-07 19:40 ` [PATCH v5 1/2] kasan: introduce ARCH_DEFER_KASAN and unify static key across modes Sabyrzhan Tasbolatov
2025-08-08 5:03 ` Christophe Leroy
2025-08-08 7:26 ` Sabyrzhan Tasbolatov
2025-08-08 7:33 ` Christophe Leroy
2025-08-08 15:33 ` Sabyrzhan Tasbolatov
2025-08-08 17:03 ` Christophe Leroy
2025-08-10 7:20 ` Sabyrzhan Tasbolatov [this message]
2025-08-10 7:32 ` Sabyrzhan Tasbolatov
2025-08-07 19:40 ` [PATCH v5 2/2] kasan: call kasan_init_generic in kasan_init Sabyrzhan Tasbolatov
2025-08-08 5:07 ` Christophe Leroy
2025-08-08 6:44 ` Sabyrzhan Tasbolatov
2025-08-08 7:21 ` Alexandre Ghiti
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=CACzwLxjr+Z+xUj-936rcWDSqEwfUP7bRB1xcqZQKGE7ux-gEXQ@mail.gmail.com \
--to=snovitoll@gmail.com \
--cc=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=alex@ghiti.fr \
--cc=andreyknvl@gmail.com \
--cc=bhe@redhat.com \
--cc=chenhuacai@loongson.cn \
--cc=christophe.leroy@csgroup.eu \
--cc=davidgow@google.co \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=hca@linux.ibm.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-arm-kernel@lists.infradead.org \
--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 \
--cc=vincenzo.frascino@arm.com \
--cc=zhangqing@loongson.cn \
/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