xref: /linux/arch/s390/include/asm/kasan.h (revision 376b1446153ca67e7028e6b9555d9b17477f568b)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_KASAN_H
3 #define __ASM_KASAN_H
4 
5 #include <asm/pgtable.h>
6 
7 #ifdef CONFIG_KASAN
8 
9 #define KASAN_SHADOW_SCALE_SHIFT 3
10 #define KASAN_SHADOW_SIZE						       \
11 	(_AC(1, UL) << (_REGION1_SHIFT - KASAN_SHADOW_SCALE_SHIFT))
12 #define KASAN_SHADOW_OFFSET	_AC(CONFIG_KASAN_SHADOW_OFFSET, UL)
13 #define KASAN_SHADOW_START	KASAN_SHADOW_OFFSET
14 #define KASAN_SHADOW_END	(KASAN_SHADOW_START + KASAN_SHADOW_SIZE)
15 
16 extern void kasan_early_init(void);
17 
18 /*
19  * Estimate kasan memory requirements, which it will reserve
20  * at the very end of available physical memory. To estimate
21  * that, we take into account that kasan would require
22  * 1/8 of available physical memory (for shadow memory) +
23  * creating page tables for the shadow memory region.
24  * To keep page tables estimates simple take the double of
25  * combined ptes size.
26  *
27  * physmem parameter has to be already adjusted if not entire physical memory
28  * would be used (e.g. due to effect of "mem=" option).
29  */
30 static inline unsigned long kasan_estimate_memory_needs(unsigned long physmem)
31 {
32 	unsigned long kasan_needs;
33 	unsigned long pages;
34 	/* for shadow memory */
35 	kasan_needs = round_up(physmem / 8, PAGE_SIZE);
36 	/* for paging structures */
37 	pages = DIV_ROUND_UP(kasan_needs, PAGE_SIZE);
38 	kasan_needs += DIV_ROUND_UP(pages, _PAGE_ENTRIES) * _PAGE_TABLE_SIZE * 2;
39 
40 	return kasan_needs;
41 }
42 #else
43 static inline void kasan_early_init(void) { }
44 static inline unsigned long kasan_estimate_memory_needs(unsigned long physmem) { return 0; }
45 #endif
46 
47 #endif
48