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