summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZenghui Yu (Huawei) <zenghui.yu@linux.dev>2026-03-28 13:31:55 +0800
committerMarc Zyngier <maz@kernel.org>2026-03-28 10:02:55 +0000
commit570428601ba506e76c265a65626524ef3c5cbc04 (patch)
treee94ae3bf2d4a512d96fdf2db60eb51bd9ea3a616
parent19e15dc73f0fc74eaf63ad9b3a50648450269b4d (diff)
downloadlinux-570428601ba506e76c265a65626524ef3c5cbc04.tar.gz
linux-570428601ba506e76c265a65626524ef3c5cbc04.zip
KVM: arm64: ptdump: Initialize parser_state before pgtable walk
If we go through the "need a bigger buffer" path in seq_read_iter(), which is likely to happen as we're dumping page tables, we will pass the populated-by-last-run st::parser_state to kvm_pgtable_walk()/kvm_ptdump_visitor(). As a result, the output of stage2_page_tables on my box looks like 0x0000000240000000-0x0000000000000000 17179869175G 1 0x0000000000000000-0x0000000000200000 2M 2 R px ux AF BLK 0x0000000000200000-0x0000000040000000 1022M 2 0x0000000040000000-0x0000000040200000 2M 2 R W PXNUXN AF BLK [...] Fix it by always initializing st::parser_state before starting a new pgtable walk. Besides, remove st::range as it's not used by note_page(); remove the explicit initialization of parser_state::start_address as it will be initialized in note_page() anyway. Signed-off-by: Zenghui Yu (Huawei) <zenghui.yu@linux.dev> Link: https://patch.msgid.link/20260328053155.12219-1-zenghui.yu@linux.dev [maz: rebased on top of NV support] Signed-off-by: Marc Zyngier <maz@kernel.org>
-rw-r--r--arch/arm64/kvm/ptdump.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c
index f5753ac37a05..c9140e22abcf 100644
--- a/arch/arm64/kvm/ptdump.c
+++ b/arch/arm64/kvm/ptdump.c
@@ -24,7 +24,6 @@ struct kvm_ptdump_guest_state {
struct ptdump_pg_state parser_state;
struct addr_marker ipa_marker[MARKERS_LEN];
struct ptdump_pg_level level[KVM_PGTABLE_MAX_LEVELS];
- struct ptdump_range range[MARKERS_LEN];
};
static const struct ptdump_prot_bits stage2_pte_bits[] = {
@@ -132,17 +131,8 @@ static struct kvm_ptdump_guest_state *kvm_ptdump_parser_create(struct kvm_s2_mmu
st->ipa_marker[0].name = "Guest IPA";
st->ipa_marker[1].start_address = BIT(pgtable->ia_bits);
- st->range[0].end = BIT(pgtable->ia_bits);
st->mmu = mmu;
- st->parser_state = (struct ptdump_pg_state) {
- .marker = &st->ipa_marker[0],
- .level = -1,
- .pg_level = &st->level[0],
- .ptdump.range = &st->range[0],
- .start_address = 0,
- };
-
return st;
}
@@ -152,14 +142,18 @@ static int kvm_ptdump_guest_show(struct seq_file *m, void *unused)
struct kvm_ptdump_guest_state *st = m->private;
struct kvm_s2_mmu *mmu = st->mmu;
struct kvm *kvm = kvm_s2_mmu_to_kvm(mmu);
- struct ptdump_pg_state *parser_state = &st->parser_state;
struct kvm_pgtable_walker walker = (struct kvm_pgtable_walker) {
.cb = kvm_ptdump_visitor,
- .arg = parser_state,
+ .arg = &st->parser_state,
.flags = KVM_PGTABLE_WALK_LEAF,
};
- parser_state->seq = m;
+ st->parser_state = (struct ptdump_pg_state) {
+ .marker = &st->ipa_marker[0],
+ .level = -1,
+ .pg_level = &st->level[0],
+ .seq = m,
+ };
write_lock(&kvm->mmu_lock);
ret = kvm_pgtable_walk(mmu->pgt, 0, BIT(mmu->pgt->ia_bits), &walker);