On Sat, Jun 28, 2025 at 3:25 PM Sabyrzhan Tasbolatov <snovit...@gmail.com> wrote: > > On Sat, Jun 28, 2025 at 3:57 PM Andrey Konovalov <andreyk...@gmail.com> wrote: > > > > On Thu, Jun 26, 2025 at 5:32 PM Sabyrzhan Tasbolatov > > <snovit...@gmail.com> wrote: > > > > > > This patch series unifies the kasan_arch_is_ready() and kasan_enabled() > > > interfaces by extending the existing kasan_enabled() infrastructure to > > > work consistently across all KASAN modes (Generic, SW_TAGS, HW_TAGS). > > > > > > Currently, kasan_enabled() only works for HW_TAGS mode using a static key, > > > while other modes either return IS_ENABLED(CONFIG_KASAN) (compile-time > > > constant) or rely on architecture-specific kasan_arch_is_ready() > > > implementations with custom static keys and global variables. > > > > > > This leads to: > > > - Code duplication across architectures > > > - Inconsistent runtime behavior between KASAN modes > > > - Architecture-specific readiness tracking > > > > > > After this series: > > > - All KASAN modes use the same kasan_flag_enabled static key > > > - Consistent runtime enable/disable behavior across modes > > > - Simplified architecture code with unified kasan_init_generic() calls > > > - Elimination of arch specific kasan_arch_is_ready() implementations > > > - Unified vmalloc integration using kasan_enabled() checks > > > > > > This addresses the bugzilla issue [1] about making > > > kasan_flag_enabled and kasan_enabled() work for Generic mode, > > > and extends it to provide true unification across all modes. > > > > > > [1] https://bugzilla.kernel.org/show_bug.cgi?id=217049 > > > > Hi Sabyrzhan, > > > > Thank you for working on this! > > > > One aspect that is missing from the patches is moving the > > kasan_arch_is_ready() calls into the include/linux/kasan.h (this is > > not explicitly mentioned in the issue, but this is what the "adding > > __wrappers" part is about). > > > > Another thing that needs careful consideration is whether it's > > possible to combine kasan_arch_is_ready() and kasan_enabled() into the > > same check logically at all. There's one issue mentioned in [1]: > > Hello, > I've removed kasan_arch_is_ready() at all in this series: > [PATCH v2 11/11] kasan: replace kasan_arch_is_ready with kasan_enabled > > Is it not what's expected by unification?
I guess the issue description diverged a bit from what needs to be done, sorry about that. The core 2 things I wanted to address with the unification are: 1. Avoid spraying kasan_arch_is_ready() throughout the KASAN implementation and move these checks into include/linux/kasan.h (and add __wrappers when required). 2. Avoid architectures redefining the same kasan_enabled global variable/static key. Initially, I thought that s/kasan_arch_is_ready/kasan_enabled + simply moving the calls into affected include/linux/kasan.h functions would be enough. But then, based on [1], turns out it's not that simple. So now, I think we likely still need two separate checks/flags: kasan_enabled() that controls whether KASAN is enabled at all and kasan_arch_is_ready() that gets turned on by kasan_init() when shadow is initialized (should we rename it to kasan_shadow_initialized()?). But then we can still move kasan_arch_is_ready() into include/linux/kasan.h and use the proper combination of checks for each affected function before calling __wrappers. And we can still remove the duplicated flags/keys code from the arch code. [1] https://lore.kernel.org/linux-mm/ca+fcnzf7jqth46c7og2wk9nnlu7hgivdek0ea8ratyr-kgk...@mail.gmail.com/