mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] KVM: Remove kvm_debugfs_dir on kvm_init() error paths
@ 2026-07-06  9:59 leixiang
  2026-07-14 18:41 ` Sean Christopherson
  0 siblings, 1 reply; 2+ messages in thread
From: leixiang @ 2026-07-06  9:59 UTC (permalink / raw)
  Cc: leixiang, Paolo Bonzini, Sean Christopherson, kvm, linux-kernel

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: 2b0128127373 ("KVM: Register /dev/kvm as the _very_ last thing during initialization")
Signed-off-by: leixiang <leixiang@kylinos.cn>
---
 virt/kvm/kvm_main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e44c20c04961..d4420ebfd972 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -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();
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] KVM: Remove kvm_debugfs_dir on kvm_init() error paths
  2026-07-06  9:59 [PATCH] KVM: Remove kvm_debugfs_dir on kvm_init() error paths leixiang
@ 2026-07-14 18:41 ` Sean Christopherson
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2026-07-14 18:41 UTC (permalink / raw)
  To: Sean Christopherson, leixiang; +Cc: Paolo Bonzini, kvm, linux-kernel

On Mon, 06 Jul 2026 17:59:06 +0800, leixiang wrote:
> 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().
> 
> [...]

Applied to kvm-x86 generic, thanks!

[1/1] KVM: Remove kvm_debugfs_dir on kvm_init() error paths
      https://github.com/kvm-x86/linux/commit/db3a46e200df

--
https://github.com/kvm-x86/linux/tree/next

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-14 19:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-06  9:59 [PATCH] KVM: Remove kvm_debugfs_dir on kvm_init() error paths leixiang
2026-07-14 18:41 ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox