Nick Hu | 8ad8b72 | 2020-01-06 10:38:32 -0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* Copyright (C) 2019 Andes Technology Corporation */ |
| 3 | |
| 4 | #ifndef __ASM_KASAN_H |
| 5 | #define __ASM_KASAN_H |
| 6 | |
| 7 | #ifndef __ASSEMBLY__ |
| 8 | |
| 9 | #ifdef CONFIG_KASAN |
| 10 | |
Alexandre Ghiti | 7899ed2 | 2021-02-08 14:30:14 -0500 | [diff] [blame] | 11 | /* |
| 12 | * The following comment was copied from arm64: |
| 13 | * KASAN_SHADOW_START: beginning of the kernel virtual addresses. |
| 14 | * KASAN_SHADOW_END: KASAN_SHADOW_START + 1/N of kernel virtual addresses, |
| 15 | * where N = (1 << KASAN_SHADOW_SCALE_SHIFT). |
| 16 | * |
| 17 | * KASAN_SHADOW_OFFSET: |
| 18 | * This value is used to map an address to the corresponding shadow |
| 19 | * address by the following formula: |
| 20 | * shadow_addr = (address >> KASAN_SHADOW_SCALE_SHIFT) + KASAN_SHADOW_OFFSET |
| 21 | * |
| 22 | * (1 << (64 - KASAN_SHADOW_SCALE_SHIFT)) shadow addresses that lie in range |
| 23 | * [KASAN_SHADOW_OFFSET, KASAN_SHADOW_END) cover all 64-bits of virtual |
| 24 | * addresses. So KASAN_SHADOW_OFFSET should satisfy the following equation: |
| 25 | * KASAN_SHADOW_OFFSET = KASAN_SHADOW_END - |
| 26 | * (1ULL << (64 - KASAN_SHADOW_SCALE_SHIFT)) |
| 27 | */ |
Nick Hu | 8ad8b72 | 2020-01-06 10:38:32 -0800 | [diff] [blame] | 28 | #define KASAN_SHADOW_SCALE_SHIFT 3 |
| 29 | |
Alexandre Ghiti | 3270bfd | 2021-12-06 11:46:48 +0100 | [diff] [blame] | 30 | #define KASAN_SHADOW_SIZE (UL(1) << ((VA_BITS - 1) - KASAN_SHADOW_SCALE_SHIFT)) |
Alexandre Ghiti | e8a62cc | 2021-12-06 11:46:51 +0100 | [diff] [blame] | 31 | /* |
| 32 | * Depending on the size of the virtual address space, the region may not be |
| 33 | * aligned on PGDIR_SIZE, so force its alignment to ease its population. |
| 34 | */ |
| 35 | #define KASAN_SHADOW_START ((KASAN_SHADOW_END - KASAN_SHADOW_SIZE) & PGDIR_MASK) |
Alexandre Ghiti | f7ae023 | 2021-12-06 11:46:45 +0100 | [diff] [blame] | 36 | #define KASAN_SHADOW_END MODULES_LOWEST_VADDR |
Alexandre Ghiti | 54c5639d | 2021-10-29 06:59:27 +0200 | [diff] [blame] | 37 | #define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL) |
Nick Hu | 8ad8b72 | 2020-01-06 10:38:32 -0800 | [diff] [blame] | 38 | |
| 39 | void kasan_init(void); |
| 40 | asmlinkage void kasan_early_init(void); |
Alexandre Ghiti | 2efad17 | 2021-12-06 11:46:46 +0100 | [diff] [blame] | 41 | void kasan_swapper_init(void); |
Nick Hu | 8ad8b72 | 2020-01-06 10:38:32 -0800 | [diff] [blame] | 42 | |
| 43 | #endif |
| 44 | #endif |
| 45 | #endif /* __ASM_KASAN_H */ |