hvm: add hvm_funcs hooks for msr intercept handling
cover hvm: add hvm_funcs hooks for msr intercept handling
This patch series aims to make the msr intercept handling, performed in vpmu code, virtualization technology agnostic.
It creates a common interface for setting/clearing the msr intercepts and then add hooks to the corresponding hvm_funcs table to be able to call the svm/vmx specific handlers through a generic hvm wrapper function.
Xenia Ragiadakou (4):
x86/vpmu: rename {svm,vmx}_vpmu_initialise to
{amd,core2}_vpmu_initialise
x86/svm: split svm_intercept_msr() into
svm_{set,clear}_msr_intercept() x86/vmx: replace enum vmx_msr_intercept_type with the msr access flags x86/hvm: create hvm_funcs for {svm,vmx}_{set,clear}_msr_intercept()
xen/arch/x86/cpu/vpmu_amd.c | 15 ++--- xen/arch/x86/cpu/vpmu_intel.c | 30 +++++----- xen/arch/x86/hvm/svm/svm.c | 80 ++++++++++++++++--------- xen/arch/x86/hvm/vmx/vmcs.c | 38 ++++++------ xen/arch/x86/hvm/vmx/vmx.c | 46 +++++++------- xen/arch/x86/include/asm/hvm/hvm.h | 32 ++++++++++ xen/arch/x86/include/asm/hvm/svm/vmcb.h | 13 ++-- xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 14 +---- 8 files changed, 156 insertions(+), 112 deletions(-)
Signature · 1 line
2.37.2
PATCH 1/4 x86/vpmu: rename {svm,vmx}_vpmu_initialise to {amd,core2}_vpmu_initialise
PMU virtualization is not dependent on the hardware virtualization support. Rename {svm,vmx}_vpmu_initialise to {amd,core2}_vpmu_initialise because the {svm,vmx} prefix is misleading.
Take the opportunity to remove the also misleading comment stating that vpmu is specific to hvm guests, and correct the filename.
No functional change intended.
--- xen/arch/x86/cpu/vpmu_amd.c | 6 +++--- xen/arch/x86/cpu/vpmu_intel.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-)
xen/arch/x86/cpu/vpmu_amd.c +3 -3
@@ -1,5 +1,5 @@/* -* vpmu.c: PMU virtualization for HVM domain. +* vpmu_amd.c: AMD specific PMU virtualization. * * Copyright (c) 2010, Advanced Micro Devices, Inc. * Parts of this code are Copyright (c) 2007, Intel Corporation
@@ -480,7 +480,7 @@ static void cf_check amd_vpmu_dump(const struct vcpu *v) } } -static int cf_check svm_vpmu_initialise(struct vcpu *v) +static int cf_check amd_vpmu_initialise(struct vcpu *v) {struct xen_pmu_amd_ctxt *ctxt;struct vpmu_struct *vpmu =vcpu_vpmu (v);
@@ -527,7 +527,7 @@ static int cf_check amd_allocate_context(struct vcpu *v)#endif static const struct arch_vpmu_ops __initconst_cf_clobber amd_vpmu_ops = { - .initialise = svm_vpmu_initialise, + .initialise = amd_vpmu_initialise, .do_wrmsr = amd_vpmu_do_wrmsr, .do_rdmsr = amd_vpmu_do_rdmsr, .do_interrupt = amd_vpmu_do_interrupt,
xen/arch/x86/cpu/vpmu_intel.c +3 -3
@@ -1,5 +1,5 @@/* -* vpmu_core2.c: CORE 2 specific PMU virtualization for HVM domain. +* vpmu_intel.c: CORE 2 specific PMU virtualization. * * Copyright (c) 2007, Intel Corporation. *
@@ -833,7 +833,7 @@ static void cf_check core2_vpmu_destroy(struct vcpu *v)vpmu_clear (vpmu); } -static int cf_check vmx_vpmu_initialise(struct vcpu *v) +static int cf_check core2_vpmu_initialise(struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v);u64 msr_content;
@@ -898,7 +898,7 @@ static int cf_check vmx_vpmu_initialise(struct vcpu *v) } static const struct arch_vpmu_ops __initconst_cf_clobber core2_vpmu_ops = { - .initialise = vmx_vpmu_initialise, + .initialise = core2_vpmu_initialise, .do_wrmsr = core2_vpmu_do_wrmsr, .do_rdmsr = core2_vpmu_do_rdmsr, .do_interrupt = core2_vpmu_do_interrupt,
Signature · 1 line
2.37.2
Re: [PATCH 1/4] x86/vpmu: rename {svm,vmx}_vpmu_initialise to {amd,core2}_vpmu_initialise
Quoted 10 lines · Xenia Ragiadakou
PMU virtualization is not dependent on the hardware virtualization support. Rename {svm,vmx}_vpmu_initialise to {amd,core2}_vpmu_initialise because the {svm,vmx} prefix is misleading.
Take the opportunity to remove the also misleading comment stating that vpmu is specific to hvm guests, and correct the filename.
No functional change intended.
Signed-off-by Xenia Ragiadakou <[email protected]>
PATCH 2/4 x86/svm: split svm_intercept_msr() into svm_{set,clear}_msr_intercept()
In reply to Xenia RagiadakouThis change aims to render the control interface of MSR intercepts identical between SVM and VMX code, so that the control of the MSR intercept in common code can be done through an hvm_funcs callback.
Create two new functions:
- svm_set_msr_intercept(), enables interception of read/write accesses to the corresponding MSR, by setting the corresponding read/write bits in the MSRPM based on the flags
- svm_clear_msr_intercept(), disables interception of read/write accesses to the corresponding MSR, by clearing the corresponding read/write bits in the MSRPM based on the flags
More specifically:
- if flag is MSR_R, the functions {set,clear} the MSRPM bit that controls read access to the MSR
- if flag is MSR_W, the functions {set,clear} the MSRPM bit that controls write access to the MSR
- if flag is MSR_RW, the functions {set,clear} both MSRPM bits
Place the definitions of the flags in asm/hvm/hvm.h because there is the intention to be used by VMX code as well.
Remove svm_intercept_msr() and MSR_INTERCEPT_* definitions, and use the new functions and flags instead.
No functional change intended.
--- xen/arch/x86/cpu/vpmu_amd.c | 9 +-- xen/arch/x86/hvm/svm/svm.c | 80 ++++++++++++++++--------- xen/arch/x86/include/asm/hvm/hvm.h | 4 ++ xen/arch/x86/include/asm/hvm/svm/vmcb.h | 13 ++-- 4 files changed, 66 insertions(+), 40 deletions(-)
xen/arch/x86/cpu/vpmu_amd.c +5 -4
@@ -165,8 +165,9 @@ static void amd_vpmu_set_msr_bitmap(struct vcpu *v)for ( i =0 ; i < num_counters; i++ ) { -svm_intercept_msr (v, counters[i],MSR_INTERCEPT_NONE ); -svm_intercept_msr (v, ctrls[i],MSR_INTERCEPT_WRITE ); +svm_clear_msr_intercept (v, counters[i],MSR_RW ); +svm_set_msr_intercept (v, ctrls[i],MSR_W ); +svm_clear_msr_intercept (v, ctrls[i],MSR_R ); }msr_bitmap_on (vpmu);
@@ -179,8 +180,8 @@ static void amd_vpmu_unset_msr_bitmap(struct vcpu *v)for ( i =0 ; i < num_counters; i++ ) { -svm_intercept_msr (v, counters[i],MSR_INTERCEPT_RW ); -svm_intercept_msr (v, ctrls[i],MSR_INTERCEPT_RW ); +svm_set_msr_intercept (v, counters[i],MSR_RW ); +svm_set_msr_intercept (v, ctrls[i],MSR_RW ); }msr_bitmap_off (vpmu);
xen/arch/x86/hvm/svm/svm.c +51 -29
124 lines not on this page · raw message
xen/arch/x86/include/asm/hvm/hvm.h +4 -0
@@ -261,6 +261,10 @@ extern struct hvm_function_table hvm_funcs;extern bool_t hvm_enabled;extern s8 hvm_port80_allowed; +#define MSR_R BIT(0, U) +#define MSR_W BIT(1, U) +#define MSR_RW (MSR_W | MSR_R) +extern const struct hvm_function_table *start_svm (void );extern const struct hvm_function_table *start_vmx (void );
xen/arch/x86/include/asm/hvm/svm/vmcb.h +6 -7
@@ -585,13 +585,12 @@ void svm_destroy_vmcb(struct vcpu *v);void setup_vmcb_dump (void ); -#define MSR_INTERCEPT_NONE 0 -#define MSR_INTERCEPT_READ 1 -#define MSR_INTERCEPT_WRITE 2 -#define MSR_INTERCEPT_RW (MSR_INTERCEPT_WRITE | MSR_INTERCEPT_READ) -void svm_intercept_msr (struct vcpu *v,uint32_t msr,int enable); -#define svm_disable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), MSR_INTERCEPT_NONE) -#define svm_enable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), MSR_INTERCEPT_RW) +void svm_set_msr_intercept (struct vcpu *v,uint32_t msr,int flags); +void svm_clear_msr_intercept (struct vcpu *v,uint32_t msr,int flags); +#define svm_disable_intercept_for_msr (v, msr) \ + svm_clear_msr_intercept((v), (msr), MSR_RW) +#define svm_enable_intercept_for_msr (v, msr) \ + svm_set_intercept_msr((v), (msr), MSR_RW)/* * VMCB accessor functions.
Signature · 1 line
2.37.2
Re: [PATCH 2/4] x86/svm: split svm_intercept_msr() into svm_{set,clear}_msr_intercept()
Quoted 11 lines · Xenia Ragiadakou
This change aims to render the control interface of MSR intercepts identical between SVM and VMX code, so that the control of the MSR intercept in common code can be done through an
hvm_funcscallback.Create two new functions:
-svm_set_msr_intercept(), enables interception of read/write accesses to the corresponding MSR, by setting the corresponding read/write bits in the MSRPM based on the flags
-svm_clear_msr_intercept(), disables interception of read/write accesses to the corresponding MSR, by clearing the corresponding read/write bits in the MSRPM based on the flags
In how far is VMX'es present model better than SVM's? They both have pros and cons, depending on the specific use. I'm not asking to do it the other way around (at least not yet), I'd merely like to understand why we're going to gain two new hooks (if I'm not mistaken) when we could also get away with just one.
Quoted 15 lines
xen/arch/x86/cpu/vpmu_amd.c +3
-2@@ -165,8 +165,9 @@ static void amd_vpmu_set_msr_bitmap(struct vcpu *v)for ( i =0 ; i < num_counters; i++ ) { -svm_intercept_msr (v, counters[i],MSR_INTERCEPT_NONE ); -svm_intercept_msr (v, ctrls[i],MSR_INTERCEPT_WRITE ); +svm_clear_msr_intercept (v, counters[i],MSR_RW ); +svm_set_msr_intercept (v, ctrls[i],MSR_W ); +svm_clear_msr_intercept (v, ctrls[i],MSR_R ); }msr_bitmap_on (vpmu);
xen/arch/x86/cpu/vpmu_amd.c static void amd_vpmu_unset_msr_bitmap(struct vcpu *v) · line 185
Quoted 8 lines
xen/arch/x86/cpu/vpmu_amd.c +2
-2@@ -179,8 +180,8 @@ static void amd_vpmu_unset_msr_bitmap(struct vcpu *v)for ( i =0 ; i < num_counters; i++ ) { -svm_intercept_msr (v, counters[i],MSR_INTERCEPT_RW ); -svm_intercept_msr (v, ctrls[i],MSR_INTERCEPT_RW ); +svm_set_msr_intercept (v, counters[i],MSR_RW ); +svm_set_msr_intercept (v, ctrls[i],MSR_RW ); }
This, aiui, restores back original state (I question the condition that the caller uses, though, but that's a separate issue). Therefore is the single "set" in the earlier function actually needed?
xen/arch/x86/hvm/svm/svm.c svm_msrbit(unsigned long *msr_bitmap, uint32_t msr) · line 291
Quoted 8 lines
xen/arch/x86/hvm/svm/svm.c +1
-1@@ -288,23 +288,34 @@ svm_msrbit(unsigned long *msr_bitmap, uint32_t msr)return msr_bit; } -void svm_intercept_msr (struct vcpu *v,uint32_t msr,int flags) +void svm_set_msr_intercept (struct vcpu *v,uint32_t msr,int flags)
Can the last parameter become "unsigned int", please?
xen/arch/x86/hvm/svm/svm.c svm_msrbit(unsigned long *msr_bitmap, uint32_t msr) · line 297
Quoted 10 lines
xen/arch/x86/hvm/svm/svm.c +4
-4{ -unsigned long *msr_bit; -const struct domain *d = v->domain; +unsigned long *msr_bit =svm_msrbit (v->arch.hvm.svm.msrpm, msr); + +if ( msr_bit ==NULL ) +return ; - msr_bit =svm_msrbit (v->arch.hvm.svm.msrpm, msr); -BUG_ON (msr_bit ==NULL );
The conversion from BUG_ON() to "return" needs explanation; I don't see why that's warranted here. From all I can tell the case is impossible due to the way construct_vmcb() works, and hence BUG_ON() is appropriate (and personally I would also be fine with no check at all, provided I'm not overlooking anything).
xen/arch/x86/hvm/svm/svm.c static void cf_check svm_enable_msr_interception(struct domain *d, uint32_t msr) · line 326
Quoted 7 lines
xen/arch/x86/hvm/svm/svm.c +1
-2@@ -312,8 +323,10 @@ static void cf_check svm_enable_msr_interception(struct domain *d, uint32_t msr) {struct vcpu *v; - for_each_vcpu ( d, v ) -svm_intercept_msr (v, msr,MSR_INTERCEPT_WRITE ); + for_each_vcpu ( d, v ) {
Nit: Brace placement.
Quoted 19 lines
xen/arch/x86/hvm/svm/svm.c +4
-5@@ -595,22 +608,31 @@ static void cf_check svm_cpuid_policy_changed(struct vcpu *v)vmcb_set_exception_intercepts (vmcb, bitmap);/* Give access to MSR_SPEC_CTRL if the guest has been told about it. */ -svm_intercept_msr (v,MSR_SPEC_CTRL , - cp->extd.ibrs ?MSR_INTERCEPT_NONE :MSR_INTERCEPT_RW ); +if ( cp->extd.ibrs ) +svm_clear_msr_intercept (v,MSR_SPEC_CTRL ,MSR_RW ); +else +svm_set_msr_intercept (v,MSR_SPEC_CTRL ,MSR_RW );/* * Always trap write accesses to VIRT_SPEC_CTRL in order to cache the guest * setting and avoid having to perform a rdmsr on vmexit to get the guest * setting even if VIRT_SSBD is offered to Xen itself. */ - svm_intercept_msr(v, MSR_VIRT_SPEC_CTRL, - cp->extd.virt_ssbd && cpu_has_virt_ssbd && - !cpu_has_amd_ssbd ?
xen/arch/x86/hvm/svm/svm.c static void cf_check svm_cpuid_policy_changed(struct vcpu *v) · line 629
Quoted 10 lines
xen/arch/x86/hvm/svm/svm.c +9
-1- MSR_INTERCEPT_WRITE : MSR_INTERCEPT_RW); +if ( cp->extd.virt_ssbd && cpu_has_virt_ssbd && !cpu_has_amd_ssbd ) + { +svm_set_msr_intercept (v,MSR_VIRT_SPEC_CTRL ,MSR_W ); +svm_clear_msr_intercept (v,MSR_VIRT_SPEC_CTRL ,MSR_R ); + } +else + { +svm_set_msr_intercept (v,MSR_VIRT_SPEC_CTRL ,MSR_RW ); + }
Preferably omit the braces for "else" here, just like you do above and ...
xen/arch/x86/hvm/svm/svm.c static void cf_check svm_cpuid_policy_changed(struct vcpu *v) · line 635
Quoted 7 lines
xen/arch/x86/hvm/svm/svm.c +4
-2/* Give access to MSR_PRED_CMD if the guest has been told about it. */ -svm_intercept_msr (v,MSR_PRED_CMD , - cp->extd.ibpb ?MSR_INTERCEPT_NONE :MSR_INTERCEPT_RW ); +if ( cp->extd.ibpb ) +svm_clear_msr_intercept (v,MSR_VIRT_SPEC_CTRL ,MSR_RW ); +else +svm_set_msr_intercept (v,MSR_VIRT_SPEC_CTRL ,MSR_RW );
... here.
Quoted 9 lines
xen/arch/x86/include/asm/hvm/svm/vmcb.h +0
-3@@ -585,13 +585,12 @@ void svm_destroy_vmcb(struct vcpu *v);void setup_vmcb_dump (void ); -#define MSR_INTERCEPT_NONE 0 -#define MSR_INTERCEPT_READ 1 -#define MSR_INTERCEPT_WRITE 2
xen/arch/x86/include/asm/hvm/svm/vmcb.h void svm_destroy_vmcb(struct vcpu *v); · line 593
Quoted 10 lines
xen/arch/x86/include/asm/hvm/svm/vmcb.h +6
-4-#define MSR_INTERCEPT_RW (MSR_INTERCEPT_WRITE | MSR_INTERCEPT_READ) -void svm_intercept_msr (struct vcpu *v,uint32_t msr,int enable); -#define svm_disable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), MSR_INTERCEPT_NONE) -#define svm_enable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), MSR_INTERCEPT_RW) +void svm_set_msr_intercept (struct vcpu *v,uint32_t msr,int flags); +void svm_clear_msr_intercept (struct vcpu *v,uint32_t msr,int flags); +#define svm_disable_intercept_for_msr (v, msr) \ + svm_clear_msr_intercept((v), (msr), MSR_RW) +#define svm_enable_intercept_for_msr (v, msr) \ + svm_set_intercept_msr((v), (msr), MSR_RW)
Please avoid excess parentheses. Also could you clarify why you retain these shorthands when you don't use them in the conversion that you're doing (e.g. amd_vpmu_unset_msr_bitmap())? Are you intending them to go away down the road?
Jan
Re: [PATCH 2/4] x86/svm: split svm_intercept_msr() into svm_{set,clear}_msr_intercept()
Hi Jan,
Quoted 13 lines · Jan Beulich
Quoted 11 lines · Xenia Ragiadakou
This change aims to render the control interface of MSR intercepts identical between SVM and VMX code, so that the control of the MSR intercept in common code can be done through an
hvm_funcscallback.Create two new functions:
-svm_set_msr_intercept(), enables interception of read/write accesses to the corresponding MSR, by setting the corresponding read/write bits in the MSRPM based on the flags
-svm_clear_msr_intercept(), disables interception of read/write accesses to the corresponding MSR, by clearing the corresponding read/write bits in the MSRPM based on the flags
Quoted 5 lines
In how far is VMX'es present model better than SVM's? They both have pros and cons, depending on the specific use. I'm not asking to do it the other way around (at least not yet), I'd merely like to understand why we're going to gain two new hooks (if I'm not mistaken) when we could also get away with just one.
SVM approach always touches both read/write bits (either by setting or clearing them). I thought that using the SVM approach on VMX could be considered a functional change (because there are parts where VMX assumes that a bit is already set or cleared and does not touch it).
Quoted 17 lines
Quoted 17 lines
xen/arch/x86/cpu/vpmu_amd.c +3
-2@@ -165,8 +165,9 @@ static void amd_vpmu_set_msr_bitmap(struct vcpu *v)for ( i =0 ; i < num_counters; i++ ) { -svm_intercept_msr (v, counters[i],MSR_INTERCEPT_NONE ); -svm_intercept_msr (v, ctrls[i],MSR_INTERCEPT_WRITE ); +svm_clear_msr_intercept (v, counters[i],MSR_RW ); +svm_set_msr_intercept (v, ctrls[i],MSR_W ); +svm_clear_msr_intercept (v, ctrls[i],MSR_R ); }msr_bitmap_on (vpmu);@@ -179,8 +180,8 @@ static void amd_vpmu_unset_msr_bitmap(struct vcpu *v)
Quoted 11 lines
xen/arch/x86/cpu/vpmu_amd.c static void amd_vpmu_unset_msr_bitmap(struct vcpu *v) · line 185
Quoted 7 lines
xen/arch/x86/cpu/vpmu_amd.c +2
-2for ( i =0 ; i < num_counters; i++ ) { -svm_intercept_msr (v, counters[i],MSR_INTERCEPT_RW ); -svm_intercept_msr (v, ctrls[i],MSR_INTERCEPT_RW ); +svm_set_msr_intercept (v, counters[i],MSR_RW ); +svm_set_msr_intercept (v, ctrls[i],MSR_RW ); }This, aiui, restores back original state (I question the condition that the caller uses, though, but that's a separate issue). Therefore is the single "set" in the earlier function actually needed?
This is what the svm_intercept_msr(v, ctrls[i], MSR_INTERCEPT_WRITE) does, i.e it sets the WRITE and clears the READ. It is not needed if it is already set, but in my opinion the redundant parts should be removed in another patch.
Quoted 20 lines
xen/arch/x86/hvm/svm/svm.c svm_msrbit(unsigned long *msr_bitmap, uint32_t msr) · line 291
Quoted 9 lines
xen/arch/x86/hvm/svm/svm.c +1
-1@@ -288,23 +288,34 @@ svm_msrbit(unsigned long *msr_bitmap, uint32_t msr)return msr_bit; } -void svm_intercept_msr (struct vcpu *v,uint32_t msr,int flags) +void svm_set_msr_intercept (struct vcpu *v,uint32_t msr,int flags)Can the last parameter become "unsigned int", please?
Quoted 8 lines
xen/arch/x86/hvm/svm/svm.c +4
-2{ -unsigned long *msr_bit; -const struct domain *d = v->domain; +unsigned long *msr_bit =svm_msrbit (v->arch.hvm.svm.msrpm, msr); + +if ( msr_bit ==NULL ) +return ;
Quoted 8 lines
xen/arch/x86/hvm/svm/svm.c svm_msrbit(unsigned long *msr_bitmap, uint32_t msr) · line 297
Quoted 2 lines
xen/arch/x86/hvm/svm/svm.c +0
-2- msr_bit =svm_msrbit (v->arch.hvm.svm.msrpm, msr); -BUG_ON (msr_bit ==NULL );The conversion from
BUG_ON()to "return" needs explanation; I don't see why that's warranted here. From all I can tell the case is impossible due to the wayconstruct_vmcb()works, and henceBUG_ON()is appropriate (and personally I would also be fine with no check at all, provided I'm not overlooking anything).
It was my mistake I should have not removed it.
Quoted 10 lines
xen/arch/x86/hvm/svm/svm.c static void cf_check svm_enable_msr_interception(struct domain *d, uint32_t msr) · line 326
Quoted 8 lines
xen/arch/x86/hvm/svm/svm.c +1
-2@@ -312,8 +323,10 @@ static void cf_check svm_enable_msr_interception(struct domain *d, uint32_t msr) {struct vcpu *v; - for_each_vcpu ( d, v ) -svm_intercept_msr (v, msr,MSR_INTERCEPT_WRITE ); + for_each_vcpu ( d, v ) {Nit: Brace placement.
Sorry. I will fix.
Quoted 24 lines
Quoted 24 lines
xen/arch/x86/hvm/svm/svm.c +7
-6@@ -595,22 +608,31 @@ static void cf_check svm_cpuid_policy_changed(struct vcpu *v)vmcb_set_exception_intercepts (vmcb, bitmap);/* Give access to MSR_SPEC_CTRL if the guest has been told about it. */ -svm_intercept_msr (v,MSR_SPEC_CTRL , - cp->extd.ibrs ?MSR_INTERCEPT_NONE :MSR_INTERCEPT_RW ); +if ( cp->extd.ibrs ) +svm_clear_msr_intercept (v,MSR_SPEC_CTRL ,MSR_RW ); +else +svm_set_msr_intercept (v,MSR_SPEC_CTRL ,MSR_RW );/* * Always trap write accesses to VIRT_SPEC_CTRL in order to cache the guest * setting and avoid having to perform a rdmsr on vmexit to get the guest * setting even if VIRT_SSBD is offered to Xen itself. */ -svm_intercept_msr (v,MSR_VIRT_SPEC_CTRL , - cp->extd.virt_ssbd && cpu_has_virt_ssbd && - !cpu_has_amd_ssbd ? -MSR_INTERCEPT_WRITE :MSR_INTERCEPT_RW ); +if ( cp->extd.virt_ssbd && cpu_has_virt_ssbd && !cpu_has_amd_ssbd ) + { +svm_set_msr_intercept (v,MSR_VIRT_SPEC_CTRL ,MSR_W );
Quoted 8 lines
xen/arch/x86/hvm/svm/svm.c static void cf_check svm_cpuid_policy_changed(struct vcpu *v) · line 629
Quoted 6 lines
xen/arch/x86/hvm/svm/svm.c +6
-0+svm_clear_msr_intercept (v,MSR_VIRT_SPEC_CTRL ,MSR_R ); + } +else + { +svm_set_msr_intercept (v,MSR_VIRT_SPEC_CTRL ,MSR_RW ); + }Preferably omit the braces for "else" here, just like you do above and ...
I added them for symmetry, since the first has. I find it easier to follow, personally. I can omit it.
Quoted 27 lines
xen/arch/x86/hvm/svm/svm.c static void cf_check svm_cpuid_policy_changed(struct vcpu *v) · line 635
Quoted 8 lines
xen/arch/x86/hvm/svm/svm.c +4
-2/* Give access to MSR_PRED_CMD if the guest has been told about it. */ -svm_intercept_msr (v,MSR_PRED_CMD , - cp->extd.ibpb ?MSR_INTERCEPT_NONE :MSR_INTERCEPT_RW ); +if ( cp->extd.ibpb ) +svm_clear_msr_intercept (v,MSR_VIRT_SPEC_CTRL ,MSR_RW ); +else +svm_set_msr_intercept (v,MSR_VIRT_SPEC_CTRL ,MSR_RW );... here.
Quoted 16 lines
xen/arch/x86/include/asm/hvm/svm/vmcb.h +3
-7@@ -585,13 +585,12 @@ void svm_destroy_vmcb(struct vcpu *v);void setup_vmcb_dump (void ); -#define MSR_INTERCEPT_NONE 0 -#define MSR_INTERCEPT_READ 1 -#define MSR_INTERCEPT_WRITE 2 -#define MSR_INTERCEPT_RW (MSR_INTERCEPT_WRITE | MSR_INTERCEPT_READ) -void svm_intercept_msr (struct vcpu *v,uint32_t msr,int enable); -#define svm_disable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), MSR_INTERCEPT_NONE) -#define svm_enable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), MSR_INTERCEPT_RW) +void svm_set_msr_intercept (struct vcpu *v,uint32_t msr,int flags); +void svm_clear_msr_intercept (struct vcpu *v,uint32_t msr,int flags); +#define svm_disable_intercept_for_msr (v, msr) \
Quoted 8 lines
xen/arch/x86/include/asm/hvm/svm/vmcb.h void svm_destroy_vmcb(struct vcpu *v); · line 593
Quoted 3 lines
xen/arch/x86/include/asm/hvm/svm/vmcb.h +3
-0+ svm_clear_msr_intercept((v), (msr), MSR_RW) +#define svm_enable_intercept_for_msr (v, msr) \ + svm_set_intercept_msr((v), (msr), MSR_RW)Please avoid excess parentheses. Also could you clarify why you retain these shorthands when you don't use them in the conversion that you're doing (e.g. ())? Are you intending them to go
away down the road?
Ok.
I did not understand the question. Which shorthands?
Quoted 2 lines
Jan
Signature · 1 line
Xenia
Re: [PATCH 2/4] x86/svm: split svm_intercept_msr() into svm_{set,clear}_msr_intercept()
Quoted 20 lines · Xenia Ragiadakou
Quoted 13 lines · Jan Beulich
Quoted 11 lines · Xenia Ragiadakou
This change aims to render the control interface of MSR intercepts identical between SVM and VMX code, so that the control of the MSR intercept in common code can be done through an
hvm_funcscallback.Create two new functions:
-svm_set_msr_intercept(), enables interception of read/write accesses to the corresponding MSR, by setting the corresponding read/write bits in the MSRPM based on the flags
-svm_clear_msr_intercept(), disables interception of read/write accesses to the corresponding MSR, by clearing the corresponding read/write bits in the MSRPM based on the flagsQuoted 5 lines
In how far is VMX'es present model better than SVM's? They both have pros and cons, depending on the specific use. I'm not asking to do it the other way around (at least not yet), I'd merely like to understand why we're going to gain two new hooks (if I'm not mistaken) when we could also get away with just one.
Quoted 4 lines
SVM approach always touches both read/write bits (either by setting or clearing them). I thought that using the SVM approach on VMX could be considered a functional change (because there are parts where VMX assumes that a bit is already set or cleared and does not touch it).
As per my comment on the last patch a question is whether both actually need to become uniform. But if they do, then the new model should imo be followed right away, and that VMX'es simply leaving bits alone when already in known state.
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
xen/arch/x86/include/asm/hvm/svm/vmcb.h +3
-7@@ -585,13 +585,12 @@ void svm_destroy_vmcb(struct vcpu *v);void setup_vmcb_dump (void ); -#define MSR_INTERCEPT_NONE 0 -#define MSR_INTERCEPT_READ 1 -#define MSR_INTERCEPT_WRITE 2 -#define MSR_INTERCEPT_RW (MSR_INTERCEPT_WRITE | MSR_INTERCEPT_READ) -void svm_intercept_msr (struct vcpu *v,uint32_t msr,int enable); -#define svm_disable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), MSR_INTERCEPT_NONE) -#define svm_enable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), MSR_INTERCEPT_RW) +void svm_set_msr_intercept (struct vcpu *v,uint32_t msr,int flags); +void svm_clear_msr_intercept (struct vcpu *v,uint32_t msr,int flags); +#define svm_disable_intercept_for_msr (v, msr) \Quoted 8 lines
xen/arch/x86/include/asm/hvm/svm/vmcb.h void svm_destroy_vmcb(struct vcpu *v); · line 593
Quoted 3 lines
xen/arch/x86/include/asm/hvm/svm/vmcb.h +3
-0+ svm_clear_msr_intercept((v), (msr), MSR_RW) +#define svm_enable_intercept_for_msr (v, msr) \ + svm_set_intercept_msr((v), (msr), MSR_RW)Please avoid excess parentheses. Also could you clarify why you retain these shorthands when you don't use them in the conversion that you're doing (e.g. ())? Are you intending them to go
away down the road?
Quoted 2 lines
Ok.
I did not understand the question. Which shorthands?
svm_disable_intercept_for_msr() and svm_enable_intercept_for_msr().
Jan
Re: [PATCH 2/4] x86/svm: split svm_intercept_msr() into svm_{set,clear}_msr_intercept()
Quoted 26 lines · Jan Beulich
Quoted 20 lines · Xenia Ragiadakou
Quoted 13 lines · Jan Beulich
Quoted 11 lines · Xenia Ragiadakou
This change aims to render the control interface of MSR intercepts identical between SVM and VMX code, so that the control of the MSR intercept in common code can be done through an
hvm_funcscallback.Create two new functions:
-svm_set_msr_intercept(), enables interception of read/write accesses to the corresponding MSR, by setting the corresponding read/write bits in the MSRPM based on the flags
-svm_clear_msr_intercept(), disables interception of read/write accesses to the corresponding MSR, by clearing the corresponding read/write bits in the MSRPM based on the flagsQuoted 5 lines
In how far is VMX'es present model better than SVM's? They both have pros and cons, depending on the specific use. I'm not asking to do it the other way around (at least not yet), I'd merely like to understand why we're going to gain two new hooks (if I'm not mistaken) when we could also get away with just one.
Quoted 4 lines
SVM approach always touches both read/write bits (either by setting or clearing them). I thought that using the SVM approach on VMX could be considered a functional change (because there are parts where VMX assumes that a bit is already set or cleared and does not touch it).
Quoted 4 lines
As per my comment on the last patch a question is whether both actually need to become uniform. But if they do, then the new model should imo be followed right away, and that VMX'es simply leaving bits alone when already in known state.
But the SVM implementation does not assume. I can do it and remove the no functional change part.
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 10 lines
xen/arch/x86/include/asm/hvm/svm/vmcb.h +0
-3@@ -585,13 +585,12 @@ void svm_destroy_vmcb(struct vcpu *v);void setup_vmcb_dump (void ); -#define MSR_INTERCEPT_NONE 0 -#define MSR_INTERCEPT_READ 1 -#define MSR_INTERCEPT_WRITE 2xen/arch/x86/include/asm/hvm/svm/vmcb.h void svm_destroy_vmcb(struct vcpu *v); · line 593
Quoted 10 lines
xen/arch/x86/include/asm/hvm/svm/vmcb.h +6
-4-#define MSR_INTERCEPT_RW (MSR_INTERCEPT_WRITE | MSR_INTERCEPT_READ) -void svm_intercept_msr (struct vcpu *v,uint32_t msr,int enable); -#define svm_disable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), MSR_INTERCEPT_NONE) -#define svm_enable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), MSR_INTERCEPT_RW) +void svm_set_msr_intercept (struct vcpu *v,uint32_t msr,int flags); +void svm_clear_msr_intercept (struct vcpu *v,uint32_t msr,int flags); +#define svm_disable_intercept_for_msr (v, msr) \ + svm_clear_msr_intercept((v), (msr), MSR_RW) +#define svm_enable_intercept_for_msr (v, msr) \ + svm_set_intercept_msr((v), (msr), MSR_RW)Please avoid excess parentheses. Also could you clarify why you retain these shorthands when you don't use them in the conversion that you're doing (e.g. ())? Are you intending them to go
away down the road?
Quoted 4 lines
Quoted 2 lines
Ok.
I did not understand the question. Which shorthands?
svm_disable_intercept_for_msr()andsvm_enable_intercept_for_msr().
Are you suggesting to replace svm_{en,dis}able_intercept_for_msr() with svm_{ser,clear}_msr_intercept()? svm_disable_intercept_for_msr() is used in svm.c and vmcb.c.
Signature · 1 line
Xenia
Re: [PATCH 2/4] x86/svm: split svm_intercept_msr() into svm_{set,clear}_msr_intercept()
Quoted 29 lines · Xenia Ragiadakou
Quoted 28 lines · Jan Beulich
Quoted 27 lines · Xenia Ragiadakou
Quoted 25 lines · Jan Beulich
Quoted 9 lines · Xenia Ragiadakou
xen/arch/x86/include/asm/hvm/svm/vmcb.h +0
-3@@ -585,13 +585,12 @@ void svm_destroy_vmcb(struct vcpu *v);void setup_vmcb_dump (void ); -#define MSR_INTERCEPT_NONE 0 -#define MSR_INTERCEPT_READ 1 -#define MSR_INTERCEPT_WRITE 2xen/arch/x86/include/asm/hvm/svm/vmcb.h void svm_destroy_vmcb(struct vcpu *v); · line 593
Quoted 10 lines
xen/arch/x86/include/asm/hvm/svm/vmcb.h +6
-4-#define MSR_INTERCEPT_RW (MSR_INTERCEPT_WRITE | MSR_INTERCEPT_READ) -void svm_intercept_msr (struct vcpu *v,uint32_t msr,int enable); -#define svm_disable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), MSR_INTERCEPT_NONE) -#define svm_enable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), MSR_INTERCEPT_RW) +void svm_set_msr_intercept (struct vcpu *v,uint32_t msr,int flags); +void svm_clear_msr_intercept (struct vcpu *v,uint32_t msr,int flags); +#define svm_disable_intercept_for_msr (v, msr) \ + svm_clear_msr_intercept((v), (msr), MSR_RW) +#define svm_enable_intercept_for_msr (v, msr) \ + svm_set_intercept_msr((v), (msr), MSR_RW)Please avoid excess parentheses. Also could you clarify why you retain these shorthands when you don't use them in the conversion that you're doing (e.g. ())? Are you intending them to go
away down the road?
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Ok.
I did not understand the question. Which shorthands?
svm_disable_intercept_for_msr()andsvm_enable_intercept_for_msr().Are you suggesting to replace svm_{en,dis}able_intercept_for_msr() with svm_{ser,clear}_msr_intercept()?
svm_disable_intercept_for_msr()is used insvm.candvmcb.c.
I'm suggesting one of two possible routes leading to consistent use:
1) drop the shorthands
2) retain the shorthands and don't ever open-code them Depending on which route we want to go either your code adjustments in this regard are fine, and only a remark would want adding that they're retained until remaining uses can be cleaned up, or you want to use them in your changes wherever possible.
Jan
PATCH 3/4 x86/vmx: replace enum vmx_msr_intercept_type with the msr access flags
In reply to Xenia RagiadakouReplace enum vmx_msr_intercept_type with the msr access flags, defined in hvm.h, so that the functions {svm,vmx}_{set,clear}_msr_intercept() share the same prototype.
No functional change intended.
--- xen/arch/x86/cpu/vpmu_intel.c | 24 +++++++------- xen/arch/x86/hvm/vmx/vmcs.c | 38 ++++++++++----------- xen/arch/x86/hvm/vmx/vmx.c | 44 ++++++++++++------------- xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 14 ++------ 4 files changed, 54 insertions(+), 66 deletions(-)
xen/arch/x86/cpu/vpmu_intel.c +12 -12
@@ -230,22 +230,22 @@ static void core2_vpmu_set_msr_bitmap(struct vcpu *v)/* Allow Read/Write PMU Counters MSR Directly. */ for ( i =0 ; i < fixed_pmc_cnt; i++ ) -vmx_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,VMX_MSR_RW ); +vmx_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW );for ( i =0 ; i < arch_pmc_cnt; i++ ) { -vmx_clear_msr_intercept (v,MSR_IA32_PERFCTR0 + i,VMX_MSR_RW ); +vmx_clear_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW );if ( full_width_write ) -vmx_clear_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,VMX_MSR_RW ); +vmx_clear_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); }/* Allow Read PMU Non-global Controls Directly. */ for ( i =0 ; i < arch_pmc_cnt; i++ ) -vmx_clear_msr_intercept (v,MSR_P6_EVNTSEL (i),VMX_MSR_R ); +vmx_clear_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); -vmx_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,VMX_MSR_R ); -vmx_clear_msr_intercept (v,MSR_IA32_DS_AREA ,VMX_MSR_R ); +vmx_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); +vmx_clear_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); }static void core2_vpmu_unset_msr_bitmap (struct vcpu *v)
@@ -253,21 +253,21 @@ static void core2_vpmu_unset_msr_bitmap(struct vcpu *v)unsigned int i;for ( i =0 ; i < fixed_pmc_cnt; i++ ) -vmx_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,VMX_MSR_RW ); +vmx_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW );for ( i =0 ; i < arch_pmc_cnt; i++ ) { -vmx_set_msr_intercept (v,MSR_IA32_PERFCTR0 + i,VMX_MSR_RW ); +vmx_set_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW );if ( full_width_write ) -vmx_set_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,VMX_MSR_RW ); +vmx_set_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); }for ( i =0 ; i < arch_pmc_cnt; i++ ) -vmx_set_msr_intercept (v,MSR_P6_EVNTSEL (i),VMX_MSR_R ); +vmx_set_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); -vmx_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,VMX_MSR_R ); -vmx_set_msr_intercept (v,MSR_IA32_DS_AREA ,VMX_MSR_R ); +vmx_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); +vmx_set_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); }static inline void __core2_vpmu_save (struct vcpu *v)
xen/arch/x86/hvm/vmx/vmcs.c +18 -20
@@ -902,8 +902,7 @@ static void vmx_set_host_env(struct vcpu *v) (unsigned long)&get_cpu_info()->guest_cpu_user_regs.error_code); } -void vmx_clear_msr_intercept (struct vcpu *v,unsigned int msr, -enum vmx_msr_intercept_type type) +void vmx_clear_msr_intercept (struct vcpu *v,unsigned int msr,int type) {struct vmx_msr_bitmap *msr_bitmap = v->arch.hvm.vmx.msr_bitmap;struct domain *d = v->domain;
@@ -917,25 +916,24 @@ void vmx_clear_msr_intercept(struct vcpu *v, unsigned int msr,if ( msr <=0x1fff ) { -if ( type &VMX_MSR_R ) +if ( type &MSR_R )clear_bit (msr, msr_bitmap->read_low); -if ( type &VMX_MSR_W ) +if ( type &MSR_W )clear_bit (msr, msr_bitmap->write_low); }else if ( (msr >=0xc0000000 ) && (msr <=0xc0001fff ) ) { msr &=0x1fff ; -if ( type &VMX_MSR_R ) +if ( type &MSR_R )clear_bit (msr, msr_bitmap->read_high); -if ( type &VMX_MSR_W ) +if ( type &MSR_W )clear_bit (msr, msr_bitmap->write_high); }else ASSERT (!"MSR out of range for interception\n" ); } -void vmx_set_msr_intercept (struct vcpu *v,unsigned int msr, -enum vmx_msr_intercept_type type) +void vmx_set_msr_intercept (struct vcpu *v,unsigned int msr,int type) {struct vmx_msr_bitmap *msr_bitmap = v->arch.hvm.vmx.msr_bitmap;
@@ -945,17 +943,17 @@ void vmx_set_msr_intercept(struct vcpu *v, unsigned int msr,if ( msr <=0x1fff ) { -if ( type &VMX_MSR_R ) +if ( type &MSR_R )set_bit (msr, msr_bitmap->read_low); -if ( type &VMX_MSR_W ) +if ( type &MSR_W )set_bit (msr, msr_bitmap->write_low); }else if ( (msr >=0xc0000000 ) && (msr <=0xc0001fff ) ) { msr &=0x1fff ; -if ( type &VMX_MSR_R ) +if ( type &MSR_R )set_bit (msr, msr_bitmap->read_high); -if ( type &VMX_MSR_W ) +if ( type &MSR_W )set_bit (msr, msr_bitmap->write_high); }else
@@ -1162,17 +1160,17 @@ static int construct_vmcs(struct vcpu *v) v->arch.hvm.vmx.msr_bitmap = msr_bitmap;__vmwrite (MSR_BITMAP ,virt_to_maddr (msr_bitmap)); -vmx_clear_msr_intercept (v,MSR_FS_BASE ,VMX_MSR_RW ); -vmx_clear_msr_intercept (v,MSR_GS_BASE ,VMX_MSR_RW ); -vmx_clear_msr_intercept (v,MSR_SHADOW_GS_BASE ,VMX_MSR_RW ); -vmx_clear_msr_intercept (v,MSR_IA32_SYSENTER_CS ,VMX_MSR_RW ); -vmx_clear_msr_intercept (v,MSR_IA32_SYSENTER_ESP ,VMX_MSR_RW ); -vmx_clear_msr_intercept (v,MSR_IA32_SYSENTER_EIP ,VMX_MSR_RW ); +vmx_clear_msr_intercept (v,MSR_FS_BASE ,MSR_RW ); +vmx_clear_msr_intercept (v,MSR_GS_BASE ,MSR_RW ); +vmx_clear_msr_intercept (v,MSR_SHADOW_GS_BASE ,MSR_RW ); +vmx_clear_msr_intercept (v,MSR_IA32_SYSENTER_CS ,MSR_RW ); +vmx_clear_msr_intercept (v,MSR_IA32_SYSENTER_ESP ,MSR_RW ); +vmx_clear_msr_intercept (v,MSR_IA32_SYSENTER_EIP ,MSR_RW );if (paging_mode_hap (d) && (!is_iommu_enabled (d) || iommu_snoop) ) -vmx_clear_msr_intercept (v,MSR_IA32_CR_PAT ,VMX_MSR_RW ); +vmx_clear_msr_intercept (v,MSR_IA32_CR_PAT ,MSR_RW );if ( (vmexit_ctl &VM_EXIT_CLEAR_BNDCFGS ) && (vmentry_ctl &VM_ENTRY_LOAD_BNDCFGS ) ) -vmx_clear_msr_intercept (v,MSR_IA32_BNDCFGS ,VMX_MSR_RW ); +vmx_clear_msr_intercept (v,MSR_IA32_BNDCFGS ,MSR_RW ); }/* I/O access bitmap. */
xen/arch/x86/hvm/vmx/vmx.c +22 -22
117 lines not on this page · raw message
xen/arch/x86/include/asm/hvm/vmx/vmcs.h +2 -12
@@ -644,18 +644,8 @@ static inline int vmx_write_guest_msr(struct vcpu *v, uint32_t msr,return 0 ; } - -/* MSR intercept bitmap infrastructure. */ -enum vmx_msr_intercept_type { -VMX_MSR_R =1 , -VMX_MSR_W =2 , -VMX_MSR_RW =VMX_MSR_R |VMX_MSR_W , -}; - -void vmx_clear_msr_intercept (struct vcpu *v,unsigned int msr, -enum vmx_msr_intercept_type type); -void vmx_set_msr_intercept (struct vcpu *v,unsigned int msr, -enum vmx_msr_intercept_type type); +void vmx_clear_msr_intercept (struct vcpu *v,unsigned int msr,int type); +void vmx_set_msr_intercept (struct vcpu *v,unsigned int msr,int type);void vmx_vmcs_switch (paddr_t from,paddr_t to);void vmx_set_eoi_exit_bitmap (struct vcpu *v,u8 vector);void vmx_clear_eoi_exit_bitmap (struct vcpu *v,u8 vector);
Signature · 1 line
2.37.2
Re: [PATCH 3/4] x86/vmx: replace enum vmx_msr_intercept_type with the msr access flags
Quoted 10 lines · Xenia Ragiadakou
xen/arch/x86/include/asm/hvm/vmx/vmcs.h +0
-4@@ -644,18 +644,8 @@ static inline int vmx_write_guest_msr(struct vcpu *v, uint32_t msr,return 0 ; } - -/* MSR intercept bitmap infrastructure. */ -enum vmx_msr_intercept_type { -VMX_MSR_R =1 ,
xen/arch/x86/include/asm/hvm/vmx/vmcs.h static inline int vmx_write_guest_msr(struct vcpu *v, uint32_t msr, · line 648
Quoted 10 lines
xen/arch/x86/include/asm/hvm/vmx/vmcs.h +2
-8-VMX_MSR_W =2 , - VMX_MSR_RW = VMX_MSR_R | VMX_MSR_W, -}; - -void vmx_clear_msr_intercept (struct vcpu *v,unsigned int msr, -enum vmx_msr_intercept_type type); -void vmx_set_msr_intercept (struct vcpu *v,unsigned int msr, -enum vmx_msr_intercept_type type); +void vmx_clear_msr_intercept (struct vcpu *v,unsigned int msr,int type); +void vmx_set_msr_intercept (struct vcpu *v,unsigned int msr,int type);
unsigned int please again for the last parameter each.
Jan
Re: [PATCH 3/4] x86/vmx: replace enum vmx_msr_intercept_type with the msr access flags
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Xenia Ragiadakou
xen/arch/x86/include/asm/hvm/vmx/vmcs.h +0
-0@@ -644,18 +644,8 @@ static inline int vmx_write_guest_msr(struct vcpu *v, uint32_t msr,return 0 ; }
Quoted 16 lines
Quoted 4 lines
xen/arch/x86/include/asm/hvm/vmx/vmcs.h +0
-4- -/* MSR intercept bitmap infrastructure. */ -enum vmx_msr_intercept_type { -VMX_MSR_R =1 ,xen/arch/x86/include/asm/hvm/vmx/vmcs.h static inline int vmx_write_guest_msr(struct vcpu *v, uint32_t msr, · line 648
Quoted 10 lines
xen/arch/x86/include/asm/hvm/vmx/vmcs.h +2
-8-VMX_MSR_W =2 , - VMX_MSR_RW = VMX_MSR_R | VMX_MSR_W, -}; - -void vmx_clear_msr_intercept (struct vcpu *v,unsigned int msr, -enum vmx_msr_intercept_type type); -void vmx_set_msr_intercept (struct vcpu *v,unsigned int msr, -enum vmx_msr_intercept_type type); +void vmx_clear_msr_intercept (struct vcpu *v,unsigned int msr,int type); +void vmx_set_msr_intercept (struct vcpu *v,unsigned int msr,int type);unsigned int please again for the last parameter each.
Oh, also, another remark here towards patch 2: Note how the middle parameter each is "unsigned int msr" here, when in SVM code you make it (kind of leave it) uint32_t. As per ./CODING_STYLE unsigned int is to be preferred; in any event both (and the eventual hook) want to agree.
Jan
Re: [PATCH 3/4] x86/vmx: replace enum vmx_msr_intercept_type with the msr access flags
Quoted 25 lines · Jan Beulich
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Xenia Ragiadakou
xen/arch/x86/include/asm/hvm/vmx/vmcs.h +0
-0@@ -644,18 +644,8 @@ static inline int vmx_write_guest_msr(struct vcpu *v, uint32_t msr,return 0 ; }Quoted 16 lines
Quoted 4 lines
xen/arch/x86/include/asm/hvm/vmx/vmcs.h +0
-4- -/* MSR intercept bitmap infrastructure. */ -enum vmx_msr_intercept_type { -VMX_MSR_R =1 ,xen/arch/x86/include/asm/hvm/vmx/vmcs.h static inline int vmx_write_guest_msr(struct vcpu *v, uint32_t msr, · line 648
Quoted 10 lines
xen/arch/x86/include/asm/hvm/vmx/vmcs.h +2
-8-VMX_MSR_W =2 , - VMX_MSR_RW = VMX_MSR_R | VMX_MSR_W, -}; - -void vmx_clear_msr_intercept (struct vcpu *v,unsigned int msr, -enum vmx_msr_intercept_type type); -void vmx_set_msr_intercept (struct vcpu *v,unsigned int msr, -enum vmx_msr_intercept_type type); +void vmx_clear_msr_intercept (struct vcpu *v,unsigned int msr,int type); +void vmx_set_msr_intercept (struct vcpu *v,unsigned int msr,int type);unsigned int please again for the last parameter each.
Quoted 4 lines
Oh, also, another remark here towards patch 2: Note how the middle parameter each is "unsigned int msr" here, when in SVM code you make it (kind of leave it)
uint32_t. As per ./CODING_STYLE unsigned int is to be preferred; in any event both (and the eventual hook) want to agree.
Thx. I will fix and keep it in mind.
Quoted 2 lines
Jan
Signature · 1 line
Xenia
PATCH 4/4 x86/hvm: create hvm_funcs for {svm,vmx}_{set,clear}_msr_intercept()
In reply to Xenia RagiadakouAdd hvm_funcs hooks for {set,clear}_msr_intercept() for controlling the msr intercept in common vpmu code.
No functional change intended.
--- xen/arch/x86/cpu/vpmu_amd.c | 10 ++++----- xen/arch/x86/cpu/vpmu_intel.c | 24 ++++++++++----------- xen/arch/x86/hvm/svm/svm.c | 4 ++-- xen/arch/x86/hvm/vmx/vmcs.c | 4 ++-- xen/arch/x86/hvm/vmx/vmx.c | 2 ++ xen/arch/x86/include/asm/hvm/hvm.h | 28 +++++++++++++++++++++++++ xen/arch/x86/include/asm/hvm/svm/vmcb.h | 4 ++-- xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 4 ++-- 8 files changed, 55 insertions(+), 25 deletions(-)
xen/arch/x86/cpu/vpmu_amd.c +5 -5
@@ -165,9 +165,9 @@ static void amd_vpmu_set_msr_bitmap(struct vcpu *v)for ( i =0 ; i < num_counters; i++ ) { -svm_clear_msr_intercept (v, counters[i],MSR_RW ); -svm_set_msr_intercept (v, ctrls[i],MSR_W ); -svm_clear_msr_intercept (v, ctrls[i],MSR_R ); +hvm_clear_msr_intercept (v, counters[i],MSR_RW ); +hvm_set_msr_intercept (v, ctrls[i],MSR_W ); +hvm_clear_msr_intercept (v, ctrls[i],MSR_R ); }msr_bitmap_on (vpmu);
@@ -180,8 +180,8 @@ static void amd_vpmu_unset_msr_bitmap(struct vcpu *v)for ( i =0 ; i < num_counters; i++ ) { -svm_set_msr_intercept (v, counters[i],MSR_RW ); -svm_set_msr_intercept (v, ctrls[i],MSR_RW ); +hvm_set_msr_intercept (v, counters[i],MSR_RW ); +hvm_set_msr_intercept (v, ctrls[i],MSR_RW ); }msr_bitmap_off (vpmu);
xen/arch/x86/cpu/vpmu_intel.c +12 -12
@@ -230,22 +230,22 @@ static void core2_vpmu_set_msr_bitmap(struct vcpu *v)/* Allow Read/Write PMU Counters MSR Directly. */ for ( i =0 ; i < fixed_pmc_cnt; i++ ) -vmx_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW ); +hvm_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW );for ( i =0 ; i < arch_pmc_cnt; i++ ) { -vmx_clear_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW ); +hvm_clear_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW );if ( full_width_write ) -vmx_clear_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); +hvm_clear_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); }/* Allow Read PMU Non-global Controls Directly. */ for ( i =0 ; i < arch_pmc_cnt; i++ ) -vmx_clear_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); +hvm_clear_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); -vmx_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); -vmx_clear_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); +hvm_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); +hvm_clear_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); }static void core2_vpmu_unset_msr_bitmap (struct vcpu *v)
@@ -253,21 +253,21 @@ static void core2_vpmu_unset_msr_bitmap(struct vcpu *v)unsigned int i;for ( i =0 ; i < fixed_pmc_cnt; i++ ) -vmx_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW ); +hvm_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW );for ( i =0 ; i < arch_pmc_cnt; i++ ) { -vmx_set_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW ); +hvm_set_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW );if ( full_width_write ) -vmx_set_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); +hvm_set_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); }for ( i =0 ; i < arch_pmc_cnt; i++ ) -vmx_set_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); +hvm_set_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); -vmx_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); -vmx_set_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); +hvm_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); +hvm_set_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); }static inline void __core2_vpmu_save (struct vcpu *v)
xen/arch/x86/hvm/svm/svm.c +2 -2
@@ -288,7 +288,7 @@ svm_msrbit(unsigned long *msr_bitmap, uint32_t msr)return msr_bit; } -void svm_set_msr_intercept (struct vcpu *v,uint32_t msr,int flags) +void cf_check svm_set_msr_intercept(struct vcpu *v, uint32_t msr, int flags) {unsigned long *msr_bit =svm_msrbit (v->arch.hvm.svm.msrpm, msr);
@@ -303,7 +303,7 @@ void svm_set_msr_intercept(struct vcpu *v, uint32_t msr, int flags)__set_bit (msr *2 +1 , msr_bit); } -void svm_clear_msr_intercept (struct vcpu *v,uint32_t msr,int flags) +void cf_check svm_clear_msr_intercept(struct vcpu *v, uint32_t msr, int flags) {unsigned long *msr_bit =svm_msrbit (v->arch.hvm.svm.msrpm, msr);
xen/arch/x86/hvm/vmx/vmcs.c +2 -2
@@ -902,7 +902,7 @@ static void vmx_set_host_env(struct vcpu *v) (unsigned long)&get_cpu_info()->guest_cpu_user_regs.error_code); } -void vmx_clear_msr_intercept (struct vcpu *v,unsigned int msr,int type) +void cf_check vmx_clear_msr_intercept(struct vcpu *v, uint32_t msr, int type) {struct vmx_msr_bitmap *msr_bitmap = v->arch.hvm.vmx.msr_bitmap;struct domain *d = v->domain;
@@ -933,7 +933,7 @@ void vmx_clear_msr_intercept(struct vcpu *v, unsigned int msr, int type)ASSERT (!"MSR out of range for interception\n" ); } -void vmx_set_msr_intercept (struct vcpu *v,unsigned int msr,int type) +void cf_check vmx_set_msr_intercept(struct vcpu *v, uint32_t msr, int type) {struct vmx_msr_bitmap *msr_bitmap = v->arch.hvm.vmx.msr_bitmap;
xen/arch/x86/hvm/vmx/vmx.c +2 -0
@@ -2765,6 +2765,8 @@ static struct hvm_function_table __initdata_cf_clobber vmx_function_table = { .nhvm_domain_relinquish_resources = nvmx_domain_relinquish_resources, .update_vlapic_mode = vmx_vlapic_msr_changed, .nhvm_hap_walk_L1_p2m = nvmx_hap_walk_L1_p2m, + .set_msr_intercept = vmx_set_msr_intercept, + .clear_msr_intercept = vmx_clear_msr_intercept, .enable_msr_interception = vmx_enable_msr_interception, .altp2m_vcpu_update_p2m = vmx_vcpu_update_eptp, .altp2m_vcpu_update_vmfunc_ve = vmx_vcpu_update_vmfunc_ve,
xen/arch/x86/include/asm/hvm/hvm.h +28 -0
@@ -224,6 +224,8 @@ struct hvm_function_table { paddr_t *L1_gpa, unsigned int *page_order, uint8_t *p2m_acc, struct npfec npfec); +void (*set_msr_intercept)(struct vcpu *v,uint32_t msr,int flags); +void (*clear_msr_intercept)(struct vcpu *v,uint32_t msr,int flags);void (*enable_msr_interception)(struct domain *d,uint32_t msr);/* Alternate p2m */
@@ -658,6 +660,20 @@ static inline int nhvm_hap_walk_L1_p2m( v, L2_gpa, L1_gpa, page_order, p2m_acc, npfec); } +static inline void hvm_set_msr_intercept (struct vcpu *v,uint32_t msr, +int flags) +{ +if ( hvm_funcs.set_msr_intercept ) +alternative_vcall (hvm_funcs.set_msr_intercept, v, msr, flags); +} + +static inline void hvm_clear_msr_intercept (struct vcpu *v,uint32_t msr, +int flags) +{ +if ( hvm_funcs.clear_msr_intercept ) +alternative_vcall (hvm_funcs.clear_msr_intercept, v, msr, flags); +} +static inline void hvm_enable_msr_interception (struct domain *d,uint32_t msr) {alternative_vcall (hvm_funcs.enable_msr_interception, d, msr);
@@ -916,6 +932,18 @@ static inline void hvm_set_reg(struct vcpu *v, unsigned int reg, uint64_t val)ASSERT_UNREACHABLE (); } +static inline void hvm_set_msr_intercept (struct vcpu *v,uint32_t msr, +int flags) +{ +ASSERT_UNREACHABLE (); +} + +static inline void hvm_clear_msr_intercept (struct vcpu *v,uint32_t msr, +int flags) +{ +ASSERT_UNREACHABLE (); +} +#define is_viridian_domain (d) ((void)(d), false)#define is_viridian_vcpu (v) ((void)(v), false)#define has_viridian_time_ref_count (d) ((void)(d), false)
xen/arch/x86/include/asm/hvm/svm/vmcb.h +2 -2
@@ -585,8 +585,8 @@ void svm_destroy_vmcb(struct vcpu *v);void setup_vmcb_dump (void ); -void svm_set_msr_intercept (struct vcpu *v,uint32_t msr,int flags); -void svm_clear_msr_intercept (struct vcpu *v,uint32_t msr,int flags); +void cf_check svm_set_msr_intercept(struct vcpu *v, uint32_t msr, int flags); +void cf_check svm_clear_msr_intercept(struct vcpu *v, uint32_t msr, int flags);#define svm_disable_intercept_for_msr (v, msr) \ svm_clear_msr_intercept((v), (msr), MSR_RW)#define svm_enable_intercept_for_msr (v, msr) \
xen/arch/x86/include/asm/hvm/vmx/vmcs.h +2 -2
@@ -644,8 +644,8 @@ static inline int vmx_write_guest_msr(struct vcpu *v, uint32_t msr,return 0 ; } -void vmx_clear_msr_intercept (struct vcpu *v,unsigned int msr,int type); -void vmx_set_msr_intercept (struct vcpu *v,unsigned int msr,int type); +void cf_check vmx_clear_msr_intercept(struct vcpu *v, uint32_t msr, int type); +void cf_check vmx_set_msr_intercept(struct vcpu *v, uint32_t msr, int type);void vmx_vmcs_switch (paddr_t from,paddr_t to);void vmx_set_eoi_exit_bitmap (struct vcpu *v,u8 vector);void vmx_clear_eoi_exit_bitmap (struct vcpu *v,u8 vector);
Signature · 1 line
2.37.2
Re: [PATCH 4/4] x86/hvm: create hvm_funcs for {svm,vmx}_{set,clear}_msr_intercept()
Quoted 2 lines · Xenia Ragiadakou
Add
hvm_funcshooks for {set,clear}_msr_intercept() for controlling the msr intercept in common vpmu code.
What is this going to buy us? All calls ...
Quoted 16 lines
xen/arch/x86/cpu/vpmu_amd.c +3
-3@@ -165,9 +165,9 @@ static void amd_vpmu_set_msr_bitmap(struct vcpu *v)for ( i =0 ; i < num_counters; i++ ) { -svm_clear_msr_intercept (v, counters[i],MSR_RW ); -svm_set_msr_intercept (v, ctrls[i],MSR_W ); -svm_clear_msr_intercept (v, ctrls[i],MSR_R ); +hvm_clear_msr_intercept (v, counters[i],MSR_RW ); +hvm_set_msr_intercept (v, ctrls[i],MSR_W ); +hvm_clear_msr_intercept (v, ctrls[i],MSR_R ); }msr_bitmap_on (vpmu);
xen/arch/x86/cpu/vpmu_amd.c static void amd_vpmu_unset_msr_bitmap(struct vcpu *v) · line 187
Quoted 10 lines
xen/arch/x86/cpu/vpmu_amd.c +2
-2@@ -180,8 +180,8 @@ static void amd_vpmu_unset_msr_bitmap(struct vcpu *v)for ( i =0 ; i < num_counters; i++ ) { -svm_set_msr_intercept (v, counters[i],MSR_RW ); -svm_set_msr_intercept (v, ctrls[i],MSR_RW ); +hvm_set_msr_intercept (v, counters[i],MSR_RW ); +hvm_set_msr_intercept (v, ctrls[i],MSR_RW ); }msr_bitmap_off (vpmu);
... here will got to the SVM functions anyway, while ...
Quoted 49 lines
xen/arch/x86/cpu/vpmu_intel.c +9
-9@@ -230,22 +230,22 @@ static void core2_vpmu_set_msr_bitmap(struct vcpu *v)/* Allow Read/Write PMU Counters MSR Directly. */ for ( i =0 ; i < fixed_pmc_cnt; i++ ) -vmx_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW ); +hvm_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW );for ( i =0 ; i < arch_pmc_cnt; i++ ) { -vmx_clear_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW ); +hvm_clear_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW );if ( full_width_write ) -vmx_clear_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); +hvm_clear_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); }/* Allow Read PMU Non-global Controls Directly. */ for ( i =0 ; i < arch_pmc_cnt; i++ ) -vmx_clear_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); +hvm_clear_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); -vmx_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); -vmx_clear_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); +hvm_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); +hvm_clear_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); }static void core2_vpmu_unset_msr_bitmap (struct vcpu *v)@@ -253,21 +253,21 @@ static void core2_vpmu_unset_msr_bitmap(struct vcpu *v)unsigned int i;for ( i =0 ; i < fixed_pmc_cnt; i++ ) -vmx_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW ); +hvm_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW );for ( i =0 ; i < arch_pmc_cnt; i++ ) { -vmx_set_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW ); +hvm_set_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW );if ( full_width_write ) -vmx_set_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); +hvm_set_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); }for ( i =0 ; i < arch_pmc_cnt; i++ )
xen/arch/x86/cpu/vpmu_intel.c static void core2_vpmu_unset_msr_bitmap(struct vcpu *v) · line 273
Quoted 10 lines
xen/arch/x86/cpu/vpmu_intel.c +3
-3-vmx_set_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); +hvm_set_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); -vmx_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); -vmx_set_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); +hvm_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); +hvm_set_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); }static inline void __core2_vpmu_save (struct vcpu *v)
... all calls here will go to VMX'es. For making either vpmu_<vendor>.c build without that vendor's virtualization enabled, isn't it all it takes to have ...
Quoted 5 lines
xen/arch/x86/cpu/vpmu_intel.c +1
-0@@ -916,6 +932,18 @@ static inline void hvm_set_reg(struct vcpu *v, unsigned int reg, uint64_t val)ASSERT_UNREACHABLE (); } +static inline void hvm_set_msr_intercept(struct vcpu *v, uint32_t msr,
xen/arch/x86/cpu/vpmu_intel.c static inline void hvm_set_reg(struct vcpu *v, unsigned int reg, uint64_t val) · line 945
Quoted 10 lines
xen/arch/x86/cpu/vpmu_intel.c +10
-0+ int flags) +{ +ASSERT_UNREACHABLE (); +} + +static inline void hvm_clear_msr_intercept (struct vcpu *v,uint32_t msr, +int flags) +{ +ASSERT_UNREACHABLE (); +}
... respective SVM and VMX stubs in place instead?
Jan
Re: [PATCH 4/4] x86/hvm: create hvm_funcs for {svm,vmx}_{set,clear}_msr_intercept()
Quoted 103 lines · Jan Beulich
Quoted 2 lines · Xenia Ragiadakou
Add
hvm_funcshooks for {set,clear}_msr_intercept() for controlling the msr intercept in common vpmu code.What is this going to buy us? All calls ...
Quoted 16 lines
xen/arch/x86/cpu/vpmu_amd.c +3
-3@@ -165,9 +165,9 @@ static void amd_vpmu_set_msr_bitmap(struct vcpu *v)for ( i =0 ; i < num_counters; i++ ) { -svm_clear_msr_intercept (v, counters[i],MSR_RW ); -svm_set_msr_intercept (v, ctrls[i],MSR_W ); -svm_clear_msr_intercept (v, ctrls[i],MSR_R ); +hvm_clear_msr_intercept (v, counters[i],MSR_RW ); +hvm_set_msr_intercept (v, ctrls[i],MSR_W ); +hvm_clear_msr_intercept (v, ctrls[i],MSR_R ); }msr_bitmap_on (vpmu);xen/arch/x86/cpu/vpmu_amd.c static void amd_vpmu_unset_msr_bitmap(struct vcpu *v) · line 187
Quoted 10 lines
xen/arch/x86/cpu/vpmu_amd.c +2
-2@@ -180,8 +180,8 @@ static void amd_vpmu_unset_msr_bitmap(struct vcpu *v)for ( i =0 ; i < num_counters; i++ ) { -svm_set_msr_intercept (v, counters[i],MSR_RW ); -svm_set_msr_intercept (v, ctrls[i],MSR_RW ); +hvm_set_msr_intercept (v, counters[i],MSR_RW ); +hvm_set_msr_intercept (v, ctrls[i],MSR_RW ); }msr_bitmap_off (vpmu);... here will got to the SVM functions anyway, while ...
Quoted 49 lines
xen/arch/x86/cpu/vpmu_intel.c +9
-9@@ -230,22 +230,22 @@ static void core2_vpmu_set_msr_bitmap(struct vcpu *v)/* Allow Read/Write PMU Counters MSR Directly. */ for ( i =0 ; i < fixed_pmc_cnt; i++ ) -vmx_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW ); +hvm_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW );for ( i =0 ; i < arch_pmc_cnt; i++ ) { -vmx_clear_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW ); +hvm_clear_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW );if ( full_width_write ) -vmx_clear_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); +hvm_clear_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); }/* Allow Read PMU Non-global Controls Directly. */ for ( i =0 ; i < arch_pmc_cnt; i++ ) -vmx_clear_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); +hvm_clear_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); -vmx_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); -vmx_clear_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); +hvm_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); +hvm_clear_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); }static void core2_vpmu_unset_msr_bitmap (struct vcpu *v)@@ -253,21 +253,21 @@ static void core2_vpmu_unset_msr_bitmap(struct vcpu *v)unsigned int i;for ( i =0 ; i < fixed_pmc_cnt; i++ ) -vmx_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW ); +hvm_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW );for ( i =0 ; i < arch_pmc_cnt; i++ ) { -vmx_set_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW ); +hvm_set_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW );if ( full_width_write ) -vmx_set_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); +hvm_set_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); }for ( i =0 ; i < arch_pmc_cnt; i++ )xen/arch/x86/cpu/vpmu_intel.c static void core2_vpmu_unset_msr_bitmap(struct vcpu *v) · line 273
Quoted 10 lines
xen/arch/x86/cpu/vpmu_intel.c +3
-3-vmx_set_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); +hvm_set_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); -vmx_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); -vmx_set_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); +hvm_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); +hvm_set_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); }static inline void __core2_vpmu_save (struct vcpu *v)... all calls here will go to VMX'es. For making either vpmu_<vendor>.c build without that vendor's virtualization enabled, isn't it all it takes to have ...
Quoted 4 lines
xen/arch/x86/cpu/vpmu_intel.c +0
-0@@ -916,6 +932,18 @@ static inline void hvm_set_reg(struct vcpu *v, unsigned int reg, uint64_t val)ASSERT_UNREACHABLE (); }
Quoted 13 lines
xen/arch/x86/cpu/vpmu_intel.c static inline void hvm_set_reg(struct vcpu *v, unsigned int reg, uint64_t val) · line 945
Quoted 11 lines
xen/arch/x86/cpu/vpmu_intel.c +11
-0+static inline void hvm_set_msr_intercept (struct vcpu *v,uint32_t msr, +int flags) +{ +ASSERT_UNREACHABLE (); +} + +static inline void hvm_clear_msr_intercept (struct vcpu *v,uint32_t msr, +int flags) +{ +ASSERT_UNREACHABLE (); +}... respective SVM and VMX stubs in place instead?
IMO it is more readable and they looked very good candidates for being abstracted because they are doing the same thing under both technologies.
Are you suggesting that their usage in common code should be discouraged and should not be exported via the hvm_funcs interface? Or just that the amount of changes cannot be justified. IIUC Andrew also suggested to use hvm_funcs for msr intercept handling but I 'm not sure whether he had this or sth else in mind.
Signature · 1 line
Xenia
Re: [PATCH 4/4] x86/hvm: create hvm_funcs for {svm,vmx}_{set,clear}_msr_intercept()
Quoted 119 lines · Xenia Ragiadakou
Quoted 103 lines · Jan Beulich
Quoted 2 lines · Xenia Ragiadakou
Add
hvm_funcshooks for {set,clear}_msr_intercept() for controlling the msr intercept in common vpmu code.What is this going to buy us? All calls ...
Quoted 16 lines
xen/arch/x86/cpu/vpmu_amd.c +3
-3@@ -165,9 +165,9 @@ static void amd_vpmu_set_msr_bitmap(struct vcpu *v)for ( i =0 ; i < num_counters; i++ ) { -svm_clear_msr_intercept (v, counters[i],MSR_RW ); -svm_set_msr_intercept (v, ctrls[i],MSR_W ); -svm_clear_msr_intercept (v, ctrls[i],MSR_R ); +hvm_clear_msr_intercept (v, counters[i],MSR_RW ); +hvm_set_msr_intercept (v, ctrls[i],MSR_W ); +hvm_clear_msr_intercept (v, ctrls[i],MSR_R ); }msr_bitmap_on (vpmu);xen/arch/x86/cpu/vpmu_amd.c static void amd_vpmu_unset_msr_bitmap(struct vcpu *v) · line 187
Quoted 10 lines
xen/arch/x86/cpu/vpmu_amd.c +2
-2@@ -180,8 +180,8 @@ static void amd_vpmu_unset_msr_bitmap(struct vcpu *v)for ( i =0 ; i < num_counters; i++ ) { -svm_set_msr_intercept (v, counters[i],MSR_RW ); -svm_set_msr_intercept (v, ctrls[i],MSR_RW ); +hvm_set_msr_intercept (v, counters[i],MSR_RW ); +hvm_set_msr_intercept (v, ctrls[i],MSR_RW ); }msr_bitmap_off (vpmu);... here will got to the SVM functions anyway, while ...
Quoted 49 lines
xen/arch/x86/cpu/vpmu_intel.c +9
-9@@ -230,22 +230,22 @@ static void core2_vpmu_set_msr_bitmap(struct vcpu *v)/* Allow Read/Write PMU Counters MSR Directly. */ for ( i =0 ; i < fixed_pmc_cnt; i++ ) -vmx_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW ); +hvm_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW );for ( i =0 ; i < arch_pmc_cnt; i++ ) { -vmx_clear_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW ); +hvm_clear_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW );if ( full_width_write ) -vmx_clear_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); +hvm_clear_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); }/* Allow Read PMU Non-global Controls Directly. */ for ( i =0 ; i < arch_pmc_cnt; i++ ) -vmx_clear_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); +hvm_clear_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); -vmx_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); -vmx_clear_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); +hvm_clear_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); +hvm_clear_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); }static void core2_vpmu_unset_msr_bitmap (struct vcpu *v)@@ -253,21 +253,21 @@ static void core2_vpmu_unset_msr_bitmap(struct vcpu *v)unsigned int i;for ( i =0 ; i < fixed_pmc_cnt; i++ ) -vmx_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW ); +hvm_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR0 + i,MSR_RW );for ( i =0 ; i < arch_pmc_cnt; i++ ) { -vmx_set_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW ); +hvm_set_msr_intercept (v,MSR_IA32_PERFCTR0 + i,MSR_RW );if ( full_width_write ) -vmx_set_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); +hvm_set_msr_intercept (v,MSR_IA32_A_PERFCTR0 + i,MSR_RW ); }for ( i =0 ; i < arch_pmc_cnt; i++ )xen/arch/x86/cpu/vpmu_intel.c static void core2_vpmu_unset_msr_bitmap(struct vcpu *v) · line 273
Quoted 10 lines
xen/arch/x86/cpu/vpmu_intel.c +3
-3-vmx_set_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); +hvm_set_msr_intercept (v,MSR_P6_EVNTSEL (i),MSR_R ); -vmx_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); -vmx_set_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); +hvm_set_msr_intercept (v,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_R ); +hvm_set_msr_intercept (v,MSR_IA32_DS_AREA ,MSR_R ); }static inline void __core2_vpmu_save (struct vcpu *v)... all calls here will go to VMX'es. For making either vpmu_<vendor>.c build without that vendor's virtualization enabled, isn't it all it takes to have ...
Quoted 4 lines
xen/arch/x86/cpu/vpmu_intel.c +0
-0@@ -916,6 +932,18 @@ static inline void hvm_set_reg(struct vcpu *v, unsigned int reg, uint64_t val)ASSERT_UNREACHABLE (); }Quoted 13 lines
xen/arch/x86/cpu/vpmu_intel.c static inline void hvm_set_reg(struct vcpu *v, unsigned int reg, uint64_t val) · line 945
Quoted 11 lines
xen/arch/x86/cpu/vpmu_intel.c +11
-0+static inline void hvm_set_msr_intercept (struct vcpu *v,uint32_t msr, +int flags) +{ +ASSERT_UNREACHABLE (); +} + +static inline void hvm_clear_msr_intercept (struct vcpu *v,uint32_t msr, +int flags) +{ +ASSERT_UNREACHABLE (); +}... respective SVM and VMX stubs in place instead?
Quoted 5 lines
IMO it is more readable and they looked very good candidates for being abstracted because they are doing the same thing under both technologies. Are you suggesting that their usage in common code should be discouraged and should not be exported via the
hvm_funcsinterface? Or just that the amount of changes cannot be justified.
The amount of changes is okay if the route taken is deemed useful going forward. For now I view vPMU as too special to provide sufficient justification for yet another pair of hook functions. The more that - as indicated before - every single call site will only ever call one of the two possible callees.
Quoted 2 lines
IIUC Andrew also suggested to use
hvm_funcsfor msr intercept handling but I 'm not sure whether he had this or sth else in mind.
Andrew, any chance you could outline your thinking / further plans here? In particular, do you have other future use sites in mind that would live outside of vendor-specific code?
Jan