mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-01 10:45:49 +00:00
kasan: Cleanup the __HAVE_ARCH_SHADOW_MAP usage
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@linux-foundation.org> Reviewed-by: WANG Xuerui <git@xen0n.name> Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
This commit is contained in:
parent
b795fb9f58
commit
2a86f1b56a
@ -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);
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user