[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 6/9] x86/vmx: Pass an MSR value into vmx_msr_add()
The main purpose of this change is to allow us to set a specific MSR value, without needing to know whether there is already a load/save list slot for it. Previously, callers wanting this property needed to call both vmx_add_*_msr() and vmx_write_*_msr() to cover both cases. As a result of this API improvement, the default value for guest MSRs need not be 0, and the default for host MSRs need not be passed via hardware register. In practice, this cleans up the VPMU allocation logic, and avoids an MSR read as part of vcpu construction. Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> --- CC: Jan Beulich <JBeulich@xxxxxxxx> CC: Jun Nakajima <jun.nakajima@xxxxxxxxx> CC: Kevin Tian <kevin.tian@xxxxxxxxx> CC: Wei Liu <wei.liu2@xxxxxxxxxx> CC: Roger Pau Monné <roger.pau@xxxxxxxxxx> --- xen/arch/x86/cpu/vpmu_intel.c | 6 ++---- xen/arch/x86/hvm/vmx/vmcs.c | 17 +++++++++-------- xen/arch/x86/hvm/vmx/vmx.c | 2 +- xen/include/asm-x86/hvm/vmx/vmcs.h | 13 +++++++------ 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/xen/arch/x86/cpu/vpmu_intel.c b/xen/arch/x86/cpu/vpmu_intel.c index c499e69..1fc79c9 100644 --- a/xen/arch/x86/cpu/vpmu_intel.c +++ b/xen/arch/x86/cpu/vpmu_intel.c @@ -454,13 +454,11 @@ static int core2_vpmu_alloc_resource(struct vcpu *v) if ( is_hvm_vcpu(v) ) { - wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0); - if ( vmx_add_host_load_msr(v, MSR_CORE_PERF_GLOBAL_CTRL) ) + if ( vmx_add_host_load_msr(v, MSR_CORE_PERF_GLOBAL_CTRL, 0) ) goto out_err; - if ( vmx_add_guest_msr(v, MSR_CORE_PERF_GLOBAL_CTRL) ) + if ( vmx_add_guest_msr(v, MSR_CORE_PERF_GLOBAL_CTRL, 0) ) goto out_err; - vmx_write_guest_msr(v, MSR_CORE_PERF_GLOBAL_CTRL, 0); } core2_vpmu_cxt = xzalloc_bytes(sizeof(*core2_vpmu_cxt) + diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 2035a6d..b75cc90 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -1269,7 +1269,8 @@ static int construct_vmcs(struct vcpu *v) /* If using host debugging, restore Xen's setting on vmexit. */ if ( this_cpu(ler_msr) && - (rc = vmx_add_host_load_msr(v, MSR_IA32_DEBUGCTLMSR)) ) + (rc = vmx_add_host_load_msr(v, MSR_IA32_DEBUGCTLMSR, + IA32_DEBUGCTLMSR_LBR)) ) return rc; vmx_vmcs_exit(v); @@ -1341,7 +1342,8 @@ struct vmx_msr_entry *vmx_find_msr(struct vcpu *v, uint32_t msr, return ((ent < end) && (ent->index == msr)) ? ent : NULL; } -int vmx_add_msr(struct vcpu *v, uint32_t msr, enum vmx_msr_list_type type) +int vmx_add_msr(struct vcpu *v, uint32_t msr, uint64_t val, + enum vmx_msr_list_type type) { struct arch_vmx_struct *arch_vmx = &v->arch.hvm_vmx; struct vmx_msr_entry **ptr, *start = NULL, *ent, *end; @@ -1400,11 +1402,9 @@ int vmx_add_msr(struct vcpu *v, uint32_t msr, enum vmx_msr_list_type type) ent = locate_msr_entry(start, end, msr); if ( (ent < end) && (ent->index == msr) ) - { - rc = 0; - goto out; - } + goto found; + /* If there isn't an existing entry for msr, insert room for one. */ if ( total == (PAGE_SIZE / sizeof(*ent)) ) { rc = -ENOSPC; @@ -1419,17 +1419,18 @@ int vmx_add_msr(struct vcpu *v, uint32_t msr, enum vmx_msr_list_type type) switch ( type ) { case VMX_MSR_HOST: - rdmsrl(msr, ent->data); __vmwrite(VM_EXIT_MSR_LOAD_COUNT, ++arch_vmx->host_msr_count); break; case VMX_MSR_GUEST: - ent->data = 0; __vmwrite(VM_EXIT_MSR_STORE_COUNT, ++arch_vmx->msr_count); __vmwrite(VM_ENTRY_MSR_LOAD_COUNT, arch_vmx->msr_count); break; } + /* Set the msr's value. */ + found: + ent->data = val; rc = 0; out: diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index f9cfb6d..1783cd8 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -3109,7 +3109,7 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) for ( ; (rc == 0) && lbr->count; lbr++ ) for ( i = 0; (rc == 0) && (i < lbr->count); i++ ) - if ( (rc = vmx_add_guest_msr(v, lbr->base + i)) == 0 ) + if ( (rc = vmx_add_guest_msr(v, lbr->base + i, 0)) == 0 ) { vmx_clear_msr_intercept(v, lbr->base + i, VMX_MSR_RW); if ( lbr_tsx_fixup_needed ) diff --git a/xen/include/asm-x86/hvm/vmx/vmcs.h b/xen/include/asm-x86/hvm/vmx/vmcs.h index f66f121..accd6fb 100644 --- a/xen/include/asm-x86/hvm/vmx/vmcs.h +++ b/xen/include/asm-x86/hvm/vmx/vmcs.h @@ -544,16 +544,17 @@ enum vmx_msr_list_type { VMX_MSR_GUEST, }; -int vmx_add_msr(struct vcpu *v, uint32_t msr, enum vmx_msr_list_type type); +int vmx_add_msr(struct vcpu *v, uint32_t msr, uint64_t val, + enum vmx_msr_list_type type); -static inline int vmx_add_guest_msr(struct vcpu *v, uint32_t msr) +static inline int vmx_add_guest_msr(struct vcpu *v, uint32_t msr, uint64_t val) { - return vmx_add_msr(v, msr, VMX_MSR_GUEST); + return vmx_add_msr(v, msr, val, VMX_MSR_GUEST); } - -static inline int vmx_add_host_load_msr(struct vcpu *v, uint32_t msr) +static inline int vmx_add_host_load_msr(struct vcpu *v, uint32_t msr, + uint64_t val) { - return vmx_add_msr(v, msr, VMX_MSR_HOST); + return vmx_add_msr(v, msr, val, VMX_MSR_HOST); } struct vmx_msr_entry *vmx_find_msr(struct vcpu *v, uint32_t msr, -- 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |