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(-) -- 2.21.0