From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B9476C4451B for ; Mon, 20 Jul 2026 09:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=JlH6bBHsx0iUgxzN2Wc0xmjFP/YXdJ+cTewN5QULG2A=; b=aIehO8Mv9xgr3qHObhKe9uul9c SbSz3K5e6DvXgc6Z3Kkv1YHrMMEOxvcOecWbcberYE9iscLNB1mucSNf1JEW7YSsViO2kqTsNAkCR KucXAL8DCnsKFo7fhkim72678srPvVzkqJp3iTAtWU7W9AFwbffD1W+pJ9pRQmrfFDzmMQSXEoqvQ 0+ii7dpTMCyVa5WFxCKpE1eelP7snYzU5IIOHyDumHib+ZMy+/nZZ/dHcUcnVYBi2tzium1drav6C VgutK0bcAY+huyDh3badi2Rqq7F5NpqjDeDK/n8runPcDk09sAyaRJ86skJFcJniZvwaSNxsepYsp //eg0Cyg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wljut-00000006GOw-02fv; Mon, 20 Jul 2026 09:04:03 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wljur-00000006GOo-10Uh for linux-arm-kernel@lists.infradead.org; Mon, 20 Jul 2026 09:04:01 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 978CC414AC; Mon, 20 Jul 2026 09:04:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77E131F000E9; Mon, 20 Jul 2026 09:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784538240; bh=JlH6bBHsx0iUgxzN2Wc0xmjFP/YXdJ+cTewN5QULG2A=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=F63DBJYlQvbDo0WzO97R/H784F8hXmRqb12FCBhAk8GqjhhrAyM7mD569fP3TBK4L 31c3rRzU12mu6agMPFHDGJQvStIyqG/vNon5cDyk+nYV7X7/YmDrm+QZ69kJePIv1/ F8s1nIc6VarzN4yrmeYen78DVge4SWPU6DEWCvBEc2BW0BIHyT5dnPLTI+RZ7E45qR KDS/RPTYzfPw1lCYGxfT0ClISm/K8USEsMeKNFcZPBZEQKWXinhEjvAoixbJKre4u2 9pm1nIlLTdB7rQ2dU4HWUeyVG9Ru5Kp3Gpah2maLKQT0ILbrMm+YuhPxrtUzSbVOAb QiILg3g7Yjq8Q== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wljuo-00000006iJd-1MQG; Mon, 20 Jul 2026 09:03:58 +0000 Date: Mon, 20 Jul 2026 10:03:57 +0100 Message-ID: <868q76f2wy.wl-maz@kernel.org> From: Marc Zyngier To: Dev Jain Cc: Wei-Lin Chang , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Ryan Roberts , Sebastian Ene , Vincent Donnefort Subject: Re: [PATCH] KVM: arm64: ptdump: Flush the last region In-Reply-To: References: <20260717231233.2299068-1-weilin.chang@arm.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: dev.jain@arm.com, weilin.chang@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, oupton@kernel.org, tabba@google.com, joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, ryan.roberts@arm.com, sebastianene@google.com, vdonnefort@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 20 Jul 2026 09:53:29 +0100, Dev Jain wrote: > > > > On 18/07/26 4:42 am, Wei-Lin Chang wrote: > > 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 == -1 to trigger a level > > change after the last region. Additionally treat level == -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 creation") > > Reported-by: Sashiko AI > > Closes: https://lore.kernel.org/kvmarm/20260630122758.891011F00A3A@smtp.kernel.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 = m, > > }; > > > > - write_lock(&kvm->mmu_lock); > > + guard(write_lock)(&kvm->mmu_lock); > > The guard clause change has nothing to do with the fix I think? Although the change > is small and the fix is for a recent commit so maybe we don't care having this > in the same patch - not sure how strict kvm reviewers are about this : ) > Look at the quality spaghetti code this would otherwise result in: write_lock(); ret = kvm_pgtable_walk(); if (ret) { write_unlock(); return ret; } note_page_flush(); write_unlock(); return 0; How is that better? So it has *everything* to do with the fix. And FWIW, the policy for KVM is that we don't do lock->guard conversions as a separate patches. Only when we need to change the code, and as part of the patch that changes that code. Which is exactly what is happening here. > > > ret = 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); > > > > - return ret; > > + return 0; > > } > > > > 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 long addr, int level, > > struct ptdump_pg_state *st = container_of(pt_st, struct ptdump_pg_state, ptdump); > > struct ptdump_pg_level *pg_level = st->pg_level; > > static const char units[] = "KMGTPE"; > > + bool flush = level == -1; > > Can we do something similar to what S1 ptdump does (note_page_flush in ptdump_walk_pgd). See Mark's email. M. -- Without deviation from the norm, progress is not possible.