2008-06-24 09:08:45

by Yang, Sheng

[permalink] [raw]
Subject: [PATCH 2/2] x86: Add "virt flag" in /proc/cpuinfo

From 54b1bb9fe5d2fe40fc047b43dd4e1a480d41a977 Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Tue, 24 Jun 2008 17:03:17 +0800
Subject: [PATCH] x86: Add "virt flag" in /proc/cpuinfo

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

The patch add a new item under /proc/cpuinfo, named "virt flag". The "virt
flag" got the similar function as "flag". It is used to indicate what
features does this CPU supported. It don't cover all features but only the
important ones.

Current implement just cover Intel VMX side.

Signed-off-by: Sheng Yang <[email protected]>
---
arch/x86/kernel/cpu/proc.c | 28 ++++++++++++++++++++++++++++
include/asm-x86/cpufeature.h | 9 +++++++++
2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c
index 0d0d905..03b30d0 100644
--- a/arch/x86/kernel/cpu/proc.c
+++ b/arch/x86/kernel/cpu/proc.c
@@ -77,6 +77,31 @@ static void show_cpuinfo_misc(struct seq_file *m, struct
cpuinfo_x86 *c)
}
#endif

+static void show_cpuinfo_vmx_virtflag(struct seq_file *m)
+{
+ u32 vmx_msr_low, vmx_msr_high, msr_ctl, msr_ctl2;
+
+ seq_printf(m, "\nvirt flag\t:");
+ rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, vmx_msr_low, vmx_msr_high);
+ msr_ctl = 0xffffffff & vmx_msr_high | vmx_msr_low;
+ if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW)
+ seq_printf(m, " tpr_shadow");
+ if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_VNMI)
+ seq_printf(m, " vnmi");
+ if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS) {
+ rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2,
+ vmx_msr_low, vmx_msr_high);
+ msr_ctl2 = 0xffffffff & vmx_msr_high | vmx_msr_low;
+ if ((msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC) &&
+ (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW))
+ seq_printf(m, " flexpriority");
+ if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_EPT)
+ seq_printf(m, " ept");
+ if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VPID)
+ seq_printf(m, " vpid");
+ }
+}
+
static int show_cpuinfo(struct seq_file *m, void *v)
{
struct cpuinfo_x86 *c = v;
@@ -123,6 +148,9 @@ static int show_cpuinfo(struct seq_file *m, void *v)
if (cpu_has(c, i) && x86_cap_flags[i] != NULL)
seq_printf(m, " %s", x86_cap_flags[i]);

+ if (cpu_has(c, X86_FEATURE_VMX))
+ show_cpuinfo_vmx_virtflag(m);
+
seq_printf(m, "\nbogomips\t: %lu.%02lu\n",
c->loops_per_jiffy/(500000/HZ),
(c->loops_per_jiffy/(5000/HZ)) % 100);
diff --git a/include/asm-x86/cpufeature.h b/include/asm-x86/cpufeature.h
index 0d609c8..87d8084 100644
--- a/include/asm-x86/cpufeature.h
+++ b/include/asm-x86/cpufeature.h
@@ -84,6 +84,7 @@
#define X86_FEATURE_XMM3 (4*32+ 0) /* Streaming SIMD Extensions-3 */
#define X86_FEATURE_MWAIT (4*32+ 3) /* Monitor/Mwait support */
#define X86_FEATURE_DSCPL (4*32+ 4) /* CPL Qualified Debug Store */
+#define X86_FEATURE_VMX (4*32+ 5) /* Virtual Machine eXtensions */
#define X86_FEATURE_EST (4*32+ 7) /* Enhanced SpeedStep */
#define X86_FEATURE_TM2 (4*32+ 8) /* Thermal Monitor 2 */
#define X86_FEATURE_CID (4*32+10) /* Context ID */
@@ -113,6 +114,14 @@
*/
#define X86_FEATURE_IDA (7*32+ 0) /* Intel Dynamic Acceleration */

+/* Intel VMX MSR indicated features */
+#define X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW 0x00200000
+#define X86_VMX_FEATURE_PROC_CTLS_VNMI 0x00400000
+#define X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS 0x80000000
+#define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC 0x00000001
+#define X86_VMX_FEATURE_PROC_CTLS2_EPT 0x00000002
+#define X86_VMX_FEATURE_PROC_CTLS2_VPID 0x00000020
+
#if defined(__KERNEL__) && !defined(__ASSEMBLY__)

#include <linux/bitops.h>
--
1.5.5


Attachments:
(No filename) (3.64 kB)
0003-x86-Add-virt-flag-in-proc-cpuinfo.patch (3.65 kB)
Download all attachments

2008-06-25 10:38:18

by Avi Kivity

[permalink] [raw]
Subject: Re: [PATCH 2/2] x86: Add "virt flag" in /proc/cpuinfo

(copying Ingo)


Yang, Sheng wrote:
> From 54b1bb9fe5d2fe40fc047b43dd4e1a480d41a977 Mon Sep 17 00:00:00 2001
> From: Sheng Yang <[email protected]>
> Date: Tue, 24 Jun 2008 17:03:17 +0800
> Subject: [PATCH] x86: Add "virt flag" in /proc/cpuinfo
>
> The hardware virtualization technology evolves very fast. But currently
> it's hard to tell if your CPU support a certain kind of HW technology without
> dig into the source code.
>
> The patch add a new item under /proc/cpuinfo, named "virt flag". The "virt
> flag" got the similar function as "flag". It is used to indicate what
> features does this CPU supported. It don't cover all features but only the
> important ones.
>
>

Ingo, do you prefer this as a separate 'virt flags' line or as addition
to the 'flag' line?

> Current implement just cover Intel VMX side.
>
> Signed-off-by: Sheng Yang <[email protected]>
> ---
> arch/x86/kernel/cpu/proc.c | 28 ++++++++++++++++++++++++++++
> include/asm-x86/cpufeature.h | 9 +++++++++
> 2 files changed, 37 insertions(+), 0 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c
> index 0d0d905..03b30d0 100644
> --- a/arch/x86/kernel/cpu/proc.c
> +++ b/arch/x86/kernel/cpu/proc.c
> @@ -77,6 +77,31 @@ static void show_cpuinfo_misc(struct seq_file *m, struct
> cpuinfo_x86 *c)
> }
> #endif
>
> +static void show_cpuinfo_vmx_virtflag(struct seq_file *m)
> +{
> + u32 vmx_msr_low, vmx_msr_high, msr_ctl, msr_ctl2;
> +
> + seq_printf(m, "\nvirt flag\t:");
> + rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, vmx_msr_low, vmx_msr_high);
> + msr_ctl = 0xffffffff & vmx_msr_high | vmx_msr_low;
> + if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW)
> + seq_printf(m, " tpr_shadow");
> + if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_VNMI)
> + seq_printf(m, " vnmi");
> + if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS) {
> + rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2,
> + vmx_msr_low, vmx_msr_high);
> + msr_ctl2 = 0xffffffff & vmx_msr_high | vmx_msr_low;
> + if ((msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC) &&
> + (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW))
> + seq_printf(m, " flexpriority");
> + if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_EPT)
> + seq_printf(m, " ept");
> + if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VPID)
> + seq_printf(m, " vpid");
> + }
> +}
> +
> static int show_cpuinfo(struct seq_file *m, void *v)
> {
> struct cpuinfo_x86 *c = v;
> @@ -123,6 +148,9 @@ static int show_cpuinfo(struct seq_file *m, void *v)
> if (cpu_has(c, i) && x86_cap_flags[i] != NULL)
> seq_printf(m, " %s", x86_cap_flags[i]);
>
> + if (cpu_has(c, X86_FEATURE_VMX))
> + show_cpuinfo_vmx_virtflag(m);
> +
> seq_printf(m, "\nbogomips\t: %lu.%02lu\n",
> c->loops_per_jiffy/(500000/HZ),
> (c->loops_per_jiffy/(5000/HZ)) % 100);
> diff --git a/include/asm-x86/cpufeature.h b/include/asm-x86/cpufeature.h
> index 0d609c8..87d8084 100644
> --- a/include/asm-x86/cpufeature.h
> +++ b/include/asm-x86/cpufeature.h
> @@ -84,6 +84,7 @@
> #define X86_FEATURE_XMM3 (4*32+ 0) /* Streaming SIMD Extensions-3 */
> #define X86_FEATURE_MWAIT (4*32+ 3) /* Monitor/Mwait support */
> #define X86_FEATURE_DSCPL (4*32+ 4) /* CPL Qualified Debug Store */
> +#define X86_FEATURE_VMX (4*32+ 5) /* Virtual Machine eXtensions */
> #define X86_FEATURE_EST (4*32+ 7) /* Enhanced SpeedStep */
> #define X86_FEATURE_TM2 (4*32+ 8) /* Thermal Monitor 2 */
> #define X86_FEATURE_CID (4*32+10) /* Context ID */
> @@ -113,6 +114,14 @@
> */
> #define X86_FEATURE_IDA (7*32+ 0) /* Intel Dynamic Acceleration */
>
> +/* Intel VMX MSR indicated features */
> +#define X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW 0x00200000
> +#define X86_VMX_FEATURE_PROC_CTLS_VNMI 0x00400000
> +#define X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS 0x80000000
> +#define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC 0x00000001
> +#define X86_VMX_FEATURE_PROC_CTLS2_EPT 0x00000002
> +#define X86_VMX_FEATURE_PROC_CTLS2_VPID 0x00000020
> +
> #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
>
> #include <linux/bitops.h>
> --
> 1.5.5
>
>


--
error compiling committee.c: too many arguments to function

2008-06-27 03:26:42

by Jeremy Fitzhardinge

[permalink] [raw]
Subject: Re: [PATCH 2/2] x86: Add "virt flag" in /proc/cpuinfo

Yang, Sheng wrote:
> From 54b1bb9fe5d2fe40fc047b43dd4e1a480d41a977 Mon Sep 17 00:00:00 2001
> From: Sheng Yang <[email protected]>
> Date: Tue, 24 Jun 2008 17:03:17 +0800
> Subject: [PATCH] x86: Add "virt flag" in /proc/cpuinfo
>
> The hardware virtualization technology evolves very fast. But currently
> it's hard to tell if your CPU support a certain kind of HW technology without
> dig into the source code.
>
> The patch add a new item under /proc/cpuinfo, named "virt flag". The "virt
> flag" got the similar function as "flag". It is used to indicate what
> features does this CPU supported. It don't cover all features but only the
> important ones.
>

A cpu feature is a cpu feature. I'd prefer to see all this in "flags:".

J

> Current implement just cover Intel VMX side.
>
> Signed-off-by: Sheng Yang <[email protected]>
> ---
> arch/x86/kernel/cpu/proc.c | 28 ++++++++++++++++++++++++++++
> include/asm-x86/cpufeature.h | 9 +++++++++
> 2 files changed, 37 insertions(+), 0 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c
> index 0d0d905..03b30d0 100644
> --- a/arch/x86/kernel/cpu/proc.c
> +++ b/arch/x86/kernel/cpu/proc.c
> @@ -77,6 +77,31 @@ static void show_cpuinfo_misc(struct seq_file *m, struct
> cpuinfo_x86 *c)
> }
> #endif
>
> +static void show_cpuinfo_vmx_virtflag(struct seq_file *m)
> +{
> + u32 vmx_msr_low, vmx_msr_high, msr_ctl, msr_ctl2;
> +
> + seq_printf(m, "\nvirt flag\t:");
> + rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, vmx_msr_low, vmx_msr_high);
> + msr_ctl = 0xffffffff & vmx_msr_high | vmx_msr_low;
> + if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW)
> + seq_printf(m, " tpr_shadow");
> + if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_VNMI)
> + seq_printf(m, " vnmi");
> + if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS) {
> + rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2,
> + vmx_msr_low, vmx_msr_high);
> + msr_ctl2 = 0xffffffff & vmx_msr_high | vmx_msr_low;
> + if ((msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC) &&
> + (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW))
> + seq_printf(m, " flexpriority");
> + if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_EPT)
> + seq_printf(m, " ept");
> + if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VPID)
> + seq_printf(m, " vpid");
> + }
> +}
> +
> static int show_cpuinfo(struct seq_file *m, void *v)
> {
> struct cpuinfo_x86 *c = v;
> @@ -123,6 +148,9 @@ static int show_cpuinfo(struct seq_file *m, void *v)
> if (cpu_has(c, i) && x86_cap_flags[i] != NULL)
> seq_printf(m, " %s", x86_cap_flags[i]);
>
> + if (cpu_has(c, X86_FEATURE_VMX))
> + show_cpuinfo_vmx_virtflag(m);
> +
> seq_printf(m, "\nbogomips\t: %lu.%02lu\n",
> c->loops_per_jiffy/(500000/HZ),
> (c->loops_per_jiffy/(5000/HZ)) % 100);
> diff --git a/include/asm-x86/cpufeature.h b/include/asm-x86/cpufeature.h
> index 0d609c8..87d8084 100644
> --- a/include/asm-x86/cpufeature.h
> +++ b/include/asm-x86/cpufeature.h
> @@ -84,6 +84,7 @@
> #define X86_FEATURE_XMM3 (4*32+ 0) /* Streaming SIMD Extensions-3 */
> #define X86_FEATURE_MWAIT (4*32+ 3) /* Monitor/Mwait support */
> #define X86_FEATURE_DSCPL (4*32+ 4) /* CPL Qualified Debug Store */
> +#define X86_FEATURE_VMX (4*32+ 5) /* Virtual Machine eXtensions */
> #define X86_FEATURE_EST (4*32+ 7) /* Enhanced SpeedStep */
> #define X86_FEATURE_TM2 (4*32+ 8) /* Thermal Monitor 2 */
> #define X86_FEATURE_CID (4*32+10) /* Context ID */
> @@ -113,6 +114,14 @@
> */
> #define X86_FEATURE_IDA (7*32+ 0) /* Intel Dynamic Acceleration */
>
> +/* Intel VMX MSR indicated features */
> +#define X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW 0x00200000
> +#define X86_VMX_FEATURE_PROC_CTLS_VNMI 0x00400000
> +#define X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS 0x80000000
> +#define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC 0x00000001
> +#define X86_VMX_FEATURE_PROC_CTLS2_EPT 0x00000002
> +#define X86_VMX_FEATURE_PROC_CTLS2_VPID 0x00000020
> +
> #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
>
> #include <linux/bitops.h>
> --
> 1.5.5
>
>

2008-06-27 03:31:21

by Yang, Sheng

[permalink] [raw]
Subject: Re: [PATCH 2/2] x86: Add "virt flag" in /proc/cpuinfo

On Friday 27 June 2008 11:26:15 Jeremy Fitzhardinge wrote:
> Yang, Sheng wrote:
> > From 54b1bb9fe5d2fe40fc047b43dd4e1a480d41a977 Mon Sep 17 00:00:00
> > 2001 From: Sheng Yang <[email protected]>
> > Date: Tue, 24 Jun 2008 17:03:17 +0800
> > Subject: [PATCH] x86: Add "virt flag" in /proc/cpuinfo
> >
> > The hardware virtualization technology evolves very fast. But
> > currently it's hard to tell if your CPU support a certain kind of
> > HW technology without dig into the source code.
> >
> > The patch add a new item under /proc/cpuinfo, named "virt flag".
> > The "virt flag" got the similar function as "flag". It is used to
> > indicate what features does this CPU supported. It don't cover
> > all features but only the important ones.
>
> A cpu feature is a cpu feature. I'd prefer to see all this in
> "flags:".
>
> J

But I think (as I said before)

1. The standard flag covered upper level of cpu capability, they are
covered by CPUID. And virt flag was enabled by vmx/svm (we can leave
it blank also), and covered by MSR. It's very different.

2. If we add virtual feature to standard flag, I am afraid it would
grow too fast, though we just add some key feature to it.

--
Thanks
Yang, Sheng

2008-06-27 14:51:19

by Aurelien Jarno

[permalink] [raw]
Subject: Re: [PATCH 2/2] x86: Add "virt flag" in /proc/cpuinfo

On Fri, Jun 27, 2008 at 11:31:38AM +0800, Yang, Sheng wrote:
> On Friday 27 June 2008 11:26:15 Jeremy Fitzhardinge wrote:
> > Yang, Sheng wrote:
> > > From 54b1bb9fe5d2fe40fc047b43dd4e1a480d41a977 Mon Sep 17 00:00:00
> > > 2001 From: Sheng Yang <[email protected]>
> > > Date: Tue, 24 Jun 2008 17:03:17 +0800
> > > Subject: [PATCH] x86: Add "virt flag" in /proc/cpuinfo
> > >
> > > The hardware virtualization technology evolves very fast. But
> > > currently it's hard to tell if your CPU support a certain kind of
> > > HW technology without dig into the source code.
> > >
> > > The patch add a new item under /proc/cpuinfo, named "virt flag".
> > > The "virt flag" got the similar function as "flag". It is used to
> > > indicate what features does this CPU supported. It don't cover
> > > all features but only the important ones.
> >
> > A cpu feature is a cpu feature. I'd prefer to see all this in
> > "flags:".
> >
> > J
>
> But I think (as I said before)
>
> 1. The standard flag covered upper level of cpu capability, they are
> covered by CPUID. And virt flag was enabled by vmx/svm (we can leave
> it blank also), and covered by MSR. It's very different.
>
> 2. If we add virtual feature to standard flag, I am afraid it would
> grow too fast, though we just add some key feature to it.
>

What about dumping the virtualisation flags to the kernel log when the
vmx/svm module is loaded?

Also do we have an idea of the number of flags that would appear on a
current CPU?

--
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73
: :' : Debian developer | Electrical Engineer
`. `' [email protected] | [email protected]
`- people.debian.org/~aurel32 | http://www.aurel32.net

2008-06-28 03:12:28

by Yang, Sheng

[permalink] [raw]
Subject: Re: [PATCH 2/2] x86: Add "virt flag" in /proc/cpuinfo

On Friday 27 June 2008 22:50:06 Aurelien Jarno wrote:
> On Fri, Jun 27, 2008 at 11:31:38AM +0800, Yang, Sheng wrote:
> > On Friday 27 June 2008 11:26:15 Jeremy Fitzhardinge wrote:
> > > Yang, Sheng wrote:
> > > > From 54b1bb9fe5d2fe40fc047b43dd4e1a480d41a977 Mon Sep 17
> > > > 00:00:00 2001 From: Sheng Yang <[email protected]>
> > > > Date: Tue, 24 Jun 2008 17:03:17 +0800
> > > > Subject: [PATCH] x86: Add "virt flag" in /proc/cpuinfo
> > > >
> > > > The hardware virtualization technology evolves very fast. But
> > > > currently it's hard to tell if your CPU support a certain
> > > > kind of HW technology without dig into the source code.
> > > >
> > > > The patch add a new item under /proc/cpuinfo, named "virt
> > > > flag". The "virt flag" got the similar function as "flag". It
> > > > is used to indicate what features does this CPU supported. It
> > > > don't cover all features but only the important ones.
> > >
> > > A cpu feature is a cpu feature. I'd prefer to see all this in
> > > "flags:".
> > >
> > > J
> >
> > But I think (as I said before)
> >
> > 1. The standard flag covered upper level of cpu capability, they
> > are covered by CPUID. And virt flag was enabled by vmx/svm (we
> > can leave it blank also), and covered by MSR. It's very
> > different.
> >
> > 2. If we add virtual feature to standard flag, I am afraid it
> > would grow too fast, though we just add some key feature to it.
>
> What about dumping the virtualisation flags to the kernel log when
> the vmx/svm module is loaded?
>
> Also do we have an idea of the number of flags that would appear on
> a current CPU?

I think dmesg is not so reliable...

At the time, I exported 5 flags for vmx, and 3 of them can be find in
current CPU.

My originally patch add a attribute on sysfs for kvm. But later Avi
suggest to use /proc/cpuinfo, for virtualization feature is becoming
more important part of CPU. And I agreed with him.

--
Thanks
Yang, Sheng