Commit | Line | Data |
---|---|---|
09c434b8 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
8609d1b5 | 2 | #include <linux/debugfs.h> |
3ede3417 | 3 | #include <linux/efi.h> |
8609d1b5 KC |
4 | #include <linux/module.h> |
5 | #include <linux/seq_file.h> | |
ca5999fd | 6 | #include <linux/pgtable.h> |
8609d1b5 KC |
7 | |
8 | static int ptdump_show(struct seq_file *m, void *v) | |
9 | { | |
c5cfae12 | 10 | ptdump_walk_pgd_level_debugfs(m, &init_mm, false); |
8609d1b5 KC |
11 | return 0; |
12 | } | |
13 | ||
6848ac7c | 14 | DEFINE_SHOW_ATTRIBUTE(ptdump); |
8609d1b5 | 15 | |
6848ac7c | 16 | static int ptdump_curknl_show(struct seq_file *m, void *v) |
a4b51ef6 | 17 | { |
e47690d7 | 18 | if (current->mm->pgd) |
c5cfae12 | 19 | ptdump_walk_pgd_level_debugfs(m, current->mm, false); |
a4b51ef6 TG |
20 | return 0; |
21 | } | |
22 | ||
6848ac7c | 23 | DEFINE_SHOW_ATTRIBUTE(ptdump_curknl); |
a4b51ef6 TG |
24 | |
25 | #ifdef CONFIG_PAGE_TABLE_ISOLATION | |
6848ac7c | 26 | static int ptdump_curusr_show(struct seq_file *m, void *v) |
a4b51ef6 | 27 | { |
e47690d7 | 28 | if (current->mm->pgd) |
c5cfae12 | 29 | ptdump_walk_pgd_level_debugfs(m, current->mm, true); |
a4b51ef6 TG |
30 | return 0; |
31 | } | |
32 | ||
6848ac7c | 33 | DEFINE_SHOW_ATTRIBUTE(ptdump_curusr); |
a4b51ef6 TG |
34 | #endif |
35 | ||
116fef64 | 36 | #if defined(CONFIG_EFI) && defined(CONFIG_X86_64) |
6848ac7c | 37 | static int ptdump_efi_show(struct seq_file *m, void *v) |
116fef64 | 38 | { |
3ede3417 | 39 | if (efi_mm.pgd) |
c5cfae12 | 40 | ptdump_walk_pgd_level_debugfs(m, &efi_mm, false); |
116fef64 AL |
41 | return 0; |
42 | } | |
43 | ||
6848ac7c | 44 | DEFINE_SHOW_ATTRIBUTE(ptdump_efi); |
116fef64 AL |
45 | #endif |
46 | ||
5dd82ba9 | 47 | static struct dentry *dir; |
8609d1b5 KC |
48 | |
49 | static int __init pt_dump_debug_init(void) | |
50 | { | |
75298aa1 | 51 | dir = debugfs_create_dir("page_tables", NULL); |
a4b51ef6 | 52 | |
5dd82ba9 GKH |
53 | debugfs_create_file("kernel", 0400, dir, NULL, &ptdump_fops); |
54 | debugfs_create_file("current_kernel", 0400, dir, NULL, | |
55 | &ptdump_curknl_fops); | |
a4b51ef6 TG |
56 | |
57 | #ifdef CONFIG_PAGE_TABLE_ISOLATION | |
5dd82ba9 GKH |
58 | debugfs_create_file("current_user", 0400, dir, NULL, |
59 | &ptdump_curusr_fops); | |
a4b51ef6 | 60 | #endif |
116fef64 | 61 | #if defined(CONFIG_EFI) && defined(CONFIG_X86_64) |
5dd82ba9 | 62 | debugfs_create_file("efi", 0400, dir, NULL, &ptdump_efi_fops); |
116fef64 | 63 | #endif |
8609d1b5 KC |
64 | return 0; |
65 | } | |
66 | ||
67 | static void __exit pt_dump_debug_exit(void) | |
68 | { | |
75298aa1 | 69 | debugfs_remove_recursive(dir); |
8609d1b5 KC |
70 | } |
71 | ||
72 | module_init(pt_dump_debug_init); | |
73 | module_exit(pt_dump_debug_exit); | |
8609d1b5 KC |
74 | MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>"); |
75 | MODULE_DESCRIPTION("Kernel debugging helper that dumps pagetables"); |