Skip to content

Commit 0261a50

Browse files
chleroympe
authored andcommitted
powerpc/mm: dump segment registers on book3s/32
This patch creates a debugfs file to see content of segment registers # cat /sys/kernel/debug/segment_registers ---[ User Segments ]--- 0x00000000-0x0fffffff Kern key 1 User key 1 VSID 0xade2b0 0x10000000-0x1fffffff Kern key 1 User key 1 VSID 0xade3c1 0x20000000-0x2fffffff Kern key 1 User key 1 VSID 0xade4d2 0x30000000-0x3fffffff Kern key 1 User key 1 VSID 0xade5e3 0x40000000-0x4fffffff Kern key 1 User key 1 VSID 0xade6f4 0x50000000-0x5fffffff Kern key 1 User key 1 VSID 0xade805 0x60000000-0x6fffffff Kern key 1 User key 1 VSID 0xade916 0x70000000-0x7fffffff Kern key 1 User key 1 VSID 0xadea27 0x80000000-0x8fffffff Kern key 1 User key 1 VSID 0xadeb38 0x90000000-0x9fffffff Kern key 1 User key 1 VSID 0xadec49 0xa0000000-0xafffffff Kern key 1 User key 1 VSID 0xaded5a 0xb0000000-0xbfffffff Kern key 1 User key 1 VSID 0xadee6b ---[ Kernel Segments ]--- 0xc0000000-0xcfffffff Kern key 0 User key 1 VSID 0x000ccc 0xd0000000-0xdfffffff Kern key 0 User key 1 VSID 0x000ddd 0xe0000000-0xefffffff Kern key 0 User key 1 VSID 0x000eee 0xf0000000-0xffffffff Kern key 0 User key 1 VSID 0x000fff Signed-off-by: Christophe Leroy <[email protected]> [mpe: Move it under /sys/kernel/debug/powerpc, make sr_init() __init] Signed-off-by: Michael Ellerman <[email protected]>
1 parent b682c86 commit 0261a50

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

arch/powerpc/mm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ ifdef CONFIG_PPC_PTDUMP
5050
obj-$(CONFIG_4xx) += dump_linuxpagetables-generic.o
5151
obj-$(CONFIG_PPC_8xx) += dump_linuxpagetables-8xx.o
5252
obj-$(CONFIG_PPC_BOOK3E_MMU) += dump_linuxpagetables-generic.o
53-
obj-$(CONFIG_PPC_BOOK3S_32) += dump_linuxpagetables-generic.o
53+
obj-$(CONFIG_PPC_BOOK3S_32) += dump_linuxpagetables-generic.o dump_sr.o
5454
obj-$(CONFIG_PPC_BOOK3S_64) += dump_linuxpagetables-book3s64.o
5555
endif
5656
obj-$(CONFIG_PPC_HTDUMP) += dump_hashpagetable.o

arch/powerpc/mm/dump_sr.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* Copyright 2018, Christophe Leroy CS S.I.
4+
5+
*
6+
* This dumps the content of Segment Registers
7+
*/
8+
9+
#include <asm/debugfs.h>
10+
11+
static void seg_show(struct seq_file *m, int i)
12+
{
13+
u32 val = mfsrin(i << 28);
14+
15+
seq_printf(m, "0x%01x0000000-0x%01xfffffff ", i, i);
16+
seq_printf(m, "Kern key %d ", (val >> 30) & 1);
17+
seq_printf(m, "User key %d ", (val >> 29) & 1);
18+
if (val & 0x80000000) {
19+
seq_printf(m, "Device 0x%03x", (val >> 20) & 0x1ff);
20+
seq_printf(m, "-0x%05x", val & 0xfffff);
21+
} else {
22+
if (val & 0x10000000)
23+
seq_puts(m, "No Exec ");
24+
seq_printf(m, "VSID 0x%06x", val & 0xffffff);
25+
}
26+
seq_puts(m, "\n");
27+
}
28+
29+
static int sr_show(struct seq_file *m, void *v)
30+
{
31+
int i;
32+
33+
seq_puts(m, "---[ User Segments ]---\n");
34+
for (i = 0; i < TASK_SIZE >> 28; i++)
35+
seg_show(m, i);
36+
37+
seq_puts(m, "\n---[ Kernel Segments ]---\n");
38+
for (; i < 16; i++)
39+
seg_show(m, i);
40+
41+
return 0;
42+
}
43+
44+
static int sr_open(struct inode *inode, struct file *file)
45+
{
46+
return single_open(file, sr_show, NULL);
47+
}
48+
49+
static const struct file_operations sr_fops = {
50+
.open = sr_open,
51+
.read = seq_read,
52+
.llseek = seq_lseek,
53+
.release = single_release,
54+
};
55+
56+
static int __init sr_init(void)
57+
{
58+
struct dentry *debugfs_file;
59+
60+
debugfs_file = debugfs_create_file("segment_registers", 0400,
61+
powerpc_debugfs_root, NULL, &sr_fops);
62+
return debugfs_file ? 0 : -ENOMEM;
63+
}
64+
device_initcall(sr_init);

0 commit comments

Comments
 (0)