Message ID | 20220219012945.894950-1-pcc@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v5,1/2] kasan: split kasan_*enabled() functions into a separate header | expand |
On Sat, Feb 19, 2022 at 2:30 AM Peter Collingbourne <pcc@google.com> wrote: > > In an upcoming commit we are going to need to call > kasan_hw_tags_enabled() from arch/arm64/include/asm/mte.h. This > would create a circular dependency between headers if KASAN_GENERIC > or KASAN_SW_TAGS is enabled: linux/kasan.h -> linux/pgtable.h -> > asm/pgtable.h -> asm/mte.h -> linux/kasan.h. Break the cycle > by introducing a new header linux/kasan-enabled.h with the > kasan_*enabled() functions that can be included from asm/mte.h. > > Link: https://linux-review.googlesource.com/id/I5b0d96c6ed0026fc790899e14d42b2fac6ab568e > Signed-off-by: Peter Collingbourne <pcc@google.com> > --- > include/linux/kasan-enabled.h | 33 +++++++++++++++++++++++++++++++++ > include/linux/kasan.h | 23 +---------------------- > 2 files changed, 34 insertions(+), 22 deletions(-) > create mode 100644 include/linux/kasan-enabled.h > > diff --git a/include/linux/kasan-enabled.h b/include/linux/kasan-enabled.h > new file mode 100644 > index 000000000000..4b6615375022 > --- /dev/null > +++ b/include/linux/kasan-enabled.h > @@ -0,0 +1,33 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _LINUX_KASAN_ENABLED_H > +#define _LINUX_KASAN_ENABLED_H > + > +#ifdef CONFIG_KASAN_HW_TAGS > + > +DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled); > + > +static __always_inline bool kasan_enabled(void) > +{ > + return static_branch_likely(&kasan_flag_enabled); > +} > + > +static inline bool kasan_hw_tags_enabled(void) > +{ > + return kasan_enabled(); > +} > + > +#else /* CONFIG_KASAN_HW_TAGS */ > + > +static inline bool kasan_enabled(void) > +{ > + return IS_ENABLED(CONFIG_KASAN); > +} > + > +static inline bool kasan_hw_tags_enabled(void) > +{ > + return false; > +} > + > +#endif /* CONFIG_KASAN_HW_TAGS */ > + > +#endif /* LINUX_KASAN_ENABLED_H */ > diff --git a/include/linux/kasan.h b/include/linux/kasan.h > index 4a45562d8893..b6a93261c92a 100644 > --- a/include/linux/kasan.h > +++ b/include/linux/kasan.h > @@ -3,6 +3,7 @@ > #define _LINUX_KASAN_H > > #include <linux/bug.h> > +#include <linux/kasan-enabled.h> > #include <linux/kernel.h> > #include <linux/static_key.h> > #include <linux/types.h> > @@ -83,33 +84,11 @@ static inline void kasan_disable_current(void) {} > > #ifdef CONFIG_KASAN_HW_TAGS > > -DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled); > - > -static __always_inline bool kasan_enabled(void) > -{ > - return static_branch_likely(&kasan_flag_enabled); > -} > - > -static inline bool kasan_hw_tags_enabled(void) > -{ > - return kasan_enabled(); > -} > - > void kasan_alloc_pages(struct page *page, unsigned int order, gfp_t flags); > void kasan_free_pages(struct page *page, unsigned int order); > > #else /* CONFIG_KASAN_HW_TAGS */ > > -static inline bool kasan_enabled(void) > -{ > - return IS_ENABLED(CONFIG_KASAN); > -} > - > -static inline bool kasan_hw_tags_enabled(void) > -{ > - return false; > -} > - > static __always_inline void kasan_alloc_pages(struct page *page, > unsigned int order, gfp_t flags) > { > -- > 2.35.1.473.g83b2b277ed-goog > Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>
On Fri, 18 Feb 2022 17:29:44 -0800, Peter Collingbourne wrote: > In an upcoming commit we are going to need to call > kasan_hw_tags_enabled() from arch/arm64/include/asm/mte.h. This > would create a circular dependency between headers if KASAN_GENERIC > or KASAN_SW_TAGS is enabled: linux/kasan.h -> linux/pgtable.h -> > asm/pgtable.h -> asm/mte.h -> linux/kasan.h. Break the cycle > by introducing a new header linux/kasan-enabled.h with the > kasan_*enabled() functions that can be included from asm/mte.h. > > [...] Applied to arm64 (for-next/mte), thanks! [1/2] kasan: split kasan_*enabled() functions into a separate header https://git.kernel.org/arm64/c/f9b5e46f4097 [2/2] arm64: mte: avoid clearing PSTATE.TCO on entry unless necessary https://git.kernel.org/arm64/c/38ddf7dafaea Cheers,
diff --git a/include/linux/kasan-enabled.h b/include/linux/kasan-enabled.h new file mode 100644 index 000000000000..4b6615375022 --- /dev/null +++ b/include/linux/kasan-enabled.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_KASAN_ENABLED_H +#define _LINUX_KASAN_ENABLED_H + +#ifdef CONFIG_KASAN_HW_TAGS + +DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled); + +static __always_inline bool kasan_enabled(void) +{ + return static_branch_likely(&kasan_flag_enabled); +} + +static inline bool kasan_hw_tags_enabled(void) +{ + return kasan_enabled(); +} + +#else /* CONFIG_KASAN_HW_TAGS */ + +static inline bool kasan_enabled(void) +{ + return IS_ENABLED(CONFIG_KASAN); +} + +static inline bool kasan_hw_tags_enabled(void) +{ + return false; +} + +#endif /* CONFIG_KASAN_HW_TAGS */ + +#endif /* LINUX_KASAN_ENABLED_H */ diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 4a45562d8893..b6a93261c92a 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -3,6 +3,7 @@ #define _LINUX_KASAN_H #include <linux/bug.h> +#include <linux/kasan-enabled.h> #include <linux/kernel.h> #include <linux/static_key.h> #include <linux/types.h> @@ -83,33 +84,11 @@ static inline void kasan_disable_current(void) {} #ifdef CONFIG_KASAN_HW_TAGS -DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled); - -static __always_inline bool kasan_enabled(void) -{ - return static_branch_likely(&kasan_flag_enabled); -} - -static inline bool kasan_hw_tags_enabled(void) -{ - return kasan_enabled(); -} - void kasan_alloc_pages(struct page *page, unsigned int order, gfp_t flags); void kasan_free_pages(struct page *page, unsigned int order); #else /* CONFIG_KASAN_HW_TAGS */ -static inline bool kasan_enabled(void) -{ - return IS_ENABLED(CONFIG_KASAN); -} - -static inline bool kasan_hw_tags_enabled(void) -{ - return false; -} - static __always_inline void kasan_alloc_pages(struct page *page, unsigned int order, gfp_t flags) {
In an upcoming commit we are going to need to call kasan_hw_tags_enabled() from arch/arm64/include/asm/mte.h. This would create a circular dependency between headers if KASAN_GENERIC or KASAN_SW_TAGS is enabled: linux/kasan.h -> linux/pgtable.h -> asm/pgtable.h -> asm/mte.h -> linux/kasan.h. Break the cycle by introducing a new header linux/kasan-enabled.h with the kasan_*enabled() functions that can be included from asm/mte.h. Link: https://linux-review.googlesource.com/id/I5b0d96c6ed0026fc790899e14d42b2fac6ab568e Signed-off-by: Peter Collingbourne <pcc@google.com> --- include/linux/kasan-enabled.h | 33 +++++++++++++++++++++++++++++++++ include/linux/kasan.h | 23 +---------------------- 2 files changed, 34 insertions(+), 22 deletions(-) create mode 100644 include/linux/kasan-enabled.h