1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 239d114ddSAndrey Ryabinin #ifndef __ASM_KASAN_H 339d114ddSAndrey Ryabinin #define __ASM_KASAN_H 439d114ddSAndrey Ryabinin 539d114ddSAndrey Ryabinin #ifndef __ASSEMBLY__ 639d114ddSAndrey Ryabinin 783040123SWill Deacon #include <linux/linkage.h> 839d114ddSAndrey Ryabinin #include <asm/memory.h> 9*2cb34276SAndrey Konovalov #include <asm/mte-kasan.h> 10068a17a5SMark Rutland #include <asm/pgtable-types.h> 1139d114ddSAndrey Ryabinin 123c9e3aa1SAndrey Konovalov #define arch_kasan_set_tag(addr, tag) __tag_set(addr, tag) 133c9e3aa1SAndrey Konovalov #define arch_kasan_reset_tag(addr) __tag_reset(addr) 143c9e3aa1SAndrey Konovalov #define arch_kasan_get_tag(addr) __tag_get(addr) 153c9e3aa1SAndrey Konovalov 16afe6ef80SAndrey Konovalov #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) 173c9e3aa1SAndrey Konovalov 1828ab3584SAndrey Konovalov void kasan_init(void); 1928ab3584SAndrey Konovalov 2039d114ddSAndrey Ryabinin /* 2139d114ddSAndrey Ryabinin * KASAN_SHADOW_START: beginning of the kernel virtual addresses. 22917538e2SAndrey Konovalov * KASAN_SHADOW_END: KASAN_SHADOW_START + 1/N of kernel virtual addresses, 23917538e2SAndrey Konovalov * where N = (1 << KASAN_SHADOW_SCALE_SHIFT). 246bd1d0beSSteve Capper * 256bd1d0beSSteve Capper * KASAN_SHADOW_OFFSET: 2639d114ddSAndrey Ryabinin * This value is used to map an address to the corresponding shadow 2739d114ddSAndrey Ryabinin * address by the following formula: 28917538e2SAndrey Konovalov * shadow_addr = (address >> KASAN_SHADOW_SCALE_SHIFT) + KASAN_SHADOW_OFFSET 2939d114ddSAndrey Ryabinin * 30917538e2SAndrey Konovalov * (1 << (64 - KASAN_SHADOW_SCALE_SHIFT)) shadow addresses that lie in range 31917538e2SAndrey Konovalov * [KASAN_SHADOW_OFFSET, KASAN_SHADOW_END) cover all 64-bits of virtual 32917538e2SAndrey Konovalov * addresses. So KASAN_SHADOW_OFFSET should satisfy the following equation: 33917538e2SAndrey Konovalov * KASAN_SHADOW_OFFSET = KASAN_SHADOW_END - 34917538e2SAndrey Konovalov * (1ULL << (64 - KASAN_SHADOW_SCALE_SHIFT)) 3539d114ddSAndrey Ryabinin */ 366bd1d0beSSteve Capper #define _KASAN_SHADOW_START(va) (KASAN_SHADOW_END - (1UL << ((va) - KASAN_SHADOW_SCALE_SHIFT))) 375383cc6eSSteve Capper #define KASAN_SHADOW_START _KASAN_SHADOW_START(vabits_actual) 3839d114ddSAndrey Ryabinin 39068a17a5SMark Rutland void kasan_copy_shadow(pgd_t *pgdir); 4083040123SWill Deacon asmlinkage void kasan_early_init(void); 4139d114ddSAndrey Ryabinin 4239d114ddSAndrey Ryabinin #else kasan_init(void)4328ab3584SAndrey Konovalovstatic inline void kasan_init(void) { } kasan_copy_shadow(pgd_t * pgdir)44068a17a5SMark Rutlandstatic inline void kasan_copy_shadow(pgd_t *pgdir) { } 4539d114ddSAndrey Ryabinin #endif 4639d114ddSAndrey Ryabinin 4739d114ddSAndrey Ryabinin #endif 4839d114ddSAndrey Ryabinin #endif 49