diff mbox series

[09/11] KVM: vmx: always initialize HOST_{FS,GS}_BASE to zero during setup

Message ID 20180723193250.13555-10-sean.j.christopherson@intel.com (mailing list archive)
State New, archived
Headers show
Series KVM: vmx: optimize VMWRITEs to host FS/GS fields | expand

Commit Message

Sean Christopherson July 23, 2018, 7:32 p.m. UTC
The HOST_{FS,GS}_BASE fields are guaranteed to be written prior to
VMENTER, by way of vmx_prepare_switch_to_guest().  Initialize the
fields to zero for 64-bit kernels instead of pulling the base values
from their respective MSRs.  In addition to eliminating two RDMSRs,
vmx_prepare_switch_to_guest() can safely assume the initial value of
the fields is zero in all cases.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/kvm/vmx.c | 10 ----------
 1 file changed, 10 deletions(-)

Comments

Peter Shier July 24, 2018, 10:40 p.m. UTC | #1
On Mon, Jul 23, 2018 at 12:33 PM Sean Christopherson
<sean.j.christopherson@intel.com> wrote:
>
> The HOST_{FS,GS}_BASE fields are guaranteed to be written prior to
> VMENTER, by way of vmx_prepare_switch_to_guest().  Initialize the
> fields to zero for 64-bit kernels instead of pulling the base values
> from their respective MSRs.  In addition to eliminating two RDMSRs,
> vmx_prepare_switch_to_guest() can safely assume the initial value of
> the fields is zero in all cases.
>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>

Reviewed-by: Peter Shier <pshier@google.com>
Tested-by: Peter Shier <pshier@google.com>
diff mbox series

Patch

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index c66fcb01f355..b24cd74c905c 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -6223,9 +6223,6 @@  static void ept_set_mmio_spte_mask(void)
  */
 static void vmx_vcpu_setup(struct vcpu_vmx *vmx)
 {
-#ifdef CONFIG_X86_64
-	unsigned long a;
-#endif
 	int i;
 
 	if (enable_shadow_vmcs) {
@@ -6280,15 +6277,8 @@  static void vmx_vcpu_setup(struct vcpu_vmx *vmx)
 	vmcs_write16(HOST_FS_SELECTOR, 0);            /* 22.2.4 */
 	vmcs_write16(HOST_GS_SELECTOR, 0);            /* 22.2.4 */
 	vmx_set_constant_host_state(vmx);
-#ifdef CONFIG_X86_64
-	rdmsrl(MSR_FS_BASE, a);
-	vmcs_writel(HOST_FS_BASE, a); /* 22.2.4 */
-	rdmsrl(MSR_GS_BASE, a);
-	vmcs_writel(HOST_GS_BASE, a); /* 22.2.4 */
-#else
 	vmcs_writel(HOST_FS_BASE, 0); /* 22.2.4 */
 	vmcs_writel(HOST_GS_BASE, 0); /* 22.2.4 */
-#endif
 
 	if (cpu_has_vmx_vmfunc())
 		vmcs_write64(VM_FUNCTION_CONTROL, 0);