From nobody Thu Oct 2 21:58:18 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71290245005; Wed, 10 Sep 2025 09:46:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757497603; cv=none; b=Nho85TPYDyaqJoqa6G8GqXMgDgzyvimQXUnDSCkGOdi0LanZOS1AdVRz3fsF/sdxdgKM27SPGME7hNGSNIlpmS4I83CXhNN8iENNhIooJ+B2SGr8XSz9D68La+zv7Xhx+bi7p/FBlt/PqHHOOFeH0NKk8xDtBM43KSxtHpBtvKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757497603; c=relaxed/simple; bh=zKcHjDfjBiEI9vc1dnbqF+VbIa8mY2JWaa4I9KS6lbw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pechU0IZHl6VmJHzdER9cDbBYaCgo0j7IbkSsZBchDxCObzFdKfUokkP5GPdGBl8TWgLu0hJEmgmIwQjPpWMOTpPVtvVyue2Qm3uMaFLs764mrt68zGekNBWVLtbheE+bP/d8n2ktld/UAs7Xwo5WBP+0SZ/cNqpDcGoOUwPFE8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6A1C916F8; Wed, 10 Sep 2025 02:46:32 -0700 (PDT) Received: from a076716.blr.arm.com (a076716.blr.arm.com [10.164.21.47]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5687D3F63F; Wed, 10 Sep 2025 02:46:36 -0700 (PDT) From: Anshuman Khandual To: linux-arm-kernel@lists.infradead.org Cc: Anshuman Khandual , Catalin Marinas , Will Deacon , Mark Brown , Ryan Roberts , Mark Rutland , Ard Biesheuvel , Ritesh Harjani , linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH 1/3] arm64/ptdump: Re-organize ptdump_init() Date: Wed, 10 Sep 2025 15:16:21 +0530 Message-Id: <20250910094623.2356282-2-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250910094623.2356282-1-anshuman.khandual@arm.com> References: <20250910094623.2356282-1-anshuman.khandual@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Cc: Will Deacon Cc: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Cc: linux-efi@vger.kernel.org Suggested-by: Ryan Roberts Signed-off-by: Anshuman Khandual --- 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/ptdum= p.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; }; =20 +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 add= r, int level, pteval_t val) { } static inline void note_page_pte(struct ptdump_state *st, unsigned long ad= dr, 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 #include #include +#include #include #include #include @@ -332,6 +333,7 @@ void __init __no_sanitize_address setup_arch(char **cmd= line_p) arm64_memblock_init(); =20 paging_init(); + ptdump_init(); =20 acpi_table_upgrade(); =20 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) } } =20 -static int __init ptdump_init(void) +void __init ptdump_init(void) { u64 page_offset =3D _PAGE_OFFSET(vabits_actual); u64 vmemmap_start =3D (u64)virt_to_page((void *)page_offset); @@ -396,7 +396,11 @@ static int __init ptdump_init(void) kernel_ptdump_info.base_addr =3D page_offset; =20 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 =3D { .base_addr =3D 0, }; =20 -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"); =20 return 0; } -device_initcall(ptdump_init); +device_initcall(ptdump_debugfs_init); =20 #endif =20 --=20 2.25.1 From nobody Thu Oct 2 21:58:18 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 740272C0272; Wed, 10 Sep 2025 09:46:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757497608; cv=none; b=eSCALAFp/TuWimDt2RmmEWRoQ8wq5LifuaXfhKd/ZLYRZjjwg1QhCREVQnZmRpg0thSZ5B+KKcP+xCZ7EwVjtvye0rul5FBP3feJQ/izH7HyRACttctUvQ2/iYDmwZOHh7bxC90DRoU2zd8DhinCMq+Acnv7Jp9s1pwfDSYgadM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757497608; c=relaxed/simple; bh=ogZAHzDejeGowGzC8WuXgZtgM9HJGsCDsh+LyWS9kYI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dSXS8U+P3yesVNvYH5G8VXi2KJEltUWu7xp1pwfbQcGjVh8yDI50dDYeExQOgx9YjV352zN2kkfTtHiVdw9B+OZL6KDRETVMxyDsX1oriep0y/ghpMRQbZR8CLcizJY4IYPA0hoToGgADzDBTnYE0JS/AmeaZqyxVWJBO4jDJTc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8B44516F8; Wed, 10 Sep 2025 02:46:37 -0700 (PDT) Received: from a076716.blr.arm.com (a076716.blr.arm.com [10.164.21.47]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 660793F63F; Wed, 10 Sep 2025 02:46:41 -0700 (PDT) From: Anshuman Khandual To: linux-arm-kernel@lists.infradead.org Cc: Anshuman Khandual , Catalin Marinas , Will Deacon , Mark Brown , Ryan Roberts , Mark Rutland , Ard Biesheuvel , Ritesh Harjani , linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH 2/3] arm64/ptdump: Enable console output in pt_dump_seq_[printf|puts]() Date: Wed, 10 Sep 2025 15:16:22 +0530 Message-Id: <20250910094623.2356282-3-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250910094623.2356282-1-anshuman.khandual@arm.com> References: <20250910094623.2356282-1-anshuman.khandual@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Cc: Will Deacon Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Suggested-by: Ryan Roberts Signed-off-by: Anshuman Khandual --- 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 #include =20 - -#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 =3D=3D CONSOLE) \ + pr_cont(fmt, ##args); \ + else \ + seq_printf(m, fmt, ##args); \ + } \ }) =20 -#define pt_dump_seq_puts(m, fmt) \ -({ \ - if (m) \ - seq_printf(m, fmt); \ +#define pt_dump_seq_puts(m, fmt) \ +({ \ + if (m) { \ + if (m =3D=3D CONSOLE) \ + pr_cont(fmt); \ + else \ + seq_printf(m, fmt); \ + } \ }) =20 static const struct ptdump_prot_bits pte_bits[] =3D { --=20 2.25.1 From nobody Thu Oct 2 21:58:18 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AFA0031D37D; Wed, 10 Sep 2025 09:46:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757497614; cv=none; b=P+2WBWkep+5iOEN2RFeO8ElXnGp8BOF7SCDq9yIPy0ySYGdiNO5rhE1JBomNIRZcdDRH8sORLI6gTan9ZmmU1T0M8cIheEu1hyqw2q0k0feMPiz1PDrtSC0qFmhF5PsCggOLXlj3tug+I2dAZsIMNqSjxhobj/C5PukHoRpwcbI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757497614; c=relaxed/simple; bh=IS5IwAzX7TFHjXEEXmEPIusDZxypsR4BPH7MgERJxek=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pCGiYkIRRYuHT9+9w5XhswuE69Eg5ir8IkXyI9vGNXXOHaq+q5kwlpQ0YTKIhDCT+W/yF9no7gJZ7t8bAR12FYu81qDckvFM1XOMH1GyE/RGe+jsllWXNVBNNRrGczECBjtWN7Efs8b7O6zxOSyV9mzP9+LrUJ4Z2WMQbl+akSo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B328D16F8; Wed, 10 Sep 2025 02:46:43 -0700 (PDT) Received: from a076716.blr.arm.com (a076716.blr.arm.com [10.164.21.47]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8AE313F63F; Wed, 10 Sep 2025 02:46:46 -0700 (PDT) From: Anshuman Khandual To: linux-arm-kernel@lists.infradead.org Cc: Anshuman Khandual , Catalin Marinas , Will Deacon , Mark Brown , Ryan Roberts , Mark Rutland , Ard Biesheuvel , Ritesh Harjani , linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, Jonathan Corbet , Andrew Morton , linux-doc@vger.kernel.org Subject: [PATCH 3/3] arm64/ptdump: Add 'early_ptdump' kernel command line option Date: Wed, 10 Sep 2025 15:16:23 +0530 Message-Id: <20250910094623.2356282-4-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250910094623.2356282-1-anshuman.khandual@arm.com> References: <20250910094623.2356282-1-anshuman.khandual@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Cc: Catalin Marinas Cc: Will Deacon Cc: Andrew Morton Cc: linux-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Suggested-by: Ryan Roberts Signed-off-by: Anshuman Khandual --- 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/Documentatio= n/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[=3Don] + Enable kernel page table dump during boot in current + ptdump format. This helps analyze early boot mapping + kernel regions. =20 earlycon=3D [KNL,EARLY] Output early console device and options. =20 diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdum= p.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 add= r, int level, pteval_t val) { } static inline void note_page_pte(struct ptdump_state *st, unsigned long ad= dr, 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 **cmd= line_p) init_bootcpu_ops(); smp_init_cpus(); smp_build_mpidr_hash(); + arm64_kernel_pgtable_dump(); =20 #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(); } =20 +static bool early_ptdump __initdata; + +static int __init parse_early_ptdump(char *arg) +{ + if (strcmp(arg, "on") =3D=3D 0) + early_ptdump =3D 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"); --=20 2.25.1