* [PATCH 0/3] arm64/ptdump: Add cmdline 'early_ptdump'
@ 2025-09-10 9:46 Anshuman Khandual
2025-09-10 9:46 ` [PATCH 1/3] arm64/ptdump: Re-organize ptdump_init() Anshuman Khandual
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Anshuman Khandual @ 2025-09-10 9:46 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Anshuman Khandual, Catalin Marinas, Will Deacon, Mark Brown,
Ryan Roberts, Mark Rutland, Ard Biesheuvel, Ritesh Harjani,
linux-kernel, linux-efi
Enable early kernel page table dump for debug purpose when required through
a new kernel command line option 'early_ptdump'. But first this reorganizes
ptdump_init() separating out the debugfs creation, so that it can be called
early on in setup_arch(). This also adds kernel dmesg console print support
for existing pt_dump_seq_[printf|puts]() helpers.
This series applies on v6.17-rc5
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Brown <broonie@kernel.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-efi@vger.kernel.org
Changes in V1:
- Dropped ARM64_PTDUMP_CONSOLE and instead enabled cmdline 'early_ptdump'
Changes in RFC:
https://lore.kernel.org/all/20250818091436.938517-1-anshuman.khandual@arm.com/
Anshuman Khandual (3):
arm64/ptdump: Re-organize ptdump_init()
arm64/ptdump: Enable console output in pt_dump_seq_[printf|puts]()
arm64/ptdump: Add 'early_ptdump' kernel command line option
.../admin-guide/kernel-parameters.txt | 4 ++
arch/arm64/include/asm/ptdump.h | 4 ++
arch/arm64/kernel/setup.c | 3 ++
arch/arm64/mm/ptdump.c | 51 +++++++++++++++----
drivers/firmware/efi/arm-runtime.c | 4 +-
5 files changed, 53 insertions(+), 13 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] arm64/ptdump: Re-organize ptdump_init()
2025-09-10 9:46 [PATCH 0/3] arm64/ptdump: Add cmdline 'early_ptdump' Anshuman Khandual
@ 2025-09-10 9:46 ` Anshuman Khandual
2025-09-10 9:46 ` [PATCH 2/3] arm64/ptdump: Enable console output in pt_dump_seq_[printf|puts]() Anshuman Khandual
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Anshuman Khandual @ 2025-09-10 9:46 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Anshuman Khandual, Catalin Marinas, Will Deacon, Mark Brown,
Ryan Roberts, Mark Rutland, Ard Biesheuvel, Ritesh Harjani,
linux-kernel, linux-efi
Split ptdump_debugfs_register() from ptdump_init() which there after can be
called early on during the boot and also enable dump kernel page table when
required. While here rename ptdump_init() as ptdump_debugfs_init() to avoid
name space collision.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-efi@vger.kernel.org
Suggested-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
arch/arm64/include/asm/ptdump.h | 2 ++
arch/arm64/kernel/setup.c | 2 ++
arch/arm64/mm/ptdump.c | 8 ++++++--
drivers/firmware/efi/arm-runtime.c | 4 ++--
4 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h
index fded5358641f..27e774134e7f 100644
--- a/arch/arm64/include/asm/ptdump.h
+++ b/arch/arm64/include/asm/ptdump.h
@@ -57,6 +57,7 @@ struct ptdump_pg_state {
unsigned long uxn_pages;
};
+void __init ptdump_init(void);
void ptdump_walk(struct seq_file *s, struct ptdump_info *info);
void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
pteval_t val);
@@ -74,6 +75,7 @@ static inline void ptdump_debugfs_register(struct ptdump_info *info,
const char *name) { }
#endif /* CONFIG_PTDUMP_DEBUGFS */
#else
+static inline void __init ptdump_init(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 77c7926a4df6..0a3812c8e177 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -43,6 +43,7 @@
#include <asm/cpu_ops.h>
#include <asm/kasan.h>
#include <asm/numa.h>
+#include <asm/ptdump.h>
#include <asm/rsi.h>
#include <asm/scs.h>
#include <asm/sections.h>
@@ -332,6 +333,7 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p)
arm64_memblock_init();
paging_init();
+ ptdump_init();
acpi_table_upgrade();
diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c
index 421a5de806c6..7c42be62898b 100644
--- a/arch/arm64/mm/ptdump.c
+++ b/arch/arm64/mm/ptdump.c
@@ -367,7 +367,7 @@ bool ptdump_check_wx(void)
}
}
-static int __init ptdump_init(void)
+void __init ptdump_init(void)
{
u64 page_offset = _PAGE_OFFSET(vabits_actual);
u64 vmemmap_start = (u64)virt_to_page((void *)page_offset);
@@ -396,7 +396,11 @@ static int __init ptdump_init(void)
kernel_ptdump_info.base_addr = page_offset;
ptdump_initialize();
+}
+
+static int __init ptdump_debugfs_init(void)
+{
ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables");
return 0;
}
-device_initcall(ptdump_init);
+device_initcall(ptdump_debugfs_init);
diff --git a/drivers/firmware/efi/arm-runtime.c b/drivers/firmware/efi/arm-runtime.c
index 83092d93f36a..3c84e84dc6ea 100644
--- a/drivers/firmware/efi/arm-runtime.c
+++ b/drivers/firmware/efi/arm-runtime.c
@@ -38,14 +38,14 @@ static struct ptdump_info efi_ptdump_info = {
.base_addr = 0,
};
-static int __init ptdump_init(void)
+static int __init ptdump_debugfs_init(void)
{
if (efi_enabled(EFI_RUNTIME_SERVICES))
ptdump_debugfs_register(&efi_ptdump_info, "efi_page_tables");
return 0;
}
-device_initcall(ptdump_init);
+device_initcall(ptdump_debugfs_init);
#endif
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] arm64/ptdump: Enable console output in pt_dump_seq_[printf|puts]()
2025-09-10 9:46 [PATCH 0/3] arm64/ptdump: Add cmdline 'early_ptdump' Anshuman Khandual
2025-09-10 9:46 ` [PATCH 1/3] arm64/ptdump: Re-organize ptdump_init() Anshuman Khandual
@ 2025-09-10 9:46 ` Anshuman Khandual
2025-09-10 9:46 ` [PATCH 3/3] arm64/ptdump: Add 'early_ptdump' kernel command line option Anshuman Khandual
2025-09-18 12:02 ` [PATCH 0/3] arm64/ptdump: Add cmdline 'early_ptdump' Will Deacon
3 siblings, 0 replies; 5+ messages in thread
From: Anshuman Khandual @ 2025-09-10 9:46 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Anshuman Khandual, Catalin Marinas, Will Deacon, Mark Brown,
Ryan Roberts, Mark Rutland, Ard Biesheuvel, Ritesh Harjani,
linux-kernel, linux-efi
Enable console output in pt_dump_seq_[printf|puts]() in order to dump early
kernel page tables when required. CONFIG_DEBUG_WX enabled ptdump_check_wx()
already sets seq file as NULL to avoid all output. Hence let's introduce a
special sentinel named CONSOLE as ((struct seq_file *)-1) which can be used
to identify kernel console output request for early kernel page table dump.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Suggested-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
arch/arm64/mm/ptdump.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c
index 7c42be62898b..c78e6b496dea 100644
--- a/arch/arm64/mm/ptdump.c
+++ b/arch/arm64/mm/ptdump.c
@@ -25,17 +25,26 @@
#include <asm/pgtable-hwdef.h>
#include <asm/ptdump.h>
-
-#define pt_dump_seq_printf(m, fmt, args...) \
-({ \
- if (m) \
- seq_printf(m, fmt, ##args); \
+#define CONSOLE ((struct seq_file *)-1)
+
+#define pt_dump_seq_printf(m, fmt, args...) \
+({ \
+ if (m) { \
+ if (m == CONSOLE) \
+ pr_cont(fmt, ##args); \
+ else \
+ seq_printf(m, fmt, ##args); \
+ } \
})
-#define pt_dump_seq_puts(m, fmt) \
-({ \
- if (m) \
- seq_printf(m, fmt); \
+#define pt_dump_seq_puts(m, fmt) \
+({ \
+ if (m) { \
+ if (m == CONSOLE) \
+ pr_cont(fmt); \
+ else \
+ seq_printf(m, fmt); \
+ } \
})
static const struct ptdump_prot_bits pte_bits[] = {
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] arm64/ptdump: Add 'early_ptdump' kernel command line option
2025-09-10 9:46 [PATCH 0/3] arm64/ptdump: Add cmdline 'early_ptdump' Anshuman Khandual
2025-09-10 9:46 ` [PATCH 1/3] arm64/ptdump: Re-organize ptdump_init() Anshuman Khandual
2025-09-10 9:46 ` [PATCH 2/3] arm64/ptdump: Enable console output in pt_dump_seq_[printf|puts]() Anshuman Khandual
@ 2025-09-10 9:46 ` Anshuman Khandual
2025-09-18 12:02 ` [PATCH 0/3] arm64/ptdump: Add cmdline 'early_ptdump' Will Deacon
3 siblings, 0 replies; 5+ messages in thread
From: Anshuman Khandual @ 2025-09-10 9:46 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Anshuman Khandual, Catalin Marinas, Will Deacon, Mark Brown,
Ryan Roberts, Mark Rutland, Ard Biesheuvel, Ritesh Harjani,
linux-kernel, linux-efi, Jonathan Corbet, Andrew Morton,
linux-doc
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@lwn.net>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-doc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Suggested-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] arm64/ptdump: Add cmdline 'early_ptdump'
2025-09-10 9:46 [PATCH 0/3] arm64/ptdump: Add cmdline 'early_ptdump' Anshuman Khandual
` (2 preceding siblings ...)
2025-09-10 9:46 ` [PATCH 3/3] arm64/ptdump: Add 'early_ptdump' kernel command line option Anshuman Khandual
@ 2025-09-18 12:02 ` Will Deacon
3 siblings, 0 replies; 5+ messages in thread
From: Will Deacon @ 2025-09-18 12:02 UTC (permalink / raw)
To: Anshuman Khandual
Cc: linux-arm-kernel, Catalin Marinas, Mark Brown, Ryan Roberts,
Mark Rutland, Ard Biesheuvel, Ritesh Harjani, linux-kernel,
linux-efi
On Wed, Sep 10, 2025 at 03:16:20PM +0530, Anshuman Khandual wrote:
> Enable early kernel page table dump for debug purpose when required through
> a new kernel command line option 'early_ptdump'. But first this reorganizes
> ptdump_init() separating out the debugfs creation, so that it can be called
> early on in setup_arch(). This also adds kernel dmesg console print support
> for existing pt_dump_seq_[printf|puts]() helpers.
>
> This series applies on v6.17-rc5
>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Ryan Roberts <ryan.roberts@arm.com>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-efi@vger.kernel.org
I'm really not convinced this is particularly useful and I've certainly
never felt the need to have something like it. If you're debugging really
early page-table issues, why you want to rely on all the ptdump
infrastructure to get logs out?
On the other hand, if people do find this useful, then I think it should
be implemented in the core code rather than done behind its back in the
arch code.
Will
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-09-18 12:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-10 9:46 [PATCH 0/3] arm64/ptdump: Add cmdline 'early_ptdump' Anshuman Khandual
2025-09-10 9:46 ` [PATCH 1/3] arm64/ptdump: Re-organize ptdump_init() Anshuman Khandual
2025-09-10 9:46 ` [PATCH 2/3] arm64/ptdump: Enable console output in pt_dump_seq_[printf|puts]() Anshuman Khandual
2025-09-10 9:46 ` [PATCH 3/3] arm64/ptdump: Add 'early_ptdump' kernel command line option Anshuman Khandual
2025-09-18 12:02 ` [PATCH 0/3] arm64/ptdump: Add cmdline 'early_ptdump' Will Deacon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).