[lkml]   [2020]   [Sep]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH v3 25/39] arm64: kasan: Add arch layer for memory tagging helpers
This patch add a set of arch_*() memory tagging helpers currently only
defined for arm64 when hardware tag-based KASAN is enabled. These helpers
will be used by KASAN runtime to implement the hardware tag-based mode.

The arch-level indirection level is introduced to simplify adding hardware
tag-based KASAN support for other architectures in the future by defining
the appropriate arch_*() macros.

Signed-off-by: Andrey Konovalov <>
Co-developed-by: Vincenzo Frascino <>
Signed-off-by: Vincenzo Frascino <>
Reviewed-by: Catalin Marinas <>
Change-Id: I42b0795a28067872f8308e00c6f0195bca435c2a
arch/arm64/include/asm/memory.h | 8 ++++++++
mm/kasan/kasan.h | 18 ++++++++++++++++++
2 files changed, 26 insertions(+)

diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index e424fc3a68cb..268a3b6cebd2 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -231,6 +231,14 @@ static inline const void *__tag_set(const void *addr, u8 tag)
return (const void *)(__addr | __tag_shifted(tag));

+#define arch_init_tags(max_tag) mte_init_tags(max_tag)
+#define arch_get_random_tag() mte_get_random_tag()
+#define arch_get_mem_tag(addr) mte_get_mem_tag(addr)
+#define arch_set_mem_tag_range(addr, size, tag) \
+ mte_set_mem_tag_range((addr), (size), (tag))
+#endif /* CONFIG_KASAN_HW_TAGS */
* Physical vs virtual RAM address space conversion. These are
* private definitions which should NOT be used outside memory.h
diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
index 50b59c8f8be2..9c73f324e3ce 100644
--- a/mm/kasan/kasan.h
+++ b/mm/kasan/kasan.h
@@ -241,6 +241,24 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag)
#define reset_tag(addr) ((void *)arch_kasan_reset_tag(addr))
#define get_tag(addr) arch_kasan_get_tag(addr)

+#ifndef arch_init_tags
+#define arch_init_tags(max_tag)
+#ifndef arch_get_random_tag
+#define arch_get_random_tag() (0xFF)
+#ifndef arch_get_mem_tag
+#define arch_get_mem_tag(addr) (0xFF)
+#ifndef arch_set_mem_tag_range
+#define arch_set_mem_tag_range(addr, size, tag) ((void *)(addr))
+#define init_tags(max_tag) arch_init_tags(max_tag)
+#define get_random_tag() arch_get_random_tag()
+#define get_mem_tag(addr) arch_get_mem_tag(addr)
+#define set_mem_tag_range(addr, size, tag) arch_set_mem_tag_range((addr), (size), (tag))
* Exported functions for interfaces called from assembly or from generated
* code. Declarations here to avoid warning about missing declarations.
 \ /
  Last update: 2020-09-25 00:52    [W:0.484 / U:4.588 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site