]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: arm64: nv: Expose shadow page tables in debugfs
authorWei-Lin Chang <weilin.chang@arm.com>
Tue, 17 Mar 2026 18:26:38 +0000 (18:26 +0000)
committerMarc Zyngier <maz@kernel.org>
Mon, 23 Mar 2026 10:06:50 +0000 (10:06 +0000)
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<vttbr>-0x<vtcr>-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 <maz@kernel.org>
Reviewed-by: Sebastian Ene <sebastianene@google.com>
Signed-off-by: Wei-Lin Chang <weilin.chang@arm.com>
Reviewed-by: Joey Gouly <joey.gouly@arm.com>
Link: https://patch.msgid.link/20260317182638.1592507-3-weilin.chang@arm.com
[maz: minor refactor, full 16 chars addresses]
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/include/asm/kvm_host.h
arch/arm64/include/asm/kvm_mmu.h
arch/arm64/kvm/nested.c
arch/arm64/kvm/ptdump.c

index 2ca264b3db5fa0322cc8dd788284b0a98e995fee..70d9f6855cce36593f33c689b20ecaf99fc07966 100644 (file)
@@ -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 {
index d968aca0461a229330b77bf61f621b83a4c4745e..01e9c72d6aa7a67f0a470ec6f8e916de9facf195 100644 (file)
@@ -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__ */
index 12c9f6e8dfdab81c541e8f5542234d2ef197fb33..34bab84b18fe353be48167124c874e6f7d214907 100644 (file)
@@ -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);
 
index 8713001e992dd825f3550e2a3b5a87cda16eed5d..f5753ac37a05c8181e1a38e071bca9d1ab84c001 100644 (file)
 #include <linux/kvm_host.h>
 #include <linux/seq_file.h>
 
+#include <asm/cpufeature.h>
 #include <asm/kvm_mmu.h>
 #include <asm/kvm_pgtable.h>
 #include <asm/ptdump.h>
 
 #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%016llx-0x%016llx-s2-%sabled",
+                mmu->tlb_vttbr,
+                mmu->tlb_vtcr,
+                mmu->nested_stage2_enabled ? "en" : "dis");
+
+       dent = debugfs_create_file(file_name, 0400,
+                                  mmu->arch->debugfs_nv_dentry, mmu,
+                                  &kvm_ptdump_guest_fops);
+
+       mmu->shadow_pt_debugfs_dentry = dent;
+}
+
+void kvm_nested_s2_ptdump_remove_debugfs(struct kvm_s2_mmu *mmu)
+{
+       debugfs_remove(mmu->shadow_pt_debugfs_dentry);
+}
+
 void kvm_s2_ptdump_create_debugfs(struct kvm *kvm)
 {
        debugfs_create_file("stage2_page_tables", 0400, kvm->debugfs_dentry,
@@ -285,4 +309,6 @@ void kvm_s2_ptdump_create_debugfs(struct kvm *kvm)
                            &kvm->arch.mmu, &kvm_pgtable_range_fops);
        debugfs_create_file("stage2_levels", 0400, kvm->debugfs_dentry,
                            &kvm->arch.mmu, &kvm_pgtable_levels_fops);
+       if (cpus_have_final_cap(ARM64_HAS_NESTED_VIRT))
+               kvm->arch.debugfs_nv_dentry = debugfs_create_dir("nested", kvm->debugfs_dentry);
 }