All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Whitchurch <vincent.whitchurch@axis.com>
To: Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>
Cc: <kernel@axis.com>,
	Vincent Whitchurch <vincent.whitchurch@axis.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH v2] arm64: ptdump: Support userspace page tables
Date: Thu, 14 Oct 2021 10:14:41 +0200	[thread overview]
Message-ID: <20211014081441.7982-1-vincent.whitchurch@axis.com> (raw)

The kernel_page_tables debugfs file can be used to examine the page
table entries for mappings in kernel space but there is currently no
easy way to check userspace mappings.  /proc/*/pagemap provides some
information but it does not include architecture-specific details such
as the memory type (Normal, Device etc).

Add a user_page_tables debugfs file to dump out the userspace page
tables for the current process.  This is enabled by the same config
options as kernel_page_tables.

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---

Notes:
    v2: Reworded commit message.

 arch/arm64/mm/ptdump.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

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);
-- 
2.28.0


WARNING: multiple messages have this Message-ID (diff)
From: Vincent Whitchurch <vincent.whitchurch@axis.com>
To: Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>
Cc: <kernel@axis.com>,
	Vincent Whitchurch <vincent.whitchurch@axis.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH v2] arm64: ptdump: Support userspace page tables
Date: Thu, 14 Oct 2021 10:14:41 +0200	[thread overview]
Message-ID: <20211014081441.7982-1-vincent.whitchurch@axis.com> (raw)

The kernel_page_tables debugfs file can be used to examine the page
table entries for mappings in kernel space but there is currently no
easy way to check userspace mappings.  /proc/*/pagemap provides some
information but it does not include architecture-specific details such
as the memory type (Normal, Device etc).

Add a user_page_tables debugfs file to dump out the userspace page
tables for the current process.  This is enabled by the same config
options as kernel_page_tables.

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---

Notes:
    v2: Reworded commit message.

 arch/arm64/mm/ptdump.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

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);
-- 
2.28.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

             reply	other threads:[~2021-10-14  8:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-14  8:14 Vincent Whitchurch [this message]
2021-10-14  8:14 ` [PATCH v2] arm64: ptdump: Support userspace page tables Vincent Whitchurch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211014081441.7982-1-vincent.whitchurch@axis.com \
    --to=vincent.whitchurch@axis.com \
    --cc=catalin.marinas@arm.com \
    --cc=kernel@axis.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.