kvm->arch.debugfs_nv_dentry is only set if the VM's debugfs directory was created, but kvm_nested_s2_ptdump_create_debugfs() uses it unconditionally. If it is NULL, e.g. because the VM's debugfs directory name was a duplicate, the nested_mmu* files are created in the root of debugfs and are never removed, leaving dangling pointers to the nested MMUs after the VM is destroyed. Skip creating the files if there is no "nested" directory. Fixes: 19e15dc73f0f ("KVM: arm64: nv: Expose shadow page tables in debugfs") Signed-off-by: Peng Hao --- arch/arm64/kvm/ptdump.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c index 9f0aebacea5b..c7a1d2f1e0aa 100644 --- a/arch/arm64/kvm/ptdump.c +++ b/arch/arm64/kvm/ptdump.c @@ -312,6 +312,10 @@ void kvm_nested_s2_ptdump_create_debugfs(struct kvm_s2_mmu *mmu, int idx) { char file_name[S2FNAMESZ]; + /* The "nested" directory doesn't exist without a VM debugfs directory. */ + if (IS_ERR_OR_NULL(mmu->arch->debugfs_nv_dentry)) + return; + snprintf(file_name, sizeof(file_name), "nested_mmu%d", idx); debugfs_create_file(file_name, 0400, -- 2.43.7