x86: Consolidate the storage of MSR_AMD64_DR{0-3}_ADDRESS_MASK
PATCH 1/1 x86: Consolidate the storage of MSR_AMD64_DR{0-3}_ADDRESS_MASK
The PV and HVM code both have a copy of these, which gives the false impression in the context switch code that they are PV/HVM specific.
Move the storage into struct vcpu_msrs, and update all users to match.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Boris Ostrovsky <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Brian Woods <[email protected]>
The second half of this (switching these MSRs to use the guest_{rd,wr}msr() infrastructure) isn't ready yet, so I've pulled out this half of the patch to simplify Wei's CONFIG_PV series.
--- xen/arch/x86/domctl.c | 12 ++++++------ xen/arch/x86/hvm/svm/svm.c | 36 ++++++++++++++++++------------------ xen/arch/x86/pv/emul-priv-op.c | 8 ++++---- xen/arch/x86/traps.c | 8 ++++---- xen/include/asm-x86/domain.h | 3 --- xen/include/asm-x86/hvm/svm/vmcb.h | 3 --- xen/include/asm-x86/msr.h | 6 ++++++ 7 files changed, 38 insertions(+), 38 deletions(-)
xen/arch/x86/domctl.c +6 -6
@@ -1328,12 +1328,12 @@ long arch_do_domctl(if (boot_cpu_has (X86_FEATURE_DBEXT ) ) { -if ( v->arch.pv.dr_mask[0 ] ) +if ( v->arch.msrs->dr_mask[0 ] ) {if ( i < vmsrs->msr_count && !ret ) { msr.index =MSR_AMD64_DR0_ADDRESS_MASK ; - msr.value = v->arch.pv.dr_mask[0 ]; + msr.value = v->arch.msrs->dr_mask[0 ];if (copy_to_guest_offset (vmsrs->msrs, i, &msr,1 ) ) ret = -EFAULT ; }
@@ -1342,12 +1342,12 @@ long arch_do_domctl(for ( j =0 ; j <3 ; ++j ) { -if ( !v->arch.pv.dr_mask[1 + j] ) +if ( !v->arch.msrs->dr_mask[1 + j] )continue ;if ( i < vmsrs->msr_count && !ret ) { msr.index =MSR_AMD64_DR1_ADDRESS_MASK + j; - msr.value = v->arch.pv.dr_mask[1 + j]; + msr.value = v->arch.msrs->dr_mask[1 + j];if (copy_to_guest_offset (vmsrs->msrs, i, &msr,1 ) ) ret = -EFAULT ; }
@@ -1392,7 +1392,7 @@ long arch_do_domctl(if ( !boot_cpu_has (X86_FEATURE_DBEXT ) || (msr.value >>32 ) )break ; - v->arch.pv.dr_mask[0 ] = msr.value; + v->arch.msrs->dr_mask[0 ] = msr.value;continue ; case MSR_AMD64_DR1_ADDRESS_MASK ...
@@ -1401,7 +1401,7 @@ long arch_do_domctl( (msr.value >> 32) )break ; msr.index -=MSR_AMD64_DR1_ADDRESS_MASK -1 ; - v->arch.pv.dr_mask[msr.index] = msr.value; + v->arch.msrs->dr_mask[msr.index] = msr.value;continue ; }break ;
xen/arch/x86/hvm/svm/svm.c +18 -18
@@ -210,10 +210,10 @@ static void svm_save_dr(struct vcpu *v)svm_intercept_msr (v,MSR_AMD64_DR2_ADDRESS_MASK ,MSR_INTERCEPT_RW );svm_intercept_msr (v,MSR_AMD64_DR3_ADDRESS_MASK ,MSR_INTERCEPT_RW ); -rdmsrl (MSR_AMD64_DR0_ADDRESS_MASK , v->arch.hvm.svm.dr_mask[0 ]); -rdmsrl (MSR_AMD64_DR1_ADDRESS_MASK , v->arch.hvm.svm.dr_mask[1 ]); -rdmsrl (MSR_AMD64_DR2_ADDRESS_MASK , v->arch.hvm.svm.dr_mask[2 ]); -rdmsrl (MSR_AMD64_DR3_ADDRESS_MASK , v->arch.hvm.svm.dr_mask[3 ]); +rdmsrl (MSR_AMD64_DR0_ADDRESS_MASK , v->arch.msrs->dr_mask[0 ]); +rdmsrl (MSR_AMD64_DR1_ADDRESS_MASK , v->arch.msrs->dr_mask[1 ]); +rdmsrl (MSR_AMD64_DR2_ADDRESS_MASK , v->arch.msrs->dr_mask[2 ]); +rdmsrl (MSR_AMD64_DR3_ADDRESS_MASK , v->arch.msrs->dr_mask[3 ]); } v->arch.debugreg[0 ] =read_debugreg (0 );
@@ -241,10 +241,10 @@ static void __restore_debug_registers(struct vmcb_struct *vmcb, struct vcpu *v)svm_intercept_msr (v,MSR_AMD64_DR2_ADDRESS_MASK ,MSR_INTERCEPT_NONE );svm_intercept_msr (v,MSR_AMD64_DR3_ADDRESS_MASK ,MSR_INTERCEPT_NONE ); -wrmsrl (MSR_AMD64_DR0_ADDRESS_MASK , v->arch.hvm.svm.dr_mask[0 ]); -wrmsrl (MSR_AMD64_DR1_ADDRESS_MASK , v->arch.hvm.svm.dr_mask[1 ]); -wrmsrl (MSR_AMD64_DR2_ADDRESS_MASK , v->arch.hvm.svm.dr_mask[2 ]); -wrmsrl (MSR_AMD64_DR3_ADDRESS_MASK , v->arch.hvm.svm.dr_mask[3 ]); +wrmsrl (MSR_AMD64_DR0_ADDRESS_MASK , v->arch.msrs->dr_mask[0 ]); +wrmsrl (MSR_AMD64_DR1_ADDRESS_MASK , v->arch.msrs->dr_mask[1 ]); +wrmsrl (MSR_AMD64_DR2_ADDRESS_MASK , v->arch.msrs->dr_mask[2 ]); +wrmsrl (MSR_AMD64_DR3_ADDRESS_MASK , v->arch.msrs->dr_mask[3 ]); }write_debugreg (0 , v->arch.debugreg[0 ]);
@@ -421,19 +421,19 @@ static void svm_save_msr(struct vcpu *v, struct hvm_msr *ctxt) {if (boot_cpu_has (X86_FEATURE_DBEXT ) ) { - ctxt->msr[ctxt->count].val = v->arch.hvm.svm.dr_mask[0 ]; + ctxt->msr[ctxt->count].val = v->arch.msrs->dr_mask[0 ];if ( ctxt->msr[ctxt->count].val ) ctxt->msr[ctxt->count++].index =MSR_AMD64_DR0_ADDRESS_MASK ; - ctxt->msr[ctxt->count].val = v->arch.hvm.svm.dr_mask[1 ]; + ctxt->msr[ctxt->count].val = v->arch.msrs->dr_mask[1 ];if ( ctxt->msr[ctxt->count].val ) ctxt->msr[ctxt->count++].index =MSR_AMD64_DR1_ADDRESS_MASK ; - ctxt->msr[ctxt->count].val = v->arch.hvm.svm.dr_mask[2 ]; + ctxt->msr[ctxt->count].val = v->arch.msrs->dr_mask[2 ];if ( ctxt->msr[ctxt->count].val ) ctxt->msr[ctxt->count++].index =MSR_AMD64_DR2_ADDRESS_MASK ; - ctxt->msr[ctxt->count].val = v->arch.hvm.svm.dr_mask[3 ]; + ctxt->msr[ctxt->count].val = v->arch.msrs->dr_mask[3 ];if ( ctxt->msr[ctxt->count].val ) ctxt->msr[ctxt->count++].index =MSR_AMD64_DR3_ADDRESS_MASK ; }
@@ -454,7 +454,7 @@ static int svm_load_msr(struct vcpu *v, struct hvm_msr *ctxt)else if ( ctxt->msr[i].val >>32 ) err = -EDOM ;else - v->arch.hvm.svm.dr_mask[0 ] = ctxt->msr[i].val; + v->arch.msrs->dr_mask[0 ] = ctxt->msr[i].val;break ; case MSR_AMD64_DR1_ADDRESS_MASK ... MSR_AMD64_DR3_ADDRESS_MASK:
@@ -463,7 +463,7 @@ static int svm_load_msr(struct vcpu *v, struct hvm_msr *ctxt)else if ( ctxt->msr[i].val >>32 ) err = -EDOM ;else - v->arch.hvm.svm.dr_mask[idx -MSR_AMD64_DR1_ADDRESS_MASK +1 ] = + v->arch.msrs->dr_mask[idx -MSR_AMD64_DR1_ADDRESS_MASK +1 ] = ctxt->msr[i].val;break ;
@@ -2078,14 +2078,14 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)case MSR_AMD64_DR0_ADDRESS_MASK :if ( !v->domain->arch.cpuid->extd.dbext ) goto gpf; - *msr_content = v->arch.hvm.svm.dr_mask[0 ]; + *msr_content = v->arch.msrs->dr_mask[0 ];break ; case MSR_AMD64_DR1_ADDRESS_MASK ... MSR_AMD64_DR3_ADDRESS_MASK:if ( !v->domain->arch.cpuid->extd.dbext ) goto gpf; *msr_content = - v->arch.hvm.svm.dr_mask[msr -MSR_AMD64_DR1_ADDRESS_MASK +1 ]; + v->arch.msrs->dr_mask[msr -MSR_AMD64_DR1_ADDRESS_MASK +1 ];break ;case MSR_AMD_OSVW_ID_LENGTH :
@@ -2276,13 +2276,13 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content)case MSR_AMD64_DR0_ADDRESS_MASK :if ( !v->domain->arch.cpuid->extd.dbext || (msr_content >>32 ) ) goto gpf; - v->arch.hvm.svm.dr_mask[0 ] = msr_content; + v->arch.msrs->dr_mask[0 ] = msr_content;break ; case MSR_AMD64_DR1_ADDRESS_MASK ... MSR_AMD64_DR3_ADDRESS_MASK:if ( !v->domain->arch.cpuid->extd.dbext || (msr_content >>32 ) ) goto gpf; - v->arch.hvm.svm.dr_mask[msr -MSR_AMD64_DR1_ADDRESS_MASK +1 ] = + v->arch.msrs->dr_mask[msr -MSR_AMD64_DR1_ADDRESS_MASK +1 ] = msr_content;break ;
xen/arch/x86/pv/emul-priv-op.c +4 -4
@@ -917,13 +917,13 @@ static int read_msr(unsigned int reg, uint64_t *val,case MSR_AMD64_DR0_ADDRESS_MASK :if ( !boot_cpu_has (X86_FEATURE_DBEXT ) )break ; - *val = curr->arch.pv.dr_mask[0 ]; + *val = curr->arch.msrs->dr_mask[0 ];return X86EMUL_OKAY ; case MSR_AMD64_DR1_ADDRESS_MASK ... MSR_AMD64_DR3_ADDRESS_MASK:if ( !boot_cpu_has (X86_FEATURE_DBEXT ) )break ; - *val = curr->arch.pv.dr_mask[reg -MSR_AMD64_DR1_ADDRESS_MASK +1 ]; + *val = curr->arch.msrs->dr_mask[reg -MSR_AMD64_DR1_ADDRESS_MASK +1 ];return X86EMUL_OKAY ;case MSR_IA32_PERF_CAPABILITIES :
@@ -1111,7 +1111,7 @@ static int write_msr(unsigned int reg, uint64_t val,case MSR_AMD64_DR0_ADDRESS_MASK :if ( !boot_cpu_has (X86_FEATURE_DBEXT ) || (val >>32 ) )break ; - curr->arch.pv.dr_mask[0 ] = val; + curr->arch.msrs->dr_mask[0 ] = val;if ( curr->arch.debugreg[7 ] &DR7_ACTIVE_MASK )wrmsrl (MSR_AMD64_DR0_ADDRESS_MASK , val);return X86EMUL_OKAY ;
@@ -1119,7 +1119,7 @@ static int write_msr(unsigned int reg, uint64_t val, case MSR_AMD64_DR1_ADDRESS_MASK ... MSR_AMD64_DR3_ADDRESS_MASK:if ( !boot_cpu_has (X86_FEATURE_DBEXT ) || (val >>32 ) )break ; - curr->arch.pv.dr_mask[reg -MSR_AMD64_DR1_ADDRESS_MASK +1 ] = val; + curr->arch.msrs->dr_mask[reg -MSR_AMD64_DR1_ADDRESS_MASK +1 ] = val;if ( curr->arch.debugreg[7 ] &DR7_ACTIVE_MASK )wrmsrl (reg, val);return X86EMUL_OKAY ;
xen/arch/x86/traps.c +4 -4
@@ -2069,10 +2069,10 @@ void activate_debugregs(const struct vcpu *curr)if (boot_cpu_has (X86_FEATURE_DBEXT ) ) { -wrmsrl (MSR_AMD64_DR0_ADDRESS_MASK , curr->arch.pv.dr_mask[0 ]); -wrmsrl (MSR_AMD64_DR1_ADDRESS_MASK , curr->arch.pv.dr_mask[1 ]); -wrmsrl (MSR_AMD64_DR2_ADDRESS_MASK , curr->arch.pv.dr_mask[2 ]); -wrmsrl (MSR_AMD64_DR3_ADDRESS_MASK , curr->arch.pv.dr_mask[3 ]); +wrmsrl (MSR_AMD64_DR0_ADDRESS_MASK , curr->arch.msrs->dr_mask[0 ]); +wrmsrl (MSR_AMD64_DR1_ADDRESS_MASK , curr->arch.msrs->dr_mask[1 ]); +wrmsrl (MSR_AMD64_DR2_ADDRESS_MASK , curr->arch.msrs->dr_mask[2 ]); +wrmsrl (MSR_AMD64_DR3_ADDRESS_MASK , curr->arch.msrs->dr_mask[3 ]); } }
xen/include/asm-x86/domain.h +0 -3
@@ -547,9 +547,6 @@ struct pv_vcpuspinlock_t shadow_ldt_lock;#endif -/* data breakpoint extension MSRs */ -uint32_t dr_mask[4 ]; -/* Deferred VA-based update state. */ bool_t need_update_runstate_area;struct vcpu_time_info pending_system_time;
xen/include/asm-x86/hvm/svm/vmcb.h +0 -3
@@ -538,9 +538,6 @@ struct svm_vcpu {/* AMD lightweight profiling MSR */ uint64_t guest_lwp_cfg;/* guest version */ uint64_t cpu_lwp_cfg;/* CPU version */ - -/* data breakpoint extension MSRs */ -uint32_t dr_mask[4 ]; };struct vmcb_struct *alloc_vmcb (void );
xen/include/asm-x86/msr.h +6 -0
@@ -287,6 +287,12 @@ struct vcpu_msrs bool cpuid_faulting:1; }; } misc_features_enables; + +/* +* 0xc00110{27,19-1b} MSR_AMD64_DR{0-3}_ADDRESS_MASK +* TODO: Not yet handled by guest_{rd,wr}msr() infrastructure. +*/ +uint32_t dr_mask[4 ]; };void init_guest_msr_policy (void );
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines · Andrew Cooper
xen/include/asm-x86/msr.h +0
-0@@ -287,6 +287,12 @@ struct vcpu_msrs bool cpuid_faulting:1;
xen/include/asm-x86/msr.h struct vcpu_msrs · line 297
Quoted 10 lines
xen/include/asm-x86/msr.h +6
-0}; } misc_features_enables; + +/* +* 0xc00110{27,19-1b} MSR_AMD64_DR{0-3}_ADDRESS_MASK +* TODO: Not yet handled by guest_{rd,wr}msr() infrastructure. +*/ +uint32_t dr_mask[4 ]; };
You don't think wrapping these into an intel/amd union would be useful?
-boris
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines · Boris Ostrovsky
Quoted 10 lines · Andrew Cooper
xen/include/asm-x86/msr.h +2
-0@@ -287,6 +287,12 @@ struct vcpu_msrs bool cpuid_faulting:1; }; } misc_features_enables; + +/*
Quoted 8 lines
xen/include/asm-x86/msr.h struct vcpu_msrs · line 297
Quoted 6 lines
xen/include/asm-x86/msr.h +4
-0+* 0xc00110{27,19-1b} MSR_AMD64_DR{0-3}_ADDRESS_MASK +* TODO: Not yet handled by guest_{rd,wr}msr() infrastructure. +*/ +uint32_t dr_mask[4 ]; };You don't think wrapping these into an intel/amd union would be useful?
Same question here. DR masks seem to be AMD specific.
The code change itself looks good to me.
Thanks for posting this patch.
Wei.
Quoted 2 lines
-boris
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 19 lines · Wei Liu
Quoted 10 lines · Boris Ostrovsky
Quoted 9 lines · Andrew Cooper
xen/include/asm-x86/msr.h +1
-0@@ -287,6 +287,12 @@ struct vcpu_msrs bool cpuid_faulting:1; }; } misc_features_enables; +Quoted 8 lines
xen/include/asm-x86/msr.h struct vcpu_msrs · line 297
Quoted 7 lines
xen/include/asm-x86/msr.h +5
-0+/* +* 0xc00110{27,19-1b} MSR_AMD64_DR{0-3}_ADDRESS_MASK +* TODO: Not yet handled by guest_{rd,wr}msr() infrastructure. +*/ +uint32_t dr_mask[4 ]; };You don't think wrapping these into an intel/amd union would be useful?
Quoted 1 line
Same question here. DR masks seem to be AMD specific.
Does the svm/vt-x here pertain to the host processor, or the guest cross-vendor setting? (That's a rhetorical question. Its a complete can of worms which I don't want to open).
For the sake of 16 bytes, I don't think its worth it. We can always revisit this in the future if necessary.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 20 lines · Andrew Cooper
Quoted 19 lines · Wei Liu
Quoted 18 lines · Boris Ostrovsky
Quoted 6 lines · Andrew Cooper
xen/include/asm-x86/msr.h +0
-0@@ -287,6 +287,12 @@ struct vcpu_msrs bool cpuid_faulting:1;xen/include/asm-x86/msr.h struct vcpu_msrs · line 297
Quoted 10 lines
xen/include/asm-x86/msr.h +6
-0}; } misc_features_enables; + +/* +* 0xc00110{27,19-1b} MSR_AMD64_DR{0-3}_ADDRESS_MASK +* TODO: Not yet handled by guest_{rd,wr}msr() infrastructure. +*/ +uint32_t dr_mask[4 ]; };You don't think wrapping these into an intel/amd union would be useful?
Quoted 8 lines
Quoted 1 line
Same question here. DR masks seem to be AMD specific.
Does the svm/vt-x here pertain to the host processor, or the guest cross-vendor setting? (That's a rhetorical question. Its a complete can of worms which I don't want to open).
For the sake of 16 bytes, I don't think its worth it. We can always revisit this in the future if necessary.
Sure. Feel free to add my Rb to your patch.
Wei.
Quoted 2 lines
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 19.10.18 at 17:14, <[email protected]> wrote:
The PV and HVM code both have a copy of these, which gives the false impression in the context switch code that they are PV/HVM specific.
Move the storage into struct
vcpu_msrs, and update all users to match.Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel