[00/11] KVM: vmx: optimize VMWRITEs to host FS/GS fields
mbox series

Message ID 20180723193250.13555-1-sean.j.christopherson@intel.com
Headers show
Series
  • KVM: vmx: optimize VMWRITEs to host FS/GS fields
Related show

Message

Sean Christopherson July 23, 2018, 7:32 p.m. UTC
Conceptually, this series is fairly simple: the host's FS/GS selector
and base values rarely change, so only update their corresponding VMCS
fields when necessary.  VMWRITE takes ~27 cycles on modern hardware,
i.e. eliminating writes to HOST_{FS,GS}_{SEL,BASE} can save upwards of
~100 cycles when reloading a vCPU after an exit to userspace.

The actual optimization is implemented in the final two patches.  The
preceding nine patches are a mix of refactoring and cleansing; KVM's
FS/GS related code in particular has become a bit crusty as KVM has
evolved over the years.

Sean Christopherson (11):
  KVM: vmx: move msr_host_bndcfgs out of struct host_state
  KVM: vmx: refactor segmentation code in vmx_save_host_state()
  KVM: vmx: track host_state.loaded using a loaded_vmcs pointer
  KVM: vmx: add dedicated utility to access guest's kernel_gs_base
  KVM: vmx: rename __vmx_load_host_state() and vmx_save_host_state()
  KVM: nVMX: remove a misleading comment regarding vmcs02 fields
  KVM: vmx: compute need to reload FS/GS/LDT on demand
  KVM: vmx: move struct host_state usage to struct loaded_vmcs
  KVM: vmx: always initialize HOST_{FS,GS}_BASE to zero during setup
  KVM: vmx: skip VMWRITE of HOST_{FS,GS}_SEL when possible
  KVM: vmx: skip VMWRITE of HOST_{FS,GS}_BASE when possible

 arch/x86/kvm/vmx.c | 246 ++++++++++++++++++++++++++-------------------
 1 file changed, 144 insertions(+), 102 deletions(-)

Comments

Paolo Bonzini Aug. 2, 2018, 12:56 p.m. UTC | #1
On 23/07/2018 21:32, Sean Christopherson wrote:
> Conceptually, this series is fairly simple: the host's FS/GS selector
> and base values rarely change, so only update their corresponding VMCS
> fields when necessary.  VMWRITE takes ~27 cycles on modern hardware,
> i.e. eliminating writes to HOST_{FS,GS}_{SEL,BASE} can save upwards of
> ~100 cycles when reloading a vCPU after an exit to userspace.
> 
> The actual optimization is implemented in the final two patches.  The
> preceding nine patches are a mix of refactoring and cleansing; KVM's
> FS/GS related code in particular has become a bit crusty as KVM has
> evolved over the years.

Very nice, queued.

Paolo