From: Sebastian Ene <sebastianene@google.com>
To: linux-kernel@vger.kernel.org
Cc: kernel-team@android.com, will@kernel.org, ryan.roberts@arm.com,
mark.rutland@arm.com, maz@kernel.org, vdonnefort@google.com,
Sebastian Ene <sebastianene@google.com>
Subject: [PATCH 08/11] arm64: ptdump: Parse the host stage-2 page-tables from the snapshot
Date: Wed, 27 Sep 2023 11:25:14 +0000 [thread overview]
Message-ID: <20230927112517.2631674-9-sebastianene@google.com> (raw)
In-Reply-To: <20230927112517.2631674-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 | 53 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c
index 7d57fa9be724..c0e7a80992f4 100644
--- a/arch/arm64/mm/ptdump.c
+++ b/arch/arm64/mm/ptdump.c
@@ -616,6 +616,58 @@ static void stage2_ptdump_end_walk(struct ptdump_info *info)
free_pages_exact(snapshot, PAGE_SIZE);
info->priv = NULL;
}
+
+static u32 stage2_get_max_pgd_index(u32 ipa_bits, u32 start_level)
+{
+ u64 end_ipa = BIT(ipa_bits) - 1;
+ u32 shift = ARM64_HW_PGTABLE_LEVEL_SHIFT(start_level - 1);
+
+ return end_ipa >> shift;
+}
+
+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;
+ u32 pgd_index, pgd_pages, pgd_shift;
+ u64 start_ipa = 0, end_ipa;
+ pgd_t *pgd;
+
+ if (snapshot == NULL || !snapshot->pgtable.pgd)
+ return;
+
+ pgtable = &snapshot->pgtable;
+ info->mm->pgd = phys_to_virt((phys_addr_t)pgtable->pgd);
+ pgd_shift = ARM64_HW_PGTABLE_LEVEL_SHIFT(pgtable->start_level - 1);
+ pgd_pages = stage2_get_max_pgd_index(pgtable->ia_bits,
+ pgtable->start_level);
+
+ for (pgd_index = 0; pgd_index <= pgd_pages; pgd_index++) {
+ end_ipa = start_ipa + (1UL << pgd_shift);
+
+ st = (struct pg_state) {
+ .seq = s,
+ .marker = info->markers,
+ .level = pgtable->start_level,
+ .pg_level = &stage2_pg_level[0],
+ .ptdump = {
+ .note_page = note_page,
+ .range = (struct ptdump_range[]) {
+ {start_ipa, end_ipa},
+ {0, 0},
+ },
+ },
+ };
+
+ ipa_address_markers[0].start_address = start_ipa;
+ ipa_address_markers[1].start_address = end_ipa;
+
+ pgd = &info->mm->pgd[pgd_index * PTRS_PER_PTE];
+ ptdump_walk_pgd(&st.ptdump, info->mm, pgd);
+ start_ipa = end_ipa;
+ }
+}
#endif /* CONFIG_NVHE_EL2_PTDUMP_DEBUGFS */
static int __init ptdump_init(void)
@@ -634,6 +686,7 @@ static int __init ptdump_init(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,
};
init_rwsem(&ipa_init_mm.mmap_lock);
--
2.42.0.515.g380fc7ccd1-goog
next prev parent reply other threads:[~2023-09-27 11:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-27 11:25 [PATCH 00/11] arm64: ptdump: View the host stage-2 page-tables Sebastian Ene
2023-09-27 11:25 ` [PATCH 01/11] KVM: arm64: Add snap shooting the host stage-2 pagetables Sebastian Ene
2023-09-28 18:33 ` kernel test robot
2023-09-27 11:25 ` [PATCH 02/11] arm64: ptdump: Use the mask from the state structure Sebastian Ene
2023-09-27 11:25 ` [PATCH 03/11] arm64: ptdump: Add the walker function to the ptdump info structure Sebastian Ene
2023-09-27 11:25 ` [PATCH 04/11] KVM: arm64: Move pagetable definitions to common header Sebastian Ene
2023-09-27 11:25 ` [PATCH 05/11] arm64: ptdump: Introduce stage-2 pagetables format description Sebastian Ene
2023-09-27 11:25 ` [PATCH 06/11] arm64: ptdump: Register a debugfs entry for the host stage-2 page-tables Sebastian Ene
2023-09-27 11:25 ` [PATCH 07/11] arm64: ptdump: Snapshot the host stage-2 pagetables Sebastian Ene
2023-09-27 11:25 ` Sebastian Ene [this message]
2023-09-27 11:25 ` [PATCH 09/11] arm64: ptdump: Interpret memory attributes based on runtime configuration Sebastian Ene
2023-09-27 11:25 ` [PATCH 10/11] arm64: ptdump: Interpret pKVM ownership annotations Sebastian Ene
2023-09-27 11:25 ` [PATCH 11/11] arm64: ptdump: Fix format output during stage-2 pagetable dumping Sebastian Ene
2023-09-29 13:11 ` [PATCH 00/11] arm64: ptdump: View the host stage-2 page-tables Marc Zyngier
2023-09-30 16:31 ` 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=20230927112517.2631674-9-sebastianene@google.com \
--to=sebastianene@google.com \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=ryan.roberts@arm.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®