OSDN Git Service

powerpc/mm: dump segment registers on book3s/32
authorChristophe Leroy <christophe.leroy@c-s.fr>
Fri, 16 Nov 2018 17:06:43 +0000 (17:06 +0000)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 4 Dec 2018 08:45:54 +0000 (19:45 +1100)
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>
arch/powerpc/mm/Makefile
arch/powerpc/mm/dump_sr.c [new file with mode: 0644]

index 53c1ffa..e6c77b7 100644 (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
diff --git a/arch/powerpc/mm/dump_sr.c b/arch/powerpc/mm/dump_sr.c
new file mode 100644 (file)
index 0000000..5018436
--- /dev/null
@@ -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);