All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm: add kvm cap values to debugfs
@ 2019-05-28  8:35 Suraj Jitindar Singh
  2019-05-28 10:32 ` Christian Borntraeger
  2019-05-28 10:35 ` Paolo Bonzini
  0 siblings, 2 replies; 4+ messages in thread
From: Suraj Jitindar Singh @ 2019-05-28  8:35 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, paulus, dja, Suraj Jitindar Singh

KVM capabilities are used to communicate the availability of certain
capabilities to userspace.

It might be nice to know these values without having to add debug
printing to the userspace tool consuming this data.

Thus add a file in the kvm per vm debugfs file named "caps" which
contains a file for each capability number which when read returns what
would be returned when querying that capability.

Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>

---

I'm not sure if it'd be better to keep a per arch list of the revelevant
capabilities to avoid adding an entry for irrelevant ones. Comments?
---
 include/linux/kvm_host.h |  1 +
 include/uapi/linux/kvm.h |  1 +
 virt/kvm/kvm_main.c      | 31 +++++++++++++++++++++++++++++++
 3 files changed, 33 insertions(+)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 79fa4426509c..6cb45a8de818 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -500,6 +500,7 @@ struct kvm {
 	bool manual_dirty_log_protect;
 	struct dentry *debugfs_dentry;
 	struct kvm_stat_data **debugfs_stat_data;
+	int debugfs_cap_data[KVM_CAP_MAX + 1];
 	struct srcu_struct srcu;
 	struct srcu_struct irq_srcu;
 	pid_t userspace_pid;
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 2fe12b40d503..7b5042ec5902 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -993,6 +993,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_ARM_SVE 170
 #define KVM_CAP_ARM_PTRAUTH_ADDRESS 171
 #define KVM_CAP_ARM_PTRAUTH_GENERIC 172
+#define KVM_CAP_MAX	KVM_CAP_ARM_PTRAUTH_GENERIC
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 134ec0283a8a..b85a43263fb7 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -117,6 +117,7 @@ EXPORT_SYMBOL_GPL(kvm_debugfs_dir);
 static int kvm_debugfs_num_entries;
 static const struct file_operations *stat_fops_per_vm[];
 
+static long kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg);
 static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl,
 			   unsigned long arg);
 #ifdef CONFIG_KVM_COMPAT
@@ -594,6 +595,33 @@ static void kvm_destroy_vm_debugfs(struct kvm *kvm)
 	}
 }
 
+static int vm_cap_get(void *data, u64 *val)
+{
+	*val = *((int *) data);
+
+	return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(cap_fops, vm_cap_get, NULL, "%llu\n");
+
+static void kvm_create_vm_cap_debugfs(struct kvm *kvm)
+{
+	char *dir_name = "caps";
+	struct dentry *dentry_p;
+	int i;
+
+	dentry_p = debugfs_create_dir(dir_name, kvm->debugfs_dentry);
+
+	for (i = 0; i <= KVM_CAP_MAX; i++) {
+		int *cap = &kvm->debugfs_cap_data[i];
+		char file_name[ITOA_MAX_LEN];
+
+		*cap = kvm_vm_ioctl_check_extension_generic(kvm, i);
+		snprintf(file_name, sizeof(file_name), "%d", i);
+		debugfs_create_file(file_name, 0444, dentry_p, cap, &cap_fops);
+	}
+}
+
 static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
 {
 	char dir_name[ITOA_MAX_LEN * 2];
@@ -623,6 +651,9 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
 		debugfs_create_file(p->name, 0644, kvm->debugfs_dentry,
 				    stat_data, stat_fops_per_vm[p->kind]);
 	}
+
+	kvm_create_vm_cap_debugfs(kvm);
+
 	return 0;
 }
 
-- 
2.13.6


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

* Re: [PATCH] kvm: add kvm cap values to debugfs
  2019-05-28  8:35 [PATCH] kvm: add kvm cap values to debugfs Suraj Jitindar Singh
@ 2019-05-28 10:32 ` Christian Borntraeger
  2019-05-28 10:35 ` Paolo Bonzini
  1 sibling, 0 replies; 4+ messages in thread
From: Christian Borntraeger @ 2019-05-28 10:32 UTC (permalink / raw)
  To: Suraj Jitindar Singh, kvm; +Cc: pbonzini, rkrcmar, paulus, dja



On 28.05.19 10:35, Suraj Jitindar Singh wrote:
> KVM capabilities are used to communicate the availability of certain
> capabilities to userspace.
> 
> It might be nice to know these values without having to add debug
> printing to the userspace tool consuming this data.
> 
> Thus add a file in the kvm per vm debugfs file named "caps" which
> contains a file for each capability number which when read returns what
> would be returned when querying that capability.
> 
> Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
> 
> ---
> 
> I'm not sure if it'd be better to keep a per arch list of the revelevant
> capabilities to avoid adding an entry for irrelevant ones. Comments?
> ---
>  include/linux/kvm_host.h |  1 +
>  include/uapi/linux/kvm.h |  1 +
>  virt/kvm/kvm_main.c      | 31 +++++++++++++++++++++++++++++++
>  3 files changed, 33 insertions(+)
> 
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 79fa4426509c..6cb45a8de818 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -500,6 +500,7 @@ struct kvm {
>  	bool manual_dirty_log_protect;
>  	struct dentry *debugfs_dentry;
>  	struct kvm_stat_data **debugfs_stat_data;
> +	int debugfs_cap_data[KVM_CAP_MAX + 1];
>  	struct srcu_struct srcu;
>  	struct srcu_struct irq_srcu;
>  	pid_t userspace_pid;
> diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
> index 2fe12b40d503..7b5042ec5902 100644
> --- a/include/uapi/linux/kvm.h
> +++ b/include/uapi/linux/kvm.h
> @@ -993,6 +993,7 @@ struct kvm_ppc_resize_hpt {
>  #define KVM_CAP_ARM_SVE 170
>  #define KVM_CAP_ARM_PTRAUTH_ADDRESS 171
>  #define KVM_CAP_ARM_PTRAUTH_GENERIC 172
> +#define KVM_CAP_MAX	KVM_CAP_ARM_PTRAUTH_GENERIC
> 
>  #ifdef KVM_CAP_IRQ_ROUTING
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 134ec0283a8a..b85a43263fb7 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -117,6 +117,7 @@ EXPORT_SYMBOL_GPL(kvm_debugfs_dir);
>  static int kvm_debugfs_num_entries;
>  static const struct file_operations *stat_fops_per_vm[];
> 
> +static long kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg);
>  static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl,
>  			   unsigned long arg);
>  #ifdef CONFIG_KVM_COMPAT
> @@ -594,6 +595,33 @@ static void kvm_destroy_vm_debugfs(struct kvm *kvm)
>  	}
>  }
> 
> +static int vm_cap_get(void *data, u64 *val)
> +{
> +	*val = *((int *) data);
> +
> +	return 0;
> +}
> +
> +DEFINE_SIMPLE_ATTRIBUTE(cap_fops, vm_cap_get, NULL, "%llu\n");
> +
> +static void kvm_create_vm_cap_debugfs(struct kvm *kvm)
> +{
> +	char *dir_name = "caps";
> +	struct dentry *dentry_p;
> +	int i;
> +
> +	dentry_p = debugfs_create_dir(dir_name, kvm->debugfs_dentry);
> +
> +	for (i = 0; i <= KVM_CAP_MAX; i++) {
> +		int *cap = &kvm->debugfs_cap_data[i];
> +		char file_name[ITOA_MAX_LEN];
> +
> +		*cap = kvm_vm_ioctl_check_extension_generic(kvm, i);
> +		snprintf(file_name, sizeof(file_name), "%d", i);
> +		debugfs_create_file(file_name, 0444, dentry_p, cap, &cap_fops);
> +	}

So you get the information of the capabilities during creation of the VM.
Are there any capabilities that might change over time? I do not know right
now, but wouldnt it be better to actually call kvm_vm_ioctl_check_extension_generic
in the fops callback?

> +}
> +
>  static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
>  {
>  	char dir_name[ITOA_MAX_LEN * 2];
> @@ -623,6 +651,9 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
>  		debugfs_create_file(p->name, 0644, kvm->debugfs_dentry,
>  				    stat_data, stat_fops_per_vm[p->kind]);
>  	}
> +
> +	kvm_create_vm_cap_debugfs(kvm);
> +
>  	return 0;
>  }
> 


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

* Re: [PATCH] kvm: add kvm cap values to debugfs
  2019-05-28  8:35 [PATCH] kvm: add kvm cap values to debugfs Suraj Jitindar Singh
  2019-05-28 10:32 ` Christian Borntraeger
@ 2019-05-28 10:35 ` Paolo Bonzini
  2019-06-20  6:25   ` Suraj Jitindar Singh
  1 sibling, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2019-05-28 10:35 UTC (permalink / raw)
  To: Suraj Jitindar Singh, kvm; +Cc: rkrcmar, paulus, dja

On 28/05/19 10:35, Suraj Jitindar Singh wrote:
> KVM capabilities are used to communicate the availability of certain
> capabilities to userspace.
> 
> It might be nice to know these values without having to add debug
> printing to the userspace tool consuming this data.

Why not write a separate script that prints the capability values?

Paolo

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

* Re: [PATCH] kvm: add kvm cap values to debugfs
  2019-05-28 10:35 ` Paolo Bonzini
@ 2019-06-20  6:25   ` Suraj Jitindar Singh
  0 siblings, 0 replies; 4+ messages in thread
From: Suraj Jitindar Singh @ 2019-06-20  6:25 UTC (permalink / raw)
  To: Paolo Bonzini, kvm; +Cc: rkrcmar, paulus, dja

On Tue, 2019-05-28 at 12:35 +0200, Paolo Bonzini wrote:
> On 28/05/19 10:35, Suraj Jitindar Singh wrote:
> > KVM capabilities are used to communicate the availability of
> > certain
> > capabilities to userspace.
> > 
> > It might be nice to know these values without having to add debug
> > printing to the userspace tool consuming this data.
> 
> Why not write a separate script that prints the capability values?

I agree that this makes more sense as a standalone userspace script.
Dropping this patch.

Thanks,
Suraj

> 
> Paolo

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

end of thread, other threads:[~2019-06-20  6:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-28  8:35 [PATCH] kvm: add kvm cap values to debugfs Suraj Jitindar Singh
2019-05-28 10:32 ` Christian Borntraeger
2019-05-28 10:35 ` Paolo Bonzini
2019-06-20  6:25   ` Suraj Jitindar Singh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.