From nobody Sat Jul 25 04:54:27 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 767CE3B8BA1 for ; Fri, 17 Jul 2026 23:13:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784330003; cv=none; b=uWuUTmEfIvKPvJh6kgAvz0jjCschGlpztL9OT5ukCE+C5ro+mTz6iVWeXLn2L1kp1iM6/8mHKqi82Pew0U2inFvFkczFKjewL2jqpUI9XCfWNuYh62ZlQ2UOkGw1T5l1ms3WP8zdJPD/J2XgPhpsLGuBt1jfIYjvJIVXii7pMa0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784330003; c=relaxed/simple; bh=3BlVjgmV5uha5Hv39vi3jBRXCmFZY73SrcLqw6/9YjM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=uzqJSMd0GLhU1J3D823oKNkDiOIKBCXUzIaQOJs4JHujAr+oPonCLFA+JMpt4Vf4XxuO5ozZsUs4N9syZa34/2yNG5narMV/ya6btdLZU487AIYW3/Exbx1PqZCk/SezuHwXUNcXG6IW6HyF8IHAGSzNgCPDvUroYX7H7JiyqaY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=MrG2RBy/; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="MrG2RBy/" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 861851476; Fri, 17 Jul 2026 16:13:13 -0700 (PDT) Received: from workstation-e142269.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EDF783F66F; Fri, 17 Jul 2026 16:13:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1784329997; bh=3BlVjgmV5uha5Hv39vi3jBRXCmFZY73SrcLqw6/9YjM=; h=From:To:Cc:Subject:Date:From; b=MrG2RBy/Fb9HTHfDKyEJEEWtqIgzwZwHsP2O0U+aMZ70wHOhQdusEBocp3HC1ZIDn 2Uv0rWgc/CndtB/MaFd/d6FaXjhyP4lt7QBFsmdREZtL2ztY86WIEzi+3ye7n+HkJM SM96L9nvLBq35DJrPUDZ0YWZvqwEPKc5j+CWqRcQ= From: Wei-Lin Chang To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Marc Zyngier , Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Dev Jain , Ryan Roberts , Sebastian Ene , Vincent Donnefort , Wei-Lin Chang Subject: [PATCH] KVM: arm64: ptdump: Flush the last region Date: Sat, 18 Jul 2026 00:12:33 +0100 Message-ID: <20260717231233.2299068-1-weilin.chang@arm.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently the stage-2 ptdump calls note_page() at each leaf entry visit. This simply misses the output of the last region, because note_page() only dumps output when it detects a change in level/prot, or when the walk enters a next marker section. The last region in the guest IPA space with the same level/prot is not dumped since there is no change after it. To dump the final region, manually issue a note_page() call with address BIT(ia_bits) (end of guest IPA space) and level =3D=3D -1 to trigger a level change after the last region. Additionally treat level =3D=3D -1 as a last flushing note_page() call and avoid dumping the name of the next marker for this case. Fixes: 7c4f73548ed1 ("KVM: arm64: Register ptdump with debugfs on guest cre= ation") Reported-by: Sashiko AI Closes: https://lore.kernel.org/kvmarm/20260630122758.891011F00A3A@smtp.ker= nel.org/ Signed-off-by: Wei-Lin Chang --- arch/arm64/kvm/ptdump.c | 8 +++++--- arch/arm64/mm/ptdump.c | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c index c9140e22abcf..4096e4a92fae 100644 --- a/arch/arm64/kvm/ptdump.c +++ b/arch/arm64/kvm/ptdump.c @@ -155,11 +155,13 @@ static int kvm_ptdump_guest_show(struct seq_file *m, = void *unused) .seq =3D m, }; =20 - write_lock(&kvm->mmu_lock); + guard(write_lock)(&kvm->mmu_lock); ret =3D kvm_pgtable_walk(mmu->pgt, 0, BIT(mmu->pgt->ia_bits), &walker); - write_unlock(&kvm->mmu_lock); + if (ret) + return ret; + note_page(&st->parser_state.ptdump, BIT(mmu->pgt->ia_bits), -1, 0); =20 - return ret; + return 0; } =20 static int kvm_ptdump_guest_open(struct inode *m, struct file *file) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index ab9899ca1e5f..fed4e4407e0e 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -194,6 +194,7 @@ void note_page(struct ptdump_state *pt_st, unsigned lon= g addr, int level, struct ptdump_pg_state *st =3D container_of(pt_st, struct ptdump_pg_state= , ptdump); struct ptdump_pg_level *pg_level =3D st->pg_level; static const char units[] =3D "KMGTPE"; + bool flush =3D level =3D=3D -1; ptdesc_t prot =3D 0; =20 /* check if the current level has been folded dynamically */ @@ -234,7 +235,7 @@ void note_page(struct ptdump_state *pt_st, unsigned lon= g addr, int level, pg_level[st->level].num); pt_dump_seq_puts(st->seq, "\n"); =20 - if (addr >=3D st->marker[1].start_address) { + if (addr >=3D st->marker[1].start_address && !flush) { st->marker++; pt_dump_seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); } @@ -244,7 +245,7 @@ void note_page(struct ptdump_state *pt_st, unsigned lon= g addr, int level, st->level =3D level; } =20 - if (addr >=3D st->marker[1].start_address) { + if (addr >=3D st->marker[1].start_address && !flush) { st->marker++; pt_dump_seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); } --=20 2.43.0