diff mbox series

arm64: ptdump: Allow dumping user page tables

Message ID 20211001145603.22024-1-vincent.whitchurch@axis.com (mailing list archive)
State New, archived
Headers show
Series arm64: ptdump: Allow dumping user page tables | expand

Commit Message

Vincent Whitchurch Oct. 1, 2021, 2:56 p.m. UTC
Add a user_page_tables debugfs file (similar to kernel_page_tables) to
dump out the userspace page tables for the current process.  This
provides details which are not available via pagemap (such as the memory
type) and is useful when, for example, debugging ->mmap()
implementations.

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
 arch/arm64/mm/ptdump.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Will Deacon Oct. 19, 2021, 12:09 p.m. UTC | #1
On Fri, Oct 01, 2021 at 04:56:03PM +0200, Vincent Whitchurch wrote:
> Add a user_page_tables debugfs file (similar to kernel_page_tables) to
> dump out the userspace page tables for the current process.  This
> provides details which are not available via pagemap (such as the memory
> type) and is useful when, for example, debugging ->mmap()
> implementations.
> 
> Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
> ---
>  arch/arm64/mm/ptdump.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)

How does this serialise with things like task exit?

Will
Vincent Whitchurch Oct. 19, 2021, 12:33 p.m. UTC | #2
On Tue, Oct 19, 2021 at 02:09:32PM +0200, Will Deacon wrote:
> On Fri, Oct 01, 2021 at 04:56:03PM +0200, Vincent Whitchurch wrote:
> > Add a user_page_tables debugfs file (similar to kernel_page_tables) to
> > dump out the userspace page tables for the current process.  This
> > provides details which are not available via pagemap (such as the memory
> > type) and is useful when, for example, debugging ->mmap()
> > implementations.
> > 
> > Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
> > ---
> >  arch/arm64/mm/ptdump.c | 15 ++++++++++++++-
> >  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> How does this serialise with things like task exit?

A task can only read its own page tables using this file, and the mm
lock is held during the walk in ptdump_walk_pgd().  Isn't that
sufficient?
diff mbox series

Patch

diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c
index 1c403536c9bb..91a62f07eae2 100644
--- a/arch/arm64/mm/ptdump.c
+++ b/arch/arm64/mm/ptdump.c
@@ -309,6 +309,7 @@  static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
 
 void ptdump_walk(struct seq_file *s, struct ptdump_info *info)
 {
+	struct mm_struct *mm = info->mm ?: current->mm;
 	unsigned long end = ~0UL;
 	struct pg_state st;
 
@@ -328,7 +329,7 @@  void ptdump_walk(struct seq_file *s, struct ptdump_info *info)
 		}
 	};
 
-	ptdump_walk_pgd(&st.ptdump, info->mm, NULL);
+	ptdump_walk_pgd(&st.ptdump, mm, NULL);
 }
 
 static void __init ptdump_initialize(void)
@@ -347,6 +348,16 @@  static struct ptdump_info kernel_ptdump_info = {
 	.base_addr	= PAGE_OFFSET,
 };
 
+static struct addr_marker user_address_markers[] = {
+	{ 0,				"Userspace memory start" },
+	{ 0 /* TASK_SIZE_64 */,		"Userspace memory end" },
+	{ -1,				NULL },
+};
+
+static struct ptdump_info user_ptdump_info = {
+	.markers	= user_address_markers,
+};
+
 void ptdump_check_wx(void)
 {
 	struct pg_state st = {
@@ -381,8 +392,10 @@  static int __init ptdump_init(void)
 #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
 	address_markers[KASAN_START_NR].start_address = KASAN_SHADOW_START;
 #endif
+	user_address_markers[1].start_address = TASK_SIZE_64;
 	ptdump_initialize();
 	ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables");
+	ptdump_debugfs_register(&user_ptdump_info, "user_page_tables");
 	return 0;
 }
 device_initcall(ptdump_init);