diff options
author | Sean Christopherson <sean.j.christopherson@intel.com> | 2019-05-07 15:18:00 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2019-06-18 05:47:44 -0400 |
commit | 3af80fec6e7fe2e89aa131a0ebdb90be780668f8 (patch) | |
tree | 52d676e074b5f84b7dec508fe626ea134e518172 /arch/x86/kvm/vmx/nested.c | |
parent | ae81d08993cbc515e3181ee6bebce5cd878133f2 (diff) |
KVM: VMX: Explicitly initialize controls shadow at VMCS allocation
Or: Don't re-initialize vmcs02's controls on every nested VM-Entry.
VMWRITEs to the major VMCS controls are deceptively expensive. Intel
CPUs with VMCS caching (Westmere and later) also optimize away
consistency checks on VM-Entry, i.e. skip consistency checks if the
relevant fields have not 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.
Zero out the controls' shadow copies during VMCS allocation and use the
optimized setter when "initializing" controls. While this technically
affects both non-nested and nested virtualization, nested virtualization
is the primary beneficiary as avoid VMWRITEs when prepare vmcs02 allows
hardware to optimizie away consistency checks.
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm/vmx/nested.c')
-rw-r--r-- | arch/x86/kvm/vmx/nested.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index d4f529a2e194..3f76a1f3fe3c 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c | |||
@@ -2024,7 +2024,7 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12) | |||
2024 | } else { | 2024 | } else { |
2025 | exec_control &= ~PIN_BASED_POSTED_INTR; | 2025 | exec_control &= ~PIN_BASED_POSTED_INTR; |
2026 | } | 2026 | } |
2027 | pin_controls_init(vmx, exec_control); | 2027 | pin_controls_set(vmx, exec_control); |
2028 | 2028 | ||
2029 | /* | 2029 | /* |
2030 | * EXEC CONTROLS | 2030 | * EXEC CONTROLS |
@@ -2049,7 +2049,7 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12) | |||
2049 | */ | 2049 | */ |
2050 | exec_control &= ~CPU_BASED_USE_IO_BITMAPS; | 2050 | exec_control &= ~CPU_BASED_USE_IO_BITMAPS; |
2051 | exec_control |= CPU_BASED_UNCOND_IO_EXITING; | 2051 | exec_control |= CPU_BASED_UNCOND_IO_EXITING; |
2052 | exec_controls_init(vmx, exec_control); | 2052 | exec_controls_set(vmx, exec_control); |
2053 | 2053 | ||
2054 | /* | 2054 | /* |
2055 | * SECONDARY EXEC CONTROLS | 2055 | * SECONDARY EXEC CONTROLS |
@@ -2079,7 +2079,7 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12) | |||
2079 | vmcs_write16(GUEST_INTR_STATUS, | 2079 | vmcs_write16(GUEST_INTR_STATUS, |
2080 | vmcs12->guest_intr_status); | 2080 | vmcs12->guest_intr_status); |
2081 | 2081 | ||
2082 | secondary_exec_controls_init(vmx, exec_control); | 2082 | secondary_exec_controls_set(vmx, exec_control); |
2083 | } | 2083 | } |
2084 | 2084 | ||
2085 | /* | 2085 | /* |
@@ -2098,7 +2098,7 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12) | |||
2098 | if (guest_efer != host_efer) | 2098 | if (guest_efer != host_efer) |
2099 | exec_control |= VM_ENTRY_LOAD_IA32_EFER; | 2099 | exec_control |= VM_ENTRY_LOAD_IA32_EFER; |
2100 | } | 2100 | } |
2101 | vm_entry_controls_init(vmx, exec_control); | 2101 | vm_entry_controls_set(vmx, exec_control); |
2102 | 2102 | ||
2103 | /* | 2103 | /* |
2104 | * EXIT CONTROLS | 2104 | * EXIT CONTROLS |
@@ -2110,7 +2110,7 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12) | |||
2110 | exec_control = vmx_vmexit_ctrl(); | 2110 | exec_control = vmx_vmexit_ctrl(); |
2111 | if (cpu_has_load_ia32_efer() && guest_efer != host_efer) | 2111 | if (cpu_has_load_ia32_efer() && guest_efer != host_efer) |
2112 | exec_control |= VM_EXIT_LOAD_IA32_EFER; | 2112 | exec_control |= VM_EXIT_LOAD_IA32_EFER; |
2113 | vm_exit_controls_init(vmx, exec_control); | 2113 | vm_exit_controls_set(vmx, exec_control); |
2114 | 2114 | ||
2115 | /* | 2115 | /* |
2116 | * Interrupt/Exception Fields | 2116 | * Interrupt/Exception Fields |