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 <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>

authored by Atish Patra and committed by Palmer Dabbelt de22d210 b91540d5

+42 -6
+42 -6
arch/riscv/mm/ptdump.c
··· 3 3 * Copyright (C) 2019 SiFive 4 4 */ 5 5 6 + #include <linux/efi.h> 6 7 #include <linux/init.h> 7 8 #include <linux/debugfs.h> 8 9 #include <linux/seq_file.h> ··· 50 49 const char *name; 51 50 }; 52 51 52 + /* Private information for debugfs */ 53 + struct ptd_mm_info { 54 + struct mm_struct *mm; 55 + const struct addr_marker *markers; 56 + unsigned long base_addr; 57 + unsigned long end; 58 + }; 59 + 53 60 static struct addr_marker address_markers[] = { 54 61 #ifdef CONFIG_KASAN 55 62 {KASAN_SHADOW_START, "Kasan shadow start"}, ··· 76 67 {PAGE_OFFSET, "Linear mapping"}, 77 68 {-1, NULL}, 78 69 }; 70 + 71 + static struct ptd_mm_info kernel_ptd_info = { 72 + .mm = &init_mm, 73 + .markers = address_markers, 74 + .base_addr = KERN_VIRT_START, 75 + .end = ULONG_MAX, 76 + }; 77 + 78 + #ifdef CONFIG_EFI 79 + static struct addr_marker efi_addr_markers[] = { 80 + { 0, "UEFI runtime start" }, 81 + { SZ_1G, "UEFI runtime end" }, 82 + { -1, NULL } 83 + }; 84 + 85 + static struct ptd_mm_info efi_ptd_info = { 86 + .mm = &efi_mm, 87 + .markers = efi_addr_markers, 88 + .base_addr = 0, 89 + .end = SZ_2G, 90 + }; 91 + #endif 79 92 80 93 /* Page Table Entry */ 81 94 struct prot_bits { ··· 276 245 } 277 246 } 278 247 279 - static void ptdump_walk(struct seq_file *s) 248 + static void ptdump_walk(struct seq_file *s, struct ptd_mm_info *pinfo) 280 249 { 281 250 struct pg_state st = { 282 251 .seq = s, 283 - .marker = address_markers, 252 + .marker = pinfo->markers, 284 253 .level = -1, 285 254 .ptdump = { 286 255 .note_page = note_page, 287 256 .range = (struct ptdump_range[]) { 288 - {KERN_VIRT_START, ULONG_MAX}, 257 + {pinfo->base_addr, pinfo->end}, 289 258 {0, 0} 290 259 } 291 260 } 292 261 }; 293 262 294 - ptdump_walk_pgd(&st.ptdump, &init_mm, NULL); 263 + ptdump_walk_pgd(&st.ptdump, pinfo->mm, NULL); 295 264 } 296 265 297 266 void ptdump_check_wx(void) ··· 324 293 325 294 static int ptdump_show(struct seq_file *m, void *v) 326 295 { 327 - ptdump_walk(m); 296 + ptdump_walk(m, m->private); 328 297 329 298 return 0; 330 299 } ··· 339 308 for (j = 0; j < ARRAY_SIZE(pte_bits); j++) 340 309 pg_level[i].mask |= pte_bits[j].mask; 341 310 342 - debugfs_create_file("kernel_page_tables", 0400, NULL, NULL, 311 + debugfs_create_file("kernel_page_tables", 0400, NULL, &kernel_ptd_info, 343 312 &ptdump_fops); 313 + #ifdef CONFIG_EFI 314 + if (efi_enabled(EFI_RUNTIME_SERVICES)) 315 + debugfs_create_file("efi_page_tables", 0400, NULL, &efi_ptd_info, 316 + &ptdump_fops); 317 + #endif 344 318 345 319 return 0; 346 320 }