From patchwork Wed Oct 18 08:27:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 10014107 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 6F3E060215 for ; Wed, 18 Oct 2017 08:30:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D1B928AF2 for ; Wed, 18 Oct 2017 08:30:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5220828AF9; Wed, 18 Oct 2017 08:30:33 +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 E845B28AF2 for ; Wed, 18 Oct 2017 08:30:32 +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 1e4jiH-0002ih-8s; Wed, 18 Oct 2017 08:28:29 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e4jiF-0002he-W7 for xen-devel@lists.xen.org; Wed, 18 Oct 2017 08:28:28 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id E6/2D-05363-BA017E95; Wed, 18 Oct 2017 08:28:27 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprEIsWRWlGSWpSXmKPExsXitHRDpO5Kgee RBu2ftC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oy/z+8yFvxQqOj80MzWwNgm1cXIySEh4C/x fO9rFhCbTUBPYuPsV0wgtoiArMTqrjnsXYxcHMwCRxglpq46wg6SEBbwlTjZv4YZxGYRUJX40 zARLM4rYCOxa3ETM8RQeYldbRdZQWxOAVuJ66fXsIHYQkA1v99cZYWwVSVev9jFAtErKHFy5h Mwm1lAQuLgixfMExh5ZyFJzUKSWsDItIpRozi1qCy1SNfISC+pKDM9oyQ3MTNH19DAWC83tbg 4MT01JzGpWC85P3cTIzB86hkYGHcwTj3hd4hRkoNJSZRX98CzSCG+pPyUyozE4oz4otKc1OJD jDIcHEoSvBr8zyOFBItS01Mr0jJzgIEMk5bg4FES4Q0ESfMWFyTmFmemQ6ROMepydNy8+4dJi CUvPy9VSpy3AqRIAKQoozQPbgQsqi4xykoJ8zIyMDAI8RSkFuVmlqDKv2IU52BUEuZ1ApnCk5 lXArfpFdARTEBHrHN6AnJESSJCSqqBceIF3slzfnnN/iI260PSgkkTDrdLvlcrusFTwcMQN2d 9vwTrvZ1sdhwXOVmssmOyJj2ozboQHLiPcY7BrW//q3vubMy+6DnT+7N5z7UEabNq39Cl2co6 TEIrFdrVF/GUXgqdcCbc4E/27yihk+5Z77zvLCu5OLNyyqFbTnbssbVnXhax7us3VmIpzkg01 GIuKk4EAMtMeBqlAgAA X-Env-Sender: prvs=457a530fd=sergey.dyasli@citrix.com X-Msg-Ref: server-16.tower-31.messagelabs.com!1508315302!103178682!2 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 7387 invoked from network); 18 Oct 2017 08:28:25 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-16.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 18 Oct 2017 08:28:25 -0000 X-IronPort-AV: E=Sophos;i="5.43,395,1503360000"; d="scan'208";a="446828217" From: Sergey Dyasli To: Date: Wed, 18 Oct 2017 09:27:21 +0100 Message-ID: <20171018082722.6279-7-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171018082722.6279-1-sergey.dyasli@citrix.com> References: <20171018082722.6279-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Kevin Tian , Jan Beulich , Jun Nakajima , Sergey Dyasli Subject: [Xen-devel] [PATCH v4 6/7] 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. Unavailable MSRs are zeroed which allows checking availability bits in them directly without preliminary checks (e.g. cpuid->basic.vmx, activate_secondary_controls, enable_ept). Signed-off-by: Sergey Dyasli --- xen/arch/x86/domctl.c | 1 + xen/arch/x86/msr.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/msr.h | 3 +++ 3 files changed, 59 insertions(+) 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/msr.c b/xen/arch/x86/msr.c index ff270befbb..9ea7447de3 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, @@ -257,6 +258,59 @@ 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 ) + { + memset(dp->vmx.raw, 0, sizeof(dp->vmx.raw)); + dp->vmx_procbased_ctls2.raw = 0; + dp->vmx_ept_vpid_cap.raw = 0; + memset(dp->vmx_true_ctls.raw, 0, sizeof(dp->vmx_true_ctls.raw)); + dp->vmx_vmfunc.raw = 0; + } + else + { + memcpy(dp->vmx.raw, hvm_max_msr_domain_policy.vmx.raw, + sizeof(dp->vmx.raw)); + /* Get allowed CR4 bits from CPUID policy */ + dp->vmx.cr4_fixed1.raw = hvm_cr4_guest_valid_bits(d, false); + + if ( dp->vmx.procbased_ctls.allowed_1.activate_secondary_controls ) + { + dp->vmx_procbased_ctls2.raw = + hvm_max_msr_domain_policy.vmx_procbased_ctls2.raw; + + if ( dp->vmx_procbased_ctls2.allowed_1.enable_ept || + dp->vmx_procbased_ctls2.allowed_1.enable_vpid ) + dp->vmx_ept_vpid_cap.raw = + hvm_max_msr_domain_policy.vmx_ept_vpid_cap.raw; + else + dp->vmx_ept_vpid_cap.raw = 0; + } + else + { + dp->vmx_procbased_ctls2.raw = 0; + dp->vmx_ept_vpid_cap.raw = 0; + } + + if ( dp->vmx.basic.default1_zero ) + memcpy(dp->vmx_true_ctls.raw, + hvm_max_msr_domain_policy.vmx_true_ctls.raw, + sizeof(dp->vmx_true_ctls.raw)); + else + memset(dp->vmx_true_ctls.raw, 0, sizeof(dp->vmx_true_ctls.raw)); + + dp->vmx_vmfunc.raw = 0; + } +} + +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; @@ -277,6 +331,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/msr.h b/xen/include/asm-x86/msr.h index 150000551f..f19e113612 100644 --- a/xen/include/asm-x86/msr.h +++ b/xen/include/asm-x86/msr.h @@ -608,6 +608,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 */