blob: b0dc4abc358911237956c24ed12a3d64d09c4474 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Andrey Ryabinin39d114d2015-10-12 18:52:58 +03002#ifndef __ASM_KASAN_H
3#define __ASM_KASAN_H
4
5#ifndef __ASSEMBLY__
6
Will Deacon83040122015-10-13 14:01:06 +01007#include <linux/linkage.h>
Andrey Ryabinin39d114d2015-10-12 18:52:58 +03008#include <asm/memory.h>
Mark Rutland068a17a2016-01-25 11:45:12 +00009#include <asm/pgtable-types.h>
Andrey Ryabinin39d114d2015-10-12 18:52:58 +030010
Andrey Konovalov3c9e3aa2018-12-28 00:30:16 -080011#define arch_kasan_set_tag(addr, tag) __tag_set(addr, tag)
12#define arch_kasan_reset_tag(addr) __tag_reset(addr)
13#define arch_kasan_get_tag(addr) __tag_get(addr)
14
15#ifdef CONFIG_KASAN
16
Andrey Ryabinin39d114d2015-10-12 18:52:58 +030017/*
18 * KASAN_SHADOW_START: beginning of the kernel virtual addresses.
Andrey Konovalov917538e2018-02-06 15:36:44 -080019 * KASAN_SHADOW_END: KASAN_SHADOW_START + 1/N of kernel virtual addresses,
20 * where N = (1 << KASAN_SHADOW_SCALE_SHIFT).
Steve Capper6bd1d0b2019-08-07 16:55:15 +010021 *
22 * KASAN_SHADOW_OFFSET:
Andrey Ryabinin39d114d2015-10-12 18:52:58 +030023 * This value is used to map an address to the corresponding shadow
24 * address by the following formula:
Andrey Konovalov917538e2018-02-06 15:36:44 -080025 * shadow_addr = (address >> KASAN_SHADOW_SCALE_SHIFT) + KASAN_SHADOW_OFFSET
Andrey Ryabinin39d114d2015-10-12 18:52:58 +030026 *
Andrey Konovalov917538e2018-02-06 15:36:44 -080027 * (1 << (64 - KASAN_SHADOW_SCALE_SHIFT)) shadow addresses that lie in range
28 * [KASAN_SHADOW_OFFSET, KASAN_SHADOW_END) cover all 64-bits of virtual
29 * addresses. So KASAN_SHADOW_OFFSET should satisfy the following equation:
30 * KASAN_SHADOW_OFFSET = KASAN_SHADOW_END -
31 * (1ULL << (64 - KASAN_SHADOW_SCALE_SHIFT))
Andrey Ryabinin39d114d2015-10-12 18:52:58 +030032 */
Steve Capper6bd1d0b2019-08-07 16:55:15 +010033#define _KASAN_SHADOW_START(va) (KASAN_SHADOW_END - (1UL << ((va) - KASAN_SHADOW_SCALE_SHIFT)))
Steve Capper5383cc62019-08-07 16:55:18 +010034#define KASAN_SHADOW_START _KASAN_SHADOW_START(vabits_actual)
Andrey Ryabinin39d114d2015-10-12 18:52:58 +030035
36void kasan_init(void);
Mark Rutland068a17a2016-01-25 11:45:12 +000037void kasan_copy_shadow(pgd_t *pgdir);
Will Deacon83040122015-10-13 14:01:06 +010038asmlinkage void kasan_early_init(void);
Andrey Ryabinin39d114d2015-10-12 18:52:58 +030039
40#else
41static inline void kasan_init(void) { }
Mark Rutland068a17a2016-01-25 11:45:12 +000042static inline void kasan_copy_shadow(pgd_t *pgdir) { }
Andrey Ryabinin39d114d2015-10-12 18:52:58 +030043#endif
44
45#endif
46#endif