Linux 5.7.6
[linux/fpc-iii.git] / arch / x86 / mm / debug_pagetables.c
blob4a3b62f780b4058c2a34c998198a86670e42c3f9
1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/debugfs.h>
3 #include <linux/efi.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, &init_mm, false);
11 return 0;
14 DEFINE_SHOW_ATTRIBUTE(ptdump);
16 static int ptdump_curknl_show(struct seq_file *m, void *v)
18 if (current->mm->pgd)
19 ptdump_walk_pgd_level_debugfs(m, current->mm, false);
20 return 0;
23 DEFINE_SHOW_ATTRIBUTE(ptdump_curknl);
25 #ifdef CONFIG_PAGE_TABLE_ISOLATION
26 static int ptdump_curusr_show(struct seq_file *m, void *v)
28 if (current->mm->pgd)
29 ptdump_walk_pgd_level_debugfs(m, current->mm, true);
30 return 0;
33 DEFINE_SHOW_ATTRIBUTE(ptdump_curusr);
34 #endif
36 #if defined(CONFIG_EFI) && defined(CONFIG_X86_64)
37 static int ptdump_efi_show(struct seq_file *m, void *v)
39 if (efi_mm.pgd)
40 ptdump_walk_pgd_level_debugfs(m, &efi_mm, false);
41 return 0;
44 DEFINE_SHOW_ATTRIBUTE(ptdump_efi);
45 #endif
47 static struct dentry *dir;
49 static int __init pt_dump_debug_init(void)
51 dir = debugfs_create_dir("page_tables", NULL);
53 debugfs_create_file("kernel", 0400, dir, NULL, &ptdump_fops);
54 debugfs_create_file("current_kernel", 0400, dir, NULL,
55 &ptdump_curknl_fops);
57 #ifdef CONFIG_PAGE_TABLE_ISOLATION
58 debugfs_create_file("current_user", 0400, dir, NULL,
59 &ptdump_curusr_fops);
60 #endif
61 #if defined(CONFIG_EFI) && defined(CONFIG_X86_64)
62 debugfs_create_file("efi", 0400, dir, NULL, &ptdump_efi_fops);
63 #endif
64 return 0;
67 static void __exit pt_dump_debug_exit(void)
69 debugfs_remove_recursive(dir);
72 module_init(pt_dump_debug_init);
73 module_exit(pt_dump_debug_exit);
74 MODULE_LICENSE("GPL");
75 MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>");
76 MODULE_DESCRIPTION("Kernel debugging helper that dumps pagetables");