Skip to content

KVM: VMX: Reduce VMWRITEs to VMCS controls

Sean Christopherson kvm 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest13 patches 7 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/13KVM: nVMX: Use adjusted pin controls for vmcs02arch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+4 -41 reply
2/13KVM: VMX: Add builder macros for shadowing controlsarch/x86/kvm/vmx/vmx.h+37 -650 replies
3/13KVM: VMX: Shadow VMCS pin controlsarch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+8 -70 replies
4/13KVM: VMX: Shadow VMCS primary execution controlsarch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+23 -310 replies
5/13KVM: VMX: Shadow VMCS secondary execution controlsarch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+28 -261 reply
6/13KVM: nVMX: Shadow VMCS controls on a per-VMCS basisarch/x86/kvm/vmx/vmcs.h arch/x86/kvm/vmx/vmx.h+16 -150 replies
7/13KVM: nVMX: Don't reset VMCS controls shadow on VMCS switcharch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmx.h+0 -90 replies
8/13KVM: VMX: Explicitly initialize controls shadow at VMCS allocationarch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+12 -150 replies
9/13KVM: nVMX: Preserve last USE_MSR_BITMAPS when preparing vmcs02arch/x86/kvm/vmx/nested.c+2 -01 reply
10/13KVM: nVMX: Preset *DT exiting in vmcs02 when emulating UMIParch/x86/kvm/vmx/nested.c+5 -01 reply
11/13KVM: VMX: Drop hv_timer_armed from 'struct loaded_vmcs'arch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmcs.h arch/x86/kvm/vmx/vmx.c+2 -80 replies
12/13KVM: nVMX: Don't mark vmcs12 as dirty when L1 writes pin controlsarch/x86/kvm/vmx/nested.c+5 -13 replies
13/13KVM: VMX: Leave preemption timer running when it's disabledarch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmcs.h arch/x86/kvm/vmx/vmx.c+41 -250 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 00/13] KVM: VMX: Reduce VMWRITEs to VMCS controls

The overarching theme of this series is to reduce the number of VMWRITEs to VMCS controls. VMWRITEs to the major VMCS controls, i.e. vm_entry, vm_exit, pin, exec and sec_exec, are deceptively expensive. CPUs with VMCS caching (Westmere and later) also optimize away consistency checks on VM-Entry, i.e. skip consistency checks if the relevant fields haven't changed since the last successful VM-Entry (of the cached VMCS). Because uops are a precious commodity, uCode's dirty VMCS field tracking isn't as precise as software would prefer. Notably, writing any of the major VMCS fields effectively marks the entire VMCS dirty, i.e. causes the next VM-Entry to perform all consistency checks, which consumes several hundred cycles.

The majority of this series is technically vanilla VMX, but the end goal of nearly every patch is to eliminate VMWRITEs to controls when running nested guests, e.g. much of the series resolves around shadowing the various controls so that they don't need to be rewritten to vmcs02 on every nested VM-Entry.

The sole patch that is purely vanilla VMX is to avoid writing pin controls when disabling/enabling the preemption timer. This is the last known known case where semi-frequent writes to control fields can be avoided (in non-nested operation). E.g. detecting IRQ windows frequently toggles VIRTUAL_INTR_PENDING, but at this juncture that behavior is effectively unavoidable. Resolving the preemption timer case takes a somewhat adventurous approach of leaving the timer running even when it's not in use.

Sean Christopherson (13):
KVM: nVMX: Use adjusted pin controls for vmcs02
KVM: VMX: Add builder macros for shadowing controls
KVM: VMX: Shadow VMCS pin controls
KVM: VMX: Shadow VMCS primary execution controls
KVM: VMX: Shadow VMCS secondary execution controls
KVM: nVMX: Shadow VMCS controls on a per-VMCS basis
KVM: nVMX: Don't reset VMCS controls shadow on VMCS switch
KVM: VMX: Explicitly initialize controls shadow at VMCS allocation
KVM: nVMX: Preserve last USE_MSR_BITMAPS when preparing vmcs02
KVM: nVMX: Preset *DT exiting in vmcs02 when emulating UMIP
KVM: VMX: Drop hv_timer_armed from 'struct loaded_vmcs'
KVM: nVMX: Don't mark vmcs12 as dirty when L1 writes pin controls
KVM: VMX: Leave preemption timer running when it's disabled

 arch/x86/kvm/vmx/nested.c |  54 ++++++-------
 arch/x86/kvm/vmx/vmcs.h   |  11 ++-
 arch/x86/kvm/vmx/vmx.c    | 156 +++++++++++++++++++-------------------
 arch/x86/kvm/vmx/vmx.h    |  92 +++++++---------------
 4 files changed, 145 insertions(+), 168 deletions(-)
Signature · 1 line
2.21.0