hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/arch/x86/mm/debug_pagetables.c
....@@ -1,137 +1,67 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 #include <linux/debugfs.h>
23 #include <linux/efi.h>
34 #include <linux/module.h>
45 #include <linux/seq_file.h>
5
-#include <asm/pgtable.h>
6
+#include <linux/pgtable.h>
67
78 static int ptdump_show(struct seq_file *m, void *v)
89 {
9
- ptdump_walk_pgd_level_debugfs(m, NULL, false);
10
+ ptdump_walk_pgd_level_debugfs(m, &init_mm, false);
1011 return 0;
1112 }
1213
13
-static int ptdump_open(struct inode *inode, struct file *filp)
14
-{
15
- return single_open(filp, ptdump_show, NULL);
16
-}
14
+DEFINE_SHOW_ATTRIBUTE(ptdump);
1715
18
-static const struct file_operations ptdump_fops = {
19
- .owner = THIS_MODULE,
20
- .open = ptdump_open,
21
- .read = seq_read,
22
- .llseek = seq_lseek,
23
- .release = single_release,
24
-};
25
-
26
-static int ptdump_show_curknl(struct seq_file *m, void *v)
16
+static int ptdump_curknl_show(struct seq_file *m, void *v)
2717 {
28
- if (current->mm->pgd) {
29
- down_read(&current->mm->mmap_sem);
30
- ptdump_walk_pgd_level_debugfs(m, current->mm->pgd, false);
31
- up_read(&current->mm->mmap_sem);
32
- }
18
+ if (current->mm->pgd)
19
+ ptdump_walk_pgd_level_debugfs(m, current->mm, false);
3320 return 0;
3421 }
3522
36
-static int ptdump_open_curknl(struct inode *inode, struct file *filp)
37
-{
38
- return single_open(filp, ptdump_show_curknl, NULL);
39
-}
40
-
41
-static const struct file_operations ptdump_curknl_fops = {
42
- .owner = THIS_MODULE,
43
- .open = ptdump_open_curknl,
44
- .read = seq_read,
45
- .llseek = seq_lseek,
46
- .release = single_release,
47
-};
23
+DEFINE_SHOW_ATTRIBUTE(ptdump_curknl);
4824
4925 #ifdef CONFIG_PAGE_TABLE_ISOLATION
50
-static struct dentry *pe_curusr;
51
-
52
-static int ptdump_show_curusr(struct seq_file *m, void *v)
26
+static int ptdump_curusr_show(struct seq_file *m, void *v)
5327 {
54
- if (current->mm->pgd) {
55
- down_read(&current->mm->mmap_sem);
56
- ptdump_walk_pgd_level_debugfs(m, current->mm->pgd, true);
57
- up_read(&current->mm->mmap_sem);
58
- }
28
+ if (current->mm->pgd)
29
+ ptdump_walk_pgd_level_debugfs(m, current->mm, true);
5930 return 0;
6031 }
6132
62
-static int ptdump_open_curusr(struct inode *inode, struct file *filp)
63
-{
64
- return single_open(filp, ptdump_show_curusr, NULL);
65
-}
66
-
67
-static const struct file_operations ptdump_curusr_fops = {
68
- .owner = THIS_MODULE,
69
- .open = ptdump_open_curusr,
70
- .read = seq_read,
71
- .llseek = seq_lseek,
72
- .release = single_release,
73
-};
33
+DEFINE_SHOW_ATTRIBUTE(ptdump_curusr);
7434 #endif
7535
7636 #if defined(CONFIG_EFI) && defined(CONFIG_X86_64)
77
-static struct dentry *pe_efi;
78
-
79
-static int ptdump_show_efi(struct seq_file *m, void *v)
37
+static int ptdump_efi_show(struct seq_file *m, void *v)
8038 {
8139 if (efi_mm.pgd)
82
- ptdump_walk_pgd_level_debugfs(m, efi_mm.pgd, false);
40
+ ptdump_walk_pgd_level_debugfs(m, &efi_mm, false);
8341 return 0;
8442 }
8543
86
-static int ptdump_open_efi(struct inode *inode, struct file *filp)
87
-{
88
- return single_open(filp, ptdump_show_efi, NULL);
89
-}
90
-
91
-static const struct file_operations ptdump_efi_fops = {
92
- .owner = THIS_MODULE,
93
- .open = ptdump_open_efi,
94
- .read = seq_read,
95
- .llseek = seq_lseek,
96
- .release = single_release,
97
-};
44
+DEFINE_SHOW_ATTRIBUTE(ptdump_efi);
9845 #endif
9946
100
-static struct dentry *dir, *pe_knl, *pe_curknl;
47
+static struct dentry *dir;
10148
10249 static int __init pt_dump_debug_init(void)
10350 {
10451 dir = debugfs_create_dir("page_tables", NULL);
105
- if (!dir)
106
- return -ENOMEM;
10752
108
- pe_knl = debugfs_create_file("kernel", 0400, dir, NULL,
109
- &ptdump_fops);
110
- if (!pe_knl)
111
- goto err;
112
-
113
- pe_curknl = debugfs_create_file("current_kernel", 0400,
114
- dir, NULL, &ptdump_curknl_fops);
115
- if (!pe_curknl)
116
- goto err;
53
+ debugfs_create_file("kernel", 0400, dir, NULL, &ptdump_fops);
54
+ debugfs_create_file("current_kernel", 0400, dir, NULL,
55
+ &ptdump_curknl_fops);
11756
11857 #ifdef CONFIG_PAGE_TABLE_ISOLATION
119
- pe_curusr = debugfs_create_file("current_user", 0400,
120
- dir, NULL, &ptdump_curusr_fops);
121
- if (!pe_curusr)
122
- goto err;
58
+ debugfs_create_file("current_user", 0400, dir, NULL,
59
+ &ptdump_curusr_fops);
12360 #endif
124
-
12561 #if defined(CONFIG_EFI) && defined(CONFIG_X86_64)
126
- pe_efi = debugfs_create_file("efi", 0400, dir, NULL, &ptdump_efi_fops);
127
- if (!pe_efi)
128
- goto err;
62
+ debugfs_create_file("efi", 0400, dir, NULL, &ptdump_efi_fops);
12963 #endif
130
-
13164 return 0;
132
-err:
133
- debugfs_remove_recursive(dir);
134
- return -ENOMEM;
13565 }
13666
13767 static void __exit pt_dump_debug_exit(void)