0001
0002 #include <linux/debugfs.h>
0003 #include <linux/efi.h>
0004 #include <linux/module.h>
0005 #include <linux/seq_file.h>
0006 #include <linux/pgtable.h>
0007
0008 static int ptdump_show(struct seq_file *m, void *v)
0009 {
0010 ptdump_walk_pgd_level_debugfs(m, &init_mm, false);
0011 return 0;
0012 }
0013
0014 DEFINE_SHOW_ATTRIBUTE(ptdump);
0015
0016 static int ptdump_curknl_show(struct seq_file *m, void *v)
0017 {
0018 if (current->mm->pgd)
0019 ptdump_walk_pgd_level_debugfs(m, current->mm, false);
0020 return 0;
0021 }
0022
0023 DEFINE_SHOW_ATTRIBUTE(ptdump_curknl);
0024
0025 #ifdef CONFIG_PAGE_TABLE_ISOLATION
0026 static int ptdump_curusr_show(struct seq_file *m, void *v)
0027 {
0028 if (current->mm->pgd)
0029 ptdump_walk_pgd_level_debugfs(m, current->mm, true);
0030 return 0;
0031 }
0032
0033 DEFINE_SHOW_ATTRIBUTE(ptdump_curusr);
0034 #endif
0035
0036 #if defined(CONFIG_EFI) && defined(CONFIG_X86_64)
0037 static int ptdump_efi_show(struct seq_file *m, void *v)
0038 {
0039 if (efi_mm.pgd)
0040 ptdump_walk_pgd_level_debugfs(m, &efi_mm, false);
0041 return 0;
0042 }
0043
0044 DEFINE_SHOW_ATTRIBUTE(ptdump_efi);
0045 #endif
0046
0047 static struct dentry *dir;
0048
0049 static int __init pt_dump_debug_init(void)
0050 {
0051 dir = debugfs_create_dir("page_tables", NULL);
0052
0053 debugfs_create_file("kernel", 0400, dir, NULL, &ptdump_fops);
0054 debugfs_create_file("current_kernel", 0400, dir, NULL,
0055 &ptdump_curknl_fops);
0056
0057 #ifdef CONFIG_PAGE_TABLE_ISOLATION
0058 debugfs_create_file("current_user", 0400, dir, NULL,
0059 &ptdump_curusr_fops);
0060 #endif
0061 #if defined(CONFIG_EFI) && defined(CONFIG_X86_64)
0062 debugfs_create_file("efi", 0400, dir, NULL, &ptdump_efi_fops);
0063 #endif
0064 return 0;
0065 }
0066
0067 static void __exit pt_dump_debug_exit(void)
0068 {
0069 debugfs_remove_recursive(dir);
0070 }
0071
0072 module_init(pt_dump_debug_init);
0073 module_exit(pt_dump_debug_exit);
0074 MODULE_LICENSE("GPL");
0075 MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>");
0076 MODULE_DESCRIPTION("Kernel debugging helper that dumps pagetables");