Enable kernel pgtable dump during boot via a new kernel command line option 'early_ptdump'. This calls ptdump_walk() during boot right after ptdump has been initialized with ptdump_init(). Cc: Jonathan Corbet <corbet@xxxxxxx> Cc: Catalin Marinas <catalin.marinas@xxxxxxx> Cc: Will Deacon <will@xxxxxxxxxx> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> Cc: linux-doc@xxxxxxxxxxxxxxx Cc: linux-kernel@xxxxxxxxxxxxxxx Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx Suggested-by: Ryan Roberts <ryan.roberts@xxxxxxx> Signed-off-by: Anshuman Khandual <anshuman.khandual@xxxxxxx> --- Documentation/admin-guide/kernel-parameters.txt | 4 ++++ arch/arm64/include/asm/ptdump.h | 2 ++ arch/arm64/kernel/setup.c | 1 + arch/arm64/mm/ptdump.c | 16 ++++++++++++++++ 4 files changed, 23 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 747a55abf494..f8e916750e2e 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1295,6 +1295,10 @@ Enable debug messages in early_ioremap support. This is useful for tracking down temporary early mappings which are not unmapped. + early_ptdump[=on] + Enable kernel page table dump during boot in current + ptdump format. This helps analyze early boot mapping + kernel regions. earlycon= [KNL,EARLY] Output early console device and options. diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 27e774134e7f..ed30d25ca9de 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -74,8 +74,10 @@ void __init ptdump_debugfs_register(struct ptdump_info *info, const char *name); static inline void ptdump_debugfs_register(struct ptdump_info *info, const char *name) { } #endif /* CONFIG_PTDUMP_DEBUGFS */ +void __init arm64_kernel_pgtable_dump(void); #else static inline void __init ptdump_init(void) { } +static inline void __init arm64_kernel_pgtable_dump(void) { } static inline void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, pteval_t val) { } static inline void note_page_pte(struct ptdump_state *st, unsigned long addr, pte_t pte) { } diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 0a3812c8e177..86bf7607d304 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -361,6 +361,7 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) init_bootcpu_ops(); smp_init_cpus(); smp_build_mpidr_hash(); + arm64_kernel_pgtable_dump(); #ifdef CONFIG_ARM64_SW_TTBR0_PAN /* diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index c78e6b496dea..1624be5160e4 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -407,6 +407,22 @@ void __init ptdump_init(void) ptdump_initialize(); } +static bool early_ptdump __initdata; + +static int __init parse_early_ptdump(char *arg) +{ + if (strcmp(arg, "on") == 0) + early_ptdump = true; + return 0; +} +early_param("early_ptdump", parse_early_ptdump); + +void __init arm64_kernel_pgtable_dump(void) +{ + if (early_ptdump) + ptdump_walk(CONSOLE, &kernel_ptdump_info); +} + static int __init ptdump_debugfs_init(void) { ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables"); -- 2.25.1