Skip to content

Commit

Permalink
kasan: inline random_tag for HW_TAGS
Browse files Browse the repository at this point in the history
Using random_tag() currently results in a function call. Move its
definition to mm/kasan/kasan.h and turn it into a static inline function
for hardware tag-based mode to avoid uneeded function calls.

Link: https://lkml.kernel.org/r/be438471690e351e1d792e6bb432e8c03ccb15d3.1606162397.git.andreyknvl@google.com
Link: https://linux-review.googlesource.com/id/Iac5b2faf9a912900e16cca6834d621f5d4abf427
Signed-off-by: Andrey Konovalov <[email protected]>
Reviewed-by: Marco Elver <[email protected]>
Reviewed-by: Dmitry Vyukov <[email protected]>
Tested-by: Vincenzo Frascino <[email protected]>
Cc: Alexander Potapenko <[email protected]>
Cc: Andrey Ryabinin <[email protected]>
Cc: Branislav Rankov <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Evgenii Stepanov <[email protected]>
Cc: Kevin Brodsky <[email protected]>
Cc: Vasily Gorbik <[email protected]>
Cc: Will Deacon <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
xairy authored and torvalds committed Dec 22, 2020
1 parent c0054c5 commit d8dd397
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
5 changes: 0 additions & 5 deletions mm/kasan/hw_tags.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ void unpoison_range(const void *address, size_t size)
round_up(size, KASAN_GRANULE_SIZE), get_tag(address));
}

u8 random_tag(void)
{
return hw_get_random_tag();
}

bool check_invalid_free(void *addr)
{
u8 ptr_tag = get_tag(addr);
Expand Down
31 changes: 14 additions & 17 deletions mm/kasan/kasan.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ static inline bool addr_has_metadata(const void *addr)

#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */

#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS)
void print_tags(u8 addr_tag, const void *addr);
#else
static inline void print_tags(u8 addr_tag, const void *addr) { }
#endif

bool check_invalid_free(void *addr);

void *find_first_bad_addr(void *addr, size_t size);
Expand Down Expand Up @@ -225,23 +231,6 @@ static inline void quarantine_reduce(void) { }
static inline void quarantine_remove_cache(struct kmem_cache *cache) { }
#endif

#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS)

void print_tags(u8 addr_tag, const void *addr);

u8 random_tag(void);

#else

static inline void print_tags(u8 addr_tag, const void *addr) { }

static inline u8 random_tag(void)
{
return 0;
}

#endif

#ifndef arch_kasan_set_tag
static inline const void *arch_kasan_set_tag(const void *addr, u8 tag)
{
Expand Down Expand Up @@ -281,6 +270,14 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag)

#endif /* CONFIG_KASAN_HW_TAGS */

#ifdef CONFIG_KASAN_SW_TAGS
u8 random_tag(void);
#elif defined(CONFIG_KASAN_HW_TAGS)
static inline u8 random_tag(void) { return hw_get_random_tag(); }
#else
static inline u8 random_tag(void) { return 0; }
#endif

/*
* Exported functions for interfaces called from assembly or from generated
* code. Declarations here to avoid warning about missing declarations.
Expand Down

0 comments on commit d8dd397

Please sign in to comment.