expose hypervisor information on cpuid
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).
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
@@ -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
@@ -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
@@ -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
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
@@ -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
@@ -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
Re: [PATCH 1/2] show hypervisor information on cpuinfo
In reply to Glauber CostaI 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
Re: [PATCH 1/2] show hypervisor information on cpuinfo
In reply to Glauber Costaarch/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
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 guestIngo
--
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
Re: [PATCH 1/2] show hypervisor information on cpuinfo
In reply to Ingo MolnarQuoted 1 line · * Ingo Molnar ([email protected]) wrote:
virtualization: Linux guest
That's confusing. Meaning lguest? These are all Linux guests ;-)
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/cpuinfoappears as one good candidate.
What's wrong with /sys/hypervisor? That's what it's there for.
thanks,
-chris
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/cpuinfoappears 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.