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 3734C1090242 for ; Thu, 19 Mar 2026 16:02:00 +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=fzSlwQbvmCb8ZHo7kB8gWwWuKQueC65HKPjfGBPVXX8=; b=EXzErtsRN5UxfcO7caELCC4FaF Rc7r3xSVbqSJDpxl/vxkaK83ey8SUeac9z1pLeAt+x46QDFqTfISzNFRV9JDDkFGukV+U+BhV4l8y wxQpwdKoNz7T2Pwr/rixpVFfSbtWKgXFsV/CVlFbnJhh5kNySAEq2vSI0EigeJF24h7Rr7+B/AnjD m7oCl7uaOLgWmycR8vPhfNbMkz/yMJ0GN4cTsxG1WDQm3opMB2J2CRQ5/gFMT6pcBjdcqFfdldZIt 6TQFtjR2B42mrOMiTV9NBqPtOcTAZSYbJTsW1TVKnHzXl1mlvl4Ews8RVcxYzkrTPm2KGMx4rxRQX KMVpX50Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1w3Fop-0000000B1Zm-4AKK; Thu, 19 Mar 2026 16:01:55 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1w3Fop-0000000B1ZN-154T for linux-arm-kernel@lists.infradead.org; Thu, 19 Mar 2026 16:01:55 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 576B260132; Thu, 19 Mar 2026 16:01:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 008B3C2BCB0; Thu, 19 Mar 2026 16:01:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773936114; bh=N/p8hW+nirUgjIR1XBn+Q8QSshZoHwheSk4tGYv0gjw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Do4CV1fPxn0Pcv3+KCLgCbTpdLcYnxIv3stpXg7E82XUPWW3JMdiJnB3fxwnbIyzd 6kX0AETi8JWEftRQiK3zR4Gy1Kth8GZbqF/0QF2ueBOlLKTQsUDuH4kGvggqzlW4GL f1oeQbboeVT3cm6TDTg0EklF/abjeZ0z/boMRBMP6pFaa5yZDFurlOre0qWy0rcC/k xyCecAq0QoWpO/Q4LWdqVEEvJ8uWcQ4ZqLkZCcvjWIv33ad16h1ap7XpNkRWB0JTff 63JzjVKUaKBIpMzw8KmrWslOYtOJYlnqQf2OdScDsXFe4gpBe6GZs6GvLyUxrf3DOv nf7b1f1h28Wgg== 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 1w3Fol-00000003hx6-2bnD; Thu, 19 Mar 2026 16:01:51 +0000 Date: Thu, 19 Mar 2026 16:01:51 +0000 Message-ID: <86bjgj6c5s.wl-maz@kernel.org> From: Marc Zyngier To: Wei-Lin Chang Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon Subject: Re: [PATCH v2 2/2] KVM: arm64: nv: Expose shadow page tables in debugfs In-Reply-To: <20260317182638.1592507-3-weilin.chang@arm.com> References: <20260317182638.1592507-1-weilin.chang@arm.com> <20260317182638.1592507-3-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: weilin.chang@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, oupton@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org 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 Tue, 17 Mar 2026 18:26:38 +0000, Wei-Lin Chang wrote: > > Exposing shadow page tables in debugfs improves the debugability and > testability of NV. With this patch a new directory "nested" is created > for each VM created if the host is NV capable. Within the directory each > valid s2 mmu will have its shadow page table exposed as a readable file > with the file name formatted as 0x-0x-s2-{en,dis}abled. The > creation and removal of the files happen at the points when an s2 mmu > becomes valid, or the context it represents change. In the future the > "nested" directory can also hold other NV related information. > > This is gated behind CONFIG_PTDUMP_STAGE2_DEBUGFS. > > Suggested-by: Marc Zyngier > Reviewed-by: Sebastian Ene > Signed-off-by: Wei-Lin Chang > --- > arch/arm64/include/asm/kvm_host.h | 9 +++++++++ > arch/arm64/include/asm/kvm_mmu.h | 4 ++++ > arch/arm64/kvm/nested.c | 6 +++++- > arch/arm64/kvm/ptdump.c | 27 +++++++++++++++++++++++++++ > 4 files changed, 45 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > index 5d5a3bbdb95e..52977c9a11c3 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -217,6 +217,10 @@ struct kvm_s2_mmu { > */ > bool nested_stage2_enabled; > > +#ifdef CONFIG_PTDUMP_STAGE2_DEBUGFS > + struct dentry *shadow_pt_debugfs_dentry; > +#endif > + > /* > * true when this MMU needs to be unmapped before being used for a new > * purpose. > @@ -405,6 +409,11 @@ struct kvm_arch { > * the associated pKVM instance in the hypervisor. > */ > struct kvm_protected_vm pkvm; > + > +#ifdef CONFIG_PTDUMP_STAGE2_DEBUGFS > + /* Nested virtualization info */ > + struct dentry *debugfs_nv_dentry; > +#endif > }; > > struct kvm_vcpu_fault_info { > diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h > index d968aca0461a..01e9c72d6aa7 100644 > --- a/arch/arm64/include/asm/kvm_mmu.h > +++ b/arch/arm64/include/asm/kvm_mmu.h > @@ -393,8 +393,12 @@ static inline bool kvm_supports_cacheable_pfnmap(void) > > #ifdef CONFIG_PTDUMP_STAGE2_DEBUGFS > void kvm_s2_ptdump_create_debugfs(struct kvm *kvm); > +void kvm_nested_s2_ptdump_create_debugfs(struct kvm_s2_mmu *mmu); > +void kvm_nested_s2_ptdump_remove_debugfs(struct kvm_s2_mmu *mmu); > #else > static inline void kvm_s2_ptdump_create_debugfs(struct kvm *kvm) {} > +static inline void kvm_nested_s2_ptdump_create_debugfs(struct kvm_s2_mmu *mmu) {} > +static inline void kvm_nested_s2_ptdump_remove_debugfs(struct kvm_s2_mmu *mmu) {} > #endif /* CONFIG_PTDUMP_STAGE2_DEBUGFS */ > > #endif /* __ASSEMBLER__ */ > diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c > index eeea5e692370..31d74ed8449e 100644 > --- a/arch/arm64/kvm/nested.c > +++ b/arch/arm64/kvm/nested.c > @@ -730,8 +730,10 @@ static struct kvm_s2_mmu *get_s2_mmu_nested(struct kvm_vcpu *vcpu) > kvm->arch.nested_mmus_next = (i + 1) % kvm->arch.nested_mmus_size; > > /* Make sure we don't forget to do the laundry */ > - if (kvm_s2_mmu_valid(s2_mmu)) > + if (kvm_s2_mmu_valid(s2_mmu)) { > + kvm_nested_s2_ptdump_remove_debugfs(s2_mmu); > s2_mmu->pending_unmap = true; > + } > > /* > * The virtual VMID (modulo CnP) will be used as a key when matching > @@ -745,6 +747,8 @@ static struct kvm_s2_mmu *get_s2_mmu_nested(struct kvm_vcpu *vcpu) > s2_mmu->tlb_vtcr = vcpu_read_sys_reg(vcpu, VTCR_EL2); > s2_mmu->nested_stage2_enabled = vcpu_read_sys_reg(vcpu, HCR_EL2) & HCR_VM; > > + kvm_nested_s2_ptdump_create_debugfs(s2_mmu); > + > out: > atomic_inc(&s2_mmu->refcnt); > > diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c > index 98763b291956..aebbbad85d38 100644 > --- a/arch/arm64/kvm/ptdump.c > +++ b/arch/arm64/kvm/ptdump.c > @@ -10,12 +10,14 @@ > #include > #include > > +#include > #include > #include > #include > > #define MARKERS_LEN 2 > #define KVM_PGTABLE_MAX_LEVELS (KVM_PGTABLE_LAST_LEVEL + 1) > +#define S2FNAMESZ sizeof("0x0123456789abcdef-0x0123456789abcdef-s2-disabled") > > struct kvm_ptdump_guest_state { > struct kvm_s2_mmu *mmu; > @@ -277,6 +279,28 @@ static const struct file_operations kvm_pgtable_levels_fops = { > .release = kvm_pgtable_debugfs_close, > }; > > +void kvm_nested_s2_ptdump_create_debugfs(struct kvm_s2_mmu *mmu) > +{ > + struct dentry *dent; > + char file_name[S2FNAMESZ]; > + > + snprintf(file_name, sizeof(file_name), "0x%llx-0x%llx-s2-%sabled", > + mmu->tlb_vttbr, > + mmu->tlb_vtcr, > + mmu->nested_stage2_enabled ? "en" : "dis"); Here's an example of this code in action: root@semi-fraudulent:/home/maz/vminstall# ls -l /sys/kernel/debug/kvm/932-4/nested/ total 0 -r-------- 1 root root 0 Mar 19 11:58 0x0-0x80000000-s2-disabled -r-------- 1 root root 0 Mar 19 12:01 0x100010124c000-0x800c3558-s2-enabled -r-------- 1 root root 0 Mar 19 15:06 0x200010d916000-0x800c3558-s2-enabled -r-------- 1 root root 0 Mar 19 15:16 0x30001027ec000-0x800c3558-s2-enabled I think these hex values should always be padded with leading zeroes, making them more readable. I can hack that in as I queue the patches. M. -- Without deviation from the norm, progress is not possible.