From patchwork Mon Oct 16 07:42:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 10007855 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 6B023601D5 for ; Mon, 16 Oct 2017 07:44:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CC1220950 for ; Mon, 16 Oct 2017 07:44:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5087422299; Mon, 16 Oct 2017 07:44:30 +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 A2B5420950 for ; Mon, 16 Oct 2017 07:44:29 +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 1e402e-0006IH-Sy; Mon, 16 Oct 2017 07:42:28 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e402d-0006I9-Ow for xen-devel@lists.xen.org; Mon, 16 Oct 2017 07:42:27 +0000 Received: from [85.158.139.211] by server-12.bemta-5.messagelabs.com id BE/C9-19514-3E264E95; Mon, 16 Oct 2017 07:42:27 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKKsWRWlGSWpSXmKPExsWSzvfng+6jpCe RBo0TxC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oyOWYIFPyQr9s2bx9jAeEayi5GTQ0LAX2L3 rrlsIDabgJ7ExtmvmEBsEYFkiQmHO1m6GLk4mAXWMkq0z2tk7WLk4BAWCJCYezoUoiZQ4u+nF qh6K4kt+/8xg9gsAqoSvT3XWEBsXgEDiUv/XrODzBESWMoo8Xrmd1aQBKeAncTbw/PAihgFZC W+NK4Ga2YWEJe49WQ+E8RxAhJL9pxnhrBFJV4+/scKYatIPN+5gBHC1pE4e/0JlG0gsXXpPha QO5kFNCXW79KHGGkp0dv8mBHCVpSY0v2QHeI2QYmTM5+wTGAUm4Vk8yyE7llIumch6Z6FpHsB I+sqRo3i1KKy1CJdQ2O9pKLM9IyS3MTMHF1DA1O93NTi4sT01JzEpGK95PzcTYzAyGIAgh2M/ 7Z5HmKU5GBSEuV1NnwSKcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mCtz0RKCdYlJqeWpGWmQOMcZ i0BAePkghvIEiat7ggMbc4Mx0idYrRmKPj5t0/TBxPrs37yyTEkpeflyolztsFUioAUppRmgc 3CJZ6LjHKSgnzMgKdJsRTkFqUm1mCKv+KUZyDUUmYNw5kCk9mXgncvldApzABnbLOCeyUkkSE lFQDY6dCrpfGkXevrMUbN4S9f+iWZXeaacrj7bInd6x3u7NzAs8iX3bvyQft2erO6G+aVnN12 kU75m3Trbar7bp1SuyDRGZXW2Gnc/7Dv2my2bxZVxZMOpbZ3ag67WB7dXPE21r51Ip8RrPjx/ sSDGZM6G7XYY3tb7sxdc6ehILbh7QKX4avaPl/V4mlOCPRUIu5qDgRAI2C7os4AwAA X-Env-Sender: prvs=455fc6512=sergey.dyasli@citrix.com X-Msg-Ref: server-2.tower-206.messagelabs.com!1508139743!86492012!1 X-Originating-IP: [103.14.252.240] X-SpamReason: No, hits=0.0 required=7.0 tests=received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 38522 invoked from network); 16 Oct 2017 07:42:25 -0000 Received: from smtp.citrix.com.au (HELO SMTP.CITRIX.COM.AU) (103.14.252.240) by server-2.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 16 Oct 2017 07:42:25 -0000 X-IronPort-AV: E=Sophos;i="5.43,386,1503360000"; d="scan'208";a="106331787" From: Sergey Dyasli To: Andrew Cooper , "xen-devel@lists.xen.org" Thread-Topic: [PATCH v3 2/6] x86/msr: add VMX MSRs into struct msr_domain_policy Thread-Index: AQHTRB/EjyXrcO/hpkCvc2POSgPfFqLhwr+AgAQ4DwA= Date: Mon, 16 Oct 2017 07:42:19 +0000 Message-ID: <1508139738.3378.1.camel@citrix.com> References: <20171013123512.26102-1-sergey.dyasli@citrix.com> <20171013123512.26102-3-sergey.dyasli@citrix.com> In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Evolution 3.22.6-1ubuntu1 x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted Content-ID: <62013F3723CD99439F5BCD1D741AB20D@citrix.com> MIME-Version: 1.0 Cc: Sergey Dyasli , Kevin Tian , "jun.nakajima@intel.com" , "jbeulich@suse.com" Subject: Re: [Xen-devel] [PATCH v3 2/6] x86/msr: add VMX MSRs into struct msr_domain_policy 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 On Fri, 2017-10-13 at 16:16 +0100, Andrew Cooper wrote: > On 13/10/17 13:35, Sergey Dyasli wrote: > > @@ -210,6 +375,255 @@ struct msr_domain_policy > > bool available; /* This MSR is non-architectural */ > > bool cpuid_faulting; > > } plaform_info; > > + > > + /* 0x00000480 MSR_IA32_VMX_BASIC */ > > + struct { > > + bool available; > > We don't need available bits for any of these MSRs.  Their availability > is cpuid->basic.vmx, and we don't want (let alone need) to duplicate > information like this. Andrew, What do you think about the following way of checking the availability? --- Thanks, Sergey diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c index 2527fdd1d1..828f1bb503 100644 --- a/xen/arch/x86/msr.c +++ b/xen/arch/x86/msr.c @@ -33,6 +33,43 @@ struct msr_domain_policy __read_mostly     raw_msr_domain_policy,  struct msr_vcpu_policy __read_mostly hvm_max_msr_vcpu_policy,                         __read_mostly  pv_max_msr_vcpu_policy;   +bool msr_vmx_available(const struct domain *d, uint32_t msr) +{ +    const struct msr_domain_policy *dp = d->arch.msr; +    bool secondary_available; + +    if ( !nestedhvm_enabled(d) || !d->arch.cpuid->basic.vmx ) +        return false; + +    secondary_available = +        dp->vmx_procbased_ctls.u.allowed_1.activate_secondary_controls; + +    switch (msr) +    { +    case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMCS_ENUM: +        return true; + +    case MSR_IA32_VMX_PROCBASED_CTLS2: +        return secondary_available; + +    case MSR_IA32_VMX_EPT_VPID_CAP: +        return ( secondary_available && +                 (dp->vmx_procbased_ctls2.u.allowed_1.enable_ept || +                  dp->vmx_procbased_ctls2.u.allowed_1.enable_vpid) ); + +    case MSR_IA32_VMX_TRUE_PINBASED_CTLS ... MSR_IA32_VMX_TRUE_ENTRY_CTLS: +        return dp->vmx_basic.u.default1_zero; + +    case MSR_IA32_VMX_VMFUNC: +        return ( secondary_available && +                 dp->vmx_procbased_ctls2.u.allowed_1.enable_vm_functions ); + +    default: break; +    } + +    return false; +} +  static void __init calculate_raw_vmx_policy(struct msr_domain_policy *dp)  {      if ( !cpu_has_vmx )