Message ID | 20160929213257.30505-2-labbott@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Hi, On Thu, Sep 29, 2016 at 02:32:55PM -0700, Laura Abbott wrote: > 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. > > Signed-off-by: Laura Abbott <labbott@redhat.com> > --- > arch/arm64/Kconfig.debug | 6 +++++- > arch/arm64/include/asm/ptdump.h | 15 +++++++++++++-- > arch/arm64/mm/Makefile | 3 ++- > arch/arm64/mm/dump.c | 30 +++++++++--------------------- > arch/arm64/mm/ptdump_debugfs.c | 33 +++++++++++++++++++++++++++++++++ > 5 files changed, 62 insertions(+), 25 deletions(-) > create mode 100644 arch/arm64/mm/ptdump_debugfs.c As a heads-up, Ard has new ARM64_PTUMP user under drivers/firmware/efi queued up in the EFI tree, which will also need fixing up. See commit d80448ac92b72051 ("efi/arm64: Add debugfs node to dump UEFI runtime page tables") [1]. [...] > +#include <linux/seq_file.h> > #include <linux/mm_types.h> Nit: please keep headers in alphabetical order. > -static void walk_pgd(struct pg_state *st, struct mm_struct *mm, > +static void __walk_pgd(struct pg_state *st, struct mm_struct *mm, Can we leave this name as-is? We didn't change walk_{pud,pmd,pte}, so this is inconsistent, and we haven't reused the name. [...] > +int ptdump_register(struct ptdump_info *info, const char *name) > +{ > + ptdump_initialize(info); > + return ptdump_debugfs_create(info, name); > } It feels like a layering violation to have the core ptdump code call the debugfs ptdump code. Is there some reason this has to live here? Other than the above points, this looks good to me. Thanks, Mark. [1] https://git.kernel.org/cgit/linux/kernel/git/mfleming/efi.git/commit/?h=next&id=9d80448ac92b720512c415265597d349d8b5c3e8
On 09/29/2016 05:13 PM, Mark Rutland wrote: > Hi, > > On Thu, Sep 29, 2016 at 02:32:55PM -0700, Laura Abbott wrote: >> 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. >> >> Signed-off-by: Laura Abbott <labbott@redhat.com> >> --- >> arch/arm64/Kconfig.debug | 6 +++++- >> arch/arm64/include/asm/ptdump.h | 15 +++++++++++++-- >> arch/arm64/mm/Makefile | 3 ++- >> arch/arm64/mm/dump.c | 30 +++++++++--------------------- >> arch/arm64/mm/ptdump_debugfs.c | 33 +++++++++++++++++++++++++++++++++ >> 5 files changed, 62 insertions(+), 25 deletions(-) >> create mode 100644 arch/arm64/mm/ptdump_debugfs.c > > As a heads-up, Ard has new ARM64_PTUMP user under drivers/firmware/efi queued > up in the EFI tree, which will also need fixing up. See commit d80448ac92b72051 > ("efi/arm64: Add debugfs node to dump UEFI runtime page tables") [1]. > > [...] > I'll take a look at that, thanks for the pointer! >> +#include <linux/seq_file.h> >> #include <linux/mm_types.h> > > Nit: please keep headers in alphabetical order. > >> -static void walk_pgd(struct pg_state *st, struct mm_struct *mm, >> +static void __walk_pgd(struct pg_state *st, struct mm_struct *mm, > > Can we leave this name as-is? We didn't change walk_{pud,pmd,pte}, so this is > inconsistent, and we haven't reused the name. > Yes, I think this is a relic of earlier refactoring attempts. > [...] > >> +int ptdump_register(struct ptdump_info *info, const char *name) >> +{ >> + ptdump_initialize(info); >> + return ptdump_debugfs_create(info, name); >> } > > It feels like a layering violation to have the core ptdump code call the > debugfs ptdump code. Is there some reason this has to live here? > Which 'this' are you referring to here? Are you suggesting moving the ptdump_register elsewhere or moving the debugfs create elsewhere? > Other than the above points, this looks good to me. > > Thanks, > Mark. > > [1] https://git.kernel.org/cgit/linux/kernel/git/mfleming/efi.git/commit/?h=next&id=9d80448ac92b720512c415265597d349d8b5c3e8 >
On Thu, Sep 29, 2016 at 05:31:09PM -0700, Laura Abbott wrote: > On 09/29/2016 05:13 PM, Mark Rutland wrote: > >On Thu, Sep 29, 2016 at 02:32:55PM -0700, Laura Abbott wrote: > >>+int ptdump_register(struct ptdump_info *info, const char *name) > >>+{ > >>+ ptdump_initialize(info); > >>+ return ptdump_debugfs_create(info, name); > >> } > > > >It feels like a layering violation to have the core ptdump code call the > >debugfs ptdump code. Is there some reason this has to live here? > > Which 'this' are you referring to here? Are you suggesting moving > the ptdump_register elsewhere or moving the debugfs create elsewhere? Sorry, I should have worded that better. I meant moving ptdump_register into ptdump_debugfs.c, perhaps renamed to make it clear it's debugfs-specific. We could instead update existing users to call ptdump_debugfs_create() directly, and have that call ptdump_initialize(), which could itself become a staic inline in a header. Thanks, Mark.
On 09/29/2016 05:48 PM, Mark Rutland wrote: > On Thu, Sep 29, 2016 at 05:31:09PM -0700, Laura Abbott wrote: >> On 09/29/2016 05:13 PM, Mark Rutland wrote: >>> On Thu, Sep 29, 2016 at 02:32:55PM -0700, Laura Abbott wrote: >>>> +int ptdump_register(struct ptdump_info *info, const char *name) >>>> +{ >>>> + ptdump_initialize(info); >>>> + return ptdump_debugfs_create(info, name); >>>> } >>> >>> It feels like a layering violation to have the core ptdump code call the >>> debugfs ptdump code. Is there some reason this has to live here? >> >> Which 'this' are you referring to here? Are you suggesting moving >> the ptdump_register elsewhere or moving the debugfs create elsewhere? > > Sorry, I should have worded that better. > > I meant moving ptdump_register into ptdump_debugfs.c, perhaps renamed to make it > clear it's debugfs-specific. > > We could instead update existing users to call ptdump_debugfs_create() > directly, and have that call ptdump_initialize(), which could itself become a > staic inline in a header. Ah okay, I see what you are suggesting. ptdump_initialize should still happen regardless of debugfs status though so I guess ptdump_debugfs_create would just get turned into just ptdump_initialize which seems a little unclear. I'll come up with some other shed colors^W^Wfunction names. Thanks, Laura
On Thu, Sep 29, 2016 at 06:11:44PM -0700, Laura Abbott wrote: > On 09/29/2016 05:48 PM, Mark Rutland wrote: > >On Thu, Sep 29, 2016 at 05:31:09PM -0700, Laura Abbott wrote: > >>On 09/29/2016 05:13 PM, Mark Rutland wrote: > >>>On Thu, Sep 29, 2016 at 02:32:55PM -0700, Laura Abbott wrote: > >>>>+int ptdump_register(struct ptdump_info *info, const char *name) > >>>>+{ > >>>>+ ptdump_initialize(info); > >>>>+ return ptdump_debugfs_create(info, name); > >>>>} > >I meant moving ptdump_register into ptdump_debugfs.c, perhaps renamed to make it > >clear it's debugfs-specific. > > > >We could instead update existing users to call ptdump_debugfs_create() > >directly, and have that call ptdump_initialize(), which could itself become a > >staic inline in a header. > > Ah okay, I see what you are suggesting. ptdump_initialize should still > happen regardless of debugfs status though so I guess ptdump_debugfs_create > would just get turned into just ptdump_initialize > which seems a little unclear. I'll come up with some other shed > colors^W^Wfunction names. Cheers! FWIW, given ptsump_initialize() is only going to be called with the ptdump core and debugfs code, I'm not all that concerned by what it's called. A few leading underscores is about the only thing that comes to mind, but even as-is I think it should be fine. Thanks, Mark.
diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug index 0cc758c..9015f02 100644 --- a/arch/arm64/Kconfig.debug +++ b/arch/arm64/Kconfig.debug @@ -2,9 +2,13 @@ menu "Kernel hacking" source "lib/Kconfig.debug" -config ARM64_PTDUMP +config ARM64_PTDUMP_CORE + def_bool n + +config ARM64_PTDUMP_DEBUGFS bool "Export kernel pagetable layout to userspace via debugfs" depends on DEBUG_KERNEL + select ARM64_PTDUMP_CORE select DEBUG_FS help Say Y here if you want to show the kernel pagetable layout in a diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 07b8ed0..b18a62c 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -16,8 +16,9 @@ #ifndef __ASM_PTDUMP_H #define __ASM_PTDUMP_H -#ifdef CONFIG_ARM64_PTDUMP +#ifdef CONFIG_ARM64_PTDUMP_CORE +#include <linux/seq_file.h> #include <linux/mm_types.h> struct addr_marker { @@ -33,12 +34,22 @@ struct ptdump_info { }; int ptdump_register(struct ptdump_info *info, const char *name); +void ptdump_walk_pgd(struct seq_file *s, struct ptdump_info *info); +#ifdef CONFIG_ARM64_PTDUMP_DEBUGFS +int ptdump_debugfs_create(struct ptdump_info *info, const char *name); +#else +static inline int ptdump_debugfs_create(struct ptdump_info *info, + const char *name) +{ + return 0; +} +#endif #else static inline int ptdump_register(struct ptdump_info *info, const char *name) { return 0; } -#endif /* CONFIG_ARM64_PTDUMP */ +#endif /* CONFIG_ARM64_PTDUMP_CORE */ #endif /* __ASM_PTDUMP_H */ diff --git a/arch/arm64/mm/Makefile b/arch/arm64/mm/Makefile index 54bb209..e703fb9 100644 --- a/arch/arm64/mm/Makefile +++ b/arch/arm64/mm/Makefile @@ -3,7 +3,8 @@ obj-y := dma-mapping.o extable.o fault.o init.o \ ioremap.o mmap.o pgd.o mmu.o \ context.o proc.o pageattr.o obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o -obj-$(CONFIG_ARM64_PTDUMP) += dump.o +obj-$(CONFIG_ARM64_PTDUMP_CORE) += dump.o +obj-$(CONFIG_ARM64_PTDUMP_DEBUGFS) += ptdump_debugfs.o obj-$(CONFIG_NUMA) += numa.o obj-$(CONFIG_KASAN) += kasan_init.o diff --git a/arch/arm64/mm/dump.c b/arch/arm64/mm/dump.c index 9c3e75d..29e0838 100644 --- a/arch/arm64/mm/dump.c +++ b/arch/arm64/mm/dump.c @@ -286,7 +286,7 @@ static void walk_pud(struct pg_state *st, pgd_t *pgd, unsigned long start) } } -static void walk_pgd(struct pg_state *st, struct mm_struct *mm, +static void __walk_pgd(struct pg_state *st, struct mm_struct *mm, unsigned long start) { pgd_t *pgd = pgd_offset(mm, 0UL); @@ -304,44 +304,32 @@ static void walk_pgd(struct pg_state *st, struct mm_struct *mm, } } -static int ptdump_show(struct seq_file *m, void *v) +void ptdump_walk_pgd(struct seq_file *m, struct ptdump_info *info) { - struct ptdump_info *info = m->private; struct pg_state st = { .seq = m, .marker = info->markers, }; - walk_pgd(&st, info->mm, info->base_addr); + __walk_pgd(&st, info->mm, info->base_addr); note_page(&st, 0, 0, 0); - return 0; } -static int ptdump_open(struct inode *inode, struct file *file) +static void ptdump_initialize(struct ptdump_info *info) { - return single_open(file, ptdump_show, inode->i_private); -} - -static const struct file_operations ptdump_fops = { - .open = ptdump_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -int ptdump_register(struct ptdump_info *info, const char *name) -{ - struct dentry *pe; unsigned i, j; for (i = 0; i < ARRAY_SIZE(pg_level); i++) if (pg_level[i].bits) for (j = 0; j < pg_level[i].num; j++) pg_level[i].mask |= pg_level[i].bits[j].mask; +} - pe = debugfs_create_file(name, 0400, NULL, info, &ptdump_fops); - return pe ? 0 : -ENOMEM; +int ptdump_register(struct ptdump_info *info, const char *name) +{ + ptdump_initialize(info); + return ptdump_debugfs_create(info, name); } static struct ptdump_info kernel_ptdump_info = { diff --git a/arch/arm64/mm/ptdump_debugfs.c b/arch/arm64/mm/ptdump_debugfs.c new file mode 100644 index 0000000..03e161f --- /dev/null +++ b/arch/arm64/mm/ptdump_debugfs.c @@ -0,0 +1,33 @@ +#include <linux/debugfs.h> +#include <linux/seq_file.h> + +#include <asm/ptdump.h> + +static int ptdump_show(struct seq_file *m, void *v) +{ + struct ptdump_info *info = m->private; + ptdump_walk_pgd(m, info); + return 0; +} + +static int ptdump_open(struct inode *inode, struct file *file) +{ + return single_open(file, ptdump_show, inode->i_private); +} + +static const struct file_operations ptdump_fops = { + .open = ptdump_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +int ptdump_debugfs_create(struct ptdump_info *info, const char *name) +{ + struct dentry *pe; + pe = debugfs_create_file(name, 0400, NULL, info, &ptdump_fops); + return pe ? 0 : -ENOMEM; + +} + +
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. Signed-off-by: Laura Abbott <labbott@redhat.com> --- arch/arm64/Kconfig.debug | 6 +++++- arch/arm64/include/asm/ptdump.h | 15 +++++++++++++-- arch/arm64/mm/Makefile | 3 ++- arch/arm64/mm/dump.c | 30 +++++++++--------------------- arch/arm64/mm/ptdump_debugfs.c | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 25 deletions(-) create mode 100644 arch/arm64/mm/ptdump_debugfs.c