Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Link: https://lkml.kernel.org/r/fc9e5bb71201c03131a2fc00a74125723568dda9.1606161801.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Co-developed-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Tested-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Branislav Rankov <Branislav.Rankov@arm.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Evgenii Stepanov <eugenis@google.com>
Cc: Kevin Brodsky <kevin.brodsky@arm.com>
Cc: Marco Elver <elver@google.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Andrey Konovalov and committed by
Linus Torvalds
ccbe2aab dc09b29f

+35
+9
arch/arm64/include/asm/memory.h
··· 230 230 return (const void *)(__addr | __tag_shifted(tag)); 231 231 } 232 232 233 + #ifdef CONFIG_KASAN_HW_TAGS 234 + #define arch_enable_tagging() mte_enable_kernel() 235 + #define arch_init_tags(max_tag) mte_init_tags(max_tag) 236 + #define arch_get_random_tag() mte_get_random_tag() 237 + #define arch_get_mem_tag(addr) mte_get_mem_tag(addr) 238 + #define arch_set_mem_tag_range(addr, size, tag) \ 239 + mte_set_mem_tag_range((addr), (size), (tag)) 240 + #endif /* CONFIG_KASAN_HW_TAGS */ 241 + 233 242 /* 234 243 * Physical vs virtual RAM address space conversion. These are 235 244 * private definitions which should NOT be used outside memory.h
+26
mm/kasan/kasan.h
··· 243 243 #define reset_tag(addr) ((void *)arch_kasan_reset_tag(addr)) 244 244 #define get_tag(addr) arch_kasan_get_tag(addr) 245 245 246 + #ifdef CONFIG_KASAN_HW_TAGS 247 + 248 + #ifndef arch_enable_tagging 249 + #define arch_enable_tagging() 250 + #endif 251 + #ifndef arch_init_tags 252 + #define arch_init_tags(max_tag) 253 + #endif 254 + #ifndef arch_get_random_tag 255 + #define arch_get_random_tag() (0xFF) 256 + #endif 257 + #ifndef arch_get_mem_tag 258 + #define arch_get_mem_tag(addr) (0xFF) 259 + #endif 260 + #ifndef arch_set_mem_tag_range 261 + #define arch_set_mem_tag_range(addr, size, tag) ((void *)(addr)) 262 + #endif 263 + 264 + #define hw_enable_tagging() arch_enable_tagging() 265 + #define hw_init_tags(max_tag) arch_init_tags(max_tag) 266 + #define hw_get_random_tag() arch_get_random_tag() 267 + #define hw_get_mem_tag(addr) arch_get_mem_tag(addr) 268 + #define hw_set_mem_tag_range(addr, size, tag) arch_set_mem_tag_range((addr), (size), (tag)) 269 + 270 + #endif /* CONFIG_KASAN_HW_TAGS */ 271 + 246 272 /* 247 273 * Exported functions for interfaces called from assembly or from generated 248 274 * code. Declarations here to avoid warning about missing declarations.