1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __ASM_KASAN_H 3 #define __ASM_KASAN_H 4 5 #ifndef __ASSEMBLY__ 6 7 #include <linux/linkage.h> 8 #include <asm/memory.h> 9 #include <asm/pgtable-types.h> 10 11 #define arch_kasan_set_tag(addr, tag) __tag_set(addr, tag) 12 #define arch_kasan_reset_tag(addr) __tag_reset(addr) 13 #define arch_kasan_get_tag(addr) __tag_get(addr) 14 15 #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) 16 17 void kasan_init(void); 18 19 /* 20 * KASAN_SHADOW_START: beginning of the kernel virtual addresses. 21 * KASAN_SHADOW_END: KASAN_SHADOW_START + 1/N of kernel virtual addresses, 22 * where N = (1 << KASAN_SHADOW_SCALE_SHIFT). 23 * 24 * KASAN_SHADOW_OFFSET: 25 * This value is used to map an address to the corresponding shadow 26 * address by the following formula: 27 * shadow_addr = (address >> KASAN_SHADOW_SCALE_SHIFT) + KASAN_SHADOW_OFFSET 28 * 29 * (1 << (64 - KASAN_SHADOW_SCALE_SHIFT)) shadow addresses that lie in range 30 * [KASAN_SHADOW_OFFSET, KASAN_SHADOW_END) cover all 64-bits of virtual 31 * addresses. So KASAN_SHADOW_OFFSET should satisfy the following equation: 32 * KASAN_SHADOW_OFFSET = KASAN_SHADOW_END - 33 * (1ULL << (64 - KASAN_SHADOW_SCALE_SHIFT)) 34 */ 35 #define _KASAN_SHADOW_START(va) (KASAN_SHADOW_END - (1UL << ((va) - KASAN_SHADOW_SCALE_SHIFT))) 36 #define KASAN_SHADOW_START _KASAN_SHADOW_START(vabits_actual) 37 38 void kasan_copy_shadow(pgd_t *pgdir); 39 asmlinkage void kasan_early_init(void); 40 41 #else 42 static inline void kasan_init(void) { } 43 static inline void kasan_copy_shadow(pgd_t *pgdir) { } 44 #endif 45 46 #endif 47 #endif 48