From nobody Fri Jul 24 20:48:44 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C9A1139CD12 for ; Fri, 24 Jul 2026 18:54:52 +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=1784919294; cv=none; b=rFPyu2/zMXwCiDCMz/bOIH4fTYYlEcVwQEXoQCGiIYA6sNP0nsv5+cQESdcBGpIzzO5BZAzveKuR4nucm8pvx6cQqhjALdha7JkCpJAytmpvvN81tD18+ToYFTxHlPge2rAYLZ8y0zg+GRLEi8QnXmYoFoLJScXbJweUxmA1Yqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784919294; c=relaxed/simple; bh=Q1VDWNE3+I+GnOSFyuDonVkxr0L9zZfgPrVh56WS1Qk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AVgGGYLwARsUnLy1TN2WWW7KpRqLQhYVJSUO6HlrTFNqrzPEU85+UR/VGFZL8ZTGGeEiO2mmIhwdIoDhfzpgcSNPE7ecaeHntVyLl2ir9/qePE/24FpF1P6j+KxO5J+Xv5wcT1SI8Kk/PRjDKV1JL2clTA6vZeVZJ8HHY1Cs+/A= 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=g9Vf+KnT; 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="g9Vf+KnT" 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 DAA761477; Fri, 24 Jul 2026 11:54:47 -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 1FDBC3F66F; Fri, 24 Jul 2026 11:54:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1784919291; bh=Q1VDWNE3+I+GnOSFyuDonVkxr0L9zZfgPrVh56WS1Qk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g9Vf+KnTliDRWqJjoKnA+b5v6XKx7QBT+pJsfwfjJ+ysReEdEXy0X5qYYLI3BkmBu fmS1+8R7aREni5OTtvOScazpwKh1LUJMB6u5QPQFp9bCQavu2TclJ0zXHxZizvcwiY qzESB4GmQv2eAdc0IxLtZmmwUFFVFUu1aJL6ux4w= 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 , Anshuman Khandual , Ryan Roberts , Dev Jain , "David Hildenbrand (Arm)" , Matt Fleming , Ard Biesheuvel , Mark Rutland , Sebastian Ene , Vincent Donnefort , Wei-Lin Chang Subject: [PATCH v2 1/2] arm64: ptdump: Make note_page_flush() range aware Date: Fri, 24 Jul 2026 19:54:30 +0100 Message-ID: <20260724185431.2990395-2-weilin.chang@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260724185431.2990395-1-weilin.chang@arm.com> References: <20260724185431.2990395-1-weilin.chang@arm.com> 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" note_page_flush() calls note_page() with addr =3D=3D 0 and level =3D=3D -1 = to dump the last row of a ptdump. addr =3D=3D 0 (1 << 64 wrapped around) renders a huge region with enormous size for address spaces with IA bits < 64. For example the stage-2 page tables and the EFI runtime page table. More importantly, the last region of the address space and everything after the address space up to 1 << 64 are merged into one row of output. If the last region within the address space is valid, it will appear to remain valid up to 1 << 64 with the same attributes. Currently only the EFI runtime ptdump is affected by this, but KVM will soon fix its stage-2 ptdump by using note_page_flush(). Here is an example of an EFI runtime ptdump (last row): 0x0000008000000000-0x0000000000000000 17179868672G PGD With this patch: 0x0000008000000000-0x0001000000000000 261632G PGD To fix this, use ptdump_state.range[] to figure out where the address space ends, and call note_page() with that. Fixes: 9d80448ac92b ("efi/arm64: Add debugfs node to dump UEFI runtime page= tables") Signed-off-by: Wei-Lin Chang --- arch/arm64/mm/ptdump.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 1c20144700d7..5b34060ceb96 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -278,9 +278,24 @@ void note_page_pgd(struct ptdump_state *pt_st, unsigne= d long addr, pgd_t pgd) =20 void note_page_flush(struct ptdump_state *pt_st) { + const struct ptdump_range *range =3D pt_st->range; + unsigned long end =3D 0; pte_t pte_zero =3D {0}; =20 - note_page(pt_st, 0, -1, pte_val(pte_zero)); + while (range->start !=3D range->end) { + end =3D range->end; + range++; + } + + /* + * Address spaces that end at 1 << 64 have range->end =3D=3D ULONG_MAX, + * but note_page() expects the exclusive end. In this case adjust end + * to the wraparound value 0. + */ + if (end =3D=3D ULONG_MAX) + end =3D 0; + + note_page(pt_st, end, -1, pte_val(pte_zero)); } =20 static void arm64_ptdump_walk_pgd(struct ptdump_state *st, struct mm_struc= t *mm) --=20 2.43.0 From nobody Fri Jul 24 20:48:44 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A5580390200 for ; Fri, 24 Jul 2026 18:54:56 +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=1784919299; cv=none; b=O8MchjEeFbHA1DWJ5wc6bRKyDgX9d+Txr1FkSLWpkfjFVIf0+xOgnQMxfkn5HQotjDgy+JXk/NajSNol7BQ2qw2yaKWOJqM9ailtPwx3rOTIJjkzW7OPLwYmAEqo8JqCnWr8ij9JvFPboWNFwT+WwY6hriiaY2dXJ1Seu+U1oN8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784919299; c=relaxed/simple; bh=gSfRHphoobs3FjVjS72N5dOppPN+9Oy9JjWdfUQiYk4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nf6yKp4OHqSaIyvN28zMsPkEKClRD/YuzUcsYzL7T6SixGcaC+8YJxOBYASZikcOjiD0M2QyjSG3Vd/WXQ/LyikWv501eLaSAgY/caydnim6OGiGmObQcYi+Fb9Lkge0DJBYr8iPy3l0nQOkxXs3h2h7lB/I9QtR5hrYYLkhOF4= 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=QM5RKC8Q; 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="QM5RKC8Q" 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 C1B581684; Fri, 24 Jul 2026 11:54:51 -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 5144A3F66F; Fri, 24 Jul 2026 11:54:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1784919295; bh=gSfRHphoobs3FjVjS72N5dOppPN+9Oy9JjWdfUQiYk4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QM5RKC8Q7q4tqPKjgYKjRsAe2jI1PdkmQIBw7RbVKHBLKyYmVw4u6JC3c7a6W8tHv HF87AYKM3MGaAR23HBposi+OkYcSeemna1ANgGsrx39+1UeMKXOcGePa5yc5zIOaPT OdHgbGZah4bVcJiRL2J2PyCbxM5dW0CfnsbafQ4I= 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 , Anshuman Khandual , Ryan Roberts , Dev Jain , "David Hildenbrand (Arm)" , Matt Fleming , Ard Biesheuvel , Mark Rutland , Sebastian Ene , Vincent Donnefort , Wei-Lin Chang , Sashiko AI Subject: [PATCH v2 2/2] KVM: arm64: ptdump: Flush the last region Date: Fri, 24 Jul 2026 19:54:31 +0100 Message-ID: <20260724185431.2990395-3-weilin.chang@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260724185431.2990395-1-weilin.chang@arm.com> References: <20260724185431.2990395-1-weilin.chang@arm.com> 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. Call note_page_flush() to dump the final region. note_page_flush() expects ptdump_state.range[] to be initialized to the range of the address space, so also do that. Also change the second marker's start address to ULONG_MAX so we never cross it. This avoids dumping redundant marker names (which are NULL), and advancing beyond the end of the marker array. 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 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c index c9140e22abcf..222577163d2b 100644 --- a/arch/arm64/kvm/ptdump.c +++ b/arch/arm64/kvm/ptdump.c @@ -130,7 +130,7 @@ static struct kvm_ptdump_guest_state *kvm_ptdump_parser= _create(struct kvm_s2_mmu } =20 st->ipa_marker[0].name =3D "Guest IPA"; - st->ipa_marker[1].start_address =3D BIT(pgtable->ia_bits); + st->ipa_marker[1].start_address =3D ULONG_MAX; =20 st->mmu =3D mmu; return st; @@ -148,18 +148,26 @@ static int kvm_ptdump_guest_show(struct seq_file *m, = void *unused) .flags =3D KVM_PGTABLE_WALK_LEAF, }; =20 + guard(write_lock)(&kvm->mmu_lock); st->parser_state =3D (struct ptdump_pg_state) { .marker =3D &st->ipa_marker[0], .level =3D -1, .pg_level =3D &st->level[0], .seq =3D m, + .ptdump =3D { + .range =3D (struct ptdump_range[]){ + {0, BIT(mmu->pgt->ia_bits)}, + {0, 0} + } + } }; =20 - 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_flush(&st->parser_state.ptdump); =20 - return ret; + return 0; } =20 static int kvm_ptdump_guest_open(struct inode *m, struct file *file) --=20 2.43.0