From: Sebastian Ene <sebastianene@google.com>
To: will@kernel.org, Oliver Upton <oliver.upton@linux.dev>,
James Morse <james.morse@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
catalin.marinas@arm.com, mark.rutland@arm.com,
akpm@linux-foundation.org, maz@kernel.org
Cc: kvmarm@lists.linux.dev, 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 v4 07/10] KVM: arm64: Walk the pagetable snapshot and parse the ptdump descriptors
Date: Mon, 18 Dec 2023 13:58:57 +0000 [thread overview]
Message-ID: <20231218135859.2513568-9-sebastianene@google.com> (raw)
In-Reply-To: <20231218135859.2513568-2-sebastianene@google.com>
Define the attributes for the stage-2 pagetables that will be used by
the ptdump parser code to interepret and show the descriptors. Build the
pagetable level description dynamically and use the KVM pagetable walker
to visit the PTEs. Display the number of the bits used by the IPA
address space and the start level.
Signed-off-by: Sebastian Ene <sebastianene@google.com>
---
arch/arm64/kvm/ptdump.c | 135 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 134 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c
index e99bab427..80c338e03 100644
--- a/arch/arm64/kvm/ptdump.c
+++ b/arch/arm64/kvm/ptdump.c
@@ -40,6 +40,66 @@ static struct kvm_pgtable_mm_ops ptdump_host_mmops = {
.virt_to_phys = get_host_pa,
};
+static const struct prot_bits stage2_pte_bits[] = {
+ {
+ .mask = PTE_VALID,
+ .val = PTE_VALID,
+ .set = " ",
+ .clear = "F",
+ }, {
+ .mask = KVM_PTE_LEAF_ATTR_HI_S2_XN,
+ .val = KVM_PTE_LEAF_ATTR_HI_S2_XN,
+ .set = "XN",
+ .clear = " ",
+ }, {
+ .mask = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R,
+ .val = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R,
+ .set = "R",
+ .clear = " ",
+ }, {
+ .mask = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W,
+ .val = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W,
+ .set = "W",
+ .clear = " ",
+ }, {
+ .mask = KVM_PTE_LEAF_ATTR_LO_S2_AF,
+ .val = KVM_PTE_LEAF_ATTR_LO_S2_AF,
+ .set = "AF",
+ .clear = " ",
+ }, {
+ .mask = PTE_NG,
+ .val = PTE_NG,
+ .set = "FnXS",
+ .clear = " ",
+ }, {
+ .mask = PTE_CONT,
+ .val = PTE_CONT,
+ .set = "CON",
+ .clear = " ",
+ }, {
+ .mask = PTE_TABLE_BIT,
+ .val = PTE_TABLE_BIT,
+ .set = " ",
+ .clear = "BLK",
+ }, {
+ .mask = KVM_PGTABLE_PROT_SW0,
+ .val = KVM_PGTABLE_PROT_SW0,
+ .set = "SW0", /* PKVM_PAGE_SHARED_OWNED */
+ }, {
+ .mask = KVM_PGTABLE_PROT_SW1,
+ .val = KVM_PGTABLE_PROT_SW1,
+ .set = "SW1", /* PKVM_PAGE_SHARED_BORROWED */
+ }, {
+ .mask = KVM_PGTABLE_PROT_SW2,
+ .val = KVM_PGTABLE_PROT_SW2,
+ .set = "SW2",
+ }, {
+ .mask = KVM_PGTABLE_PROT_SW3,
+ .val = KVM_PGTABLE_PROT_SW3,
+ .set = "SW3",
+ },
+};
+
static int kvm_ptdump_open(struct inode *inode, struct file *file)
{
struct kvm_ptdump_register *reg = inode->i_private;
@@ -73,9 +133,82 @@ static int kvm_ptdump_release(struct inode *inode, struct file *file)
return 0;
}
+static int kvm_ptdump_build_levels(struct pg_level *level, unsigned int start_level)
+{
+ static const char * const level_names[] = {"PGD", "PUD", "PMD", "PTE"};
+ int i, j, name_index;
+
+ if (start_level > 2) {
+ pr_err("invalid start_level %u\n", start_level);
+ return -EINVAL;
+ }
+
+ for (i = start_level; i < KVM_PGTABLE_MAX_LEVELS; i++) {
+ name_index = i - start_level;
+ name_index += name_index * start_level;
+
+ level[i].name = level_names[name_index];
+ level[i].num = ARRAY_SIZE(stage2_pte_bits);
+ level[i].bits = stage2_pte_bits;
+
+ for (j = 0; j < level[i].num; j++)
+ level[i].mask |= level[i].bits[j].mask;
+ }
+
+ return 0;
+}
+
+static int kvm_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;
+
+ note_page(pt_st, ctx->addr, ctx->level, ctx->old);
+ return 0;
+}
+
static int kvm_ptdump_show(struct seq_file *m, void *)
{
- return -EINVAL;
+ u64 ipa_size;
+ char ipa_description[32];
+ struct pg_state st;
+ struct addr_marker ipa_addr_markers[3] = {0};
+ struct pg_level pg_level_descr[KVM_PGTABLE_MAX_LEVELS] = {0};
+ struct kvm_pgtable_snapshot *snapshot = m->private;
+ struct kvm_pgtable *pgtable = &snapshot->pgtable;
+ struct kvm_pgtable_walker walker = (struct kvm_pgtable_walker) {
+ .cb = kvm_ptdump_visitor,
+ .arg = &st,
+ .flags = KVM_PGTABLE_WALK_LEAF,
+ };
+
+ if (kvm_ptdump_build_levels(pg_level_descr, pgtable->start_level) < 0)
+ return -EINVAL;
+
+ snprintf(ipa_description, sizeof(ipa_description),
+ "IPA bits %2u start lvl %1u", pgtable->ia_bits,
+ pgtable->start_level);
+
+ ipa_size = BIT(pgtable->ia_bits);
+ ipa_addr_markers[0].name = ipa_description;
+ ipa_addr_markers[1].start_address = ipa_size;
+
+ st = (struct pg_state) {
+ .seq = m,
+ .marker = &ipa_addr_markers[0],
+ .level = -1,
+ .pg_level = &pg_level_descr[0],
+ .ptdump = {
+ .note_page = note_page,
+ .range = (struct ptdump_range[]) {
+ {0, ipa_size},
+ {0, 0},
+ },
+ },
+ };
+
+ return kvm_pgtable_walk(pgtable, 0, ipa_size, &walker);
}
static void kvm_ptdump_debugfs_register(struct kvm_ptdump_register *reg,
--
2.43.0.472.g3155946c3a-goog
next prev parent reply other threads:[~2023-12-18 14:00 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-18 13:58 [PATCH v4 00/10] arm64: ptdump: View the second stage page-tables Sebastian Ene
2023-12-18 13:58 ` [PATCH v4 01/10] KVM: arm64: Add snapshot interface for the host stage-2 pagetable Sebastian Ene
2023-12-19 11:44 ` Sebastian Ene
2023-12-18 13:58 ` [PATCH v4 02/10] KVM: arm64: Add ptdump registration with debugfs for the stage-2 pagetables Sebastian Ene
2023-12-19 11:47 ` Sebastian Ene
2023-12-21 18:14 ` Oliver Upton
2024-02-01 11:20 ` Sebastian Ene
2024-02-05 13:14 ` Oliver Upton
2024-02-05 16:05 ` Sebastian Ene
2023-12-18 13:58 ` [PATCH v4 03/10] KVM: arm64: Invoke the snapshot interface for the host stage-2 pagetable Sebastian Ene
2023-12-19 11:45 ` Sebastian Ene
2023-12-18 13:58 ` [PATCH v4 04/10] arm64: ptdump: Expose the attribute parsing functionality Sebastian Ene
2023-12-18 13:58 ` [PATCH v4 05/10] arm64: ptdump: Use the mask from the state structure Sebastian Ene
2023-12-18 13:58 ` [PATCH v4 06/10] KVM: arm64: Move pagetable definitions to common header Sebastian Ene
2023-12-18 13:58 ` Sebastian Ene [this message]
2023-12-18 13:58 ` [PATCH v4 08/10] arm64: ptdump: Interpret memory attributes based on the runtime config Sebastian Ene
2023-12-18 13:58 ` [PATCH v4 09/10] arm64: ptdump: Interpret pKVM ownership annotations Sebastian Ene
2023-12-18 13:59 ` [PATCH v4 10/10] arm64: ptdump: Add guest stage-2 pagetables dumping Sebastian Ene
2023-12-19 11:52 ` Sebastian Ene
2023-12-21 18:27 ` Oliver Upton
2023-12-21 18:36 ` [PATCH v4 00/10] arm64: ptdump: View the second stage page-tables Oliver Upton
2023-12-21 18:41 ` 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=20231218135859.2513568-9-sebastianene@google.com \
--to=sebastianene@google.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=james.morse@arm.com \
--cc=kernel-team@android.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=qperret@google.com \
--cc=smostafa@google.com \
--cc=suzuki.poulose@arm.com \
--cc=vdonnefort@google.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/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®