Skip to content

Commit e36de87

Browse files
Vineeth Pillaibonzini
authored andcommitted
KVM: debugfs: expose pid of vcpu threads
Add a new debugfs file to expose the pid of each vcpu threads. This is very helpful for userland tools to get the vcpu pids without worrying about thread naming conventions of the VMM. Signed-off-by: Vineeth Pillai (Google) <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 4de5c54 commit e36de87

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

include/linux/kvm_host.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,8 @@ int kvm_arch_pm_notifier(struct kvm *kvm, unsigned long state);
14351435

14361436
#ifdef __KVM_HAVE_ARCH_VCPU_DEBUGFS
14371437
void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry);
1438+
#else
1439+
static inline void kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu) {}
14381440
#endif
14391441

14401442
int kvm_arch_hardware_enable(void);

virt/kvm/kvm_main.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3822,9 +3822,18 @@ static int create_vcpu_fd(struct kvm_vcpu *vcpu)
38223822
return anon_inode_getfd(name, &kvm_vcpu_fops, vcpu, O_RDWR | O_CLOEXEC);
38233823
}
38243824

3825+
#ifdef __KVM_HAVE_ARCH_VCPU_DEBUGFS
3826+
static int vcpu_get_pid(void *data, u64 *val)
3827+
{
3828+
struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
3829+
*val = pid_nr(rcu_access_pointer(vcpu->pid));
3830+
return 0;
3831+
}
3832+
3833+
DEFINE_SIMPLE_ATTRIBUTE(vcpu_get_pid_fops, vcpu_get_pid, NULL, "%llu\n");
3834+
38253835
static void kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu)
38263836
{
3827-
#ifdef __KVM_HAVE_ARCH_VCPU_DEBUGFS
38283837
struct dentry *debugfs_dentry;
38293838
char dir_name[ITOA_MAX_LEN * 2];
38303839

@@ -3834,10 +3843,12 @@ static void kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu)
38343843
snprintf(dir_name, sizeof(dir_name), "vcpu%d", vcpu->vcpu_id);
38353844
debugfs_dentry = debugfs_create_dir(dir_name,
38363845
vcpu->kvm->debugfs_dentry);
3846+
debugfs_create_file("pid", 0444, debugfs_dentry, vcpu,
3847+
&vcpu_get_pid_fops);
38373848

38383849
kvm_arch_create_vcpu_debugfs(vcpu, debugfs_dentry);
3839-
#endif
38403850
}
3851+
#endif
38413852

38423853
/*
38433854
* Creates some virtual cpus. Good luck creating more than one.

0 commit comments

Comments
 (0)