Skip to content

Commit 418b4d5

Browse files
Vasily GorbikAlexander Gordeev
authored andcommitted
s390/boot: Add vmem debugging support
Introduce boot_debug() calls in vmem code to log page table mappings including KASAN shadow mappings for improved early boot debugging. Signed-off-by: Vasily Gorbik <[email protected]> Acked-by: Heiko Carstens <[email protected]> Signed-off-by: Alexander Gordeev <[email protected]>
1 parent a56827e commit 418b4d5

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

arch/s390/boot/vmem.c

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// SPDX-License-Identifier: GPL-2.0
2+
#define boot_fmt(fmt) "vmem: " fmt
23
#include <linux/sched/task.h>
34
#include <linux/pgtable.h>
45
#include <linux/kasan.h>
@@ -32,12 +33,42 @@ enum populate_mode {
3233
POPULATE_IDENTITY,
3334
POPULATE_KERNEL,
3435
#ifdef CONFIG_KASAN
36+
/* KASAN modes should be last and grouped together, see is_kasan_populate_mode() */
3537
POPULATE_KASAN_MAP_SHADOW,
3638
POPULATE_KASAN_ZERO_SHADOW,
3739
POPULATE_KASAN_SHALLOW
3840
#endif
3941
};
4042

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+
4172
static void pgtable_populate(unsigned long addr, unsigned long end, enum populate_mode mode);
4273

4374
#ifdef CONFIG_KASAN
@@ -53,9 +84,12 @@ static pte_t pte_z;
5384

5485
static inline void kasan_populate(unsigned long start, unsigned long end, enum populate_mode mode)
5586
{
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);
5993
}
6094

6195
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
418452
pgd_t *pgd;
419453
p4d_t *p4d;
420454

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+
421462
pgd = pgd_offset(&init_mm, addr);
422463
for (; addr < end; addr = next, pgd++) {
423464
next = pgd_addr_end(addr, end);

0 commit comments

Comments
 (0)