1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/debugfs.h>
4 #include <linux/module.h>
5 #include <linux/seq_file.h>
6 #include <asm/pgtable.h>
8 static int ptdump_show(struct seq_file *m, void *v)
10 ptdump_walk_pgd_level_debugfs(m, NULL, false);
14 DEFINE_SHOW_ATTRIBUTE(ptdump);
16 static int ptdump_curknl_show(struct seq_file *m, void *v)
18 if (current->mm->pgd) {
19 down_read(¤t->mm->mmap_sem);
20 ptdump_walk_pgd_level_debugfs(m, current->mm->pgd, false);
21 up_read(¤t->mm->mmap_sem);
26 DEFINE_SHOW_ATTRIBUTE(ptdump_curknl);
28 #ifdef CONFIG_PAGE_TABLE_ISOLATION
29 static int ptdump_curusr_show(struct seq_file *m, void *v)
31 if (current->mm->pgd) {
32 down_read(¤t->mm->mmap_sem);
33 ptdump_walk_pgd_level_debugfs(m, current->mm->pgd, true);
34 up_read(¤t->mm->mmap_sem);
39 DEFINE_SHOW_ATTRIBUTE(ptdump_curusr);
42 #if defined(CONFIG_EFI) && defined(CONFIG_X86_64)
43 static int ptdump_efi_show(struct seq_file *m, void *v)
46 ptdump_walk_pgd_level_debugfs(m, efi_mm.pgd, false);
50 DEFINE_SHOW_ATTRIBUTE(ptdump_efi);
53 static struct dentry *dir;
55 static int __init pt_dump_debug_init(void)
57 dir = debugfs_create_dir("page_tables", NULL);
59 debugfs_create_file("kernel", 0400, dir, NULL, &ptdump_fops);
60 debugfs_create_file("current_kernel", 0400, dir, NULL,
63 #ifdef CONFIG_PAGE_TABLE_ISOLATION
64 debugfs_create_file("current_user", 0400, dir, NULL,
67 #if defined(CONFIG_EFI) && defined(CONFIG_X86_64)
68 debugfs_create_file("efi", 0400, dir, NULL, &ptdump_efi_fops);
73 static void __exit pt_dump_debug_exit(void)
75 debugfs_remove_recursive(dir);
78 module_init(pt_dump_debug_init);
79 module_exit(pt_dump_debug_exit);
80 MODULE_LICENSE("GPL");
81 MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>");
82 MODULE_DESCRIPTION("Kernel debugging helper that dumps pagetables");