vpmu intel: Add cpuid handling when vpmu disabled
PATCH 1/1 vpmu intel: Add cpuid handling when vpmu disabled
Even though vpmu is disabled in the hypervisor in the HVM guest the call of cpuid(0xa) returns informations about usable performance counters. This may confuse guest software when trying to use the counters and nothing happens.
This patch clears most bits in registers eax and edx of cpuid(0xa) instruction for the guest when vpmu is disabled:
- version ID of architectural performance counting
- number of general pmu registers
- width of general pmu registers
- number of fixed pmu registers
- width of ixed pmu registers
Thanks.
Dietmar.
xen/arch/x86/hvm/svm/vpmu.c +4 -0
@@ -370,6 +370,10 @@ int svm_vpmu_initialise(struct vcpu *v,uint8_t family = current_cpu_data.x86;int ret =0 ; +/* vpmu enabled? */ +if (!vpmu_flags) +return 0 ; +switch ( family ) {case 0x10 :
xen/arch/x86/hvm/vmx/vpmu_core2.c +57 -0
69 lines not on this page · raw message
xen/arch/x86/hvm/vpmu.c +6 -9
@@ -67,7 +67,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 ; }
@@ -76,7 +76,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 ; }
@@ -85,7 +85,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 ; }
@@ -104,7 +104,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); }
@@ -112,7 +112,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); }
@@ -121,9 +121,6 @@ void vpmu_initialise(struct vcpu *v)struct vpmu_struct *vpmu =vcpu_vpmu (v);uint8_t vendor = current_cpu_data.x86_vendor; -if ( !opt_vpmu_enabled ) -return ; -if (vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) )vpmu_destroy (v);vpmu_clear (vpmu);
@@ -153,7 +150,7 @@ 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); }
Signature · 1 line
Company details: http://ts.fujitsu.com/imprint.html
Am Mittwoch 13 März 2013, 10:55:29 schrieb Dietmar Hahn:
Quoted 12 lines
Even though vpmu is disabled in the hypervisor in the HVM guest the call of cpuid(0xa) returns informations about usable performance counters. This may confuse guest software when trying to use the counters and nothing happens.
This patch clears most bits in registers eax and edx of cpuid(0xa) instruction for the guest when vpmu is disabled:
- version ID of architectural performance counting
- number of general pmu registers
- width of general pmu registers
- number of fixed pmu registers
- width of ixed pmu registers
Quoted 3 lines
Thanks.
Dietmar.
Ping?
Quoted 160 lines
Signed-off-by Dietmar Hahn <[email protected]>diff -r
a6b81234b189xen/arch/x86/hvm/svm/vpmu.cxen/arch/x86/hvm/svm/vpmu.c +4
-0@@ -370,6 +370,10 @@ int svm_vpmu_initialise(struct vcpu *v,uint8_t family = current_cpu_data.x86;int ret =0 ; +/* vpmu enabled? */ +if (!vpmu_flags) +return 0 ; +switch ( family ) {case 0x10 :diff -r
a6b81234b189xen/arch/x86/hvm/vmx/vpmu_core2.cxen/arch/x86/hvm/vmx/vpmu_core2.c +57
-0@@ -727,6 +727,59 @@ struct arch_vpmu_ops core2_vpmu_ops = { .arch_vpmu_load = core2_vpmu_load }; +/* cpuid 0xa - eax */ +#define X86_FEATURE_PMU_VER_OFF 0/* Version */ +#define FEATURE_PMU_VER_BITS 8/* 8 bits */ +#define X86_FEATURE_NUM_GEN_OFF 8/* Number of general pmu registers */ +#define FEATURE_NUM_GEN_BITS 8/* 8 bits */ +#define X86_FEATURE_GEN_WIDTH_OFF 16/* Width of general pmu registers */ +#define FEATURE_GEN_WIDTH_BITS 8/* 8 bits */ + +/* cpuid 0xa - edx */ +#define X86_FEATURE_NUM_FIX_OFF 0/* Number of fixed pmu registers */ +#define FEATURE_NUM_FIX_BITS 5/* 5 bits */ +#define X86_FEATURE_FIX_WIDTH_OFF 5/* Width of fixed pmu registers */ +#define FEATURE_FIX_WIDTH_BITS 8/* 8 bits */ + +static void core2_no_vpmu_do_cpuid (unsigned int input, +unsigned int *eax,unsigned int *ebx, +unsigned int *ecx,unsigned int *edx) +{ +/* +* As in this case the vpmu is not enabled reset some bits in the +* pmu part of the cpuid. +*/ +if (input ==0xa ) + { + *eax &= ~(((1 <<FEATURE_PMU_VER_BITS ) -1 ) <<X86_FEATURE_PMU_VER_OFF ); + *eax &= ~(((1 <<FEATURE_NUM_GEN_BITS ) -1 ) <<X86_FEATURE_NUM_GEN_OFF ); + *eax &= ~(((1 <<FEATURE_GEN_WIDTH_BITS ) -1 ) <<X86_FEATURE_GEN_WIDTH_OFF ); + + *edx &= ~(((1 <<FEATURE_NUM_FIX_BITS ) -1 ) <<X86_FEATURE_NUM_FIX_OFF ); + *edx &= ~(((1 <<FEATURE_FIX_WIDTH_BITS ) -1 ) <<X86_FEATURE_FIX_WIDTH_OFF ); + } +} + +/* +* If it's a vpmu msr set it to 0. +*/ +static int core2_no_vpmu_do_rdmsr (unsigned int msr,uint64_t *msr_content) +{ +int type =-1 , index =-1 ; +if ( !is_core2_vpmu_msr (msr, &type, &index) ) +return 0 ; + *msr_content =0 ; +return 1 ; +} + +/* +* These functions are used in case vpmu is not enabled. +*/ +struct arch_vpmu_ops core2_no_vpmu_ops = { + .do_rdmsr = core2_no_vpmu_do_rdmsr, + .do_cpuid = core2_no_vpmu_do_cpuid, +}; +int vmx_vpmu_initialise (struct vcpu *v,unsigned int vpmu_flags) {struct vpmu_struct *vpmu =vcpu_vpmu (v);@@ -734,6 +787,10 @@ int vmx_vpmu_initialise(struct vcpu *v,uint8_t cpu_model = current_cpu_data.x86_model;int ret =0 ; + vpmu->arch_vpmu_ops = &core2_no_vpmu_ops; +if ( !vpmu_flags ) +return 0 ; +if ( family ==6 ) { switch ( cpu_model )diff -r
a6b81234b189xen/arch/x86/hvm/vpmu.cxen/arch/x86/hvm/vpmu.c +6
-9@@ -67,7 +67,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 ; }@@ -76,7 +76,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 ; }@@ -85,7 +85,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 ; }@@ -104,7 +104,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); }@@ -112,7 +112,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); }@@ -121,9 +121,6 @@ void vpmu_initialise(struct vcpu *v)struct vpmu_struct *vpmu =vcpu_vpmu (v);uint8_t vendor = current_cpu_data.x86_vendor; -if ( !opt_vpmu_enabled ) -return ; -if (vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) )vpmu_destroy (v);vpmu_clear (vpmu);@@ -153,7 +150,7 @@ 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); }
Signature · 6 lines
Company details: http://ts.fujitsu.com/imprint.html _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 13 lines · Dietmar Hahn
Am Mittwoch 13 März 2013, 10:55:29 schrieb Dietmar Hahn:
Quoted 12 lines
Even though vpmu is disabled in the hypervisor in the HVM guest the call of cpuid(0xa) returns informations about usable performance counters. This may confuse guest software when trying to use the counters and nothing happens.
This patch clears most bits in registers eax and edx of cpuid(0xa) instruction for the guest when vpmu is disabled:
- version ID of architectural performance counting
- number of general pmu registers
- width of general pmu registers
- number of fixed pmu registers
- width of ixed pmu registers
Quoted 5 lines
Quoted 3 lines
Thanks.
Dietmar.
Ping?
You need to CC the AMD maintainer as well. CC-ing him here.
Quoted 25 lines
Quoted 25 lines
Signed-off-by Dietmar Hahn <[email protected]>diff -r
a6b81234b189xen/arch/x86/hvm/svm/vpmu.cxen/arch/x86/hvm/svm/vpmu.c +4
-0@@ -370,6 +370,10 @@ int svm_vpmu_initialise(struct vcpu *v,uint8_t family = current_cpu_data.x86;int ret =0 ; +/* vpmu enabled? */ +if (!vpmu_flags) +return 0 ; +switch ( family ) {case 0x10 :diff -r
a6b81234b189xen/arch/x86/hvm/vmx/vpmu_core2.cxen/arch/x86/hvm/vmx/vpmu_core2.c +0
-0@@ -727,6 +727,59 @@ struct arch_vpmu_ops core2_vpmu_ops = { .arch_vpmu_load = core2_vpmu_load };
Quoted 1 line
xen/arch/x86/hvm/vmx/vpmu_core2.c struct arch_vpmu_ops core2_vpmu_ops = { · line 730
Quoted 1 line
xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-0+/* cpuid 0xa - eax */
Do you think it might make sense to point out where these are defined in the Intel SDM?
Quoted 26 lines
Quoted 26 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +26
-0+#define X86_FEATURE_PMU_VER_OFF 0/* Version */ +#define FEATURE_PMU_VER_BITS 8/* 8 bits */ +#define X86_FEATURE_NUM_GEN_OFF 8/* Number of general pmu registers */ +#define FEATURE_NUM_GEN_BITS 8/* 8 bits */ +#define X86_FEATURE_GEN_WIDTH_OFF 16/* Width of general pmu registers */ +#define FEATURE_GEN_WIDTH_BITS 8/* 8 bits */ + +/* cpuid 0xa - edx */ +#define X86_FEATURE_NUM_FIX_OFF 0/* Number of fixed pmu registers */ +#define FEATURE_NUM_FIX_BITS 5/* 5 bits */ +#define X86_FEATURE_FIX_WIDTH_OFF 5/* Width of fixed pmu registers */ +#define FEATURE_FIX_WIDTH_BITS 8/* 8 bits */ + +static void core2_no_vpmu_do_cpuid (unsigned int input, +unsigned int *eax,unsigned int *ebx, +unsigned int *ecx,unsigned int *edx) +{ +/* +* As in this case the vpmu is not enabled reset some bits in the +* pmu part of the cpuid. +*/ +if (input ==0xa ) + { + *eax &= ~(((1 <<FEATURE_PMU_VER_BITS ) -1 ) <<X86_FEATURE_PMU_VER_OFF ); + *eax &= ~(((1 <<FEATURE_NUM_GEN_BITS ) -1 ) <<X86_FEATURE_NUM_GEN_OFF ); + *eax &= ~(((1 <<FEATURE_GEN_WIDTH_BITS ) -1 ) <<X86_FEATURE_GEN_WIDTH_OFF );
Quoted 8 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c struct arch_vpmu_ops core2_vpmu_ops = { · line 764
Quoted 8 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +8
-0+ + *edx &= ~(((1 <<FEATURE_NUM_FIX_BITS ) -1 ) <<X86_FEATURE_NUM_FIX_OFF ); + *edx &= ~(((1 <<FEATURE_FIX_WIDTH_BITS ) -1 ) <<X86_FEATURE_FIX_WIDTH_OFF ); + } +} + +/* +* If it's a vpmu msr set it to 0.
.. s/it/its value/
Quoted 110 lines
Quoted 102 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +22
-0+*/ +static int core2_no_vpmu_do_rdmsr (unsigned int msr,uint64_t *msr_content) +{ +int type =-1 , index =-1 ; +if ( !is_core2_vpmu_msr (msr, &type, &index) ) +return 0 ; + *msr_content =0 ; +return 1 ; +} + +/* +* These functions are used in case vpmu is not enabled. +*/ +struct arch_vpmu_ops core2_no_vpmu_ops = { + .do_rdmsr = core2_no_vpmu_do_rdmsr, + .do_cpuid = core2_no_vpmu_do_cpuid, +}; +int vmx_vpmu_initialise (struct vcpu *v,unsigned int vpmu_flags) {struct vpmu_struct *vpmu =vcpu_vpmu (v);@@ -734,6 +787,10 @@ int vmx_vpmu_initialise(struct vcpu *v,uint8_t cpu_model = current_cpu_data.x86_model;int ret =0 ; + vpmu->arch_vpmu_ops = &core2_no_vpmu_ops; +if ( !vpmu_flags ) +return 0 ; +if ( family ==6 ) { switch ( cpu_model )diff -r
a6b81234b189xen/arch/x86/hvm/vpmu.cxen/arch/x86/hvm/vpmu.c +3
-3@@ -67,7 +67,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 ; }@@ -76,7 +76,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 ; }@@ -85,7 +85,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 ;}
xen/arch/x86/hvm/vpmu.c +3
-6@@ -104,7 +104,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); }@@ -112,7 +112,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); }@@ -121,9 +121,6 @@ void vpmu_initialise(struct vcpu *v)struct vpmu_struct *vpmu =vcpu_vpmu (v);uint8_t vendor = current_cpu_data.x86_vendor; -if ( !opt_vpmu_enabled ) -return ; -if (vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) )vpmu_destroy (v);vpmu_clear (vpmu);@@ -153,7 +150,7 @@ 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); }Signature · 6 lines
Company details: http://ts.fujitsu.com/imprint.html _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 14 lines · Konrad Rzeszutek Wilk
Quoted 13 lines · Dietmar Hahn
Am Mittwoch 13 März 2013, 10:55:29 schrieb Dietmar Hahn:
Quoted 12 lines
Even though vpmu is disabled in the hypervisor in the HVM guest the call of cpuid(0xa) returns informations about usable performance counters. This may confuse guest software when trying to use the counters and nothing happens.
This patch clears most bits in registers eax and edx of cpuid(0xa) instruction for the guest when vpmu is disabled:
- version ID of architectural performance counting
- number of general pmu registers
- width of general pmu registers
- number of fixed pmu registers
- width of ixed pmu registers
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Thanks.
Dietmar.
Ping?
You need to CC the AMD maintainer as well. CC-ing him here.
This time doing it
Quoted 177 lines
Quoted 25 lines
Quoted 25 lines
Signed-off-by Dietmar Hahn <[email protected]>diff -r
a6b81234b189xen/arch/x86/hvm/svm/vpmu.cxen/arch/x86/hvm/svm/vpmu.c +4
-0@@ -370,6 +370,10 @@ int svm_vpmu_initialise(struct vcpu *v,uint8_t family = current_cpu_data.x86;int ret =0 ; +/* vpmu enabled? */ +if (!vpmu_flags) +return 0 ; +switch ( family ) {case 0x10 :diff -r
a6b81234b189xen/arch/x86/hvm/vmx/vpmu_core2.cxen/arch/x86/hvm/vmx/vpmu_core2.c +0
-0@@ -727,6 +727,59 @@ struct arch_vpmu_ops core2_vpmu_ops = { .arch_vpmu_load = core2_vpmu_load };Quoted 1 line
xen/arch/x86/hvm/vmx/vpmu_core2.c struct arch_vpmu_ops core2_vpmu_ops = { · line 730
Quoted 1 line
xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-0+/* cpuid 0xa - eax */ Do you think it might make sense to point out where these are defined in the Intel SDM?
Quoted 26 lines
Quoted 26 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +26
-0+#define X86_FEATURE_PMU_VER_OFF 0/* Version */ +#define FEATURE_PMU_VER_BITS 8/* 8 bits */ +#define X86_FEATURE_NUM_GEN_OFF 8/* Number of general pmu registers */ +#define FEATURE_NUM_GEN_BITS 8/* 8 bits */ +#define X86_FEATURE_GEN_WIDTH_OFF 16/* Width of general pmu registers */ +#define FEATURE_GEN_WIDTH_BITS 8/* 8 bits */ + +/* cpuid 0xa - edx */ +#define X86_FEATURE_NUM_FIX_OFF 0/* Number of fixed pmu registers */ +#define FEATURE_NUM_FIX_BITS 5/* 5 bits */ +#define X86_FEATURE_FIX_WIDTH_OFF 5/* Width of fixed pmu registers */ +#define FEATURE_FIX_WIDTH_BITS 8/* 8 bits */ + +static void core2_no_vpmu_do_cpuid (unsigned int input, +unsigned int *eax,unsigned int *ebx, +unsigned int *ecx,unsigned int *edx) +{ +/* +* As in this case the vpmu is not enabled reset some bits in the +* pmu part of the cpuid. +*/ +if (input ==0xa ) + { + *eax &= ~(((1 <<FEATURE_PMU_VER_BITS ) -1 ) <<X86_FEATURE_PMU_VER_OFF ); + *eax &= ~(((1 <<FEATURE_NUM_GEN_BITS ) -1 ) <<X86_FEATURE_NUM_GEN_OFF ); + *eax &= ~(((1 <<FEATURE_GEN_WIDTH_BITS ) -1 ) <<X86_FEATURE_GEN_WIDTH_OFF );Quoted 8 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c struct arch_vpmu_ops core2_vpmu_ops = { · line 764
Quoted 8 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +8
-0+ + *edx &= ~(((1 <<FEATURE_NUM_FIX_BITS ) -1 ) <<X86_FEATURE_NUM_FIX_OFF ); + *edx &= ~(((1 <<FEATURE_FIX_WIDTH_BITS ) -1 ) <<X86_FEATURE_FIX_WIDTH_OFF ); + } +} + +/* +* If it's a vpmu msr set it to 0. .. s/it/its value/
Quoted 110 lines
Quoted 102 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +22
-0+*/ +static int core2_no_vpmu_do_rdmsr (unsigned int msr,uint64_t *msr_content) +{ +int type =-1 , index =-1 ; +if ( !is_core2_vpmu_msr (msr, &type, &index) ) +return 0 ; + *msr_content =0 ; +return 1 ; +} + +/* +* These functions are used in case vpmu is not enabled. +*/ +struct arch_vpmu_ops core2_no_vpmu_ops = { + .do_rdmsr = core2_no_vpmu_do_rdmsr, + .do_cpuid = core2_no_vpmu_do_cpuid, +}; +int vmx_vpmu_initialise (struct vcpu *v,unsigned int vpmu_flags) {struct vpmu_struct *vpmu =vcpu_vpmu (v);@@ -734,6 +787,10 @@ int vmx_vpmu_initialise(struct vcpu *v,uint8_t cpu_model = current_cpu_data.x86_model;int ret =0 ; + vpmu->arch_vpmu_ops = &core2_no_vpmu_ops; +if ( !vpmu_flags ) +return 0 ; +if ( family ==6 ) { switch ( cpu_model )diff -r
a6b81234b189xen/arch/x86/hvm/vpmu.cxen/arch/x86/hvm/vpmu.c +3
-3@@ -67,7 +67,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 ; }@@ -76,7 +76,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 ; }@@ -85,7 +85,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 ;}
xen/arch/x86/hvm/vpmu.c +3
-6@@ -104,7 +104,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); }@@ -112,7 +112,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); }@@ -121,9 +121,6 @@ void vpmu_initialise(struct vcpu *v)struct vpmu_struct *vpmu =vcpu_vpmu (v);uint8_t vendor = current_cpu_data.x86_vendor; -if ( !opt_vpmu_enabled ) -return ; -if (vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) )vpmu_destroy (v);vpmu_clear (vpmu);@@ -153,7 +150,7 @@ 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); }Signature · 6 lines
Company details: http://ts.fujitsu.com/imprint.html _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 15 lines · Konrad Rzeszutek Wilk
Quoted 14 lines · Konrad Rzeszutek Wilk
Quoted 13 lines · Dietmar Hahn
Am Mittwoch 13 März 2013, 10:55:29 schrieb Dietmar Hahn:
Quoted 12 lines
Even though vpmu is disabled in the hypervisor in the HVM guest the call of cpuid(0xa) returns informations about usable performance counters. This may confuse guest software when trying to use the counters and nothing happens.
This patch clears most bits in registers eax and edx of cpuid(0xa) instruction for the guest when vpmu is disabled:
- version ID of architectural performance counting
- number of general pmu registers
- width of general pmu registers
- number of fixed pmu registers
- width of ixed pmu registers
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
Thanks.
Dietmar.
Ping?
You need to CC the AMD maintainer as well. CC-ing him here.
This time doing it
This looks fine. AMD code doesn't currently use the vpmu_flags in the AMD-specific code.
Suravee
Quoted 172 lines
Quoted 172 lines
Quoted 23 lines
Quoted 23 lines
Signed-off-by Dietmar Hahn <[email protected]>diff -r
a6b81234b189xen/arch/x86/hvm/svm/vpmu.cxen/arch/x86/hvm/svm/vpmu.c +4
-0@@ -370,6 +370,10 @@ int svm_vpmu_initialise(struct vcpu *v,uint8_t family = current_cpu_data.x86;int ret =0 ; +/* vpmu enabled? */ +if (!vpmu_flags) +return 0 ; +switch ( family ) {case 0x10 :diff -r
a6b81234b189xen/arch/x86/hvm/vmx/vpmu_core2.cxen/arch/x86/hvm/vmx/vpmu_core2.c +0
-0@@ -727,6 +727,59 @@ struct arch_vpmu_ops core2_vpmu_ops = { .arch_vpmu_load = core2_vpmu_load };Quoted 1 line
xen/arch/x86/hvm/vmx/vpmu_core2.c struct arch_vpmu_ops core2_vpmu_ops = { · line 730
Quoted 1 line
xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-0+/* cpuid 0xa - eax */ Do you think it might make sense to point out where these are defined in the Intel SDM?
Quoted 26 lines
Quoted 26 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +26
-0+#define X86_FEATURE_PMU_VER_OFF 0/* Version */ +#define FEATURE_PMU_VER_BITS 8/* 8 bits */ +#define X86_FEATURE_NUM_GEN_OFF 8/* Number of general pmu registers */ +#define FEATURE_NUM_GEN_BITS 8/* 8 bits */ +#define X86_FEATURE_GEN_WIDTH_OFF 16/* Width of general pmu registers */ +#define FEATURE_GEN_WIDTH_BITS 8/* 8 bits */ + +/* cpuid 0xa - edx */ +#define X86_FEATURE_NUM_FIX_OFF 0/* Number of fixed pmu registers */ +#define FEATURE_NUM_FIX_BITS 5/* 5 bits */ +#define X86_FEATURE_FIX_WIDTH_OFF 5/* Width of fixed pmu registers */ +#define FEATURE_FIX_WIDTH_BITS 8/* 8 bits */ + +static void core2_no_vpmu_do_cpuid (unsigned int input, +unsigned int *eax,unsigned int *ebx, +unsigned int *ecx,unsigned int *edx) +{ +/* +* As in this case the vpmu is not enabled reset some bits in the +* pmu part of the cpuid. +*/ +if (input ==0xa ) + { + *eax &= ~(((1 <<FEATURE_PMU_VER_BITS ) -1 ) <<X86_FEATURE_PMU_VER_OFF ); + *eax &= ~(((1 <<FEATURE_NUM_GEN_BITS ) -1 ) <<X86_FEATURE_NUM_GEN_OFF ); + *eax &= ~(((1 <<FEATURE_GEN_WIDTH_BITS ) -1 ) <<X86_FEATURE_GEN_WIDTH_OFF );Quoted 8 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c struct arch_vpmu_ops core2_vpmu_ops = { · line 764
Quoted 8 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +8
-0+ + *edx &= ~(((1 <<FEATURE_NUM_FIX_BITS ) -1 ) <<X86_FEATURE_NUM_FIX_OFF ); + *edx &= ~(((1 <<FEATURE_FIX_WIDTH_BITS ) -1 ) <<X86_FEATURE_FIX_WIDTH_OFF ); + } +} + +/* +* If it's a vpmu msr set it to 0. .. s/it/its value/
Quoted 109 lines
Quoted 101 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +22
-0+*/ +static int core2_no_vpmu_do_rdmsr (unsigned int msr,uint64_t *msr_content) +{ +int type =-1 , index =-1 ; +if ( !is_core2_vpmu_msr (msr, &type, &index) ) +return 0 ; + *msr_content =0 ; +return 1 ; +} + +/* +* These functions are used in case vpmu is not enabled. +*/ +struct arch_vpmu_ops core2_no_vpmu_ops = { + .do_rdmsr = core2_no_vpmu_do_rdmsr, + .do_cpuid = core2_no_vpmu_do_cpuid, +}; +int vmx_vpmu_initialise (struct vcpu *v,unsigned int vpmu_flags) {struct vpmu_struct *vpmu =vcpu_vpmu (v);@@ -734,6 +787,10 @@ int vmx_vpmu_initialise(struct vcpu *v,uint8_t cpu_model = current_cpu_data.x86_model;int ret =0 ; + vpmu->arch_vpmu_ops = &core2_no_vpmu_ops; +if ( !vpmu_flags ) +return 0 ; +if ( family ==6 ) { switch ( cpu_model )diff -r
a6b81234b189xen/arch/x86/hvm/vpmu.cxen/arch/x86/hvm/vpmu.c +6
-9@@ -67,7 +67,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 ; }@@ -76,7 +76,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 ; }@@ -85,7 +85,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 ; }@@ -104,7 +104,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); }@@ -112,7 +112,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); }@@ -121,9 +121,6 @@ void vpmu_initialise(struct vcpu *v)struct vpmu_struct *vpmu =vcpu_vpmu (v);uint8_t vendor = current_cpu_data.x86_vendor; -if ( !opt_vpmu_enabled ) -return ; -if (vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) )vpmu_destroy (v);vpmu_clear (vpmu);@@ -153,7 +150,7 @@ 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); }Signature · 6 lines
Company details: http://ts.fujitsu.com/imprint.html _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel