[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v5 4/5] x86/msr: update domain policy on CPUID policy changes
Availability of some MSRs depends on certain CPUID bits. Add function recalculate_domain_msr_policy() which updates availability of per-domain MSRs based on current domain's CPUID policy. This function is called when CPUID policy is changed from a toolstack. Add recalculate_domain_vmx_msr_policy() which changes availability of VMX MSRs based on domain's nested virt settings. If it's enabled, then the domain receives a copy of HVM_max vmx policy with allowed CR4 bits adjusted by CPUID policy. Signed-off-by: Sergey Dyasli <sergey.dyasli@xxxxxxxxxx> --- v4 --> v5: - Removed _domain from function names - Added vmx_copy_policy() helper - recalculate_vmx_msr_policy() was rewritten --- xen/arch/x86/domctl.c | 1 + xen/arch/x86/msr.c | 35 +++++++++++++++++++++++++++++++++++ xen/include/asm-x86/msr.h | 3 +++ 3 files changed, 39 insertions(+) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 8fbbf3aeb3..5bde1a22b7 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -125,6 +125,7 @@ static int update_domain_cpuid_info(struct domain *d, } recalculate_cpuid_policy(d); + recalculate_msr_policy(d); switch ( ctl->input[0] ) { diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c index f700e05570..9114b8f53b 100644 --- a/xen/arch/x86/msr.c +++ b/xen/arch/x86/msr.c @@ -23,6 +23,7 @@ #include <xen/lib.h> #include <xen/sched.h> #include <asm/msr.h> +#include <asm/hvm/nestedhvm.h> DEFINE_PER_CPU(uint32_t, tsc_aux); @@ -282,6 +283,39 @@ void __init init_guest_msr_policy(void) calculate_pv_max_policy(); } +static void vmx_copy_policy(const struct msr_domain_policy *src, + struct msr_domain_policy *dst) +{ + memcpy(dst->vmx.raw, src->vmx.raw, sizeof(dst->vmx.raw)); + dst->vmx_procbased_ctls2.raw = src->vmx_procbased_ctls2.raw; + dst->vmx_ept_vpid_cap.raw = src->vmx_ept_vpid_cap.raw; + memcpy(dst->vmx_true_ctls.raw, src->vmx_true_ctls.raw, + sizeof(dst->vmx_true_ctls.raw)); + dst->vmx_vmfunc.raw = src->vmx_vmfunc.raw; +} + +static void recalculate_vmx_msr_policy(struct domain *d) +{ + struct msr_domain_policy *dp = d->arch.msr; + + if ( !nestedhvm_enabled(d) || !d->arch.cpuid->basic.vmx ) + { + vmx_clear_policy(dp); + + return; + } + + vmx_copy_policy(&hvm_max_msr_domain_policy, dp); + + /* Get allowed CR4 bits from CPUID policy */ + dp->vmx.cr4_fixed1.allowed_1.raw = hvm_cr4_guest_valid_bits(d, false); +} + +void recalculate_msr_policy(struct domain *d) +{ + recalculate_vmx_msr_policy(d); +} + int init_domain_msr_policy(struct domain *d) { struct msr_domain_policy *dp; @@ -302,6 +336,7 @@ int init_domain_msr_policy(struct domain *d) } d->arch.msr = dp; + recalculate_msr_policy(d); return 0; } diff --git a/xen/include/asm-x86/msr.h b/xen/include/asm-x86/msr.h index 419ab6f8a7..4747572871 100644 --- a/xen/include/asm-x86/msr.h +++ b/xen/include/asm-x86/msr.h @@ -606,6 +606,9 @@ int init_vcpu_msr_policy(struct vcpu *v); int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val); int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val); +/* Update availability of per-domain MSRs based on CPUID policy */ +void recalculate_msr_policy(struct domain *d); + #endif /* !__ASSEMBLY__ */ #endif /* __ASM_MSR_H */ -- 2.14.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |