Skip to content

Commit 4f69b68

Browse files
hamoavikivity
authored andcommitted
KVM: ensure that debugfs entries have been created
by checking the return value from kvm_init_debug, we can ensure that the entries under debugfs for KVM have been created correctly. Signed-off-by: Yang Bai <hamo.by@gmail.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
1 parent d546cb4 commit 4f69b68

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

virt/kvm/kvm_main.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,15 +2654,29 @@ static const struct file_operations *stat_fops[] = {
26542654
[KVM_STAT_VM] = &vm_stat_fops,
26552655
};
26562656

2657-
static void kvm_init_debug(void)
2657+
static int kvm_init_debug(void)
26582658
{
2659+
int r = -EFAULT;
26592660
struct kvm_stats_debugfs_item *p;
26602661

26612662
kvm_debugfs_dir = debugfs_create_dir("kvm", NULL);
2662-
for (p = debugfs_entries; p->name; ++p)
2663+
if (kvm_debugfs_dir == NULL)
2664+
goto out;
2665+
2666+
for (p = debugfs_entries; p->name; ++p) {
26632667
p->dentry = debugfs_create_file(p->name, 0444, kvm_debugfs_dir,
26642668
(void *)(long)p->offset,
26652669
stat_fops[p->kind]);
2670+
if (p->dentry == NULL)
2671+
goto out_dir;
2672+
}
2673+
2674+
return 0;
2675+
2676+
out_dir:
2677+
debugfs_remove_recursive(kvm_debugfs_dir);
2678+
out:
2679+
return r;
26662680
}
26672681

26682682
static void kvm_exit_debug(void)
@@ -2806,10 +2820,16 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
28062820
kvm_preempt_ops.sched_in = kvm_sched_in;
28072821
kvm_preempt_ops.sched_out = kvm_sched_out;
28082822

2809-
kvm_init_debug();
2823+
r = kvm_init_debug();
2824+
if (r) {
2825+
printk(KERN_ERR "kvm: create debugfs files failed\n");
2826+
goto out_undebugfs;
2827+
}
28102828

28112829
return 0;
28122830

2831+
out_undebugfs:
2832+
unregister_syscore_ops(&kvm_syscore_ops);
28132833
out_unreg:
28142834
kvm_async_pf_deinit();
28152835
out_free:

0 commit comments

Comments
 (0)