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 * Copyright (C) 2019 SiFive 4 */ 5 6 #include <linux/init.h> 7 #include <linux/debugfs.h> 8 #include <linux/seq_file.h> ··· 50 const char *name; 51 }; 52 53 static struct addr_marker address_markers[] = { 54 #ifdef CONFIG_KASAN 55 {KASAN_SHADOW_START, "Kasan shadow start"}, ··· 76 {PAGE_OFFSET, "Linear mapping"}, 77 {-1, NULL}, 78 }; 79 80 /* Page Table Entry */ 81 struct prot_bits { ··· 276 } 277 } 278 279 - static void ptdump_walk(struct seq_file *s) 280 { 281 struct pg_state st = { 282 .seq = s, 283 - .marker = address_markers, 284 .level = -1, 285 .ptdump = { 286 .note_page = note_page, 287 .range = (struct ptdump_range[]) { 288 - {KERN_VIRT_START, ULONG_MAX}, 289 {0, 0} 290 } 291 } 292 }; 293 294 - ptdump_walk_pgd(&st.ptdump, &init_mm, NULL); 295 } 296 297 void ptdump_check_wx(void) ··· 324 325 static int ptdump_show(struct seq_file *m, void *v) 326 { 327 - ptdump_walk(m); 328 329 return 0; 330 } ··· 339 for (j = 0; j < ARRAY_SIZE(pte_bits); j++) 340 pg_level[i].mask |= pte_bits[j].mask; 341 342 - debugfs_create_file("kernel_page_tables", 0400, NULL, NULL, 343 &ptdump_fops); 344 345 return 0; 346 }
··· 3 * Copyright (C) 2019 SiFive 4 */ 5 6 + #include <linux/efi.h> 7 #include <linux/init.h> 8 #include <linux/debugfs.h> 9 #include <linux/seq_file.h> ··· 49 const char *name; 50 }; 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 + 60 static struct addr_marker address_markers[] = { 61 #ifdef CONFIG_KASAN 62 {KASAN_SHADOW_START, "Kasan shadow start"}, ··· 67 {PAGE_OFFSET, "Linear mapping"}, 68 {-1, NULL}, 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 92 93 /* Page Table Entry */ 94 struct prot_bits { ··· 245 } 246 } 247 248 + static void ptdump_walk(struct seq_file *s, struct ptd_mm_info *pinfo) 249 { 250 struct pg_state st = { 251 .seq = s, 252 + .marker = pinfo->markers, 253 .level = -1, 254 .ptdump = { 255 .note_page = note_page, 256 .range = (struct ptdump_range[]) { 257 + {pinfo->base_addr, pinfo->end}, 258 {0, 0} 259 } 260 } 261 }; 262 263 + ptdump_walk_pgd(&st.ptdump, pinfo->mm, NULL); 264 } 265 266 void ptdump_check_wx(void) ··· 293 294 static int ptdump_show(struct seq_file *m, void *v) 295 { 296 + ptdump_walk(m, m->private); 297 298 return 0; 299 } ··· 308 for (j = 0; j < ARRAY_SIZE(pte_bits); j++) 309 pg_level[i].mask |= pte_bits[j].mask; 310 311 + debugfs_create_file("kernel_page_tables", 0400, NULL, &kernel_ptd_info, 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 318 319 return 0; 320 }