Skip to contentSkip to conversation

vpmu: Add a vpmu cpuid function

PATCH In review Dietmar Hahn 4 participants 11 messages Jan 19, 2012 – Jan 20, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vpmu: Add a vpmu cpuid function

 tools/libxc/xc_cpuid_x86.c        |   1 +
 xen/arch/x86/hvm/vmx/vmx.c        |   2 ++
 xen/arch/x86/hvm/vmx/vpmu_core2.c |  38 ++++++++++++++++++++++++++++++++++++--
 xen/arch/x86/hvm/vpmu.c           |  25 ++++++++++++++++++-------
 xen/include/asm-x86/hvm/vpmu.h    |   6 ++++++
 5 files changed, 63 insertions(+), 9 deletions(-)

The "Debug Store" cpuid flag in the Intel processors gets enabled in the libxc. A new function call arch_vpmu_cpuid is added to the struct arch_vpmu_ops and for Intel processors the function core2_vpmu_cpuid() is added.
The aim is that always a "struct arch_vpmu_ops" is accessible at least with a cpuid function to switch off special PMU cpuid flags dynamically depending on the boot variable opt_vpmu_enabled.

tools/libxc/xc_cpuid_x86.c +1 -0
diff -r 7a82c2e2eb33 tools/libxc/xc_cpuid_x86.c
@@ -343,6 +343,7 @@ static void xc_cpuid_hvm_policy(
                     bitmaskof(X86_FEATURE_CMOV) |
                     bitmaskof(X86_FEATURE_PAT) |
                     bitmaskof(X86_FEATURE_CLFLSH) |
+                    bitmaskof(X86_FEATURE_DS) |
                     bitmaskof(X86_FEATURE_PSE36) |
                     bitmaskof(X86_FEATURE_MMX) |
                     bitmaskof(X86_FEATURE_FXSR) |
xen/arch/x86/hvm/vmx/vmx.c +2 -0
diff -r 7a82c2e2eb33 xen/arch/x86/hvm/vmx/vmx.c
@@ -1603,6 +1603,8 @@ static void vmx_cpuid_intercept(
             break;
     }
 
+    vpmu_do_cpuid(input, eax, ebx, ecx, edx);
+
     HVMTRACE_5D (CPUID, input, *eax, *ebx, *ecx, *edx);
 }
 
xen/arch/x86/hvm/vmx/vpmu_core2.c +36 -2
diff -r 7a82c2e2eb33 xen/arch/x86/hvm/vmx/vpmu_core2.c
@@ -598,6 +598,29 @@ static void core2_vpmu_destroy(struct vc
     vpmu->flags &= ~VPMU_CONTEXT_ALLOCATED;
 }
 
+/**
+ * core2_vpmu_cpuid - prepare special vpmu cpuid bits
+ * If emulation of vpmu is switched off, some bits are swtiched off, currently:
+ * - EAX[0x1].EAX[Bits 0-7]: PMC revision id.
+ * - EAX[0xa].EDX[Bit 21]:   Debug Store
+ */
+#define bitmaskof(idx)  (1U << ((idx) & 31))
+static void core2_vpmu_cpuid(unsigned int input,
+                             unsigned int *eax, unsigned int *ebx,
+                             unsigned int *ecx, unsigned int *edx)
+{
+    switch ( input )
+    {
+    case 0x1:
+        *edx &= ~bitmaskof(X86_FEATURE_DS);    /* Debug Store not supported */
+        break;
+    case 0xa:
+        if ( !opt_vpmu_enabled )
+            *eax &= ~(unsigned int)0xff;       /* Clear pmc version id. */
+        break;
+    }
+}
+
 struct arch_vpmu_ops core2_vpmu_ops = {
     .do_wrmsr = core2_vpmu_do_wrmsr,
     .do_rdmsr = core2_vpmu_do_rdmsr,
@@ -605,7 +628,13 @@ struct arch_vpmu_ops core2_vpmu_ops = {
     .arch_vpmu_initialise = core2_vpmu_initialise,
     .arch_vpmu_destroy = core2_vpmu_destroy,
     .arch_vpmu_save = core2_vpmu_save,
-    .arch_vpmu_load = core2_vpmu_load
+    .arch_vpmu_load = core2_vpmu_load,
+    .arch_vpmu_cpuid = core2_vpmu_cpuid
+};
+
+/* Used if vpmu is disabled. */
+struct arch_vpmu_ops core2_vpmu_dis_ops = {
+    .arch_vpmu_cpuid = core2_vpmu_cpuid
 };
 
 int vmx_vpmu_initialize(struct vcpu *v)
@@ -615,7 +644,7 @@ int vmx_vpmu_initialize(struct vcpu *v)
     __u8 cpu_model = current_cpu_data.x86_model;
 
     if ( !opt_vpmu_enabled )
-        return -EINVAL;
+        goto func_out;
 
     if ( family == 6 )
     {
@@ -635,6 +664,11 @@ int vmx_vpmu_initialize(struct vcpu *v)
     printk("VPMU: Initialization failed. "
            "Intel processor family %d model %d has not "
            "been supported\n", family, cpu_model);
+
+func_out:
+
+    vpmu->arch_vpmu_ops = &core2_vpmu_dis_ops;
+
     return -EINVAL;
 }
 
xen/arch/x86/hvm/vpmu.c +18 -7
diff -r 7a82c2e2eb33 xen/arch/x86/hvm/vpmu.c
@@ -39,7 +39,7 @@ int vpmu_do_wrmsr(unsigned int msr, uint
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(current);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_wrmsr )
         return vpmu->arch_vpmu_ops->do_wrmsr(msr, msr_content);
     return 0;
 }
@@ -48,7 +48,7 @@ int vpmu_do_rdmsr(unsigned int msr, uint
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(current);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_rdmsr )
         return vpmu->arch_vpmu_ops->do_rdmsr(msr, msr_content);
     return 0;
 }
@@ -57,7 +57,7 @@ int vpmu_do_interrupt(struct cpu_user_re
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(current);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_interrupt )
         return vpmu->arch_vpmu_ops->do_interrupt(regs);
     return 0;
 }
@@ -66,7 +66,7 @@ void vpmu_save(struct vcpu *v)
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(v);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_save )
         vpmu->arch_vpmu_ops->arch_vpmu_save(v);
 }
 
@@ -74,7 +74,7 @@ void vpmu_load(struct vcpu *v)
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(v);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_load )
         vpmu->arch_vpmu_ops->arch_vpmu_load(v);
 }
 
@@ -109,7 +109,8 @@ void vpmu_initialise(struct vcpu *v)
     {
         vpmu->flags = 0;
         vpmu->context = NULL;
-        vpmu->arch_vpmu_ops->arch_vpmu_initialise(v);
+        if ( vpmu->arch_vpmu_ops->arch_vpmu_initialise )
+            vpmu->arch_vpmu_ops->arch_vpmu_initialise(v);
     }
 }
 
@@ -117,7 +118,17 @@ void vpmu_destroy(struct vcpu *v)
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(v);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_destroy )
         vpmu->arch_vpmu_ops->arch_vpmu_destroy(v);
 }
 
+void vpmu_do_cpuid(unsigned int input,
+                   unsigned int *eax, unsigned int *ebx,
+                   unsigned int *ecx, unsigned int *edx)
+{
+    struct vpmu_struct *vpmu = vcpu_vpmu(current);
+
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_cpuid)
+        vpmu->arch_vpmu_ops->arch_vpmu_cpuid(input, eax, ebx, ecx, edx);
+}
+
xen/include/asm-x86/hvm/vpmu.h +6 -0
diff -r 7a82c2e2eb33 xen/include/asm-x86/hvm/vpmu.h
@@ -56,6 +56,9 @@ struct arch_vpmu_ops {
     void (*arch_vpmu_destroy)(struct vcpu *v);
     void (*arch_vpmu_save)(struct vcpu *v);
     void (*arch_vpmu_load)(struct vcpu *v);
+    void (*arch_vpmu_cpuid)(unsigned int input,
+                            unsigned int *eax, unsigned int *ebx,
+                            unsigned int *ecx, unsigned int *edx);
 };
 
 int vmx_vpmu_initialize(struct vcpu *v);
@@ -78,6 +81,9 @@ void vpmu_initialise(struct vcpu *v);
 void vpmu_destroy(struct vcpu *v);
 void vpmu_save(struct vcpu *v);
 void vpmu_load(struct vcpu *v);
+void vpmu_do_cpuid(unsigned int input,
+                   unsigned int *eax, unsigned int *ebx,
+                   unsigned int *ecx, unsigned int *edx);
 
 extern int acquire_pmu_ownership(int pmu_ownership);
 extern void release_pmu_ownership(int pmu_ownership);
Signature · 1 line
Company details: http://ts.fujitsu.com/imprint.html
#1 lore raw
Quoted 10 lines · Dietmar Hahn
 tools/libxc/xc_cpuid_x86.c        |   1 +
 xen/arch/x86/hvm/vmx/vmx.c        |   2 ++
 xen/arch/x86/hvm/vmx/vpmu_core2.c |  38
++++++++++++++++++++++++++++++++++++--
 xen/arch/x86/hvm/vpmu.c           |  25 ++++++++++++++++++-------
 xen/include/asm-x86/hvm/vpmu.h    |   6 ++++++
 5 files changed, 63 insertions(+), 9 deletions(-)
Quoted 9 lines

The "Debug Store" cpuid flag in the Intel processors gets enabled in the libxc.
A new function call arch_vpmu_cpuid is added to the struct arch_vpmu_ops and for
Intel processors the function core2_vpmu_cpuid() is added.
The aim is that always a "struct arch_vpmu_ops" is accessible at least with a cpuid function to switch off special PMU cpuid flags dynamically depending on
the boot variable opt_vpmu_enabled.

Our CPUID configuration is done per-domain, and from tools/libxc/xc_cpuid_x86.c. CPUID adjustments implemented within the hypervisor are generally not acceptable without very good reason.

-- Keir

Quoted 196 lines

diff -r 7a82c2e2eb33 tools/libxc/xc_cpuid_x86.c

tools/libxc/xc_cpuid_x86.c Thu Jan 19 14:37:17 2012 +0100 renamed from tools/libxc/xc_cpuid_x86.c Thu Jan 19 13:14:02 2012 +0100 +1 -0
@@ -343,6 +343,7 @@ static void xc_cpuid_hvm_policy(
                     bitmaskof(X86_FEATURE_CMOV) |
                     bitmaskof(X86_FEATURE_PAT) |
                     bitmaskof(X86_FEATURE_CLFLSH) |
+                    bitmaskof(X86_FEATURE_DS) |
                     bitmaskof(X86_FEATURE_PSE36) |
                     bitmaskof(X86_FEATURE_MMX) |
                     bitmaskof(X86_FEATURE_FXSR) |

diff -r 7a82c2e2eb33 xen/arch/x86/hvm/vmx/vmx.c

xen/arch/x86/hvm/vmx/vmx.c Thu Jan 19 14:37:17 2012 +0100 renamed from xen/arch/x86/hvm/vmx/vmx.c Thu Jan 19 13:14:02 2012 +0100 +2 -0
@@ -1603,6 +1603,8 @@ static void vmx_cpuid_intercept(
             break;
     }
 
+    vpmu_do_cpuid(input, eax, ebx, ecx, edx);
+
     HVMTRACE_5D (CPUID, input, *eax, *ebx, *ecx, *edx);
 }
 

diff -r 7a82c2e2eb33 xen/arch/x86/hvm/vmx/vpmu_core2.c

xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 14:37:17 2012 +0100 renamed from xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 13:14:02 2012 +0100 +3 -0
@@ -598,6 +598,29 @@ static void core2_vpmu_destroy(struct vc
     vpmu->flags &= ~VPMU_CONTEXT_ALLOCATED;
 }
 
+/**
+ * core2_vpmu_cpuid - prepare special vpmu cpuid bits
+ * If emulation of vpmu is switched off, some bits are swtiched off,

currently:
+ * - EAX[0x1].EAX[Bits 0-7]: PMC revision id.
+ * - EAX[0xa].EDX[Bit 21]: Debug Store
+ */

xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 14:37:17 2012 +0100 renamed from xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 13:14:02 2012 +0100 +9 -0
+#define bitmaskof(idx)  (1U << ((idx) & 31))
+static void core2_vpmu_cpuid(unsigned int input,
+                             unsigned int *eax, unsigned int *ebx,
+                             unsigned int *ecx, unsigned int *edx)
+{
+    switch ( input )
+    {
+    case 0x1:
+        *edx &= ~bitmaskof(X86_FEATURE_DS);    /* Debug Store not supported

*/

xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 14:37:17 2012 +0100 renamed from xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 13:14:02 2012 +0100 +21 -2
+        break;
+    case 0xa:
+        if ( !opt_vpmu_enabled )
+            *eax &= ~(unsigned int)0xff;       /* Clear pmc version id. */
+        break;
+    }
+}
+
 struct arch_vpmu_ops core2_vpmu_ops = {
     .do_wrmsr = core2_vpmu_do_wrmsr,
     .do_rdmsr = core2_vpmu_do_rdmsr,
@@ -605,7 +628,13 @@ struct arch_vpmu_ops core2_vpmu_ops = {
     .arch_vpmu_initialise = core2_vpmu_initialise,
     .arch_vpmu_destroy = core2_vpmu_destroy,
     .arch_vpmu_save = core2_vpmu_save,
-    .arch_vpmu_load = core2_vpmu_load
+    .arch_vpmu_load = core2_vpmu_load,
+    .arch_vpmu_cpuid = core2_vpmu_cpuid
+};
+
+/* Used if vpmu is disabled. */
+struct arch_vpmu_ops core2_vpmu_dis_ops = {
+    .arch_vpmu_cpuid = core2_vpmu_cpuid
 };
 
 int vmx_vpmu_initialize(struct vcpu *v)
@@ -615,7 +644,7 @@ int vmx_vpmu_initialize(struct vcpu *v)
     __u8 cpu_model = current_cpu_data.x86_model;
 
     if ( !opt_vpmu_enabled )
-        return -EINVAL;
+        goto func_out;
 
     if ( family == 6 )
     {
@@ -635,6 +664,11 @@ int vmx_vpmu_initialize(struct vcpu *v)
     printk("VPMU: Initialization failed. "
            "Intel processor family %d model %d has not "
            "been supported\n", family, cpu_model);
+
+func_out:
+
+    vpmu->arch_vpmu_ops = &core2_vpmu_dis_ops;
+
     return -EINVAL;
 }
 

diff -r 7a82c2e2eb33 xen/arch/x86/hvm/vpmu.c

xen/arch/x86/hvm/vpmu.c Thu Jan 19 14:37:17 2012 +0100 renamed from xen/arch/x86/hvm/vpmu.c Thu Jan 19 13:14:02 2012 +0100 +18 -7
@@ -39,7 +39,7 @@ int vpmu_do_wrmsr(unsigned int msr, uint
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(current);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_wrmsr )
         return vpmu->arch_vpmu_ops->do_wrmsr(msr, msr_content);
     return 0;
 }
@@ -48,7 +48,7 @@ int vpmu_do_rdmsr(unsigned int msr, uint
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(current);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_rdmsr )
         return vpmu->arch_vpmu_ops->do_rdmsr(msr, msr_content);
     return 0;
 }
@@ -57,7 +57,7 @@ int vpmu_do_interrupt(struct cpu_user_re
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(current);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_interrupt )
         return vpmu->arch_vpmu_ops->do_interrupt(regs);
     return 0;
 }
@@ -66,7 +66,7 @@ void vpmu_save(struct vcpu *v)
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(v);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_save )
         vpmu->arch_vpmu_ops->arch_vpmu_save(v);
 }
 
@@ -74,7 +74,7 @@ void vpmu_load(struct vcpu *v)
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(v);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_load )
         vpmu->arch_vpmu_ops->arch_vpmu_load(v);
 }
 
@@ -109,7 +109,8 @@ void vpmu_initialise(struct vcpu *v)
     {
         vpmu->flags = 0;
         vpmu->context = NULL;
-        vpmu->arch_vpmu_ops->arch_vpmu_initialise(v);
+        if ( vpmu->arch_vpmu_ops->arch_vpmu_initialise )
+            vpmu->arch_vpmu_ops->arch_vpmu_initialise(v);
     }
 }
 
@@ -117,7 +118,17 @@ void vpmu_destroy(struct vcpu *v)
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(v);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_destroy )
         vpmu->arch_vpmu_ops->arch_vpmu_destroy(v);
 }
 
+void vpmu_do_cpuid(unsigned int input,
+                   unsigned int *eax, unsigned int *ebx,
+                   unsigned int *ecx, unsigned int *edx)
+{
+    struct vpmu_struct *vpmu = vcpu_vpmu(current);
+
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_cpuid)
+        vpmu->arch_vpmu_ops->arch_vpmu_cpuid(input, eax, ebx, ecx, edx);
+}
+

diff -r 7a82c2e2eb33 xen/include/asm-x86/hvm/vpmu.h

xen/include/asm-x86/hvm/vpmu.h Thu Jan 19 14:37:17 2012 +0100 renamed from xen/include/asm-x86/hvm/vpmu.h Thu Jan 19 13:14:02 2012 +0100 +6 -0
@@ -56,6 +56,9 @@ struct arch_vpmu_ops {
     void (*arch_vpmu_destroy)(struct vcpu *v);
     void (*arch_vpmu_save)(struct vcpu *v);
     void (*arch_vpmu_load)(struct vcpu *v);
+    void (*arch_vpmu_cpuid)(unsigned int input,
+                            unsigned int *eax, unsigned int *ebx,
+                            unsigned int *ecx, unsigned int *edx);
 };
 
 int vmx_vpmu_initialize(struct vcpu *v);
@@ -78,6 +81,9 @@ void vpmu_initialise(struct vcpu *v);
 void vpmu_destroy(struct vcpu *v);
 void vpmu_save(struct vcpu *v);
 void vpmu_load(struct vcpu *v);
+void vpmu_do_cpuid(unsigned int input,
+                   unsigned int *eax, unsigned int *ebx,
+                   unsigned int *ecx, unsigned int *edx);
 
 extern int acquire_pmu_ownership(int pmu_ownership);
 extern void release_pmu_ownership(int pmu_ownership);
#2 lore raw

Am Freitag 20 Januar 2012, 10:29:41 schrieb Keir Fraser:

Quoted 22 lines · Dietmar Hahn
Quoted 11 lines

 tools/libxc/xc_cpuid_x86.c        |   1 +
 xen/arch/x86/hvm/vmx/vmx.c        |   2 ++
 xen/arch/x86/hvm/vmx/vpmu_core2.c |  38
++++++++++++++++++++++++++++++++++++--
 xen/arch/x86/hvm/vpmu.c           |  25 ++++++++++++++++++-------
 xen/include/asm-x86/hvm/vpmu.h    |   6 ++++++
 5 files changed, 63 insertions(+), 9 deletions(-)
Quoted 9 lines

The "Debug Store" cpuid flag in the Intel processors gets enabled in the libxc.
A new function call arch_vpmu_cpuid is added to the struct arch_vpmu_ops and for
Intel processors the function core2_vpmu_cpuid() is added.
The aim is that always a "struct arch_vpmu_ops" is accessible at least with a cpuid function to switch off special PMU cpuid flags dynamically depending on
the boot variable opt_vpmu_enabled.

Quoted 3 lines

Our CPUID configuration is done per-domain, and from tools/libxc/xc_cpuid_x86.c. CPUID adjustments implemented within the hypervisor are generally not acceptable without very good reason.

Then a way is needed to have access to the opt_vpmu_enabled variable within the hypervisor from the tools to decide the enabling of the flag (is there such a way?) or the mechanism with the boot variable must be changed.
The opt_vpmu_enabled boot variable was introduced because of a PMU problem in the Nehalem cpus leading sometimes to hypervisor crashes. But with the done quirk we never had a crash anymore.
So maybe we can always switch on the vpmu stuff in the hypervisor and add a flag in the domain configuration when somebody wants to do some performance tests?

Dietmar.

Quoted 202 lines

-- Keir

Quoted 196 lines

diff -r 7a82c2e2eb33 tools/libxc/xc_cpuid_x86.c

tools/libxc/xc_cpuid_x86.c Thu Jan 19 14:37:17 2012 +0100 renamed from tools/libxc/xc_cpuid_x86.c Thu Jan 19 13:14:02 2012 +0100 +1 -0
@@ -343,6 +343,7 @@ static void xc_cpuid_hvm_policy(
                     bitmaskof(X86_FEATURE_CMOV) |
                     bitmaskof(X86_FEATURE_PAT) |
                     bitmaskof(X86_FEATURE_CLFLSH) |
+                    bitmaskof(X86_FEATURE_DS) |
                     bitmaskof(X86_FEATURE_PSE36) |
                     bitmaskof(X86_FEATURE_MMX) |
                     bitmaskof(X86_FEATURE_FXSR) |

diff -r 7a82c2e2eb33 xen/arch/x86/hvm/vmx/vmx.c

xen/arch/x86/hvm/vmx/vmx.c Thu Jan 19 14:37:17 2012 +0100 renamed from xen/arch/x86/hvm/vmx/vmx.c Thu Jan 19 13:14:02 2012 +0100 +2 -0
@@ -1603,6 +1603,8 @@ static void vmx_cpuid_intercept(
             break;
     }
 
+    vpmu_do_cpuid(input, eax, ebx, ecx, edx);
+
     HVMTRACE_5D (CPUID, input, *eax, *ebx, *ecx, *edx);
 }
 

diff -r 7a82c2e2eb33 xen/arch/x86/hvm/vmx/vpmu_core2.c

xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 14:37:17 2012 +0100 renamed from xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 13:14:02 2012 +0100 +3 -0
@@ -598,6 +598,29 @@ static void core2_vpmu_destroy(struct vc
     vpmu->flags &= ~VPMU_CONTEXT_ALLOCATED;
 }
 
+/**
+ * core2_vpmu_cpuid - prepare special vpmu cpuid bits
+ * If emulation of vpmu is switched off, some bits are swtiched off,

currently:
+ * - EAX[0x1].EAX[Bits 0-7]: PMC revision id.
+ * - EAX[0xa].EDX[Bit 21]: Debug Store
+ */

xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 14:37:17 2012 +0100 renamed from xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 13:14:02 2012 +0100 +9 -0
+#define bitmaskof(idx)  (1U << ((idx) & 31))
+static void core2_vpmu_cpuid(unsigned int input,
+                             unsigned int *eax, unsigned int *ebx,
+                             unsigned int *ecx, unsigned int *edx)
+{
+    switch ( input )
+    {
+    case 0x1:
+        *edx &= ~bitmaskof(X86_FEATURE_DS);    /* Debug Store not supported

*/

xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 14:37:17 2012 +0100 renamed from xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 13:14:02 2012 +0100 +21 -2
+        break;
+    case 0xa:
+        if ( !opt_vpmu_enabled )
+            *eax &= ~(unsigned int)0xff;       /* Clear pmc version id. */
+        break;
+    }
+}
+
 struct arch_vpmu_ops core2_vpmu_ops = {
     .do_wrmsr = core2_vpmu_do_wrmsr,
     .do_rdmsr = core2_vpmu_do_rdmsr,
@@ -605,7 +628,13 @@ struct arch_vpmu_ops core2_vpmu_ops = {
     .arch_vpmu_initialise = core2_vpmu_initialise,
     .arch_vpmu_destroy = core2_vpmu_destroy,
     .arch_vpmu_save = core2_vpmu_save,
-    .arch_vpmu_load = core2_vpmu_load
+    .arch_vpmu_load = core2_vpmu_load,
+    .arch_vpmu_cpuid = core2_vpmu_cpuid
+};
+
+/* Used if vpmu is disabled. */
+struct arch_vpmu_ops core2_vpmu_dis_ops = {
+    .arch_vpmu_cpuid = core2_vpmu_cpuid
 };
 
 int vmx_vpmu_initialize(struct vcpu *v)
@@ -615,7 +644,7 @@ int vmx_vpmu_initialize(struct vcpu *v)
     __u8 cpu_model = current_cpu_data.x86_model;
 
     if ( !opt_vpmu_enabled )
-        return -EINVAL;
+        goto func_out;
 
     if ( family == 6 )
     {
@@ -635,6 +664,11 @@ int vmx_vpmu_initialize(struct vcpu *v)
     printk("VPMU: Initialization failed. "
            "Intel processor family %d model %d has not "
            "been supported\n", family, cpu_model);
+
+func_out:
+
+    vpmu->arch_vpmu_ops = &core2_vpmu_dis_ops;
+
     return -EINVAL;
 }
 

diff -r 7a82c2e2eb33 xen/arch/x86/hvm/vpmu.c

xen/arch/x86/hvm/vpmu.c Thu Jan 19 14:37:17 2012 +0100 renamed from xen/arch/x86/hvm/vpmu.c Thu Jan 19 13:14:02 2012 +0100 +18 -7
@@ -39,7 +39,7 @@ int vpmu_do_wrmsr(unsigned int msr, uint
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(current);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_wrmsr )
         return vpmu->arch_vpmu_ops->do_wrmsr(msr, msr_content);
     return 0;
 }
@@ -48,7 +48,7 @@ int vpmu_do_rdmsr(unsigned int msr, uint
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(current);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_rdmsr )
         return vpmu->arch_vpmu_ops->do_rdmsr(msr, msr_content);
     return 0;
 }
@@ -57,7 +57,7 @@ int vpmu_do_interrupt(struct cpu_user_re
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(current);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_interrupt )
         return vpmu->arch_vpmu_ops->do_interrupt(regs);
     return 0;
 }
@@ -66,7 +66,7 @@ void vpmu_save(struct vcpu *v)
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(v);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_save )
         vpmu->arch_vpmu_ops->arch_vpmu_save(v);
 }
 
@@ -74,7 +74,7 @@ void vpmu_load(struct vcpu *v)
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(v);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_load )
         vpmu->arch_vpmu_ops->arch_vpmu_load(v);
 }
 
@@ -109,7 +109,8 @@ void vpmu_initialise(struct vcpu *v)
     {
         vpmu->flags = 0;
         vpmu->context = NULL;
-        vpmu->arch_vpmu_ops->arch_vpmu_initialise(v);
+        if ( vpmu->arch_vpmu_ops->arch_vpmu_initialise )
+            vpmu->arch_vpmu_ops->arch_vpmu_initialise(v);
     }
 }
 
@@ -117,7 +118,17 @@ void vpmu_destroy(struct vcpu *v)
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(v);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_destroy )
         vpmu->arch_vpmu_ops->arch_vpmu_destroy(v);
 }
 
+void vpmu_do_cpuid(unsigned int input,
+                   unsigned int *eax, unsigned int *ebx,
+                   unsigned int *ecx, unsigned int *edx)
+{
+    struct vpmu_struct *vpmu = vcpu_vpmu(current);
+
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_cpuid)
+        vpmu->arch_vpmu_ops->arch_vpmu_cpuid(input, eax, ebx, ecx, edx);
+}
+

diff -r 7a82c2e2eb33 xen/include/asm-x86/hvm/vpmu.h

xen/include/asm-x86/hvm/vpmu.h Thu Jan 19 14:37:17 2012 +0100 renamed from xen/include/asm-x86/hvm/vpmu.h Thu Jan 19 13:14:02 2012 +0100 +6 -0
@@ -56,6 +56,9 @@ struct arch_vpmu_ops {
     void (*arch_vpmu_destroy)(struct vcpu *v);
     void (*arch_vpmu_save)(struct vcpu *v);
     void (*arch_vpmu_load)(struct vcpu *v);
+    void (*arch_vpmu_cpuid)(unsigned int input,
+                            unsigned int *eax, unsigned int *ebx,
+                            unsigned int *ecx, unsigned int *edx);
 };
 
 int vmx_vpmu_initialize(struct vcpu *v);
@@ -78,6 +81,9 @@ void vpmu_initialise(struct vcpu *v);
 void vpmu_destroy(struct vcpu *v);
 void vpmu_save(struct vcpu *v);
 void vpmu_load(struct vcpu *v);
+void vpmu_do_cpuid(unsigned int input,
+                   unsigned int *eax, unsigned int *ebx,
+                   unsigned int *ecx, unsigned int *edx);
 
 extern int acquire_pmu_ownership(int pmu_ownership);
 extern void release_pmu_ownership(int pmu_ownership);
Signature · 1 line
Company details: http://ts.fujitsu.com/imprint.html
#3 lore raw
Quoted 4 lines · Dietmar Hahn
Quoted 3 lines

Our CPUID configuration is done per-domain, and from tools/libxc/xc_cpuid_x86.c. CPUID adjustments implemented within the hypervisor are generally not acceptable without very good reason.

Quoted 10 lines

Then a way is needed to have access to the opt_vpmu_enabled variable within the
hypervisor from the tools to decide the enabling of the flag (is there such a way?) or the mechanism with the boot variable must be changed. The opt_vpmu_enabled boot variable was introduced because of a PMU problem in the Nehalem cpus leading sometimes to hypervisor crashes. But with the done quirk we never had a crash anymore.
So maybe we can always switch on the vpmu stuff in the hypervisor and add a flag in the domain configuration when somebody wants to do some performance tests?

Yes!

It's obviously an option of fairly narrow interest. If someone tries to enable the per-domain option on a CPU which has problems, you can fail the domain creation, or print a warning in the hypervisor log, or whatever. Any sensible option in that respect is fine by me!

-- Keir

#4 lore raw

Hi Ian,

Am Freitag 20 Januar 2012, 10:54:44 schrieb Keir Fraser:

Quoted 17 lines · Dietmar Hahn
Quoted 5 lines
Quoted 4 lines

Our CPUID configuration is done per-domain, and from tools/libxc/xc_cpuid_x86.c. CPUID adjustments implemented within the hypervisor are generally not acceptable without very good reason.

Quoted 10 lines

Then a way is needed to have access to the opt_vpmu_enabled variable within the
hypervisor from the tools to decide the enabling of the flag (is there such a way?) or the mechanism with the boot variable must be changed. The opt_vpmu_enabled boot variable was introduced because of a PMU problem in the Nehalem cpus leading sometimes to hypervisor crashes. But with the done quirk we never had a crash anymore.
So maybe we can always switch on the vpmu stuff in the hypervisor and add a flag in the domain configuration when somebody wants to do some performance tests?

Quoted 6 lines

Yes!

It's obviously an option of fairly narrow interest. If someone tries to enable the per-domain option on a CPU which has problems, you can fail the domain creation, or print a warning in the hypervisor log, or whatever. Any sensible option in that respect is fine by me!

What is the best solution for this?
A domain specific configuration option is needed (vpmu?) which is usable in libxc/xc_cpuid_x86.c to select/deselect special vpmu bits in the cpuid command. Can you point me to an proper example?
Thanks.

Dietmar.

Signature · 1 line
Company details: http://ts.fujitsu.com/imprint.html
#5 lore raw
Quoted 27 lines · Dietmar Hahn

Hi Ian,

Am Freitag 20 Januar 2012, 10:54:44 schrieb Keir Fraser:

Quoted 17 lines · Dietmar Hahn
Quoted 5 lines
Quoted 4 lines

Our CPUID configuration is done per-domain, and from tools/libxc/xc_cpuid_x86.c. CPUID adjustments implemented within the hypervisor are generally not acceptable without very good reason.

Quoted 10 lines

Then a way is needed to have access to the opt_vpmu_enabled variable within the
hypervisor from the tools to decide the enabling of the flag (is there such a way?) or the mechanism with the boot variable must be changed. The opt_vpmu_enabled boot variable was introduced because of a PMU problem in the Nehalem cpus leading sometimes to hypervisor crashes. But with the done quirk we never had a crash anymore.
So maybe we can always switch on the vpmu stuff in the hypervisor and add a flag in the domain configuration when somebody wants to do some performance tests?

Quoted 6 lines

Yes!

It's obviously an option of fairly narrow interest. If someone tries to enable the per-domain option on a CPU which has problems, you can fail the domain creation, or print a warning in the hypervisor log, or whatever. Any sensible option in that respect is fine by me!

Quoted 4 lines

What is the best solution for this?
A domain specific configuration option is needed (vpmu?) which is usable in libxc/xc_cpuid_x86.c to select/deselect special vpmu bits in the cpuid command. Can you point me to an proper example?

Can't this already be done via the cpuid domain option given the correct runes? Maybe with an addition to the table in libxl_cpuid_parse_config?

Ian.

#6 lore raw
Quoted 5 lines · Ian Campbell
Quoted 5 lines
Quoted 4 lines

It's obviously an option of fairly narrow interest. If someone tries to enable the per-domain option on a CPU which has problems, you can fail the domain creation, or print a warning in the hypervisor log, or whatever. Any sensible option in that respect is fine by me!

Quoted 8 lines
Quoted 5 lines

What is the best solution for this?
A domain specific configuration option is needed (vpmu?) which is usable in libxc/xc_cpuid_x86.c to select/deselect special vpmu bits in the cpuid command.
Can you point me to an proper example?

Can't this already be done via the cpuid domain option given the correct runes? Maybe with an addition to the table in libxl_cpuid_parse_config?

Yes that's probably the way to do it. If the resulting required configuration runes are too cryptic or vendor-specific, it may make sense to have the libxl cpuid logic consume a 'vpmu' option which it then turns into a set of lower-level cpuid settings to eventually pass down to the code in libxc/xc_cpuid.

It's a trifle messy I will admit. Arguably the 'default policy' bits of xc_cpuid_x86.c would better belong in libxl these days, where we would have better access to a domain's configuration state. As it is, we may end up with a spread of default policy across Xen (for dom0), libxc, and libxl.

-- Keir

#7 lore raw
Quoted 22 lines · Keir Fraser
Quoted 5 lines · Ian Campbell
Quoted 5 lines
Quoted 4 lines

It's obviously an option of fairly narrow interest. If someone tries to enable the per-domain option on a CPU which has problems, you can fail the domain creation, or print a warning in the hypervisor log, or whatever. Any sensible option in that respect is fine by me!

Quoted 8 lines
Quoted 5 lines

What is the best solution for this?
A domain specific configuration option is needed (vpmu?) which is usable in libxc/xc_cpuid_x86.c to select/deselect special vpmu bits in the cpuid command.
Can you point me to an proper example?

Can't this already be done via the cpuid domain option given the correct runes? Maybe with an addition to the table in libxl_cpuid_parse_config?

Yes that's probably the way to do it. If the resulting required configuration runes are too cryptic or vendor-specific, it may make sense to have the libxl cpuid logic consume a 'vpmu' option which it then turns into a set of lower-level cpuid settings to eventually pass down to the code in libxc/xc_cpuid.

Quoted 4 lines

It's a trifle messy I will admit. Arguably the 'default policy' bits of xc_cpuid_x86.c would better belong in libxl these days, where we would have better access to a domain's configuration state. As it is, we may end up with a spread of default policy across Xen (for dom0), libxc, and libxl.

Plus a bunch of ad-hoc stuff which predates the cpuid bit-fiddling support but is reflected in the cpuid (pae, apic, acpi etc).

Ian.

#8 lore raw
Quoted 6 lines · Ian Campbell
Quoted 6 lines

Yes that's probably the way to do it. If the resulting required configuration runes are too cryptic or vendor-specific, it may make sense to have the libxl cpuid logic consume a 'vpmu' option which it then turns into a set of lower-level cpuid settings to eventually pass down to the code in libxc/xc_cpuid.

Quoted 7 lines
Quoted 4 lines

It's a trifle messy I will admit. Arguably the 'default policy' bits of xc_cpuid_x86.c would better belong in libxl these days, where we would have better access to a domain's configuration state. As it is, we may end up with a spread of default policy across Xen (for dom0), libxc, and libxl.

Plus a bunch of ad-hoc stuff which predates the cpuid bit-fiddling support but is reflected in the cpuid (pae, apic, acpi etc).

Well, this is done in libxc now, so I think I included it in my list. ;) But it would be cleaner done in libxl.

I don't think anyone will be straining their arm to volunteer for this cleanup, but we shouldn't be shy about putting new policy stuff in libxl if it makes best sense to put it there.

-- Keir

#9 lore raw

Am Freitag 20 Januar 2012, 13:47:24 schrieb Keir Fraser:

Quoted 16 lines · Ian Campbell
Quoted 7 lines
Quoted 7 lines

Yes that's probably the way to do it. If the resulting required configuration runes are too cryptic or vendor-specific, it may make sense to have the libxl cpuid logic consume a 'vpmu' option which it then turns into a set of lower-level cpuid settings to eventually pass down to the code in libxc/xc_cpuid.

Quoted 7 lines
Quoted 4 lines

It's a trifle messy I will admit. Arguably the 'default policy' bits of xc_cpuid_x86.c would better belong in libxl these days, where we would have better access to a domain's configuration state. As it is, we may end up with a spread of default policy across Xen (for dom0), libxc, and libxl.

Plus a bunch of ad-hoc stuff which predates the cpuid bit-fiddling support but is reflected in the cpuid (pae, apic, acpi etc).

Quoted 6 lines

Well, this is done in libxc now, so I think I included it in my list. ;) But it would be cleaner done in libxl.

I don't think anyone will be straining their arm to volunteer for this cleanup, but we shouldn't be shy about putting new policy stuff in libxl if it makes best sense to put it there.

Thanks for the hints. For the first time I'll go through the source and try to understand what you are talking about.

Dietmar.

#10 lore raw
In reply to Keir Fraser
Quoted 10 lines · Keir Fraser
Quoted 9 lines

The "Debug Store" cpuid flag in the Intel processors gets enabled in the libxc.
A new function call arch_vpmu_cpuid is added to the struct arch_vpmu_ops and for
Intel processors the function core2_vpmu_cpuid() is added.
The aim is that always a "struct arch_vpmu_ops" is accessible at least with a cpuid function to switch off special PMU cpuid flags dynamically depending on
the boot variable opt_vpmu_enabled.

Quoted 3 lines

Our CPUID configuration is done per-domain, and from tools/libxc/xc_cpuid_x86.c. CPUID adjustments implemented within the hypervisor are generally not acceptable without very good reason.

I'll preempt you saying that you need to depend on opt_vpmu_enabled by saying you should get rid of that hacky global configuration flag, and allow VPMU to be properly enabled per domain, via the toolstack. Then configuration via libxc/xc_cpuid_x86.c will fall naturally into place. Perhaps you can allow configuration straightforwardly via the existing libxl_cpuid.c mechanism, or perhaps you need a higher-level config option than that, and then cook it down into CPUID fiddling from within libxl, or libxc. One of the toolstack maintainers (Ian Jackson for example) may have better ideas than me on that.

Also, there are AMD- and Intel-specific sections to xc_cpuid_x86.c for HVM guests -- {amd,intel}_xc_cpuid_policy(). You can use those to set flags differently for the two vendors.

Quoted 200 lines

-- Keir

Quoted 196 lines

diff -r 7a82c2e2eb33 tools/libxc/xc_cpuid_x86.c

tools/libxc/xc_cpuid_x86.c Thu Jan 19 14:37:17 2012 +0100 renamed from tools/libxc/xc_cpuid_x86.c Thu Jan 19 13:14:02 2012 +0100 +1 -0
@@ -343,6 +343,7 @@ static void xc_cpuid_hvm_policy(
                     bitmaskof(X86_FEATURE_CMOV) |
                     bitmaskof(X86_FEATURE_PAT) |
                     bitmaskof(X86_FEATURE_CLFLSH) |
+                    bitmaskof(X86_FEATURE_DS) |
                     bitmaskof(X86_FEATURE_PSE36) |
                     bitmaskof(X86_FEATURE_MMX) |
                     bitmaskof(X86_FEATURE_FXSR) |

diff -r 7a82c2e2eb33 xen/arch/x86/hvm/vmx/vmx.c

xen/arch/x86/hvm/vmx/vmx.c Thu Jan 19 14:37:17 2012 +0100 renamed from xen/arch/x86/hvm/vmx/vmx.c Thu Jan 19 13:14:02 2012 +0100 +2 -0
@@ -1603,6 +1603,8 @@ static void vmx_cpuid_intercept(
             break;
     }
 
+    vpmu_do_cpuid(input, eax, ebx, ecx, edx);
+
     HVMTRACE_5D (CPUID, input, *eax, *ebx, *ecx, *edx);
 }
 

diff -r 7a82c2e2eb33 xen/arch/x86/hvm/vmx/vpmu_core2.c

xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 14:37:17 2012 +0100 renamed from xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 13:14:02 2012 +0100 +3 -0
@@ -598,6 +598,29 @@ static void core2_vpmu_destroy(struct vc
     vpmu->flags &= ~VPMU_CONTEXT_ALLOCATED;
 }
 
+/**
+ * core2_vpmu_cpuid - prepare special vpmu cpuid bits
+ * If emulation of vpmu is switched off, some bits are swtiched off,

currently:
+ * - EAX[0x1].EAX[Bits 0-7]: PMC revision id.
+ * - EAX[0xa].EDX[Bit 21]: Debug Store
+ */

xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 14:37:17 2012 +0100 renamed from xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 13:14:02 2012 +0100 +9 -0
+#define bitmaskof(idx)  (1U << ((idx) & 31))
+static void core2_vpmu_cpuid(unsigned int input,
+                             unsigned int *eax, unsigned int *ebx,
+                             unsigned int *ecx, unsigned int *edx)
+{
+    switch ( input )
+    {
+    case 0x1:
+        *edx &= ~bitmaskof(X86_FEATURE_DS);    /* Debug Store not supported

*/

xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 14:37:17 2012 +0100 renamed from xen/arch/x86/hvm/vmx/vpmu_core2.c Thu Jan 19 13:14:02 2012 +0100 +21 -2
+        break;
+    case 0xa:
+        if ( !opt_vpmu_enabled )
+            *eax &= ~(unsigned int)0xff;       /* Clear pmc version id. */
+        break;
+    }
+}
+
 struct arch_vpmu_ops core2_vpmu_ops = {
     .do_wrmsr = core2_vpmu_do_wrmsr,
     .do_rdmsr = core2_vpmu_do_rdmsr,
@@ -605,7 +628,13 @@ struct arch_vpmu_ops core2_vpmu_ops = {
     .arch_vpmu_initialise = core2_vpmu_initialise,
     .arch_vpmu_destroy = core2_vpmu_destroy,
     .arch_vpmu_save = core2_vpmu_save,
-    .arch_vpmu_load = core2_vpmu_load
+    .arch_vpmu_load = core2_vpmu_load,
+    .arch_vpmu_cpuid = core2_vpmu_cpuid
+};
+
+/* Used if vpmu is disabled. */
+struct arch_vpmu_ops core2_vpmu_dis_ops = {
+    .arch_vpmu_cpuid = core2_vpmu_cpuid
 };
 
 int vmx_vpmu_initialize(struct vcpu *v)
@@ -615,7 +644,7 @@ int vmx_vpmu_initialize(struct vcpu *v)
     __u8 cpu_model = current_cpu_data.x86_model;
 
     if ( !opt_vpmu_enabled )
-        return -EINVAL;
+        goto func_out;
 
     if ( family == 6 )
     {
@@ -635,6 +664,11 @@ int vmx_vpmu_initialize(struct vcpu *v)
     printk("VPMU: Initialization failed. "
            "Intel processor family %d model %d has not "
            "been supported\n", family, cpu_model);
+
+func_out:
+
+    vpmu->arch_vpmu_ops = &core2_vpmu_dis_ops;
+
     return -EINVAL;
 }
 

diff -r 7a82c2e2eb33 xen/arch/x86/hvm/vpmu.c

xen/arch/x86/hvm/vpmu.c Thu Jan 19 14:37:17 2012 +0100 renamed from xen/arch/x86/hvm/vpmu.c Thu Jan 19 13:14:02 2012 +0100 +18 -7
@@ -39,7 +39,7 @@ int vpmu_do_wrmsr(unsigned int msr, uint
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(current);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_wrmsr )
         return vpmu->arch_vpmu_ops->do_wrmsr(msr, msr_content);
     return 0;
 }
@@ -48,7 +48,7 @@ int vpmu_do_rdmsr(unsigned int msr, uint
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(current);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_rdmsr )
         return vpmu->arch_vpmu_ops->do_rdmsr(msr, msr_content);
     return 0;
 }
@@ -57,7 +57,7 @@ int vpmu_do_interrupt(struct cpu_user_re
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(current);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_interrupt )
         return vpmu->arch_vpmu_ops->do_interrupt(regs);
     return 0;
 }
@@ -66,7 +66,7 @@ void vpmu_save(struct vcpu *v)
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(v);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_save )
         vpmu->arch_vpmu_ops->arch_vpmu_save(v);
 }
 
@@ -74,7 +74,7 @@ void vpmu_load(struct vcpu *v)
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(v);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_load )
         vpmu->arch_vpmu_ops->arch_vpmu_load(v);
 }
 
@@ -109,7 +109,8 @@ void vpmu_initialise(struct vcpu *v)
     {
         vpmu->flags = 0;
         vpmu->context = NULL;
-        vpmu->arch_vpmu_ops->arch_vpmu_initialise(v);
+        if ( vpmu->arch_vpmu_ops->arch_vpmu_initialise )
+            vpmu->arch_vpmu_ops->arch_vpmu_initialise(v);
     }
 }
 
@@ -117,7 +118,17 @@ void vpmu_destroy(struct vcpu *v)
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(v);
 
-    if ( vpmu->arch_vpmu_ops )
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_destroy )
         vpmu->arch_vpmu_ops->arch_vpmu_destroy(v);
 }
 
+void vpmu_do_cpuid(unsigned int input,
+                   unsigned int *eax, unsigned int *ebx,
+                   unsigned int *ecx, unsigned int *edx)
+{
+    struct vpmu_struct *vpmu = vcpu_vpmu(current);
+
+    if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_cpuid)
+        vpmu->arch_vpmu_ops->arch_vpmu_cpuid(input, eax, ebx, ecx, edx);
+}
+

diff -r 7a82c2e2eb33 xen/include/asm-x86/hvm/vpmu.h

xen/include/asm-x86/hvm/vpmu.h Thu Jan 19 14:37:17 2012 +0100 renamed from xen/include/asm-x86/hvm/vpmu.h Thu Jan 19 13:14:02 2012 +0100 +6 -0
@@ -56,6 +56,9 @@ struct arch_vpmu_ops {
     void (*arch_vpmu_destroy)(struct vcpu *v);
     void (*arch_vpmu_save)(struct vcpu *v);
     void (*arch_vpmu_load)(struct vcpu *v);
+    void (*arch_vpmu_cpuid)(unsigned int input,
+                            unsigned int *eax, unsigned int *ebx,
+                            unsigned int *ecx, unsigned int *edx);
 };
 
 int vmx_vpmu_initialize(struct vcpu *v);
@@ -78,6 +81,9 @@ void vpmu_initialise(struct vcpu *v);
 void vpmu_destroy(struct vcpu *v);
 void vpmu_save(struct vcpu *v);
 void vpmu_load(struct vcpu *v);
+void vpmu_do_cpuid(unsigned int input,
+                   unsigned int *eax, unsigned int *ebx,
+                   unsigned int *ecx, unsigned int *edx);
 
 extern int acquire_pmu_ownership(int pmu_ownership);
 extern void release_pmu_ownership(int pmu_ownership);