Skip to content

Commit de22d21

Browse files
atishp04palmer-dabbelt
authored andcommitted
RISC-V: Add page table dump support for uefi
Extend the current page table dump support in RISC-V to include efi pages as well. Here is the output of efi runtime page table mappings. ---[ UEFI runtime start ]--- 0x0000000020002000-0x0000000020003000 0x00000000be732000 4K PTE D A . . . W R V 0x0000000020018000-0x0000000020019000 0x00000000be738000 4K PTE D A . . . W R V 0x000000002002c000-0x000000002002d000 0x00000000be73c000 4K PTE D A . . . W R V 0x0000000020031000-0x0000000020032000 0x00000000bff61000 4K PTE D A . . X W R V ---[ UEFI runtime end ]--- Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent b91540d commit de22d21

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

arch/riscv/mm/ptdump.c

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (C) 2019 SiFive
44
*/
55

6+
#include <linux/efi.h>
67
#include <linux/init.h>
78
#include <linux/debugfs.h>
89
#include <linux/seq_file.h>
@@ -49,6 +50,14 @@ struct addr_marker {
4950
const char *name;
5051
};
5152

53+
/* Private information for debugfs */
54+
struct ptd_mm_info {
55+
struct mm_struct *mm;
56+
const struct addr_marker *markers;
57+
unsigned long base_addr;
58+
unsigned long end;
59+
};
60+
5261
static struct addr_marker address_markers[] = {
5362
#ifdef CONFIG_KASAN
5463
{KASAN_SHADOW_START, "Kasan shadow start"},
@@ -68,6 +77,28 @@ static struct addr_marker address_markers[] = {
6877
{-1, NULL},
6978
};
7079

80+
static struct ptd_mm_info kernel_ptd_info = {
81+
.mm = &init_mm,
82+
.markers = address_markers,
83+
.base_addr = KERN_VIRT_START,
84+
.end = ULONG_MAX,
85+
};
86+
87+
#ifdef CONFIG_EFI
88+
static struct addr_marker efi_addr_markers[] = {
89+
{ 0, "UEFI runtime start" },
90+
{ SZ_1G, "UEFI runtime end" },
91+
{ -1, NULL }
92+
};
93+
94+
static struct ptd_mm_info efi_ptd_info = {
95+
.mm = &efi_mm,
96+
.markers = efi_addr_markers,
97+
.base_addr = 0,
98+
.end = SZ_2G,
99+
};
100+
#endif
101+
71102
/* Page Table Entry */
72103
struct prot_bits {
73104
u64 mask;
@@ -245,22 +276,22 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr,
245276
}
246277
}
247278

248-
static void ptdump_walk(struct seq_file *s)
279+
static void ptdump_walk(struct seq_file *s, struct ptd_mm_info *pinfo)
249280
{
250281
struct pg_state st = {
251282
.seq = s,
252-
.marker = address_markers,
283+
.marker = pinfo->markers,
253284
.level = -1,
254285
.ptdump = {
255286
.note_page = note_page,
256287
.range = (struct ptdump_range[]) {
257-
{KERN_VIRT_START, ULONG_MAX},
288+
{pinfo->base_addr, pinfo->end},
258289
{0, 0}
259290
}
260291
}
261292
};
262293

263-
ptdump_walk_pgd(&st.ptdump, &init_mm, NULL);
294+
ptdump_walk_pgd(&st.ptdump, pinfo->mm, NULL);
264295
}
265296

266297
void ptdump_check_wx(void)
@@ -293,7 +324,7 @@ void ptdump_check_wx(void)
293324

294325
static int ptdump_show(struct seq_file *m, void *v)
295326
{
296-
ptdump_walk(m);
327+
ptdump_walk(m, m->private);
297328

298329
return 0;
299330
}
@@ -308,8 +339,13 @@ static int ptdump_init(void)
308339
for (j = 0; j < ARRAY_SIZE(pte_bits); j++)
309340
pg_level[i].mask |= pte_bits[j].mask;
310341

311-
debugfs_create_file("kernel_page_tables", 0400, NULL, NULL,
342+
debugfs_create_file("kernel_page_tables", 0400, NULL, &kernel_ptd_info,
312343
&ptdump_fops);
344+
#ifdef CONFIG_EFI
345+
if (efi_enabled(EFI_RUNTIME_SERVICES))
346+
debugfs_create_file("efi_page_tables", 0400, NULL, &efi_ptd_info,
347+
&ptdump_fops);
348+
#endif
313349

314350
return 0;
315351
}

0 commit comments

Comments
 (0)