Re: [PATCH 1/2] powerpc/pagetable: Add option to dump the linux pagetables
On 22/03/16 09:04, Rashmica Gupta wrote: > Useful to be able to dump the kernels page tables to check permissions > and memory types - derived from arm64's implementation. > > Add a debugfs file to check the page tables. To use this the PPC_PTDUMP > config option must be selected. > > Signed-off-by: Rashmica Gupta> --- > arch/powerpc/Kconfig.debug | 12 ++ > arch/powerpc/mm/Makefile | 1 + > arch/powerpc/mm/dump_linuxpagetables.c | 377 > + > 3 files changed, 390 insertions(+) > create mode 100644 arch/powerpc/mm/dump_linuxpagetables.c > > diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug > index 638f9ce740f5..26a60effea1a 100644 > --- a/arch/powerpc/Kconfig.debug > +++ b/arch/powerpc/Kconfig.debug > @@ -344,4 +344,16 @@ config FAIL_IOMMU > > If you are unsure, say N. > > +config PPC_PTDUMP > +bool "Export kernel pagetable layout to userspace via debugfs" > +depends on DEBUG_KERNEL > +select DEBUG_FS > +help > + This option exports the state of the kernel pagetables to a > + debugfs file. This is only useful for kernel developers who are > + working in architecture specific areas of the kernel - probably > + not a good idea to enable this feature in a production kernel. > + > + If you are unsure, say N. > + Some minor comments below, but otherwise Acked-by: Balbir Singh > endmenu > diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile > index adfee3f1aeb9..6935c6204fbc 100644 > --- a/arch/powerpc/mm/Makefile > +++ b/arch/powerpc/mm/Makefile > @@ -41,3 +41,4 @@ obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o > obj-$(CONFIG_HIGHMEM)+= highmem.o > obj-$(CONFIG_PPC_COPRO_BASE) += copro_fault.o > obj-$(CONFIG_SPAPR_TCE_IOMMU)+= mmu_context_iommu.o > +obj-$(CONFIG_PPC_PTDUMP) += dump_linuxpagetables.o > diff --git a/arch/powerpc/mm/dump_linuxpagetables.c > b/arch/powerpc/mm/dump_linuxpagetables.c > new file mode 100644 > index ..f97fbfdac4b9 > --- /dev/null > +++ b/arch/powerpc/mm/dump_linuxpagetables.c > @@ -0,0 +1,377 @@ > +/* > + * Copyright 2016, Rashmica Gupta, IBM Corp. > + * > + * This traverses the kernel pagetables and dumps the > + * information about the used sections of memory to > + * /sys/kernel/debug/kernel_pagetables. > + * > + * Derived from the arm64 implementation: > + * Copyright (c) 2014, The Linux Foundation, Laura Abbott. > + * (C) Copyright 2008 Intel Corporation, Arjan van de Ven. > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License > + * as published by the Free Software Foundation; version 2 > + * of the License. > + */ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +struct addr_marker { > + unsigned long start_address; > + const char *name; > +}; > + > +static struct addr_marker address_markers[] = { > + { VMALLOC_START,"vmalloc() Area" }, > + { VMALLOC_END, "vmalloc() End" }, > + { ISA_IO_BASE, "isa I/O start" }, > + { ISA_IO_END, "isa I/O end" }, > + { PHB_IO_BASE, "phb I/O start" }, > + { PHB_IO_END, "phb I/O end" }, > + { IOREMAP_BASE, "I/O remap start" }, > + { IOREMAP_END, "I/O remap end" }, > + { -1, NULL }, > +}; > + > +/* > + * To visualise what is happening, > + * > + * - PTRS_PER_P** = how many entries there are in the corresponding P** > + * - P**_SHIFT = how many bits of the address we use to index into the > + * corresponding P** > + * - P**_SIZE is how much memory we can access through the table - not the > + * size of the table itself. > + * P**={PGD, PUD, PMD, PTE} > + * > + * > + * Each entry of the PGD points to a PUD. Each entry of a PUD points to a > + * PMD. Each entry of a PMD points to a PTE. And every PTE entry points to > + * a page. > + * > + * In the case where there are only 3 levels, the PUD is folded into the > + * PGD: every PUD has only one entry which points to the PMD. > + * > + * The page dumper groups page table entries of the same type into a single > + * description. It uses pg_state to track the range information while > + * iterating over the PTE entries. When the continuity is broken it then > + * dumps out a description of the range - ie PTEs that are virtually > contiguous > + * with the same PTE flags are chunked together. This is to make it clear how > + * different areas of the kernel virtual memory are used. > + * > + */ > +struct pg_state { > + struct seq_file *seq; > + const struct addr_marker *marker; > + unsigned long start_address; > + unsigned level; > + u64 current_flags; > +}; > + > +struct flag_info { > + u64
[v2 PATCH 1/2] powerpc/pagetable: Add option to dump the linux pagetables
Useful to be able to dump the kernels page tables to check permissions and memory types - derived from arm64's implementation. Add a debugfs file to check the page tables. To use this the PPC_PTDUMP config option must be selected. Signed-off-by: Rashmica Gupta--- Do not check for COMBO pages if default page size is 4K. arch/powerpc/Kconfig.debug | 12 + arch/powerpc/mm/Makefile | 1 + arch/powerpc/mm/dump_linuxpagetables.c | 398 + 3 files changed, 411 insertions(+) create mode 100644 arch/powerpc/mm/dump_linuxpagetables.c diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug index 638f9ce740f5..26a60effea1a 100644 --- a/arch/powerpc/Kconfig.debug +++ b/arch/powerpc/Kconfig.debug @@ -344,4 +344,16 @@ config FAIL_IOMMU If you are unsure, say N. +config PPC_PTDUMP +bool "Export kernel pagetable layout to userspace via debugfs" +depends on DEBUG_KERNEL +select DEBUG_FS +help + This option exports the state of the kernel pagetables to a + debugfs file. This is only useful for kernel developers who are + working in architecture specific areas of the kernel - probably + not a good idea to enable this feature in a production kernel. + + If you are unsure, say N. + endmenu diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile index adfee3f1aeb9..6935c6204fbc 100644 --- a/arch/powerpc/mm/Makefile +++ b/arch/powerpc/mm/Makefile @@ -41,3 +41,4 @@ obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o obj-$(CONFIG_HIGHMEM) += highmem.o obj-$(CONFIG_PPC_COPRO_BASE) += copro_fault.o obj-$(CONFIG_SPAPR_TCE_IOMMU) += mmu_context_iommu.o +obj-$(CONFIG_PPC_PTDUMP) += dump_linuxpagetables.o diff --git a/arch/powerpc/mm/dump_linuxpagetables.c b/arch/powerpc/mm/dump_linuxpagetables.c new file mode 100644 index ..566ae4487a19 --- /dev/null +++ b/arch/powerpc/mm/dump_linuxpagetables.c @@ -0,0 +1,398 @@ +/* + * Copyright 2016, Rashmica Gupta, IBM Corp. + * + * This traverses the kernel pagetables and dumps the + * information about the used sections of memory to + * /sys/kernel/debug/kernel_pagetables. + * + * Derived from the arm64 implementation: + * Copyright (c) 2014, The Linux Foundation, Laura Abbott. + * (C) Copyright 2008 Intel Corporation, Arjan van de Ven. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct addr_marker { + unsigned long start_address; + const char *name; +}; + +static struct addr_marker address_markers[] = { + { VMALLOC_START,"vmalloc() Area" }, + { VMALLOC_END, "vmalloc() End" }, + { ISA_IO_BASE, "isa I/O start" }, + { ISA_IO_END, "isa I/O end" }, + { PHB_IO_BASE, "phb I/O start" }, + { PHB_IO_END, "phb I/O end" }, + { IOREMAP_BASE, "I/O remap start" }, + { IOREMAP_END, "I/O remap end" }, + { -1, NULL }, +}; + +/* + * To visualise what is happening, + * + * - PTRS_PER_P** = how many entries there are in the corresponding P** + * - P**_SHIFT = how many bits of the address we use to index into the + * corresponding P** + * - P**_SIZE is how much memory we can access through the table - not the + * size of the table itself. + * P**={PGD, PUD, PMD, PTE} + * + * + * Each entry of the PGD points to a PUD. Each entry of a PUD points to a + * PMD. Each entry of a PMD points to a PTE. And every PTE entry points to + * a page. + * + * In the case where there are only 3 levels, the PUD is folded into the + * PGD: every PUD has only one entry which points to the PMD. + * + * The page dumper groups page table entries of the same type into a single + * description. It uses pg_state to track the range information while + * iterating over the PTE entries. When the continuity is broken it then + * dumps out a description of the range - ie PTEs that are virtually contiguous + * with the same PTE flags are chunked together. This is to make it clear how + * different areas of the kernel virtual memory are used. + * + */ +struct pg_state { + struct seq_file *seq; + const struct addr_marker *marker; + unsigned long start_address; + unsigned level; + u64 current_flags; +}; + +struct flag_info { + u64 mask; + u64 val; + const char *set; + const char *clear; + boolis_val; + int shift; +}; + +static const struct flag_info flag_array[] = { + { + .mask = _PAGE_USER, + .val= _PAGE_USER, +
Re: [PATCH 1/2] powerpc/pagetable: Add option to dump the linux pagetables
Hi Rashmica, [auto build test ERROR on powerpc/next] [also build test ERROR on v4.5 next-20160322] [if your patch is applied to the wrong git tree, please drop us a note to help improving the system] url: https://github.com/0day-ci/linux/commits/Rashmica-Gupta/powerpc-pagetable-Add-option-to-dump-the-linux-pagetables/20160322-060934 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next config: powerpc-allyesconfig (attached as .config) reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross ARCH=powerpc All errors (new ones prefixed by >>): >> arch/powerpc/mm/dump_linuxpagetables.c:148:11: error: '_PAGE_COMBO' >> undeclared here (not in a function) .mask = _PAGE_COMBO, ^ vim +/_PAGE_COMBO +148 arch/powerpc/mm/dump_linuxpagetables.c 142 .clear = "", 143 }, { 144 .mask = _PAGE_BUSY, 145 .val= _PAGE_BUSY, 146 .set= "busy", 147 }, { > 148 .mask = _PAGE_COMBO, 149 .val= _PAGE_COMBO, 150 .set= "combo", 151 }, { --- 0-DAY kernel test infrastructureOpen Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation .config.gz Description: Binary data ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
[PATCH 1/2] powerpc/pagetable: Add option to dump the linux pagetables
Useful to be able to dump the kernels page tables to check permissions and memory types - derived from arm64's implementation. Add a debugfs file to check the page tables. To use this the PPC_PTDUMP config option must be selected. Signed-off-by: Rashmica Gupta--- arch/powerpc/Kconfig.debug | 12 ++ arch/powerpc/mm/Makefile | 1 + arch/powerpc/mm/dump_linuxpagetables.c | 377 + 3 files changed, 390 insertions(+) create mode 100644 arch/powerpc/mm/dump_linuxpagetables.c diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug index 638f9ce740f5..26a60effea1a 100644 --- a/arch/powerpc/Kconfig.debug +++ b/arch/powerpc/Kconfig.debug @@ -344,4 +344,16 @@ config FAIL_IOMMU If you are unsure, say N. +config PPC_PTDUMP +bool "Export kernel pagetable layout to userspace via debugfs" +depends on DEBUG_KERNEL +select DEBUG_FS +help + This option exports the state of the kernel pagetables to a + debugfs file. This is only useful for kernel developers who are + working in architecture specific areas of the kernel - probably + not a good idea to enable this feature in a production kernel. + + If you are unsure, say N. + endmenu diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile index adfee3f1aeb9..6935c6204fbc 100644 --- a/arch/powerpc/mm/Makefile +++ b/arch/powerpc/mm/Makefile @@ -41,3 +41,4 @@ obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o obj-$(CONFIG_HIGHMEM) += highmem.o obj-$(CONFIG_PPC_COPRO_BASE) += copro_fault.o obj-$(CONFIG_SPAPR_TCE_IOMMU) += mmu_context_iommu.o +obj-$(CONFIG_PPC_PTDUMP) += dump_linuxpagetables.o diff --git a/arch/powerpc/mm/dump_linuxpagetables.c b/arch/powerpc/mm/dump_linuxpagetables.c new file mode 100644 index ..f97fbfdac4b9 --- /dev/null +++ b/arch/powerpc/mm/dump_linuxpagetables.c @@ -0,0 +1,377 @@ +/* + * Copyright 2016, Rashmica Gupta, IBM Corp. + * + * This traverses the kernel pagetables and dumps the + * information about the used sections of memory to + * /sys/kernel/debug/kernel_pagetables. + * + * Derived from the arm64 implementation: + * Copyright (c) 2014, The Linux Foundation, Laura Abbott. + * (C) Copyright 2008 Intel Corporation, Arjan van de Ven. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct addr_marker { + unsigned long start_address; + const char *name; +}; + +static struct addr_marker address_markers[] = { + { VMALLOC_START,"vmalloc() Area" }, + { VMALLOC_END, "vmalloc() End" }, + { ISA_IO_BASE, "isa I/O start" }, + { ISA_IO_END, "isa I/O end" }, + { PHB_IO_BASE, "phb I/O start" }, + { PHB_IO_END, "phb I/O end" }, + { IOREMAP_BASE, "I/O remap start" }, + { IOREMAP_END, "I/O remap end" }, + { -1, NULL }, +}; + +/* + * To visualise what is happening, + * + * - PTRS_PER_P** = how many entries there are in the corresponding P** + * - P**_SHIFT = how many bits of the address we use to index into the + * corresponding P** + * - P**_SIZE is how much memory we can access through the table - not the + * size of the table itself. + * P**={PGD, PUD, PMD, PTE} + * + * + * Each entry of the PGD points to a PUD. Each entry of a PUD points to a + * PMD. Each entry of a PMD points to a PTE. And every PTE entry points to + * a page. + * + * In the case where there are only 3 levels, the PUD is folded into the + * PGD: every PUD has only one entry which points to the PMD. + * + * The page dumper groups page table entries of the same type into a single + * description. It uses pg_state to track the range information while + * iterating over the PTE entries. When the continuity is broken it then + * dumps out a description of the range - ie PTEs that are virtually contiguous + * with the same PTE flags are chunked together. This is to make it clear how + * different areas of the kernel virtual memory are used. + * + */ +struct pg_state { + struct seq_file *seq; + const struct addr_marker *marker; + unsigned long start_address; + unsigned level; + u64 current_flags; +}; + +struct flag_info { + u64 mask; + u64 val; + const char *set; + const char *clear; +}; + +static const struct flag_info flag_array[] = { + { + .mask = _PAGE_USER, + .val= _PAGE_USER, + .set= "user", + .clear = "", + }, { + .mask = _PAGE_RW, +