Skip to contentSkip to conversation

KVM: Report hardware virtualization features

PATCH In review Yang, Sheng 3 participants 8 messages Jun 19, 2008 – Jun 23, 2008 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 KVM: Report hardware virtualization features

From f02d2ccf01e8671d2da517f14a908d1df1cc42ad Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Thu, 19 Jun 2008 18:41:26 +0800
Subject: [PATCH] KVM: Report hardware virtualization features

The hardware virtualization technology evolves very fast. But currently it's hard to tell if your CPU support certain kind of HW technology without dig into the source code.

The patch introduced a virtual file called "kvm_hw_feature_report" under /sys/devices/system/kvm/kvm0 to show the mainly important current hardware virtualization feature, then it's pretty easy to tell if your CPU support some advanced virtualization technology now.

---
 include/linux/kvm_host.h |    3 +++
 virt/kvm/kvm_main.c      |   26 ++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)
include/linux/kvm_host.h +3 -0
index d220b49..654dba6 100644
@@ -278,6 +278,9 @@ int kvm_cpu_has_interrupt(struct kvm_vcpu *v);
 int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu);
 void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
 
+int kvm_register_hw_feature_report(int (*show)(char *page));
+void kvm_unregister_hw_feature_report(void);
+
 static inline void kvm_guest_enter(void)
 {
 	account_system_vtime(current);
virt/kvm/kvm_main.c +26 -0
index 4f38f5c..8eb74e5 100644
@@ -1518,6 +1518,32 @@ static struct sys_device kvm_sysdev = {
 	.cls = &kvm_sysdev_class,
 };
 
+static int (*kvm_hw_fea_show_func)(char *);
+
+static ssize_t kvm_hw_feature_show(struct sys_device *dev, char *page)
+{
+	if (!kvm_hw_fea_show_func)
+		return 0;
+	return kvm_hw_fea_show_func(page);
+}
+
+static SYSDEV_ATTR(kvm_hw_feature_report, 0444, kvm_hw_feature_show, 0)
+
+int kvm_register_hw_feature_report(int (*show)(char *page))
+{
+	if (kvm_hw_fea_show_func)
+		sysdev_remove_file(&kvm_sysdev, &attr_kvm_hw_feature_report);
+	kvm_hw_fea_show_func = show;
+	return sysdev_create_file(&kvm_sysdev, &attr_kvm_hw_feature_report);
+}
+EXPORT_SYMBOL_GPL(kvm_register_hw_feature_report);
+
+void kvm_unregister_hw_feature_report(void)
+{
+	kvm_hw_fea_show_func = NULL;
+}
+EXPORT_SYMBOL_GPL(kvm_unregister_hw_feature_report);
+
 struct page *bad_page;
 pfn_t bad_pfn;
 

--
1.5.5

From f02d2ccf01e8671d2da517f14a908d1df1cc42ad Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Thu, 19 Jun 2008 18:41:26 +0800
Subject: [PATCH] KVM: Report hardware virtualization features

The hardware virtualization technology evolves very fast. But currently it's hard to tell if your CPU support certain kind of HW technology without dig into the source code.

The patch introduced a virtual file called "kvm_hw_feature_report" under /sys/devices/system/kvm/kvm0 to show the mainly important current hardware virtualization feature, then it's pretty easy to tell if your CPU support some advanced virtualization technology now.

---
 include/linux/kvm_host.h |    3 +++
 virt/kvm/kvm_main.c      |   26 ++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)
include/linux/kvm_host.h +3 -0
index d220b49..654dba6 100644
@@ -278,6 +278,9 @@ int kvm_cpu_has_interrupt(struct kvm_vcpu *v);
 int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu);
 void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
 
+int kvm_register_hw_feature_report(int (*show)(char *page));
+void kvm_unregister_hw_feature_report(void);
+
 static inline void kvm_guest_enter(void)
 {
 	account_system_vtime(current);
virt/kvm/kvm_main.c +26 -0
index 4f38f5c..8eb74e5 100644
@@ -1518,6 +1518,32 @@ static struct sys_device kvm_sysdev = {
 	.cls = &kvm_sysdev_class,
 };
 
+static int (*kvm_hw_fea_show_func)(char *);
+
+static ssize_t kvm_hw_feature_show(struct sys_device *dev, char *page)
+{
+	if (!kvm_hw_fea_show_func)
+		return 0;
+	return kvm_hw_fea_show_func(page);
+}
+
+static SYSDEV_ATTR(kvm_hw_feature_report, 0444, kvm_hw_feature_show, 0)
+
+int kvm_register_hw_feature_report(int (*show)(char *page))
+{
+	if (kvm_hw_fea_show_func)
+		sysdev_remove_file(&kvm_sysdev, &attr_kvm_hw_feature_report);
+	kvm_hw_fea_show_func = show;
+	return sysdev_create_file(&kvm_sysdev, &attr_kvm_hw_feature_report);
+}
+EXPORT_SYMBOL_GPL(kvm_register_hw_feature_report);
+
+void kvm_unregister_hw_feature_report(void)
+{
+	kvm_hw_fea_show_func = NULL;
+}
+EXPORT_SYMBOL_GPL(kvm_unregister_hw_feature_report);
+
 struct page *bad_page;
 pfn_t bad_pfn;
 
Signature · 1 line
1.5.5
#1 lore raw
Quoted 5 lines · Sheng

From f02d2ccf01e8671d2da517f14a908d1df1cc42ad Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Thu, 19 Jun 2008 18:41:26 +0800
Subject: [PATCH] KVM: Report hardware virtualization features

Quoted 9 lines

The hardware virtualization technology evolves very fast. But currently it's hard to tell if your CPU support certain kind of HW technology without dig into the source code.

The patch introduced a virtual file called "kvm_hw_feature_report" under /sys/devices/system/kvm/kvm0 to show the mainly important current hardware virtualization feature, then it's pretty easy to tell if your CPU support some advanced virtualization technology now.

Yes, this is definitely helpful. However, I think that users will expect cpu flags under /proc/cpuinfo.

Perhaps we should add a new line 'virt flags' to /proc/cpuinfo? I think all the features are reported using msrs, so it can be done from arch/x86/kernel/cpu/proc.c without involving kvm at all.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#2 lore raw
Quoted 17 lines · Avi Kivity
Quoted 5 lines · Sheng

From f02d2ccf01e8671d2da517f14a908d1df1cc42ad Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Thu, 19 Jun 2008 18:41:26 +0800
Subject: [PATCH] KVM: Report hardware virtualization features

Quoted 10 lines

The hardware virtualization technology evolves very fast. But currently it's hard to tell if your CPU support certain kind of HW technology without dig into the source code.

The patch introduced a virtual file called "kvm_hw_feature_report" under /sys/devices/system/kvm/kvm0 to show the mainly important current hardware virtualization feature, then it's pretty easy to tell if your CPU support some advanced virtualization technology now.

Quoted 7 lines

Yes, this is definitely helpful. However, I think that users will expect cpu flags under /proc/cpuinfo.

Perhaps we should add a new line 'virt flags' to /proc/cpuinfo? I think all the features are reported using msrs, so it can be done from arch/x86/kernel/cpu/proc.c without involving kvm at all.

while I agree with Avi, it would be nice thought to see them on older kernels. At least sprinkle a printk message.

#3 lore raw
Quoted 10 lines · Dor Laor
Quoted 6 lines

Yes, this is definitely helpful. However, I think that users will expect cpu flags under /proc/cpuinfo.

Perhaps we should add a new line 'virt flags' to /proc/cpuinfo? I think all the features are reported using msrs, so it can be done from arch/x86/kernel/cpu/proc.c without involving kvm at all.

while I agree with Avi, it would be nice thought to see them on older kernels. At least sprinkle a printk message.

Oh we'll certainly hack something for the external modules.

Signature · 1 line
error compiling committee.c: too many arguments to function
#4 lore raw
Quoted 4 lines · On Sunday 22 June 2008 20:21:37 Avi Kivity wrote:
Quoted 3 lines · Dor Laor
Quoted 3 lines

Yes, this is definitely helpful. However, I think that users will expect cpu flags under /proc/cpuinfo.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Perhaps we should add a new line 'virt flags' to /proc/cpuinfo? I think all the features are reported using msrs, so it can be done from arch/x86/kernel/cpu/proc.c without involving kvm at all.

while I agree with Avi, it would be nice thought to see them on older kernels. At least sprinkle a printk message.

Oh we'll certainly hack something for the external modules.

Yeah, add a virt flags is more directly, and I think it's not hard to be accepted. I will do that.

And as Dor said, I think we also need a relative elegant method for the modules. So maybe we can keep these patches? Without that bash script. :)

--
Thanks
Yang, Sheng

#5 lore raw
Quoted 11 lines · Sheng
Quoted 9 lines · On Sunday 22 June 2008 20:21:37 Avi Kivity wrote:
Quoted 7 lines · Dor Laor
Quoted 7 lines

Yes, this is definitely helpful. However, I think that users will expect cpu flags under /proc/cpuinfo.

Perhaps we should add a new line 'virt flags' to /proc/cpuinfo? I think all the features are reported using msrs, so it can be done from arch/x86/kernel/cpu/proc.c without involving kvm at all.

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

while I agree with Avi, it would be nice thought to see them on older kernels. At least sprinkle a printk message.

Oh we'll certainly hack something for the external modules.

Yeah, add a virt flags is more directly, and I think it's not hard to be accepted. I will do that.

Perhaps just adding to the standard flags line is best, since tools already read it.

Quoted 3 lines

And as Dor said, I think we also need a relative elegant method for the modules. So maybe we can keep these patches? Without that bash script. :)

I'll just copy the code that finally makes it and put it in kernel/external-module-compat.c. Patches would stop applying soon.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#6 lore raw
Quoted 13 lines · On Monday 23 June 2008 10:40:33 Avi Kivity wrote:
Quoted 12 lines · Sheng
Quoted 11 lines · On Sunday 22 June 2008 20:21:37 Avi Kivity wrote:
Quoted 9 lines · Dor Laor
Quoted 6 lines

Yes, this is definitely helpful. However, I think that users will expect cpu flags under /proc/cpuinfo.

Perhaps we should add a new line 'virt flags' to /proc/cpuinfo? I think all the features are reported using msrs, so it can be done from arch/x86/kernel/cpu/proc.c without involving kvm at all.

while I agree with Avi, it would be nice thought to see them on older kernels. At least sprinkle a printk message.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Oh we'll certainly hack something for the external modules.

Yeah, add a virt flags is more directly, and I think it's not hard to be accepted. I will do that.

Perhaps just adding to the standard flags line is best, since tools already read it.

I was thinking of it before, but later I think it's not very proper.
1. The standard flag covered upper level of cpu capability.
2. If we add virtual feature to standard flag, I am afraid it would grow too fast.

So I prefer to add a new "virt flag".

Quoted 6 lines
Quoted 3 lines

And as Dor said, I think we also need a relative elegant method for the modules. So maybe we can keep these patches? Without that bash script. :)

I'll just copy the code that finally makes it and put it in kernel/external-module-compat.c. Patches would stop applying soon.

You means the current patchset or patch for /proc/cpuinfo? :)

--
Thanks
Yang, Sheng

#7 lore raw
Quoted 29 lines · Sheng
Quoted 13 lines · On Monday 23 June 2008 10:40:33 Avi Kivity wrote:
Quoted 12 lines · Sheng
Quoted 11 lines · On Sunday 22 June 2008 20:21:37 Avi Kivity wrote:
Quoted 9 lines · Dor Laor
Quoted 6 lines

Yes, this is definitely helpful. However, I think that users will expect cpu flags under /proc/cpuinfo.

Perhaps we should add a new line 'virt flags' to /proc/cpuinfo? I think all the features are reported using msrs, so it can be done from arch/x86/kernel/cpu/proc.c without involving kvm at all.

while I agree with Avi, it would be nice thought to see them on older kernels. At least sprinkle a printk message.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Oh we'll certainly hack something for the external modules.

Yeah, add a virt flags is more directly, and I think it's not hard to be accepted. I will do that.

Perhaps just adding to the standard flags line is best, since tools already read it.

I was thinking of it before, but later I think it's not very proper.
1. The standard flag covered upper level of cpu capability.
2. If we add virtual feature to standard flag, I am afraid it would grow too fast.

So I prefer to add a new "virt flag".

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

And as Dor said, I think we also need a relative elegant method for the modules. So maybe we can keep these patches? Without that bash script. :)

I'll just copy the code that finally makes it and put it in kernel/external-module-compat.c. Patches would stop applying soon.

You means the current patchset or patch for /proc/cpuinfo? :)

One of my colleague said that if we modify /proc/cpuinfo, it may cause some trouble for some not well designed userspace parser... So he thought we should be careful about modify this interface.

Add flag to standard flags can avoid this, but I still think it make some different things mixture...

Maybe we should contact some guy on X86 side?

--
Thanks
Yang, Sheng