18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __ASM_KASAN_H
38c2ecf20Sopenharmony_ci#define __ASM_KASAN_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/linkage.h>
88c2ecf20Sopenharmony_ci#include <asm/memory.h>
98c2ecf20Sopenharmony_ci#include <asm/pgtable-types.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#define arch_kasan_set_tag(addr, tag)	__tag_set(addr, tag)
128c2ecf20Sopenharmony_ci#define arch_kasan_reset_tag(addr)	__tag_reset(addr)
138c2ecf20Sopenharmony_ci#define arch_kasan_get_tag(addr)	__tag_get(addr)
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#ifdef CONFIG_KASAN
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/*
188c2ecf20Sopenharmony_ci * KASAN_SHADOW_START: beginning of the kernel virtual addresses.
198c2ecf20Sopenharmony_ci * KASAN_SHADOW_END: KASAN_SHADOW_START + 1/N of kernel virtual addresses,
208c2ecf20Sopenharmony_ci * where N = (1 << KASAN_SHADOW_SCALE_SHIFT).
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * KASAN_SHADOW_OFFSET:
238c2ecf20Sopenharmony_ci * This value is used to map an address to the corresponding shadow
248c2ecf20Sopenharmony_ci * address by the following formula:
258c2ecf20Sopenharmony_ci *     shadow_addr = (address >> KASAN_SHADOW_SCALE_SHIFT) + KASAN_SHADOW_OFFSET
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * (1 << (64 - KASAN_SHADOW_SCALE_SHIFT)) shadow addresses that lie in range
288c2ecf20Sopenharmony_ci * [KASAN_SHADOW_OFFSET, KASAN_SHADOW_END) cover all 64-bits of virtual
298c2ecf20Sopenharmony_ci * addresses. So KASAN_SHADOW_OFFSET should satisfy the following equation:
308c2ecf20Sopenharmony_ci *      KASAN_SHADOW_OFFSET = KASAN_SHADOW_END -
318c2ecf20Sopenharmony_ci *				(1ULL << (64 - KASAN_SHADOW_SCALE_SHIFT))
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_ci#define _KASAN_SHADOW_START(va)	(KASAN_SHADOW_END - (1UL << ((va) - KASAN_SHADOW_SCALE_SHIFT)))
348c2ecf20Sopenharmony_ci#define KASAN_SHADOW_START      _KASAN_SHADOW_START(vabits_actual)
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_civoid kasan_init(void);
378c2ecf20Sopenharmony_civoid kasan_copy_shadow(pgd_t *pgdir);
388c2ecf20Sopenharmony_ciasmlinkage void kasan_early_init(void);
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#else
418c2ecf20Sopenharmony_cistatic inline void kasan_init(void) { }
428c2ecf20Sopenharmony_cistatic inline void kasan_copy_shadow(pgd_t *pgdir) { }
438c2ecf20Sopenharmony_ci#endif
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#endif
468c2ecf20Sopenharmony_ci#endif
47