Skip to content

Commit 4ddb9bf

Browse files
labbottctmarinas
authored andcommitted
arm64: dump: Make ptdump debugfs a separate option
ptdump_register currently initializes a set of page table information and registers debugfs. There are uses for the ptdump option without wanting the debugfs options. Split this out to make it a separate option. Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Kees Cook <keescook@chromium.org> Reviewed-by: Mark Rutland <mark.rutland@arm.com> Tested-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Laura Abbott <labbott@redhat.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 0bfc445 commit 4ddb9bf

File tree

6 files changed

+54
-31
lines changed

6 files changed

+54
-31
lines changed

arch/arm64/Kconfig.debug

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ menu "Kernel hacking"
22

33
source "lib/Kconfig.debug"
44

5-
config ARM64_PTDUMP
5+
config ARM64_PTDUMP_CORE
6+
def_bool n
7+
8+
config ARM64_PTDUMP_DEBUGFS
69
bool "Export kernel pagetable layout to userspace via debugfs"
710
depends on DEBUG_KERNEL
11+
select ARM64_PTDUMP_CORE
812
select DEBUG_FS
913
help
1014
Say Y here if you want to show the kernel pagetable layout in a

arch/arm64/include/asm/ptdump.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
#ifndef __ASM_PTDUMP_H
1717
#define __ASM_PTDUMP_H
1818

19-
#ifdef CONFIG_ARM64_PTDUMP
19+
#ifdef CONFIG_ARM64_PTDUMP_CORE
2020

2121
#include <linux/mm_types.h>
22+
#include <linux/seq_file.h>
2223

2324
struct addr_marker {
2425
unsigned long start_address;
@@ -32,13 +33,15 @@ struct ptdump_info {
3233
unsigned long max_addr;
3334
};
3435

35-
int ptdump_register(struct ptdump_info *info, const char *name);
36-
36+
void ptdump_walk_pgd(struct seq_file *s, struct ptdump_info *info);
37+
#ifdef CONFIG_ARM64_PTDUMP_DEBUGFS
38+
int ptdump_debugfs_register(struct ptdump_info *info, const char *name);
3739
#else
38-
static inline int ptdump_register(struct ptdump_info *info, const char *name)
40+
static inline int ptdump_debugfs_register(struct ptdump_info *info,
41+
const char *name)
3942
{
4043
return 0;
4144
}
42-
#endif /* CONFIG_ARM64_PTDUMP */
43-
45+
#endif
46+
#endif /* CONFIG_ARM64_PTDUMP_CORE */
4447
#endif /* __ASM_PTDUMP_H */

arch/arm64/mm/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ obj-y := dma-mapping.o extable.o fault.o init.o \
33
ioremap.o mmap.o pgd.o mmu.o \
44
context.o proc.o pageattr.o
55
obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
6-
obj-$(CONFIG_ARM64_PTDUMP) += dump.o
6+
obj-$(CONFIG_ARM64_PTDUMP_CORE) += dump.o
7+
obj-$(CONFIG_ARM64_PTDUMP_DEBUGFS) += ptdump_debugfs.o
78
obj-$(CONFIG_NUMA) += numa.o
89

910
obj-$(CONFIG_KASAN) += kasan_init.o

arch/arm64/mm/dump.c

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,8 @@ static void walk_pgd(struct pg_state *st, struct mm_struct *mm,
304304
}
305305
}
306306

307-
static int ptdump_show(struct seq_file *m, void *v)
307+
void ptdump_walk_pgd(struct seq_file *m, struct ptdump_info *info)
308308
{
309-
struct ptdump_info *info = m->private;
310309
struct pg_state st = {
311310
.seq = m,
312311
.marker = info->markers,
@@ -315,33 +314,16 @@ static int ptdump_show(struct seq_file *m, void *v)
315314
walk_pgd(&st, info->mm, info->base_addr);
316315

317316
note_page(&st, 0, 0, 0);
318-
return 0;
319317
}
320318

321-
static int ptdump_open(struct inode *inode, struct file *file)
319+
static void ptdump_initialize(void)
322320
{
323-
return single_open(file, ptdump_show, inode->i_private);
324-
}
325-
326-
static const struct file_operations ptdump_fops = {
327-
.open = ptdump_open,
328-
.read = seq_read,
329-
.llseek = seq_lseek,
330-
.release = single_release,
331-
};
332-
333-
int ptdump_register(struct ptdump_info *info, const char *name)
334-
{
335-
struct dentry *pe;
336321
unsigned i, j;
337322

338323
for (i = 0; i < ARRAY_SIZE(pg_level); i++)
339324
if (pg_level[i].bits)
340325
for (j = 0; j < pg_level[i].num; j++)
341326
pg_level[i].mask |= pg_level[i].bits[j].mask;
342-
343-
pe = debugfs_create_file(name, 0400, NULL, info, &ptdump_fops);
344-
return pe ? 0 : -ENOMEM;
345327
}
346328

347329
static struct ptdump_info kernel_ptdump_info = {
@@ -352,6 +334,8 @@ static struct ptdump_info kernel_ptdump_info = {
352334

353335
static int ptdump_init(void)
354336
{
355-
return ptdump_register(&kernel_ptdump_info, "kernel_page_tables");
337+
ptdump_initialize();
338+
return ptdump_debugfs_register(&kernel_ptdump_info,
339+
"kernel_page_tables");
356340
}
357341
device_initcall(ptdump_init);

arch/arm64/mm/ptdump_debugfs.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <linux/debugfs.h>
2+
#include <linux/seq_file.h>
3+
4+
#include <asm/ptdump.h>
5+
6+
static int ptdump_show(struct seq_file *m, void *v)
7+
{
8+
struct ptdump_info *info = m->private;
9+
ptdump_walk_pgd(m, info);
10+
return 0;
11+
}
12+
13+
static int ptdump_open(struct inode *inode, struct file *file)
14+
{
15+
return single_open(file, ptdump_show, inode->i_private);
16+
}
17+
18+
static const struct file_operations ptdump_fops = {
19+
.open = ptdump_open,
20+
.read = seq_read,
21+
.llseek = seq_lseek,
22+
.release = single_release,
23+
};
24+
25+
int ptdump_debugfs_register(struct ptdump_info *info, const char *name)
26+
{
27+
struct dentry *pe;
28+
pe = debugfs_create_file(name, 0400, NULL, info, &ptdump_fops);
29+
return pe ? 0 : -ENOMEM;
30+
31+
}

drivers/firmware/efi/arm-runtime.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static struct mm_struct efi_mm = {
3939
.mmlist = LIST_HEAD_INIT(efi_mm.mmlist),
4040
};
4141

42-
#ifdef CONFIG_ARM64_PTDUMP
42+
#ifdef CONFIG_ARM64_PTDUMP_DEBUGFS
4343
#include <asm/ptdump.h>
4444

4545
static struct ptdump_info efi_ptdump_info = {
@@ -53,7 +53,7 @@ static struct ptdump_info efi_ptdump_info = {
5353

5454
static int __init ptdump_init(void)
5555
{
56-
return ptdump_register(&efi_ptdump_info, "efi_page_tables");
56+
return ptdump_debugfs_register(&efi_ptdump_info, "efi_page_tables");
5757
}
5858
device_initcall(ptdump_init);
5959

0 commit comments

Comments
 (0)