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 <christophe.leroy@c-s.fr>
[mpe: Move it under /sys/kernel/debug/powerpc, make sr_init() __init]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
This commit is contained in:
Christophe Leroy 2018-11-16 17:06:43 +00:00 committed by Michael Ellerman
parent b682c86924
commit 0261a508c9
2 changed files with 65 additions and 1 deletions

View File

@ -50,7 +50,7 @@ ifdef CONFIG_PPC_PTDUMP
obj-$(CONFIG_4xx) += dump_linuxpagetables-generic.o
obj-$(CONFIG_PPC_8xx) += dump_linuxpagetables-8xx.o
obj-$(CONFIG_PPC_BOOK3E_MMU) += dump_linuxpagetables-generic.o
obj-$(CONFIG_PPC_BOOK3S_32) += dump_linuxpagetables-generic.o
obj-$(CONFIG_PPC_BOOK3S_32) += dump_linuxpagetables-generic.o dump_sr.o
obj-$(CONFIG_PPC_BOOK3S_64) += dump_linuxpagetables-book3s64.o
endif
obj-$(CONFIG_PPC_HTDUMP) += dump_hashpagetable.o

64
arch/powerpc/mm/dump_sr.c Normal file
View File

@ -0,0 +1,64 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright 2018, Christophe Leroy CS S.I.
* <christophe.leroy@c-s.fr>
*
* This dumps the content of Segment Registers
*/
#include <asm/debugfs.h>
static void seg_show(struct seq_file *m, int i)
{
u32 val = mfsrin(i << 28);
seq_printf(m, "0x%01x0000000-0x%01xfffffff ", i, i);
seq_printf(m, "Kern key %d ", (val >> 30) & 1);
seq_printf(m, "User key %d ", (val >> 29) & 1);
if (val & 0x80000000) {
seq_printf(m, "Device 0x%03x", (val >> 20) & 0x1ff);
seq_printf(m, "-0x%05x", val & 0xfffff);
} else {
if (val & 0x10000000)
seq_puts(m, "No Exec ");
seq_printf(m, "VSID 0x%06x", val & 0xffffff);
}
seq_puts(m, "\n");
}
static int sr_show(struct seq_file *m, void *v)
{
int i;
seq_puts(m, "---[ User Segments ]---\n");
for (i = 0; i < TASK_SIZE >> 28; i++)
seg_show(m, i);
seq_puts(m, "\n---[ Kernel Segments ]---\n");
for (; i < 16; i++)
seg_show(m, i);
return 0;
}
static int sr_open(struct inode *inode, struct file *file)
{
return single_open(file, sr_show, NULL);
}
static const struct file_operations sr_fops = {
.open = sr_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int __init sr_init(void)
{
struct dentry *debugfs_file;
debugfs_file = debugfs_create_file("segment_registers", 0400,
powerpc_debugfs_root, NULL, &sr_fops);
return debugfs_file ? 0 : -ENOMEM;
}
device_initcall(sr_init);