]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm: create per-vcpu dirs in debugfs
authorLuiz Capitulino <lcapitulino@redhat.com>
Fri, 16 Sep 2016 14:27:35 +0000 (10:27 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 16 Sep 2016 14:57:47 +0000 (16:57 +0200)
This commit adds the ability for archs to export
per-vcpu information via a new per-vcpu dir in
the VM's debugfs directory.

If kvm_arch_has_vcpu_debugfs() returns true, then KVM
will create a vcpu dir for each vCPU in the VM's
debugfs directory. Then kvm_arch_create_vcpu_debugfs()
is responsible for populating each vcpu directory
with arch specific entries.

The per-vcpu path in debugfs will look like:

/sys/kernel/debug/kvm/29162-10/vcpu0
/sys/kernel/debug/kvm/29162-10/vcpu1

This is all arch specific for now because the only
user of this interface (x86) wants to export x86-specific
per-vcpu information to user-space.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
include/linux/kvm_host.h
virt/kvm/kvm_main.c

index 5486ff9aa71e8b8955e6021f2db3e304888fbbd6..01c0b9cc3915cf7b74054516e16fc43fe9fbcafb 100644 (file)
@@ -265,6 +265,7 @@ struct kvm_vcpu {
 #endif
        bool preempted;
        struct kvm_vcpu_arch arch;
+       struct dentry *debugfs_dentry;
 };
 
 static inline int kvm_vcpu_exiting_guest_mode(struct kvm_vcpu *vcpu)
index a6e864c67e35279e5eb97ff9765bb0595976de00..81dfc73d3df39851e3b44cd546f5f66046ec5e0f 100644 (file)
@@ -2371,6 +2371,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
 {
        struct kvm_vcpu *vcpu = filp->private_data;
 
+       debugfs_remove_recursive(vcpu->debugfs_dentry);
        kvm_put_kvm(vcpu->kvm);
        return 0;
 }
@@ -2393,6 +2394,32 @@ static int create_vcpu_fd(struct kvm_vcpu *vcpu)
        return anon_inode_getfd("kvm-vcpu", &kvm_vcpu_fops, vcpu, O_RDWR | O_CLOEXEC);
 }
 
+static int kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu)
+{
+       char dir_name[ITOA_MAX_LEN * 2];
+       int ret;
+
+       if (!kvm_arch_has_vcpu_debugfs())
+               return 0;
+
+       if (!debugfs_initialized())
+               return 0;
+
+       snprintf(dir_name, sizeof(dir_name), "vcpu%d", vcpu->vcpu_id);
+       vcpu->debugfs_dentry = debugfs_create_dir(dir_name,
+                                                               vcpu->kvm->debugfs_dentry);
+       if (!vcpu->debugfs_dentry)
+               return -ENOMEM;
+
+       ret = kvm_arch_create_vcpu_debugfs(vcpu);
+       if (ret < 0) {
+               debugfs_remove_recursive(vcpu->debugfs_dentry);
+               return ret;
+       }
+
+       return 0;
+}
+
 /*
  * Creates some virtual cpus.  Good luck creating more than one.
  */
@@ -2425,6 +2452,10 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
        if (r)
                goto vcpu_destroy;
 
+       r = kvm_create_vcpu_debugfs(vcpu);
+       if (r)
+               goto vcpu_destroy;
+
        mutex_lock(&kvm->lock);
        if (kvm_get_vcpu_by_id(kvm, id)) {
                r = -EEXIST;
@@ -2456,6 +2487,7 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
 
 unlock_vcpu_destroy:
        mutex_unlock(&kvm->lock);
+       debugfs_remove_recursive(vcpu->debugfs_dentry);
 vcpu_destroy:
        kvm_arch_vcpu_destroy(vcpu);
 vcpu_decrement: