1 #include <linux/debugfs.h>
3 #include <linux/module.h>
4 #include <linux/seq_file.h>
5 #include <asm/pgtable.h>
7 static int ptdump_show(struct seq_file *m, void *v)
9 ptdump_walk_pgd_level_debugfs(m, NULL, false);
13 static int ptdump_open(struct inode *inode, struct file *filp)
15 return single_open(filp, ptdump_show, NULL);
18 static const struct file_operations ptdump_fops = {
23 .release = single_release,
26 static int ptdump_show_curknl(struct seq_file *m, void *v)
28 if (current->mm->pgd) {
29 down_read(¤t->mm->mmap_sem);
30 ptdump_walk_pgd_level_debugfs(m, current->mm->pgd, false);
31 up_read(¤t->mm->mmap_sem);
36 static int ptdump_open_curknl(struct inode *inode, struct file *filp)
38 return single_open(filp, ptdump_show_curknl, NULL);
41 static const struct file_operations ptdump_curknl_fops = {
43 .open = ptdump_open_curknl,
46 .release = single_release,
49 #ifdef CONFIG_PAGE_TABLE_ISOLATION
50 static struct dentry *pe_curusr;
52 static int ptdump_show_curusr(struct seq_file *m, void *v)
54 if (current->mm->pgd) {
55 down_read(¤t->mm->mmap_sem);
56 ptdump_walk_pgd_level_debugfs(m, current->mm->pgd, true);
57 up_read(¤t->mm->mmap_sem);
62 static int ptdump_open_curusr(struct inode *inode, struct file *filp)
64 return single_open(filp, ptdump_show_curusr, NULL);
67 static const struct file_operations ptdump_curusr_fops = {
69 .open = ptdump_open_curusr,
72 .release = single_release,
76 #if defined(CONFIG_EFI) && defined(CONFIG_X86_64)
77 static struct dentry *pe_efi;
79 static int ptdump_show_efi(struct seq_file *m, void *v)
82 ptdump_walk_pgd_level_debugfs(m, efi_mm.pgd, false);
86 static int ptdump_open_efi(struct inode *inode, struct file *filp)
88 return single_open(filp, ptdump_show_efi, NULL);
91 static const struct file_operations ptdump_efi_fops = {
93 .open = ptdump_open_efi,
96 .release = single_release,
100 static struct dentry *dir, *pe_knl, *pe_curknl;
102 static int __init pt_dump_debug_init(void)
104 dir = debugfs_create_dir("page_tables", NULL);
108 pe_knl = debugfs_create_file("kernel", 0400, dir, NULL,
113 pe_curknl = debugfs_create_file("current_kernel", 0400,
114 dir, NULL, &ptdump_curknl_fops);
118 #ifdef CONFIG_PAGE_TABLE_ISOLATION
119 pe_curusr = debugfs_create_file("current_user", 0400,
120 dir, NULL, &ptdump_curusr_fops);
125 #if defined(CONFIG_EFI) && defined(CONFIG_X86_64)
126 pe_efi = debugfs_create_file("efi", 0400, dir, NULL, &ptdump_efi_fops);
133 debugfs_remove_recursive(dir);
137 static void __exit pt_dump_debug_exit(void)
139 debugfs_remove_recursive(dir);
142 module_init(pt_dump_debug_init);
143 module_exit(pt_dump_debug_exit);
144 MODULE_LICENSE("GPL");
145 MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>");
146 MODULE_DESCRIPTION("Kernel debugging helper that dumps pagetables");