From patchwork Mon Jun 26 10:44:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9809109 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 AF97B60209 for ; Mon, 26 Jun 2017 10:47:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B51C2223A6 for ; Mon, 26 Jun 2017 10:47:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A938426E74; Mon, 26 Jun 2017 10:47:15 +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 29FC5223A6 for ; Mon, 26 Jun 2017 10:47:13 +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 1dPRVb-0002AB-SP; Mon, 26 Jun 2017 10:44:43 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPRVa-00028s-9S for xen-devel@lists.xen.org; Mon, 26 Jun 2017 10:44:42 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id 49/62-03058-995E0595; Mon, 26 Jun 2017 10:44:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrohUnfm04B IgyMHeC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oxjm48yFly2rVhz9hRrA2OrXhcjJ4eEgL/E z97DbCA2m4CexMbZr5hAbBEBWYnVXXPYuxi5OJgFjjBKTF11hB0kISxgI7H80VOwBhYBVYmXK 54zg9i8ArYSr+cvZ4IYKi+xq+0iK4jNKWAnMXfBaRYQWwiopunpIjYIW1Xi9YtdLBC9ghInZz 4Bs5kFJCQOvnjBPIGRdxaS1CwkqQWMTKsY1YtTi8pSi3RN9ZKKMtMzSnITM3N0DQ3M9HJTi4s T01NzEpOK9ZLzczcxAoOHAQh2ME6/7H+IUZKDSUmUl+NJQKQQX1J+SmVGYnFGfFFpTmrxIUYZ Dg4lCd71IDnBotT01Iq0zBxgGMOkJTh4lER4jz4ESvMWFyTmFmemQ6ROMSpKifO6gPQJgCQyS vPg2mCxc4lRVkqYlxHoECGegtSi3MwSVPlXjOIcjErCvAYgU3gy80rgpr8CWswEtJhlHtjikk SElFQDY1djoTLTpq9ie3r3VRUfzLdeN+fUR+ZD/Zpdxe/yK3jNOK5XdJ/Ufxk/7eaxrHerCk9 5fjBO0k5S6OD3MWUuSYpf7JjL9sJyYzmzaU996iVBzv2Ll4o+ElqwNCTF9paw/xrmBZxP1tXf EJ9ze4JTwJX049ndbC3bSiZ7NjO8/iSdOMn4jOJZJZbijERDLeai4kQAJuaRMpgCAAA= X-Env-Sender: prvs=343936acc=sergey.dyasli@citrix.com X-Msg-Ref: server-4.tower-21.messagelabs.com!1498473878!69468191!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.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 27243 invoked from network); 26 Jun 2017 10:44:41 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-4.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 26 Jun 2017 10:44:41 -0000 X-IronPort-AV: E=Sophos;i="5.39,395,1493683200"; d="scan'208";a="429331933" From: Sergey Dyasli To: Date: Mon, 26 Jun 2017 11:44:32 +0100 Message-ID: <20170626104435.25508-4-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170626104435.25508-1-sergey.dyasli@citrix.com> References: <20170626104435.25508-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Kevin Tian , Jan Beulich , Jun Nakajima , Sergey Dyasli Subject: [Xen-devel] [PATCH v1 3/6] vmx: refactor vmx_init_vmcs_config() 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 1. Remove RDMSRs of VMX MSRs since all values are already available in raw_vmx_msr_policy. 2. Replace bit operations involving VMX bitmasks with accessing VMX features by name and using vmx_msr_available() where appropriate. Signed-off-by: Sergey Dyasli --- xen/arch/x86/hvm/vmx/vmcs.c | 56 +++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 00fbc0ccb8..dbf6eb7433 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -227,7 +227,8 @@ static u32 adjust_vmx_controls( { u32 vmx_msr_low, vmx_msr_high, ctl = ctl_min | ctl_opt; - rdmsr(msr, vmx_msr_low, vmx_msr_high); + vmx_msr_low = raw_vmx_msr_policy.msr[msr - MSR_IA32_VMX_BASIC]; + vmx_msr_high = raw_vmx_msr_policy.msr[msr - MSR_IA32_VMX_BASIC] >> 32; ctl &= vmx_msr_high; /* bit == 0 in high word ==> must be zero */ ctl |= vmx_msr_low; /* bit == 1 in low word ==> must be one */ @@ -245,19 +246,16 @@ static u32 adjust_vmx_controls( static int vmx_init_vmcs_config(void) { - u32 vmx_basic_msr_low, vmx_basic_msr_high, min, opt; + u32 min, opt; u32 _vmx_pin_based_exec_control; u32 _vmx_cpu_based_exec_control; u32 _vmx_secondary_exec_control = 0; u64 _vmx_ept_vpid_cap = 0; - u64 _vmx_misc_cap = 0; u32 _vmx_vmexit_control; u32 _vmx_vmentry_control; u64 _vmx_vmfunc = 0; bool_t mismatch = 0; - rdmsr(MSR_IA32_VMX_BASIC, vmx_basic_msr_low, vmx_basic_msr_high); - min = (PIN_BASED_EXT_INTR_MASK | PIN_BASED_NMI_EXITING); opt = (PIN_BASED_VIRTUAL_NMIS | @@ -291,7 +289,7 @@ static int vmx_init_vmcs_config(void) _vmx_cpu_based_exec_control &= ~(CPU_BASED_CR8_LOAD_EXITING | CPU_BASED_CR8_STORE_EXITING); - if ( _vmx_cpu_based_exec_control & CPU_BASED_ACTIVATE_SECONDARY_CONTROLS ) + if ( vmx_msr_available(&raw_vmx_msr_policy, MSR_IA32_VMX_PROCBASED_CTLS2) ) { min = 0; opt = (SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES | @@ -305,8 +303,7 @@ static int vmx_init_vmcs_config(void) SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS | SECONDARY_EXEC_XSAVES | SECONDARY_EXEC_TSC_SCALING); - rdmsrl(MSR_IA32_VMX_MISC, _vmx_misc_cap); - if ( _vmx_misc_cap & VMX_MISC_VMWRITE_ALL ) + if ( raw_vmx_msr_policy.misc.vmwrite_all ) opt |= SECONDARY_EXEC_ENABLE_VMCS_SHADOWING; if ( opt_vpid_enabled ) opt |= SECONDARY_EXEC_ENABLE_VPID; @@ -331,10 +328,9 @@ static int vmx_init_vmcs_config(void) } /* The IA32_VMX_EPT_VPID_CAP MSR exists only when EPT or VPID available */ - if ( _vmx_secondary_exec_control & (SECONDARY_EXEC_ENABLE_EPT | - SECONDARY_EXEC_ENABLE_VPID) ) + if ( vmx_msr_available(&raw_vmx_msr_policy, MSR_IA32_VMX_EPT_VPID_CAP) ) { - rdmsrl(MSR_IA32_VMX_EPT_VPID_CAP, _vmx_ept_vpid_cap); + _vmx_ept_vpid_cap = raw_vmx_msr_policy.ept_vpid_cap.raw; if ( !opt_ept_ad ) _vmx_ept_vpid_cap &= ~VMX_EPT_AD_BIT; @@ -379,10 +375,14 @@ static int vmx_init_vmcs_config(void) * To use EPT we expect to be able to clear certain intercepts. * We check VMX_BASIC_MSR[55] to correctly handle default controls. */ - uint32_t must_be_one, must_be_zero, msr = MSR_IA32_VMX_PROCBASED_CTLS; - if ( vmx_basic_msr_high & (VMX_BASIC_DEFAULT1_ZERO >> 32) ) - msr = MSR_IA32_VMX_TRUE_PROCBASED_CTLS; - rdmsr(msr, must_be_one, must_be_zero); + uint32_t must_be_one = raw_vmx_msr_policy.procbased_ctls.allowed_0.raw; + uint32_t must_be_zero = raw_vmx_msr_policy.procbased_ctls.allowed_1.raw; + if ( vmx_msr_available(&raw_vmx_msr_policy, + MSR_IA32_VMX_TRUE_PROCBASED_CTLS) ) + { + must_be_one = raw_vmx_msr_policy.true_procbased_ctls.allowed_0.raw; + must_be_zero = raw_vmx_msr_policy.true_procbased_ctls.allowed_1.raw; + } if ( must_be_one & (CPU_BASED_INVLPG_EXITING | CPU_BASED_CR3_LOAD_EXITING | CPU_BASED_CR3_STORE_EXITING) ) @@ -423,9 +423,9 @@ static int vmx_init_vmcs_config(void) _vmx_pin_based_exec_control &= ~ PIN_BASED_POSTED_INTERRUPT; /* The IA32_VMX_VMFUNC MSR exists only when VMFUNC is available */ - if ( _vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_VM_FUNCTIONS ) + if ( vmx_msr_available(&raw_vmx_msr_policy, MSR_IA32_VMX_VMFUNC) ) { - rdmsrl(MSR_IA32_VMX_VMFUNC, _vmx_vmfunc); + _vmx_vmfunc = raw_vmx_msr_policy.vmfunc.raw; /* * VMFUNC leaf 0 (EPTP switching) must be supported. @@ -451,33 +451,31 @@ static int vmx_init_vmcs_config(void) if ( !vmx_pin_based_exec_control ) { /* First time through. */ - vmcs_revision_id = vmx_basic_msr_low & VMX_BASIC_REVISION_MASK; + vmcs_revision_id = raw_vmx_msr_policy.basic.vmcs_revision_id; vmx_pin_based_exec_control = _vmx_pin_based_exec_control; vmx_cpu_based_exec_control = _vmx_cpu_based_exec_control; vmx_secondary_exec_control = _vmx_secondary_exec_control; vmx_ept_vpid_cap = _vmx_ept_vpid_cap; vmx_vmexit_control = _vmx_vmexit_control; vmx_vmentry_control = _vmx_vmentry_control; - vmx_basic_msr = ((u64)vmx_basic_msr_high << 32) | - vmx_basic_msr_low; + vmx_basic_msr = raw_vmx_msr_policy.basic.raw; vmx_vmfunc = _vmx_vmfunc; vmx_virt_exception = !!(_vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS); vmx_display_features(); /* IA-32 SDM Vol 3B: VMCS size is never greater than 4kB. */ - if ( (vmx_basic_msr_high & (VMX_BASIC_VMCS_SIZE_MASK >> 32)) > - PAGE_SIZE ) + if ( raw_vmx_msr_policy.basic.vmcs_region_size > PAGE_SIZE ) { - printk("VMX: CPU%d VMCS size is too big (%Lu bytes)\n", + printk("VMX: CPU%d VMCS size is too big (%d bytes)\n", smp_processor_id(), - vmx_basic_msr_high & (VMX_BASIC_VMCS_SIZE_MASK >> 32)); + raw_vmx_msr_policy.basic.vmcs_region_size); return -EINVAL; } } /* IA-32 SDM Vol 3B: 64-bit CPUs always have VMX_BASIC_MSR[48]==0. */ - if ( vmx_basic_msr_high & (VMX_BASIC_32BIT_ADDRESSES >> 32) ) + if ( raw_vmx_msr_policy.basic.addresses_32bit ) { printk("VMX: CPU%d limits VMX structure pointers to 32 bits\n", smp_processor_id()); @@ -485,9 +483,7 @@ static int vmx_init_vmcs_config(void) } /* Require Write-Back (WB) memory type for VMCS accesses. */ - opt = (vmx_basic_msr_high & (VMX_BASIC_MEMORY_TYPE_MASK >> 32)) / - ((VMX_BASIC_MEMORY_TYPE_MASK & -VMX_BASIC_MEMORY_TYPE_MASK) >> 32); - if ( opt != MTRR_TYPE_WRBACK ) + if ( raw_vmx_msr_policy.basic.memory_type != MTRR_TYPE_WRBACK ) { printk("VMX: CPU%d has unexpected VMCS access type %u\n", smp_processor_id(), opt); @@ -632,8 +628,8 @@ int vmx_cpu_up(void) * the requred CRO fixed bits in VMX operation. */ cr0 = read_cr0(); - rdmsrl(MSR_IA32_VMX_CR0_FIXED0, vmx_cr0_fixed0); - rdmsrl(MSR_IA32_VMX_CR0_FIXED1, vmx_cr0_fixed1); + vmx_cr0_fixed0 = raw_vmx_msr_policy.cr0_fixed_0.raw; + vmx_cr0_fixed1 = raw_vmx_msr_policy.cr0_fixed_1.raw; if ( (~cr0 & vmx_cr0_fixed0) || (cr0 & ~vmx_cr0_fixed1) ) { printk("CPU%d: some settings of host CR0 are "