From: Sebastian Ene <sebastianene@google.com>
To: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com,
akpm@linux-foundation.org, maz@kernel.org
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, kernel-team@android.com,
vdonnefort@google.com, qperret@google.com, smostafa@google.com,
Sebastian Ene <sebastianene@google.com>
Subject: [PATCH v2 08/11] arm64: ptdump: Parse the host stage-2 page-tables from the snapshot
Date: Thu, 19 Oct 2023 14:40:30 +0000 [thread overview]
Message-ID: <20231019144032.2943044-10-sebastianene@google.com> (raw)
In-Reply-To: <20231019144032.2943044-1-sebastianene@google.com>
Add a walker function which configures ptdump to parse the page-tables
from the snapshot. Convert the physical address of the pagetable's start
address to a host virtual address and use the ptdump walker to parse the
page-table descriptors.
Signed-off-by: Sebastian Ene <sebastianene@google.com>
---
arch/arm64/mm/ptdump.c | 63 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c
index 7c78b8994ca1..3ba4848272df 100644
--- a/arch/arm64/mm/ptdump.c
+++ b/arch/arm64/mm/ptdump.c
@@ -479,6 +479,11 @@ static void *ptdump_host_va(phys_addr_t phys)
return __va(phys);
}
+static struct kvm_pgtable_mm_ops host_mmops = {
+ .phys_to_virt = ptdump_host_va,
+ .virt_to_phys = ptdump_host_pa,
+};
+
static size_t stage2_get_pgd_len(void)
{
u64 mmfr0, mmfr1, vtcr;
@@ -604,6 +609,63 @@ static void stage2_ptdump_end_walk(struct ptdump_info *info)
free_pages_exact(snapshot, PAGE_SIZE);
info->priv = NULL;
}
+
+static int stage2_ptdump_visitor(const struct kvm_pgtable_visit_ctx *ctx,
+ enum kvm_pgtable_walk_flags visit)
+{
+ struct pg_state *st = ctx->arg;
+ struct ptdump_state *pt_st = &st->ptdump;
+
+ if (st->pg_level[ctx->level].mask & ctx->old)
+ pt_st->note_page(pt_st, ctx->addr, ctx->level, ctx->old);
+
+ return 0;
+}
+
+static void stage2_ptdump_walk(struct seq_file *s, struct ptdump_info *info)
+{
+ struct kvm_pgtable_snapshot *snapshot = info->priv;
+ struct pg_state st;
+ struct kvm_pgtable *pgtable;
+ u64 start_ipa = 0, end_ipa;
+ struct addr_marker ipa_address_markers[3];
+ struct kvm_pgtable_walker walker = (struct kvm_pgtable_walker) {
+ .cb = stage2_ptdump_visitor,
+ .arg = &st,
+ .flags = KVM_PGTABLE_WALK_LEAF,
+ };
+
+ if (snapshot == NULL || !snapshot->pgtable.pgd)
+ return;
+
+ pgtable = &snapshot->pgtable;
+ pgtable->mm_ops = &host_mmops;
+ end_ipa = BIT(pgtable->ia_bits) - 1;
+
+ memset(&ipa_address_markers[0], 0, sizeof(ipa_address_markers));
+
+ ipa_address_markers[0].start_address = start_ipa;
+ ipa_address_markers[0].name = "IPA start";
+
+ ipa_address_markers[1].start_address = end_ipa;
+ ipa_address_markers[1].name = "IPA end";
+
+ st = (struct pg_state) {
+ .seq = s,
+ .marker = &ipa_address_markers[0],
+ .level = pgtable->start_level - 1,
+ .pg_level = &stage2_pg_level[0],
+ .ptdump = {
+ .note_page = note_page,
+ .range = (struct ptdump_range[]) {
+ {start_ipa, end_ipa},
+ {0, 0},
+ },
+ },
+ };
+
+ kvm_pgtable_walk(pgtable, start_ipa, end_ipa, &walker);
+}
#endif /* CONFIG_NVHE_EL2_PTDUMP_DEBUGFS */
static void __init ptdump_register_host_stage2(void)
@@ -616,6 +678,7 @@ static void __init ptdump_register_host_stage2(void)
.mc_len = host_s2_pgtable_pages(),
.ptdump_prepare_walk = stage2_ptdump_prepare_walk,
.ptdump_end_walk = stage2_ptdump_end_walk,
+ .ptdump_walk = stage2_ptdump_walk,
};
mutex_init(&stage2_kernel_ptdump_info.file_lock);
--
2.42.0.655.g421f12c284-goog
next prev parent reply other threads:[~2023-10-19 14:41 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-19 14:40 [PATCH v2 00/11] arm64: ptdump: View the second stage page-tables Sebastian Ene
2023-10-19 14:40 ` [PATCH v2 01/11] KVM: arm64: Add snap shooting the host stage-2 pagetables Sebastian Ene
2023-10-26 12:45 ` kernel test robot
2023-10-19 14:40 ` [PATCH v2 02/11] arm64: ptdump: Use the mask from the state structure Sebastian Ene
2023-10-19 14:40 ` [PATCH v2 03/11] arm64: ptdump: Add the walker function to the ptdump info structure Sebastian Ene
2023-10-19 14:40 ` [PATCH v2 04/11] KVM: arm64: Move pagetable definitions to common header Sebastian Ene
2023-10-19 14:40 ` [PATCH v2 05/11] arm64: ptdump: Introduce stage-2 pagetables format description Sebastian Ene
2023-10-19 14:40 ` [PATCH v2 06/11] arm64: ptdump: Add hooks on debugfs file operations Sebastian Ene
2023-10-19 14:40 ` [PATCH v2 07/11] arm64: ptdump: Register a debugfs entry for the host stage-2 page-tables Sebastian Ene
2023-10-19 14:40 ` Sebastian Ene [this message]
2023-10-19 14:40 ` [PATCH v2 09/11] arm64: ptdump: Interpret memory attributes based on runtime configuration Sebastian Ene
2023-10-19 14:40 ` [PATCH v2 10/11] arm64: ptdump: Interpret pKVM ownership annotations Sebastian Ene
2023-10-19 14:40 ` [PATCH v2 11/11] arm64: ptdump: Add support for guest stage-2 pagetables dumping Sebastian Ene
2023-10-20 8:40 ` Vincent Donnefort
2023-10-23 14:45 ` Sebastian Ene
2023-10-20 8:19 ` [PATCH v2 00/11] arm64: ptdump: View the second stage page-tables Vincent Donnefort
2023-10-23 14:32 ` Sebastian Ene
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=20231019144032.2943044-10-sebastianene@google.com \
--to=sebastianene@google.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=kernel-team@android.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=qperret@google.com \
--cc=smostafa@google.com \
--cc=vdonnefort@google.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®