diff options
author | Luiz Capitulino <lcapitulino@redhat.com> | 2016-09-16 10:27:35 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2016-09-16 10:57:47 -0400 |
commit | 45b5939e50746b92fd4cb47c02524f79ba8fabe6 (patch) | |
tree | 2913b6e168819a11ff761d4d5106f89e1c5ae224 | |
parent | 235539b48a2357da28f52d66d04bec04f3dcb9dd (diff) |
kvm: create per-vcpu dirs in debugfs
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>
-rw-r--r-- | include/linux/kvm_host.h | 1 | ||||
-rw-r--r-- | virt/kvm/kvm_main.c | 32 |
2 files changed, 33 insertions, 0 deletions
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 5486ff9aa71e..01c0b9cc3915 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h | |||
@@ -265,6 +265,7 @@ struct kvm_vcpu { | |||
265 | #endif | 265 | #endif |
266 | bool preempted; | 266 | bool preempted; |
267 | struct kvm_vcpu_arch arch; | 267 | struct kvm_vcpu_arch arch; |
268 | struct dentry *debugfs_dentry; | ||
268 | }; | 269 | }; |
269 | 270 | ||
270 | static inline int kvm_vcpu_exiting_guest_mode(struct kvm_vcpu *vcpu) | 271 | static inline int kvm_vcpu_exiting_guest_mode(struct kvm_vcpu *vcpu) |
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index a6e864c67e35..81dfc73d3df3 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -2371,6 +2371,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp) | |||
2371 | { | 2371 | { |
2372 | struct kvm_vcpu *vcpu = filp->private_data; | 2372 | struct kvm_vcpu *vcpu = filp->private_data; |
2373 | 2373 | ||
2374 | debugfs_remove_recursive(vcpu->debugfs_dentry); | ||
2374 | kvm_put_kvm(vcpu->kvm); | 2375 | kvm_put_kvm(vcpu->kvm); |
2375 | return 0; | 2376 | return 0; |
2376 | } | 2377 | } |
@@ -2393,6 +2394,32 @@ static int create_vcpu_fd(struct kvm_vcpu *vcpu) | |||
2393 | return anon_inode_getfd("kvm-vcpu", &kvm_vcpu_fops, vcpu, O_RDWR | O_CLOEXEC); | 2394 | return anon_inode_getfd("kvm-vcpu", &kvm_vcpu_fops, vcpu, O_RDWR | O_CLOEXEC); |
2394 | } | 2395 | } |
2395 | 2396 | ||
2397 | static int kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu) | ||
2398 | { | ||
2399 | char dir_name[ITOA_MAX_LEN * 2]; | ||
2400 | int ret; | ||
2401 | |||
2402 | if (!kvm_arch_has_vcpu_debugfs()) | ||
2403 | return 0; | ||
2404 | |||
2405 | if (!debugfs_initialized()) | ||
2406 | return 0; | ||
2407 | |||
2408 | snprintf(dir_name, sizeof(dir_name), "vcpu%d", vcpu->vcpu_id); | ||
2409 | vcpu->debugfs_dentry = debugfs_create_dir(dir_name, | ||
2410 | vcpu->kvm->debugfs_dentry); | ||
2411 | if (!vcpu->debugfs_dentry) | ||
2412 | return -ENOMEM; | ||
2413 | |||
2414 | ret = kvm_arch_create_vcpu_debugfs(vcpu); | ||
2415 | if (ret < 0) { | ||
2416 | debugfs_remove_recursive(vcpu->debugfs_dentry); | ||
2417 | return ret; | ||
2418 | } | ||
2419 | |||
2420 | return 0; | ||
2421 | } | ||
2422 | |||
2396 | /* | 2423 | /* |
2397 | * Creates some virtual cpus. Good luck creating more than one. | 2424 | * Creates some virtual cpus. Good luck creating more than one. |
2398 | */ | 2425 | */ |
@@ -2425,6 +2452,10 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id) | |||
2425 | if (r) | 2452 | if (r) |
2426 | goto vcpu_destroy; | 2453 | goto vcpu_destroy; |
2427 | 2454 | ||
2455 | r = kvm_create_vcpu_debugfs(vcpu); | ||
2456 | if (r) | ||
2457 | goto vcpu_destroy; | ||
2458 | |||
2428 | mutex_lock(&kvm->lock); | 2459 | mutex_lock(&kvm->lock); |
2429 | if (kvm_get_vcpu_by_id(kvm, id)) { | 2460 | if (kvm_get_vcpu_by_id(kvm, id)) { |
2430 | r = -EEXIST; | 2461 | r = -EEXIST; |
@@ -2456,6 +2487,7 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id) | |||
2456 | 2487 | ||
2457 | unlock_vcpu_destroy: | 2488 | unlock_vcpu_destroy: |
2458 | mutex_unlock(&kvm->lock); | 2489 | mutex_unlock(&kvm->lock); |
2490 | debugfs_remove_recursive(vcpu->debugfs_dentry); | ||
2459 | vcpu_destroy: | 2491 | vcpu_destroy: |
2460 | kvm_arch_vcpu_destroy(vcpu); | 2492 | kvm_arch_vcpu_destroy(vcpu); |
2461 | vcpu_decrement: | 2493 | vcpu_decrement: |