xref: /openbmc/linux/arch/arm64/include/asm/kasan.h (revision 068a17a5)
139d114ddSAndrey Ryabinin #ifndef __ASM_KASAN_H
239d114ddSAndrey Ryabinin #define __ASM_KASAN_H
339d114ddSAndrey Ryabinin 
439d114ddSAndrey Ryabinin #ifndef __ASSEMBLY__
539d114ddSAndrey Ryabinin 
639d114ddSAndrey Ryabinin #ifdef CONFIG_KASAN
739d114ddSAndrey Ryabinin 
883040123SWill Deacon #include <linux/linkage.h>
939d114ddSAndrey Ryabinin #include <asm/memory.h>
10068a17a5SMark Rutland #include <asm/pgtable-types.h>
1139d114ddSAndrey Ryabinin 
1239d114ddSAndrey Ryabinin /*
1339d114ddSAndrey Ryabinin  * KASAN_SHADOW_START: beginning of the kernel virtual addresses.
1439d114ddSAndrey Ryabinin  * KASAN_SHADOW_END: KASAN_SHADOW_START + 1/8 of kernel virtual addresses.
1539d114ddSAndrey Ryabinin  */
1639d114ddSAndrey Ryabinin #define KASAN_SHADOW_START      (VA_START)
1739d114ddSAndrey Ryabinin #define KASAN_SHADOW_END        (KASAN_SHADOW_START + (1UL << (VA_BITS - 3)))
1839d114ddSAndrey Ryabinin 
1939d114ddSAndrey Ryabinin /*
2039d114ddSAndrey Ryabinin  * This value is used to map an address to the corresponding shadow
2139d114ddSAndrey Ryabinin  * address by the following formula:
2239d114ddSAndrey Ryabinin  *     shadow_addr = (address >> 3) + KASAN_SHADOW_OFFSET;
2339d114ddSAndrey Ryabinin  *
2439d114ddSAndrey Ryabinin  * (1 << 61) shadow addresses - [KASAN_SHADOW_OFFSET,KASAN_SHADOW_END]
2539d114ddSAndrey Ryabinin  * cover all 64-bits of virtual addresses. So KASAN_SHADOW_OFFSET
2639d114ddSAndrey Ryabinin  * should satisfy the following equation:
2739d114ddSAndrey Ryabinin  *      KASAN_SHADOW_OFFSET = KASAN_SHADOW_END - (1ULL << 61)
2839d114ddSAndrey Ryabinin  */
2939d114ddSAndrey Ryabinin #define KASAN_SHADOW_OFFSET     (KASAN_SHADOW_END - (1ULL << (64 - 3)))
3039d114ddSAndrey Ryabinin 
3139d114ddSAndrey Ryabinin void kasan_init(void);
32068a17a5SMark Rutland void kasan_copy_shadow(pgd_t *pgdir);
3383040123SWill Deacon asmlinkage void kasan_early_init(void);
3439d114ddSAndrey Ryabinin 
3539d114ddSAndrey Ryabinin #else
3639d114ddSAndrey Ryabinin static inline void kasan_init(void) { }
37068a17a5SMark Rutland static inline void kasan_copy_shadow(pgd_t *pgdir) { }
3839d114ddSAndrey Ryabinin #endif
3939d114ddSAndrey Ryabinin 
4039d114ddSAndrey Ryabinin #endif
4139d114ddSAndrey Ryabinin #endif
42