162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci#ifndef _ASM_X86_KASAN_H 362306a36Sopenharmony_ci#define _ASM_X86_KASAN_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#include <linux/const.h> 662306a36Sopenharmony_ci#define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL) 762306a36Sopenharmony_ci#define KASAN_SHADOW_SCALE_SHIFT 3 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci/* 1062306a36Sopenharmony_ci * Compiler uses shadow offset assuming that addresses start 1162306a36Sopenharmony_ci * from 0. Kernel addresses don't start from 0, so shadow 1262306a36Sopenharmony_ci * for kernel really starts from compiler's shadow offset + 1362306a36Sopenharmony_ci * 'kernel address space start' >> KASAN_SHADOW_SCALE_SHIFT 1462306a36Sopenharmony_ci */ 1562306a36Sopenharmony_ci#define KASAN_SHADOW_START (KASAN_SHADOW_OFFSET + \ 1662306a36Sopenharmony_ci ((-1UL << __VIRTUAL_MASK_SHIFT) >> \ 1762306a36Sopenharmony_ci KASAN_SHADOW_SCALE_SHIFT)) 1862306a36Sopenharmony_ci/* 1962306a36Sopenharmony_ci * 47 bits for kernel address -> (47 - KASAN_SHADOW_SCALE_SHIFT) bits for shadow 2062306a36Sopenharmony_ci * 56 bits for kernel address -> (56 - KASAN_SHADOW_SCALE_SHIFT) bits for shadow 2162306a36Sopenharmony_ci */ 2262306a36Sopenharmony_ci#define KASAN_SHADOW_END (KASAN_SHADOW_START + \ 2362306a36Sopenharmony_ci (1ULL << (__VIRTUAL_MASK_SHIFT - \ 2462306a36Sopenharmony_ci KASAN_SHADOW_SCALE_SHIFT))) 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci#ifndef __ASSEMBLY__ 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci#ifdef CONFIG_KASAN 2962306a36Sopenharmony_civoid __init kasan_early_init(void); 3062306a36Sopenharmony_civoid __init kasan_init(void); 3162306a36Sopenharmony_civoid __init kasan_populate_shadow_for_vaddr(void *va, size_t size, int nid); 3262306a36Sopenharmony_ci#else 3362306a36Sopenharmony_cistatic inline void kasan_early_init(void) { } 3462306a36Sopenharmony_cistatic inline void kasan_init(void) { } 3562306a36Sopenharmony_cistatic inline void kasan_populate_shadow_for_vaddr(void *va, size_t size, 3662306a36Sopenharmony_ci int nid) { } 3762306a36Sopenharmony_ci#endif 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci#endif 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci#endif 42