1 #include <linux/debugfs.h>
2 #include <linux/module.h>
3 #include <linux/seq_file.h>
4 #include <asm/pgtable.h>
6 static int ptdump_show(struct seq_file *m, void *v)
8 ptdump_walk_pgd_level_debugfs(m, NULL, false);
12 static int ptdump_open(struct inode *inode, struct file *filp)
14 return single_open(filp, ptdump_show, NULL);
17 static const struct file_operations ptdump_fops = {
22 .release = single_release,
25 static int ptdump_show_curknl(struct seq_file *m, void *v)
27 if (current->mm->pgd) {
28 down_read(¤t->mm->mmap_sem);
29 ptdump_walk_pgd_level_debugfs(m, current->mm->pgd, false);
30 up_read(¤t->mm->mmap_sem);
35 static int ptdump_open_curknl(struct inode *inode, struct file *filp)
37 return single_open(filp, ptdump_show_curknl, NULL);
40 static const struct file_operations ptdump_curknl_fops = {
42 .open = ptdump_open_curknl,
45 .release = single_release,
48 #ifdef CONFIG_PAGE_TABLE_ISOLATION
49 static struct dentry *pe_curusr;
51 static int ptdump_show_curusr(struct seq_file *m, void *v)
53 if (current->mm->pgd) {
54 down_read(¤t->mm->mmap_sem);
55 ptdump_walk_pgd_level_debugfs(m, current->mm->pgd, true);
56 up_read(¤t->mm->mmap_sem);
61 static int ptdump_open_curusr(struct inode *inode, struct file *filp)
63 return single_open(filp, ptdump_show_curusr, NULL);
66 static const struct file_operations ptdump_curusr_fops = {
68 .open = ptdump_open_curusr,
71 .release = single_release,
75 static struct dentry *dir, *pe_knl, *pe_curknl;
77 static int __init pt_dump_debug_init(void)
79 dir = debugfs_create_dir("page_tables", NULL);
83 pe_knl = debugfs_create_file("kernel", 0400, dir, NULL,
88 pe_curknl = debugfs_create_file("current_kernel", 0400,
89 dir, NULL, &ptdump_curknl_fops);
93 #ifdef CONFIG_PAGE_TABLE_ISOLATION
94 pe_curusr = debugfs_create_file("current_user", 0400,
95 dir, NULL, &ptdump_curusr_fops);
101 debugfs_remove_recursive(dir);
105 static void __exit pt_dump_debug_exit(void)
107 debugfs_remove_recursive(dir);
110 module_init(pt_dump_debug_init);
111 module_exit(pt_dump_debug_exit);
112 MODULE_LICENSE("GPL");
113 MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>");
114 MODULE_DESCRIPTION("Kernel debugging helper that dumps pagetables");