xref: /openbmc/linux/arch/arm64/include/asm/kasan.h (revision 337cbeb2)
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 #ifdef CONFIG_KASAN
16 
17 /*
18  * KASAN_SHADOW_START: beginning of the kernel virtual addresses.
19  * KASAN_SHADOW_END: KASAN_SHADOW_START + 1/N of kernel virtual addresses,
20  * where N = (1 << KASAN_SHADOW_SCALE_SHIFT).
21  *
22  * KASAN_SHADOW_OFFSET:
23  * This value is used to map an address to the corresponding shadow
24  * address by the following formula:
25  *     shadow_addr = (address >> KASAN_SHADOW_SCALE_SHIFT) + KASAN_SHADOW_OFFSET
26  *
27  * (1 << (64 - KASAN_SHADOW_SCALE_SHIFT)) shadow addresses that lie in range
28  * [KASAN_SHADOW_OFFSET, KASAN_SHADOW_END) cover all 64-bits of virtual
29  * addresses. So KASAN_SHADOW_OFFSET should satisfy the following equation:
30  *      KASAN_SHADOW_OFFSET = KASAN_SHADOW_END -
31  *				(1ULL << (64 - KASAN_SHADOW_SCALE_SHIFT))
32  */
33 #define _KASAN_SHADOW_START(va)	(KASAN_SHADOW_END - (1UL << ((va) - KASAN_SHADOW_SCALE_SHIFT)))
34 #define KASAN_SHADOW_START      _KASAN_SHADOW_START(vabits_actual)
35 
36 void kasan_init(void);
37 void kasan_copy_shadow(pgd_t *pgdir);
38 asmlinkage void kasan_early_init(void);
39 
40 #else
41 static inline void kasan_init(void) { }
42 static inline void kasan_copy_shadow(pgd_t *pgdir) { }
43 #endif
44 
45 #endif
46 #endif
47