* [RFC 0/3] arm64/ptdump: Add ARM64_PTDUMP_CONSOLE
@ 2025-08-18 9:14 Anshuman Khandual
2025-08-18 9:14 ` [RFC 1/3] arm64/ptdump: Re-organize ptdump_init() Anshuman Khandual
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Anshuman Khandual @ 2025-08-18 9:14 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Anshuman Khandual, Catalin Marinas, Will Deacon, Mark Brown,
Ryan Roberts, Mark Rutland, linux-kernel
Enable early kernel page table dump for debug purpose when required through
a new config ARM64_PTDUMP_CONSOLE. But first this reorganizes ptdump_init()
separating out the debugfs creation so that it can be called early on. Then
adds kernel console print support for existing pt_dump_seq_[printf|puts]()
helpers.
This series applies on v6.17-rc2
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: linux-kernel@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Anshuman Khandual (3):
arm64/ptdump: Re-organize ptdump_init()
arm64/ptdump: Enable console output in pt_dump_seq_[printf|puts]()
arm64/ptdump: Add ARM64_PTDUMP_CONSOLE
arch/arm64/Kconfig.debug | 12 +++++++++
arch/arm64/include/asm/ptdump.h | 9 +++++++
arch/arm64/kernel/setup.c | 3 +++
arch/arm64/mm/ptdump.c | 42 ++++++++++++++++++++++--------
drivers/firmware/efi/arm-runtime.c | 4 +--
5 files changed, 57 insertions(+), 13 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [RFC 1/3] arm64/ptdump: Re-organize ptdump_init()
2025-08-18 9:14 [RFC 0/3] arm64/ptdump: Add ARM64_PTDUMP_CONSOLE Anshuman Khandual
@ 2025-08-18 9:14 ` Anshuman Khandual
2025-08-18 9:14 ` [RFC 2/3] arm64/ptdump: Enable console output in pt_dump_seq_[printf|puts]() Anshuman Khandual
2025-08-18 9:14 ` [RFC 3/3] arm64/ptdump: Add ARM64_PTDUMP_CONSOLE Anshuman Khandual
2 siblings, 0 replies; 8+ messages in thread
From: Anshuman Khandual @ 2025-08-18 9:14 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Anshuman Khandual, Catalin Marinas, Will Deacon, Mark Brown,
Ryan Roberts, Mark Rutland, linux-kernel
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.
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] 8+ messages in thread
* [RFC 2/3] arm64/ptdump: Enable console output in pt_dump_seq_[printf|puts]()
2025-08-18 9:14 [RFC 0/3] arm64/ptdump: Add ARM64_PTDUMP_CONSOLE Anshuman Khandual
2025-08-18 9:14 ` [RFC 1/3] arm64/ptdump: Re-organize ptdump_init() Anshuman Khandual
@ 2025-08-18 9:14 ` Anshuman Khandual
2025-08-18 9:14 ` [RFC 3/3] arm64/ptdump: Add ARM64_PTDUMP_CONSOLE Anshuman Khandual
2 siblings, 0 replies; 8+ messages in thread
From: Anshuman Khandual @ 2025-08-18 9:14 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Anshuman Khandual, Catalin Marinas, Will Deacon, Mark Brown,
Ryan Roberts, Mark Rutland, linux-kernel
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 any output. Hence just 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.
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] 8+ messages in thread
* [RFC 3/3] arm64/ptdump: Add ARM64_PTDUMP_CONSOLE
2025-08-18 9:14 [RFC 0/3] arm64/ptdump: Add ARM64_PTDUMP_CONSOLE Anshuman Khandual
2025-08-18 9:14 ` [RFC 1/3] arm64/ptdump: Re-organize ptdump_init() Anshuman Khandual
2025-08-18 9:14 ` [RFC 2/3] arm64/ptdump: Enable console output in pt_dump_seq_[printf|puts]() Anshuman Khandual
@ 2025-08-18 9:14 ` Anshuman Khandual
2025-08-26 15:46 ` Ritesh Harjani
2 siblings, 1 reply; 8+ messages in thread
From: Anshuman Khandual @ 2025-08-18 9:14 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Anshuman Khandual, Catalin Marinas, Will Deacon, Mark Brown,
Ryan Roberts, Mark Rutland, linux-kernel
Enable early kernel page table dump for debug purpose when required via new
config ARM64_PDUMP_CONSOLE. This calls existing ptdump_walk() early on just
after ptdump has been initialized with ptdump_init().
Suggested-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
arch/arm64/Kconfig.debug | 12 ++++++++++++
arch/arm64/include/asm/ptdump.h | 7 +++++++
arch/arm64/kernel/setup.c | 1 +
arch/arm64/mm/ptdump.c | 7 +++++++
4 files changed, 27 insertions(+)
diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug
index 265c4461031f..0f8af0dd0f4c 100644
--- a/arch/arm64/Kconfig.debug
+++ b/arch/arm64/Kconfig.debug
@@ -20,4 +20,16 @@ config ARM64_RELOC_TEST
depends on m
tristate "Relocation testing module"
+config ARM64_PTDUMP_CONSOLE
+ bool "Dump early kernel page table"
+ depends on DEBUG_KERNEL
+ depends on ARCH_HAS_PTDUMP
+ select PTDUMP
+ help
+ Enable this option to dump early kernel page table entries during
+ boot using the PTDUMP framework. This helps in examining kernel's
+ page table mapping entries and their attributes etc.
+
+ If in doubt, say N.
+
source "drivers/hwtracing/coresight/Kconfig"
diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h
index 27e774134e7f..81dc53ca9643 100644
--- a/arch/arm64/include/asm/ptdump.h
+++ b/arch/arm64/include/asm/ptdump.h
@@ -74,8 +74,15 @@ 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 */
+
+#ifdef CONFIG_ARM64_PTDUMP_CONSOLE
+void __init arm64_kernel_pgtable_dump(void);
+#else
+static inline void __init arm64_kernel_pgtable_dump(void) { }
+#endif /* CONFIG_ARM64_PTDUMP_CONSOLE */
#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..f6d22462add6 100644
--- a/arch/arm64/mm/ptdump.c
+++ b/arch/arm64/mm/ptdump.c
@@ -407,6 +407,13 @@ void __init ptdump_init(void)
ptdump_initialize();
}
+#ifdef CONFIG_ARM64_PTDUMP_CONSOLE
+void __init arm64_kernel_pgtable_dump(void)
+{
+ ptdump_walk(CONSOLE, &kernel_ptdump_info);
+}
+#endif
+
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] 8+ messages in thread
* Re: [RFC 3/3] arm64/ptdump: Add ARM64_PTDUMP_CONSOLE
2025-08-18 9:14 ` [RFC 3/3] arm64/ptdump: Add ARM64_PTDUMP_CONSOLE Anshuman Khandual
@ 2025-08-26 15:46 ` Ritesh Harjani
2025-08-28 2:22 ` Anshuman Khandual
0 siblings, 1 reply; 8+ messages in thread
From: Ritesh Harjani @ 2025-08-26 15:46 UTC (permalink / raw)
To: Anshuman Khandual, linux-arm-kernel
Cc: Anshuman Khandual, Catalin Marinas, Will Deacon, Mark Brown,
Ryan Roberts, Mark Rutland, linux-kernel
Anshuman Khandual <anshuman.khandual@arm.com> writes:
> Enable early kernel page table dump for debug purpose when required via new
> config ARM64_PDUMP_CONSOLE. This calls existing ptdump_walk() early on just
> after ptdump has been initialized with ptdump_init().
I happen to stumble upon this while looking for something else related
to ptdump and was curious to understand where this will be really
useful?
So instead of dumping it via cat /sys/kernel/debug/kernel_page_tables,
this will dump at early boot during arch setup and before start_kernel().
I was curious, since this anyway gets enabled only in debug kernels.
There we can always just boot with minimal busybox image which can jump
to shell quickly and dump the kernel page tables, correct?
Also is ARM64_PTDUMP_CONSOLE config option added on purpose? A kernel cmdline
like early_ptdump=yes|1|true could come much handy, right?
(Since I am fixing few issues on powerpc ptdump - hence was just curious
to know whether this can come useful for me too or not :) )
Thanks!
-ritesh
>
> Suggested-by: Ryan Roberts <ryan.roberts@arm.com>
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> ---
> arch/arm64/Kconfig.debug | 12 ++++++++++++
> arch/arm64/include/asm/ptdump.h | 7 +++++++
> arch/arm64/kernel/setup.c | 1 +
> arch/arm64/mm/ptdump.c | 7 +++++++
> 4 files changed, 27 insertions(+)
>
> diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug
> index 265c4461031f..0f8af0dd0f4c 100644
> --- a/arch/arm64/Kconfig.debug
> +++ b/arch/arm64/Kconfig.debug
> @@ -20,4 +20,16 @@ config ARM64_RELOC_TEST
> depends on m
> tristate "Relocation testing module"
>
> +config ARM64_PTDUMP_CONSOLE
> + bool "Dump early kernel page table"
> + depends on DEBUG_KERNEL
> + depends on ARCH_HAS_PTDUMP
> + select PTDUMP
> + help
> + Enable this option to dump early kernel page table entries during
> + boot using the PTDUMP framework. This helps in examining kernel's
> + page table mapping entries and their attributes etc.
> +
> + If in doubt, say N.
> +
> source "drivers/hwtracing/coresight/Kconfig"
> diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h
> index 27e774134e7f..81dc53ca9643 100644
> --- a/arch/arm64/include/asm/ptdump.h
> +++ b/arch/arm64/include/asm/ptdump.h
> @@ -74,8 +74,15 @@ 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 */
> +
> +#ifdef CONFIG_ARM64_PTDUMP_CONSOLE
> +void __init arm64_kernel_pgtable_dump(void);
> +#else
> +static inline void __init arm64_kernel_pgtable_dump(void) { }
> +#endif /* CONFIG_ARM64_PTDUMP_CONSOLE */
> #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..f6d22462add6 100644
> --- a/arch/arm64/mm/ptdump.c
> +++ b/arch/arm64/mm/ptdump.c
> @@ -407,6 +407,13 @@ void __init ptdump_init(void)
> ptdump_initialize();
> }
>
> +#ifdef CONFIG_ARM64_PTDUMP_CONSOLE
> +void __init arm64_kernel_pgtable_dump(void)
> +{
> + ptdump_walk(CONSOLE, &kernel_ptdump_info);
> +}
> +#endif
> +
> static int __init ptdump_debugfs_init(void)
> {
> ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables");
> --
> 2.25.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFC 3/3] arm64/ptdump: Add ARM64_PTDUMP_CONSOLE
2025-08-26 15:46 ` Ritesh Harjani
@ 2025-08-28 2:22 ` Anshuman Khandual
2025-08-29 3:42 ` Ritesh Harjani
0 siblings, 1 reply; 8+ messages in thread
From: Anshuman Khandual @ 2025-08-28 2:22 UTC (permalink / raw)
To: Ritesh Harjani (IBM), linux-arm-kernel
Cc: Catalin Marinas, Will Deacon, Mark Brown, Ryan Roberts,
Mark Rutland, linux-kernel
On 26/08/25 9:16 PM, Ritesh Harjani (IBM) wrote:
> Anshuman Khandual <anshuman.khandual@arm.com> writes:
>
>> Enable early kernel page table dump for debug purpose when required via new
>> config ARM64_PDUMP_CONSOLE. This calls existing ptdump_walk() early on just
>> after ptdump has been initialized with ptdump_init().
>
> I happen to stumble upon this while looking for something else related
> to ptdump and was curious to understand where this will be really
> useful?
>
> So instead of dumping it via cat /sys/kernel/debug/kernel_page_tables,
> this will dump at early boot during arch setup and before start_kernel().
Right, primarily before vmalloc() space gets crowded. Also this provides
an opportunity to do a diff between early boot and after boot kernel page
table states.
>
> I was curious, since this anyway gets enabled only in debug kernels.
> There we can always just boot with minimal busybox image which can jump
> to shell quickly and dump the kernel page tables, correct?
Here the kernel page table dump could happen earlier than that as well.
>
> Also is ARM64_PTDUMP_CONSOLE config option added on purpose? A kernel cmdline
> like early_ptdump=yes|1|true could come much handy, right?
Currently this is just for arm64 platform but could be enabled in general
for other platforms as well. Yes, early_ptdump=yes|1|true will be useful
as well. ARM64_PTDUMP_CONSOLE just build guards the additional code. But
if required cmdline option "early_ptdump=" could just provide the runtime
switch and then this could always be built enabled on CONFIG_PTDUMP.
>
> (Since I am fixing few issues on powerpc ptdump - hence was just curious
> to know whether this can come useful for me too or not :) )
This feature could be extended in general to other platforms. Let me know
if you find this useful for powerpc.
>
> Thanks!
> -ritesh
>
>>
>> Suggested-by: Ryan Roberts <ryan.roberts@arm.com>
>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>> ---
>> arch/arm64/Kconfig.debug | 12 ++++++++++++
>> arch/arm64/include/asm/ptdump.h | 7 +++++++
>> arch/arm64/kernel/setup.c | 1 +
>> arch/arm64/mm/ptdump.c | 7 +++++++
>> 4 files changed, 27 insertions(+)
>>
>> diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug
>> index 265c4461031f..0f8af0dd0f4c 100644
>> --- a/arch/arm64/Kconfig.debug
>> +++ b/arch/arm64/Kconfig.debug
>> @@ -20,4 +20,16 @@ config ARM64_RELOC_TEST
>> depends on m
>> tristate "Relocation testing module"
>>
>> +config ARM64_PTDUMP_CONSOLE
>> + bool "Dump early kernel page table"
>> + depends on DEBUG_KERNEL
>> + depends on ARCH_HAS_PTDUMP
>> + select PTDUMP
>> + help
>> + Enable this option to dump early kernel page table entries during
>> + boot using the PTDUMP framework. This helps in examining kernel's
>> + page table mapping entries and their attributes etc.
>> +
>> + If in doubt, say N.
>> +
>> source "drivers/hwtracing/coresight/Kconfig"
>> diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h
>> index 27e774134e7f..81dc53ca9643 100644
>> --- a/arch/arm64/include/asm/ptdump.h
>> +++ b/arch/arm64/include/asm/ptdump.h
>> @@ -74,8 +74,15 @@ 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 */
>> +
>> +#ifdef CONFIG_ARM64_PTDUMP_CONSOLE
>> +void __init arm64_kernel_pgtable_dump(void);
>> +#else
>> +static inline void __init arm64_kernel_pgtable_dump(void) { }
>> +#endif /* CONFIG_ARM64_PTDUMP_CONSOLE */
>> #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..f6d22462add6 100644
>> --- a/arch/arm64/mm/ptdump.c
>> +++ b/arch/arm64/mm/ptdump.c
>> @@ -407,6 +407,13 @@ void __init ptdump_init(void)
>> ptdump_initialize();
>> }
>>
>> +#ifdef CONFIG_ARM64_PTDUMP_CONSOLE
>> +void __init arm64_kernel_pgtable_dump(void)
>> +{
>> + ptdump_walk(CONSOLE, &kernel_ptdump_info);
>> +}
>> +#endif
>> +
>> static int __init ptdump_debugfs_init(void)
>> {
>> ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables");
>> --
>> 2.25.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFC 3/3] arm64/ptdump: Add ARM64_PTDUMP_CONSOLE
2025-08-28 2:22 ` Anshuman Khandual
@ 2025-08-29 3:42 ` Ritesh Harjani
2025-08-29 6:12 ` Anshuman Khandual
0 siblings, 1 reply; 8+ messages in thread
From: Ritesh Harjani @ 2025-08-29 3:42 UTC (permalink / raw)
To: Anshuman Khandual, linux-arm-kernel
Cc: Catalin Marinas, Will Deacon, Mark Brown, Ryan Roberts,
Mark Rutland, linux-kernel
Anshuman Khandual <anshuman.khandual@arm.com> writes:
> On 26/08/25 9:16 PM, Ritesh Harjani (IBM) wrote:
>> Anshuman Khandual <anshuman.khandual@arm.com> writes:
>>
>>> Enable early kernel page table dump for debug purpose when required via new
>>> config ARM64_PDUMP_CONSOLE. This calls existing ptdump_walk() early on just
>>> after ptdump has been initialized with ptdump_init().
>>
>> I happen to stumble upon this while looking for something else related
>> to ptdump and was curious to understand where this will be really
>> useful?
>>
>> So instead of dumping it via cat /sys/kernel/debug/kernel_page_tables,
>> this will dump at early boot during arch setup and before start_kernel().
>
> Right, primarily before vmalloc() space gets crowded. Also this provides
> an opportunity to do a diff between early boot and after boot kernel page
> table states.
Just want to understand this better - the diff here will mainly show the
new page table entries for the remaining layout which will get populated
in start_kernel() right? The existing mappings created during
setup_arch() won't get changed right?
>>
>> I was curious, since this anyway gets enabled only in debug kernels.
>> There we can always just boot with minimal busybox image which can jump
>> to shell quickly and dump the kernel page tables, correct?
>
> Here the kernel page table dump could happen earlier than that as well.
>>
>> Also is ARM64_PTDUMP_CONSOLE config option added on purpose? A kernel cmdline
>> like early_ptdump=yes|1|true could come much handy, right?
>
> Currently this is just for arm64 platform but could be enabled in general
> for other platforms as well. Yes, early_ptdump=yes|1|true will be useful
> as well. ARM64_PTDUMP_CONSOLE just build guards the additional code. But
> if required cmdline option "early_ptdump=" could just provide the runtime
> switch and then this could always be built enabled on CONFIG_PTDUMP.
>>
>> (Since I am fixing few issues on powerpc ptdump - hence was just curious
>> to know whether this can come useful for me too or not :) )
>
> This feature could be extended in general to other platforms. Let me know
> if you find this useful for powerpc.
Sure - as of now I don't have a direct usecase. But let me try to do
an early page table dump by taking some inspiration from your patch to
see if this adds value for powerpc case or not.
Thanks for sharing the info.
-ritesh
>>
>> Thanks!
>> -ritesh
>>
>>>
>>> Suggested-by: Ryan Roberts <ryan.roberts@arm.com>
>>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>>> ---
>>> arch/arm64/Kconfig.debug | 12 ++++++++++++
>>> arch/arm64/include/asm/ptdump.h | 7 +++++++
>>> arch/arm64/kernel/setup.c | 1 +
>>> arch/arm64/mm/ptdump.c | 7 +++++++
>>> 4 files changed, 27 insertions(+)
>>>
>>> diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug
>>> index 265c4461031f..0f8af0dd0f4c 100644
>>> --- a/arch/arm64/Kconfig.debug
>>> +++ b/arch/arm64/Kconfig.debug
>>> @@ -20,4 +20,16 @@ config ARM64_RELOC_TEST
>>> depends on m
>>> tristate "Relocation testing module"
>>>
>>> +config ARM64_PTDUMP_CONSOLE
>>> + bool "Dump early kernel page table"
>>> + depends on DEBUG_KERNEL
>>> + depends on ARCH_HAS_PTDUMP
>>> + select PTDUMP
>>> + help
>>> + Enable this option to dump early kernel page table entries during
>>> + boot using the PTDUMP framework. This helps in examining kernel's
>>> + page table mapping entries and their attributes etc.
>>> +
>>> + If in doubt, say N.
>>> +
>>> source "drivers/hwtracing/coresight/Kconfig"
>>> diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h
>>> index 27e774134e7f..81dc53ca9643 100644
>>> --- a/arch/arm64/include/asm/ptdump.h
>>> +++ b/arch/arm64/include/asm/ptdump.h
>>> @@ -74,8 +74,15 @@ 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 */
>>> +
>>> +#ifdef CONFIG_ARM64_PTDUMP_CONSOLE
>>> +void __init arm64_kernel_pgtable_dump(void);
>>> +#else
>>> +static inline void __init arm64_kernel_pgtable_dump(void) { }
>>> +#endif /* CONFIG_ARM64_PTDUMP_CONSOLE */
>>> #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..f6d22462add6 100644
>>> --- a/arch/arm64/mm/ptdump.c
>>> +++ b/arch/arm64/mm/ptdump.c
>>> @@ -407,6 +407,13 @@ void __init ptdump_init(void)
>>> ptdump_initialize();
>>> }
>>>
>>> +#ifdef CONFIG_ARM64_PTDUMP_CONSOLE
>>> +void __init arm64_kernel_pgtable_dump(void)
>>> +{
>>> + ptdump_walk(CONSOLE, &kernel_ptdump_info);
>>> +}
>>> +#endif
>>> +
>>> static int __init ptdump_debugfs_init(void)
>>> {
>>> ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables");
>>> --
>>> 2.25.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFC 3/3] arm64/ptdump: Add ARM64_PTDUMP_CONSOLE
2025-08-29 3:42 ` Ritesh Harjani
@ 2025-08-29 6:12 ` Anshuman Khandual
0 siblings, 0 replies; 8+ messages in thread
From: Anshuman Khandual @ 2025-08-29 6:12 UTC (permalink / raw)
To: Ritesh Harjani (IBM), linux-arm-kernel
Cc: Catalin Marinas, Will Deacon, Mark Brown, Ryan Roberts,
Mark Rutland, linux-kernel
On 29/08/25 9:12 AM, Ritesh Harjani (IBM) wrote:
> Anshuman Khandual <anshuman.khandual@arm.com> writes:
>
>> On 26/08/25 9:16 PM, Ritesh Harjani (IBM) wrote:
>>> Anshuman Khandual <anshuman.khandual@arm.com> writes:
>>>
>>>> Enable early kernel page table dump for debug purpose when required via new
>>>> config ARM64_PDUMP_CONSOLE. This calls existing ptdump_walk() early on just
>>>> after ptdump has been initialized with ptdump_init().
>>>
>>> I happen to stumble upon this while looking for something else related
>>> to ptdump and was curious to understand where this will be really
>>> useful?
>>>
>>> So instead of dumping it via cat /sys/kernel/debug/kernel_page_tables,
>>> this will dump at early boot during arch setup and before start_kernel().
>>
>> Right, primarily before vmalloc() space gets crowded. Also this provides
>> an opportunity to do a diff between early boot and after boot kernel page
>> table states.
>
> Just want to understand this better - the diff here will mainly show the
> new page table entries for the remaining layout which will get populated
> in start_kernel() right? The existing mappings created during
> setup_arch() won't get changed right?
Correct.
>
>>>
>>> I was curious, since this anyway gets enabled only in debug kernels.
>>> There we can always just boot with minimal busybox image which can jump
>>> to shell quickly and dump the kernel page tables, correct?
>>
>> Here the kernel page table dump could happen earlier than that as well.
>>>
>>> Also is ARM64_PTDUMP_CONSOLE config option added on purpose? A kernel cmdline
>>> like early_ptdump=yes|1|true could come much handy, right?
>>
>> Currently this is just for arm64 platform but could be enabled in general
>> for other platforms as well. Yes, early_ptdump=yes|1|true will be useful
>> as well. ARM64_PTDUMP_CONSOLE just build guards the additional code. But
>> if required cmdline option "early_ptdump=" could just provide the runtime
>> switch and then this could always be built enabled on CONFIG_PTDUMP.
>>>
>>> (Since I am fixing few issues on powerpc ptdump - hence was just curious
>>> to know whether this can come useful for me too or not :) )
>>
>> This feature could be extended in general to other platforms. Let me know
>> if you find this useful for powerpc.
>
> Sure - as of now I don't have a direct usecase. But let me try to do
> an early page table dump by taking some inspiration from your patch to
> see if this adds value for powerpc case or not.
Sure, please do let us know how that goes.
> > Thanks for sharing the info.
>
> -ritesh
>
>>>
>>> Thanks!
>>> -ritesh
>>>
>>>>
>>>> Suggested-by: Ryan Roberts <ryan.roberts@arm.com>
>>>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>>>> ---
>>>> arch/arm64/Kconfig.debug | 12 ++++++++++++
>>>> arch/arm64/include/asm/ptdump.h | 7 +++++++
>>>> arch/arm64/kernel/setup.c | 1 +
>>>> arch/arm64/mm/ptdump.c | 7 +++++++
>>>> 4 files changed, 27 insertions(+)
>>>>
>>>> diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug
>>>> index 265c4461031f..0f8af0dd0f4c 100644
>>>> --- a/arch/arm64/Kconfig.debug
>>>> +++ b/arch/arm64/Kconfig.debug
>>>> @@ -20,4 +20,16 @@ config ARM64_RELOC_TEST
>>>> depends on m
>>>> tristate "Relocation testing module"
>>>>
>>>> +config ARM64_PTDUMP_CONSOLE
>>>> + bool "Dump early kernel page table"
>>>> + depends on DEBUG_KERNEL
>>>> + depends on ARCH_HAS_PTDUMP
>>>> + select PTDUMP
>>>> + help
>>>> + Enable this option to dump early kernel page table entries during
>>>> + boot using the PTDUMP framework. This helps in examining kernel's
>>>> + page table mapping entries and their attributes etc.
>>>> +
>>>> + If in doubt, say N.
>>>> +
>>>> source "drivers/hwtracing/coresight/Kconfig"
>>>> diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h
>>>> index 27e774134e7f..81dc53ca9643 100644
>>>> --- a/arch/arm64/include/asm/ptdump.h
>>>> +++ b/arch/arm64/include/asm/ptdump.h
>>>> @@ -74,8 +74,15 @@ 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 */
>>>> +
>>>> +#ifdef CONFIG_ARM64_PTDUMP_CONSOLE
>>>> +void __init arm64_kernel_pgtable_dump(void);
>>>> +#else
>>>> +static inline void __init arm64_kernel_pgtable_dump(void) { }
>>>> +#endif /* CONFIG_ARM64_PTDUMP_CONSOLE */
>>>> #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..f6d22462add6 100644
>>>> --- a/arch/arm64/mm/ptdump.c
>>>> +++ b/arch/arm64/mm/ptdump.c
>>>> @@ -407,6 +407,13 @@ void __init ptdump_init(void)
>>>> ptdump_initialize();
>>>> }
>>>>
>>>> +#ifdef CONFIG_ARM64_PTDUMP_CONSOLE
>>>> +void __init arm64_kernel_pgtable_dump(void)
>>>> +{
>>>> + ptdump_walk(CONSOLE, &kernel_ptdump_info);
>>>> +}
>>>> +#endif
>>>> +
>>>> static int __init ptdump_debugfs_init(void)
>>>> {
>>>> ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables");
>>>> --
>>>> 2.25.1
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-08-29 6:19 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-18 9:14 [RFC 0/3] arm64/ptdump: Add ARM64_PTDUMP_CONSOLE Anshuman Khandual
2025-08-18 9:14 ` [RFC 1/3] arm64/ptdump: Re-organize ptdump_init() Anshuman Khandual
2025-08-18 9:14 ` [RFC 2/3] arm64/ptdump: Enable console output in pt_dump_seq_[printf|puts]() Anshuman Khandual
2025-08-18 9:14 ` [RFC 3/3] arm64/ptdump: Add ARM64_PTDUMP_CONSOLE Anshuman Khandual
2025-08-26 15:46 ` Ritesh Harjani
2025-08-28 2:22 ` Anshuman Khandual
2025-08-29 3:42 ` Ritesh Harjani
2025-08-29 6:12 ` Anshuman Khandual
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).