KVM: Remove kvm_debugfs_dir on kvm_init() error paths

kvm_init_debug() runs before several steps that can fail
(kvm_vfio_ops_init(), kvm_gmem_init(), kvm_init_virtualization() and
misc_register()), but none of the corresponding error labels remove the
"kvm" debugfs directory.  Any failure after kvm_init_debug() therefore
leaks the directory and its stat files for the lifetime of the boot.

kvm_exit() already calls debugfs_remove_recursive(kvm_debugfs_dir); add
the same at the err_vfio label, whose fall-through covers every path
taken after kvm_init_debug().

Fixes: 2b01281273 ("KVM: Register /dev/kvm as the _very_ last thing during initialization")
Signed-off-by: leixiang <leixiang@kylinos.cn>
Link: https://patch.msgid.link/20260706095910.39798-1-leixiang@kylinos.cn
Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
leixiang
2026-07-06 17:59:06 +08:00
committed by Sean Christopherson
parent a204badd84
commit db3a46e200

View File

@@ -6559,6 +6559,7 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)
err_gmem:
kvm_vfio_ops_exit();
err_vfio:
debugfs_remove_recursive(kvm_debugfs_dir);
kvm_async_pf_deinit();
err_async_pf:
kvm_irqfd_exit();