[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CA+fCnZcSZi5nPPnbC3Ce7qChUFMwwSkP13fGSG4VXpDqOUimOg@mail.gmail.com>
Date: Sat, 16 Sep 2023 18:23:13 +0200
From: Andrey Konovalov <andreyknvl@...il.com>
To: Huacai Chen <chenhuacai@...ngson.cn>
Cc: Huacai Chen <chenhuacai@...nel.org>,
Andrey Ryabinin <ryabinin.a.a@...il.com>,
Alexander Potapenko <glider@...gle.com>,
loongarch@...ts.linux.dev, Xuerui Wang <kernel@...0n.name>,
Jiaxun Yang <jiaxun.yang@...goat.com>,
Dmitry Vyukov <dvyukov@...gle.com>,
Vincenzo Frascino <vincenzo.frascino@....com>,
kasan-dev@...glegroups.com, linux-kernel@...r.kernel.org,
loongson-kernel@...ts.loongnix.cn,
Linus Torvalds <torvalds@...ux-foundation.org>,
WANG Xuerui <git@...0n.name>
Subject: Re: [PATCH V2] kasan: Cleanup the __HAVE_ARCH_SHADOW_MAP usage
On Tue, Sep 12, 2023 at 5:18 AM Huacai Chen <chenhuacai@...ngson.cn> wrote:
>
> As Linus suggested, __HAVE_ARCH_XYZ is "stupid" and "having historical
> uses of it doesn't make it good". So migrate __HAVE_ARCH_SHADOW_MAP to
> separate macros named after the respective functions.
>
> Suggested-by: Linus Torvalds <torvalds@...ux-foundation.org>
> Reviewed-by: WANG Xuerui <git@...0n.name>
> Signed-off-by: Huacai Chen <chenhuacai@...ngson.cn>
> ---
> V2: Update commit messages.
>
> arch/loongarch/include/asm/kasan.h | 10 ++++++++--
> include/linux/kasan.h | 2 +-
> mm/kasan/kasan.h | 8 +++-----
> 3 files changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/arch/loongarch/include/asm/kasan.h b/arch/loongarch/include/asm/kasan.h
> index deeff8158f45..a12ecab37da7 100644
> --- a/arch/loongarch/include/asm/kasan.h
> +++ b/arch/loongarch/include/asm/kasan.h
> @@ -10,8 +10,6 @@
> #include <asm/io.h>
> #include <asm/pgtable.h>
>
> -#define __HAVE_ARCH_SHADOW_MAP
> -
> #define KASAN_SHADOW_SCALE_SHIFT 3
> #define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL)
>
> @@ -68,6 +66,7 @@ static __always_inline bool kasan_arch_is_ready(void)
> return !kasan_early_stage;
> }
>
> +#define kasan_mem_to_shadow kasan_mem_to_shadow
> static inline void *kasan_mem_to_shadow(const void *addr)
> {
> if (!kasan_arch_is_ready()) {
> @@ -97,6 +96,7 @@ static inline void *kasan_mem_to_shadow(const void *addr)
> }
> }
>
> +#define kasan_shadow_to_mem kasan_shadow_to_mem
> static inline const void *kasan_shadow_to_mem(const void *shadow_addr)
> {
> unsigned long addr = (unsigned long)shadow_addr;
> @@ -119,6 +119,12 @@ static inline const void *kasan_shadow_to_mem(const void *shadow_addr)
> }
> }
>
> +#define addr_has_metadata addr_has_metadata
> +static __always_inline bool addr_has_metadata(const void *addr)
> +{
> + return (kasan_mem_to_shadow((void *)addr) != NULL);
> +}
> +
> void kasan_init(void);
> asmlinkage void kasan_early_init(void);
>
> diff --git a/include/linux/kasan.h b/include/linux/kasan.h
> index 3df5499f7936..842623d708c2 100644
> --- a/include/linux/kasan.h
> +++ b/include/linux/kasan.h
> @@ -54,7 +54,7 @@ extern p4d_t kasan_early_shadow_p4d[MAX_PTRS_PER_P4D];
> int kasan_populate_early_shadow(const void *shadow_start,
> const void *shadow_end);
>
> -#ifndef __HAVE_ARCH_SHADOW_MAP
> +#ifndef kasan_mem_to_shadow
> static inline void *kasan_mem_to_shadow(const void *addr)
> {
> return (void *)((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT)
> diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
> index f70e3d7a602e..d37831b8511c 100644
> --- a/mm/kasan/kasan.h
> +++ b/mm/kasan/kasan.h
> @@ -291,7 +291,7 @@ struct kasan_stack_ring {
>
> #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
>
> -#ifndef __HAVE_ARCH_SHADOW_MAP
> +#ifndef kasan_shadow_to_mem
> static inline const void *kasan_shadow_to_mem(const void *shadow_addr)
> {
> return (void *)(((unsigned long)shadow_addr - KASAN_SHADOW_OFFSET)
> @@ -299,15 +299,13 @@ static inline const void *kasan_shadow_to_mem(const void *shadow_addr)
> }
> #endif
>
> +#ifndef addr_has_metadata
> static __always_inline bool addr_has_metadata(const void *addr)
> {
> -#ifdef __HAVE_ARCH_SHADOW_MAP
> - return (kasan_mem_to_shadow((void *)addr) != NULL);
> -#else
> return (kasan_reset_tag(addr) >=
> kasan_shadow_to_mem((void *)KASAN_SHADOW_START));
> -#endif
> }
> +#endif
>
> /**
> * kasan_check_range - Check memory region, and report if invalid access.
> --
> 2.39.3
>
Reviewed-by: Andrey Konovalov <andreyknvl@...il.com>
Thanks!
Powered by blists - more mailing lists