From patchwork Fri Oct 13 12:35:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 10004429 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0DC96602B3 for ; Fri, 13 Oct 2017 12:41:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F381428883 for ; Fri, 13 Oct 2017 12:41:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E85692905E; Fri, 13 Oct 2017 12:41:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6BB3D28883 for ; Fri, 13 Oct 2017 12:41:05 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2zF5-0006fJ-53; Fri, 13 Oct 2017 12:39:07 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2zF3-0006dK-Gj for xen-devel@lists.xen.org; Fri, 13 Oct 2017 12:39:05 +0000 Received: from [85.158.143.35] by server-5.bemta-6.messagelabs.com id 3D/E2-29911-8E3B0E95; Fri, 13 Oct 2017 12:39:04 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprIIsWRWlGSWpSXmKPExsXitHRDpO7TzQ8 iDaZsF7JY8nExiwOjx9Hdv5kCGKNYM/OS8isSWDOmLL3MWvDetOLxjBfMDYxztbsYOTkkBPwl mk49ZgKx2QT0JDbOfgVmiwjISqzumsPexcjFwSxwhFFi6qoj7CAJYQFfiTMLnzOC2CwCqhJXb i0Hi/MK2EosedDMDjFUXmJX20VWEJtTwE5i8d5JzCC2EFDN370TWCFsVYnXL3axQPQKSpyc+Q TMZhaQkDj44gXzBEbeWUhSs5CkFjAyrWJUL04tKkst0jXVSyrKTM8oyU3MzNE1NDDTy00tLk5 MT81JTCrWS87P3cQIDB4GINjBOP2y/yFGSQ4mJVFetcgHkUJ8SfkplRmJxRnxRaU5qcWHGGU4 OJQkeOs3AeUEi1LTUyvSMnOAYQyTluDgURLhNQdJ8xYXJOYWZ6ZDpE4x6nJ03Lz7h0mIJS8/L 1VKnFcapEgApCijNA9uBCymLjHKSgnzMgIdJcRTkFqUm1mCKv+KUZyDUUmY1wdkCk9mXgncpl dARzABHfEuAuyIkkSElFQD4/YJS8vCeDf+ZUta/Tjn91EpRx6fXEbmXbfufV8tKbVymsbGHJM PH7/v+LpHdV2Rwq2Syb84TPZlnXv6ZeoCTe2ZtlpHedanmBu7hyg6T9lo7/grO6RjybdrJ4+d Nn95ti376yZrLsv9BxjXbj2e7itstH/2be+AO5vUF235Oo1XeeWafQ37E24rsRRnJBpqMRcVJ wIAA8PYGaQCAAA= X-Env-Sender: prvs=452ef7b8b=sergey.dyasli@citrix.com X-Msg-Ref: server-6.tower-21.messagelabs.com!1507898337!54001903!3 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 51438 invoked from network); 13 Oct 2017 12:39:00 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-6.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 13 Oct 2017 12:39:00 -0000 X-IronPort-AV: E=Sophos;i="5.43,371,1503360000"; d="scan'208";a="445898693" From: Sergey Dyasli To: Date: Fri, 13 Oct 2017 13:35:11 +0100 Message-ID: <20171013123512.26102-6-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171013123512.26102-1-sergey.dyasli@citrix.com> References: <20171013123512.26102-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Kevin Tian , Jan Beulich , Jun Nakajima , Sergey Dyasli Subject: [Xen-devel] [PATCH v3 5/6] x86/msr: update domain policy on CPUID policy changes X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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. Introduce hvm_cr4_domain_valid_bits() which accepts struct domain * instead of struct vcpu *. Signed-off-by: Sergey Dyasli --- xen/arch/x86/domctl.c | 1 + xen/arch/x86/hvm/hvm.c | 8 +++-- xen/arch/x86/msr.c | 70 ++++++++++++++++++++++++++++++++++++++++++- xen/include/asm-x86/hvm/hvm.h | 1 + xen/include/asm-x86/msr.h | 3 ++ 5 files changed, 80 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 80b4df9ec9..334c67d261 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -124,6 +124,7 @@ static int update_domain_cpuid_info(struct domain *d, } recalculate_cpuid_policy(d); + recalculate_domain_msr_policy(d); switch ( ctl->input[0] ) { diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 205b4cb685..7e6b15f8d7 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -928,9 +928,8 @@ const char *hvm_efer_valid(const struct vcpu *v, uint64_t value, X86_CR0_CD | X86_CR0_PG))) /* These bits in CR4 can be set by the guest. */ -unsigned long hvm_cr4_guest_valid_bits(const struct vcpu *v, bool restore) +unsigned long hvm_cr4_domain_valid_bits(const struct domain *d, bool restore) { - const struct domain *d = v->domain; const struct cpuid_policy *p; bool mce, vmxe; @@ -963,6 +962,11 @@ unsigned long hvm_cr4_guest_valid_bits(const struct vcpu *v, bool restore) (p->feat.pku ? X86_CR4_PKE : 0)); } +unsigned long hvm_cr4_guest_valid_bits(const struct vcpu *v, bool restore) +{ + return hvm_cr4_domain_valid_bits(v->domain, restore); +} + static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h) { int vcpuid; diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c index 388f19e50d..a22e3dfaf2 100644 --- a/xen/arch/x86/msr.c +++ b/xen/arch/x86/msr.c @@ -23,6 +23,7 @@ #include #include #include +#include struct msr_domain_policy __read_mostly raw_msr_domain_policy, __read_mostly host_msr_domain_policy, @@ -220,7 +221,7 @@ static void __init calculate_hvm_max_vmx_policy(struct msr_domain_policy *dp) dp->vmx_cr4_fixed1.available = true; /* * Allowed CR4 bits will be updated during domain creation by - * hvm_cr4_guest_valid_bits() + * hvm_cr4_domain_valid_bits() */ dp->vmx_cr4_fixed1.u.raw = host_msr_domain_policy.vmx_cr4_fixed1.u.raw; @@ -312,6 +313,72 @@ void __init init_guest_msr_policy(void) calculate_pv_max_policy(); } +static void recalculate_domain_vmx_msr_policy(struct domain *d) +{ + struct msr_domain_policy *dp = d->arch.msr; + + if ( !nestedhvm_enabled(d) || !d->arch.cpuid->basic.vmx ) + { + dp->vmx_basic.available = false; + dp->vmx_pinbased_ctls.available = false; + dp->vmx_procbased_ctls.available = false; + dp->vmx_exit_ctls.available = false; + dp->vmx_entry_ctls.available = false; + dp->vmx_misc.available = false; + dp->vmx_cr0_fixed0.available = false; + dp->vmx_cr0_fixed1.available = false; + dp->vmx_cr4_fixed0.available = false; + dp->vmx_cr4_fixed1.available = false; + dp->vmx_vmcs_enum.available = false; + dp->vmx_procbased_ctls2.available = false; + dp->vmx_ept_vpid_cap.available = false; + dp->vmx_true_pinbased_ctls.available = false; + dp->vmx_true_procbased_ctls.available = false; + dp->vmx_true_exit_ctls.available = false; + dp->vmx_true_entry_ctls.available = false; + } + else + { + dp->vmx_basic.available = true; + dp->vmx_pinbased_ctls.available = true; + dp->vmx_procbased_ctls.available = true; + dp->vmx_exit_ctls.available = true; + dp->vmx_entry_ctls.available = true; + dp->vmx_misc.available = true; + dp->vmx_cr0_fixed0.available = true; + dp->vmx_cr0_fixed1.available = true; + dp->vmx_cr4_fixed0.available = true; + dp->vmx_cr4_fixed1.available = true; + /* Get allowed CR4 bits from CPUID policy */ + dp->vmx_cr4_fixed1.u.raw = hvm_cr4_domain_valid_bits(d, false); + dp->vmx_vmcs_enum.available = true; + + if ( dp->vmx_procbased_ctls.u.allowed_1.activate_secondary_controls ) + { + dp->vmx_procbased_ctls2.available = true; + + if ( dp->vmx_procbased_ctls2.u.allowed_1.enable_ept || + dp->vmx_procbased_ctls2.u.allowed_1.enable_vpid ) + dp->vmx_ept_vpid_cap.available = true; + } + + if ( dp->vmx_basic.u.default1_zero ) + { + dp->vmx_true_pinbased_ctls.available = true; + dp->vmx_true_procbased_ctls.available = true; + dp->vmx_true_exit_ctls.available = true; + dp->vmx_true_entry_ctls.available = true; + } + } + + dp->vmx_vmfunc.available = false; +} + +void recalculate_domain_msr_policy(struct domain *d) +{ + recalculate_domain_vmx_msr_policy(d); +} + int init_domain_msr_policy(struct domain *d) { struct msr_domain_policy *dp; @@ -332,6 +399,7 @@ int init_domain_msr_policy(struct domain *d) } d->arch.msr = dp; + recalculate_domain_msr_policy(d); return 0; } diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h index b687e03dce..6ff38a6400 100644 --- a/xen/include/asm-x86/hvm/hvm.h +++ b/xen/include/asm-x86/hvm/hvm.h @@ -613,6 +613,7 @@ static inline bool altp2m_vcpu_emulate_ve(struct vcpu *v) const char *hvm_efer_valid(const struct vcpu *v, uint64_t value, signed int cr0_pg); unsigned long hvm_cr4_guest_valid_bits(const struct vcpu *v, bool restore); +unsigned long hvm_cr4_domain_valid_bits(const struct domain *d, bool restore); /* * This must be defined as a macro instead of an inline function, diff --git a/xen/include/asm-x86/msr.h b/xen/include/asm-x86/msr.h index fc99612cca..df8f60e538 100644 --- a/xen/include/asm-x86/msr.h +++ b/xen/include/asm-x86/msr.h @@ -649,6 +649,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_domain_msr_policy(struct domain *d); + #endif /* !__ASSEMBLY__ */ #endif /* __ASM_MSR_H */