1
1
// SPDX-License-Identifier: GPL-2.0
2
+ #define boot_fmt (fmt ) "vmem: " fmt
2
3
#include <linux/sched/task.h>
3
4
#include <linux/pgtable.h>
4
5
#include <linux/kasan.h>
@@ -32,12 +33,42 @@ enum populate_mode {
32
33
POPULATE_IDENTITY ,
33
34
POPULATE_KERNEL ,
34
35
#ifdef CONFIG_KASAN
36
+ /* KASAN modes should be last and grouped together, see is_kasan_populate_mode() */
35
37
POPULATE_KASAN_MAP_SHADOW ,
36
38
POPULATE_KASAN_ZERO_SHADOW ,
37
39
POPULATE_KASAN_SHALLOW
38
40
#endif
39
41
};
40
42
43
+ #define POPULATE_MODE_NAME (t ) case POPULATE_ ## t: return #t
44
+ static inline const char * get_populate_mode_name (enum populate_mode t )
45
+ {
46
+ switch (t ) {
47
+ POPULATE_MODE_NAME (NONE );
48
+ POPULATE_MODE_NAME (DIRECT );
49
+ POPULATE_MODE_NAME (LOWCORE );
50
+ POPULATE_MODE_NAME (ABS_LOWCORE );
51
+ POPULATE_MODE_NAME (IDENTITY );
52
+ POPULATE_MODE_NAME (KERNEL );
53
+ #ifdef CONFIG_KASAN
54
+ POPULATE_MODE_NAME (KASAN_MAP_SHADOW );
55
+ POPULATE_MODE_NAME (KASAN_ZERO_SHADOW );
56
+ POPULATE_MODE_NAME (KASAN_SHALLOW );
57
+ #endif
58
+ default :
59
+ return "UNKNOWN" ;
60
+ }
61
+ }
62
+
63
+ static bool is_kasan_populate_mode (enum populate_mode mode )
64
+ {
65
+ #ifdef CONFIG_KASAN
66
+ return mode >= POPULATE_KASAN_MAP_SHADOW ;
67
+ #else
68
+ return false;
69
+ #endif
70
+ }
71
+
41
72
static void pgtable_populate (unsigned long addr , unsigned long end , enum populate_mode mode );
42
73
43
74
#ifdef CONFIG_KASAN
@@ -53,9 +84,12 @@ static pte_t pte_z;
53
84
54
85
static inline void kasan_populate (unsigned long start , unsigned long end , enum populate_mode mode )
55
86
{
56
- start = PAGE_ALIGN_DOWN (__sha (start ));
57
- end = PAGE_ALIGN (__sha (end ));
58
- pgtable_populate (start , end , mode );
87
+ unsigned long sha_start = PAGE_ALIGN_DOWN (__sha (start ));
88
+ unsigned long sha_end = PAGE_ALIGN (__sha (end ));
89
+
90
+ boot_debug ("%-17s 0x%016lx-0x%016lx >> 0x%016lx-0x%016lx\n" , get_populate_mode_name (mode ),
91
+ start , end , sha_start , sha_end );
92
+ pgtable_populate (sha_start , sha_end , mode );
59
93
}
60
94
61
95
static void kasan_populate_shadow (unsigned long kernel_start , unsigned long kernel_end )
@@ -418,6 +452,13 @@ static void pgtable_populate(unsigned long addr, unsigned long end, enum populat
418
452
pgd_t * pgd ;
419
453
p4d_t * p4d ;
420
454
455
+ if (!is_kasan_populate_mode (mode )) {
456
+ boot_debug ("%-17s 0x%016lx-0x%016lx -> 0x%016lx-0x%016lx\n" ,
457
+ get_populate_mode_name (mode ), addr , end ,
458
+ resolve_pa_may_alloc (addr , 0 , mode ),
459
+ resolve_pa_may_alloc (end - 1 , 0 , mode ) + 1 );
460
+ }
461
+
421
462
pgd = pgd_offset (& init_mm , addr );
422
463
for (; addr < end ; addr = next , pgd ++ ) {
423
464
next = pgd_addr_end (addr , end );
0 commit comments