Skip to contentSkip to conversation

expose hypervisor information on cpuid

PATCH In review Glauber Costa 5 participants 9 messages Feb 5, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover expose hypervisor information on cpuid

This discussion happened some days ago in kvm list. We believe it's useful to advertise hypervisor information somewhere. /proc/cpuinfo appears as one good candidate.

This patch shows this information for vmware, kvm, and the string "none", otherwise. (someone would have to do it for xen, and possibly others, if this patch is to be accepted).

#1 lore raw

PATCH 1/2 show hypervisor information on cpuinfo

From: Glauber Costa <[email protected]>

It is useful to easily grab information about whether or not we're running on top of a hypervisor. And in case affirmative, which one.

This patch shows it in a newly added "hypervisor" field to cpuinfo. This seems to me like the best suited place for this.

We currently differentiate between vmware and none.

---
 arch/x86/include/asm/hypervisor.h |    1 +
 arch/x86/kernel/cpu/hypervisor.c  |    8 ++++++++
 arch/x86/kernel/cpu/proc.c        |    8 ++++++--
 3 files changed, 15 insertions(+), 2 deletions(-)
arch/x86/include/asm/hypervisor.h +1 -0
index 369f5c5..a0c0b0f 100644
@@ -22,5 +22,6 @@
 
 extern unsigned long get_hypervisor_tsc_freq(void);
 extern void init_hypervisor(struct cpuinfo_x86 *c);
+extern char *hypervisor_str(struct cpuinfo_x86 *c);
 
 #endif
arch/x86/kernel/cpu/hypervisor.c +8 -0
index fb5b86a..8c3fca7 100644
@@ -51,6 +51,14 @@ hypervisor_set_feature_bits(struct cpuinfo_x86 *c)
 	}
 }
 
+char * __cpuinit hypervisor_str(struct cpuinfo_x86 *c)
+{
+	if (c->x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE)
+		return "VMWare";
+	else
+		return "none";
+}
+
 void __cpuinit init_hypervisor(struct cpuinfo_x86 *c)
 {
 	detect_hypervisor_vendor(c);
arch/x86/kernel/cpu/proc.c +6 -2
index 01b1244..3700607 100644
@@ -4,6 +4,8 @@
 #include <linux/seq_file.h>
 #include <linux/cpufreq.h>
 
+#include <asm/hypervisor.h>
+
 /*
  *	Get CPU information for use by the procfs.
  */
@@ -90,12 +92,14 @@ static int show_cpuinfo(struct seq_file *m, void *v)
 		   "vendor_id\t: %s\n"
 		   "cpu family\t: %d\n"
 		   "model\t\t: %u\n"
-		   "model name\t: %s\n",
+		   "model name\t: %s\n"
+		   "hypervisor\t: %s\n",
 		   cpu,
 		   c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
 		   c->x86,
 		   c->x86_model,
-		   c->x86_model_id[0] ? c->x86_model_id : "unknown");
+		   c->x86_model_id[0] ? c->x86_model_id : "unknown",
+		   hypervisor_str(c));
 
 	if (c->x86_mask || c->cpuid_level >= 0)
 		seq_printf(m, "stepping\t: %d\n", c->x86_mask);
Signature · 1 line
1.5.6.5
#2 lore raw

PATCH 2/2 tell cpuinfo if we're running on top of KVM

From: Glauber Costa <[email protected]>

KVM has a specific cpuid signature, for a long time now. It's currently used in the kernel to advertise the possible availability of paravirt functions, but it's safe to assume that any reasonably recent kvm hypervisor will sign cpuid this way, regardless of any pv capability.

Use this information to fill in the hypervisor field in cpuinfo.

---
 arch/x86/include/asm/processor.h |    1 +
 arch/x86/kernel/cpu/hypervisor.c |    5 +++++
 2 files changed, 6 insertions(+), 0 deletions(-)
arch/x86/include/asm/processor.h +1 -0
index 091cd88..919c08d 100644
@@ -126,6 +126,7 @@ struct cpuinfo_x86 {
 
 #define X86_HYPER_VENDOR_NONE  0
 #define X86_HYPER_VENDOR_VMWARE 1
+#define X86_HYPER_VENDOR_KVM	2
 
 /*
  * capabilities of CPUs
arch/x86/kernel/cpu/hypervisor.c +5 -0
index 8c3fca7..251817a 100644
@@ -23,6 +23,7 @@
 
 #include <asm/processor.h>
 #include <asm/vmware.h>
+#include <asm/kvm_para.h>
 #include <asm/hypervisor.h>
 
 static inline void __cpuinit
@@ -30,6 +31,8 @@ detect_hypervisor_vendor(struct cpuinfo_x86 *c)
 {
 	if (vmware_platform()) {
 		c->x86_hyper_vendor = X86_HYPER_VENDOR_VMWARE;
+	} else if (kvm_para_available()) {
+		c->x86_hyper_vendor = X86_HYPER_VENDOR_KVM;
 	} else {
 		c->x86_hyper_vendor = X86_HYPER_VENDOR_NONE;
 	}
@@ -55,6 +58,8 @@ char * __cpuinit hypervisor_str(struct cpuinfo_x86 *c)
 {
 	if (c->x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE)
 		return "VMWare";
+	else if (c->x86_hyper_vendor == X86_HYPER_VENDOR_KVM)
+		return "KVM";
 	else
 		return "none";
 }
Signature · 1 line
1.5.6.5
#3 lore raw

Re: [PATCH 1/2] show hypervisor information on cpuinfo

In reply to Glauber Costa

I am all for it.

Just one nit, below.

arch/x86/kernel/cpu/hypervisor.c hypervisor_set_feature_bits(struct cpuinfo_x86 *c) · line 57

Quoted 5 lines
arch/x86/kernel/cpu/hypervisor.c +4 -0
+char * __cpuinit hypervisor_str(struct cpuinfo_x86 *c)
+{
+	if (c->x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE)
+		return "VMWare";

Better to have "VMware" string instead.

Thanks,
Alok

#4 lore raw

Re: [PATCH 1/2] show hypervisor information on cpuinfo

In reply to Glauber Costa

arch/x86/kernel/cpu/hypervisor.c hypervisor_set_feature_bits(struct cpuinfo_x86 *c) · line 60

Quoted 7 lines · Glauber Costa
arch/x86/kernel/cpu/hypervisor.c +7 -0
+char * __cpuinit hypervisor_str(struct cpuinfo_x86 *c)
+{
+	if (c->x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE)
+		return "VMWare";
+	else
+		return "none";
+}

i'd suggest these variants instead:

virtualization: native kernel
virtualization: KVM guest
virtualization: VMWare guest
virtualization: Linux guest

Ingo

#5 lore raw

Re: [PATCH 1/2] show hypervisor information on cpuinfo

Quoted 14 lines · Ingo Molnar

arch/x86/kernel/cpu/hypervisor.c hypervisor_set_feature_bits(struct cpuinfo_x86 *c) · line 60

Quoted 8 lines · Glauber Costa
arch/x86/kernel/cpu/hypervisor.c +7 -0
+char * __cpuinit hypervisor_str(struct cpuinfo_x86 *c)
+{
+	if (c->x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE)
+		return "VMWare";
+	else
+		return "none";
+}

i'd suggest these variants instead:

Quoted 2 lines

virtualization: native kernel

I don't think "native kernel" really ports well to other architectures (like s390 or PPC) that always have hypervisors present in some form. I think "none" makes more sense in the case of bare metal x86.

Regards,

Anthony Liguori

Quoted 10 lines

virtualization: KVM guest
virtualization: VMWare guest
virtualization: Linux guest

Ingo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw
In reply to Glauber Costa
Quoted 3 lines · * Glauber Costa ([email protected]) wrote:

This discussion happened some days ago in kvm list. We believe it's useful to advertise hypervisor information somewhere. /proc/cpuinfo appears as one good candidate.

What's wrong with /sys/hypervisor? That's what it's there for.

thanks,
-chris

#8 lore raw
Quoted 7 lines · Chris Wright
Quoted 3 lines · * Glauber Costa ([email protected]) wrote:

This discussion happened some days ago in kvm list. We believe it's useful to advertise hypervisor information somewhere. /proc/cpuinfo appears as one good candidate.

What's wrong with /sys/hypervisor? That's what it's there for.

I believe cpuinfo provides a more standard interface for that. But I'm not opposed to your suggestion.