aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Christopherson <sean.j.christopherson@intel.com>2018-07-23 15:32:50 -0400
committerPaolo Bonzini <pbonzini@redhat.com>2018-08-06 11:59:17 -0400
commit5e079c7ece1060491ef4a45414823162cce91b3d (patch)
tree31374e01961924f1ff4d32535f4677812623b975
parent8f21a0bbf36f58334695ae6e46c0cf906a217154 (diff)
KVM: vmx: skip VMWRITE of HOST_{FS,GS}_BASE when possible
The host's FS.base and GS.base rarely change, e.g. ~0.1% of host/guest swaps on my system. Cache the last value written to the VMCS and skip the VMWRITE to the associated VMCS fields when loading host state if the value hasn't changed since the last VMWRITE. Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--arch/x86/kvm/vmx.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 4937e11f971a..b23ecc04ca51 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -226,6 +226,8 @@ struct vmcs {
226struct vmcs_host_state { 226struct vmcs_host_state {
227 unsigned long cr3; /* May not match real cr3 */ 227 unsigned long cr3; /* May not match real cr3 */
228 unsigned long cr4; /* May not match real cr4 */ 228 unsigned long cr4; /* May not match real cr4 */
229 unsigned long gs_base;
230 unsigned long fs_base;
229 231
230 u16 fs_sel, gs_sel, ldt_sel; 232 u16 fs_sel, gs_sel, ldt_sel;
231#ifdef CONFIG_X86_64 233#ifdef CONFIG_X86_64
@@ -2731,9 +2733,14 @@ static void vmx_prepare_switch_to_guest(struct kvm_vcpu *vcpu)
2731 vmcs_write16(HOST_GS_SELECTOR, 0); 2733 vmcs_write16(HOST_GS_SELECTOR, 0);
2732 host_state->gs_sel = gs_sel; 2734 host_state->gs_sel = gs_sel;
2733 } 2735 }
2734 2736 if (unlikely(fs_base != host_state->fs_base)) {
2735 vmcs_writel(HOST_FS_BASE, fs_base); 2737 vmcs_writel(HOST_FS_BASE, fs_base);
2736 vmcs_writel(HOST_GS_BASE, gs_base); 2738 host_state->fs_base = fs_base;
2739 }
2740 if (unlikely(gs_base != host_state->gs_base)) {
2741 vmcs_writel(HOST_GS_BASE, gs_base);
2742 host_state->gs_base = gs_base;
2743 }
2737 2744
2738 for (i = 0; i < vmx->save_nmsrs; ++i) 2745 for (i = 0; i < vmx->save_nmsrs; ++i)
2739 kvm_set_shared_msr(vmx->guest_msrs[i].index, 2746 kvm_set_shared_msr(vmx->guest_msrs[i].index,