aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Matlack <dmatlack@google.com>2017-08-01 17:00:39 -0400
committerRadim Krčmář <rkrcmar@redhat.com>2017-08-02 16:41:03 -0400
commit8ca44e88c32f86721c6ceca8e5e9b0b40c98907d (patch)
tree563f86f01ecc6e7da419cd7e2d9d0f4c81a12338
parent9f744c59746078280ef28163aa136ef3f625804e (diff)
kvm: nVMX: don't flush VMCS12 during VMXOFF or VCPU teardown
According to the Intel SDM, software cannot rely on the current VMCS to be coherent after a VMXOFF or shutdown. So this is a valid way to handle VMCS12 flushes. 24.11.1 Software Use of Virtual-Machine Control Structures ... If a logical processor leaves VMX operation, any VMCSs active on that logical processor may be corrupted (see below). To prevent such corruption of a VMCS that may be used either after a return to VMX operation or on another logical processor, software should execute VMCLEAR for that VMCS before executing the VMXOFF instruction or removing power from the processor (e.g., as part of a transition to the S3 and S4 power states). ... This fixes a "suspicious rcu_dereference_check() usage!" warning during kvm_vm_release() because nested_release_vmcs12() calls kvm_vcpu_write_guest_page() without holding kvm->srcu. Signed-off-by: David Matlack <dmatlack@google.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
-rw-r--r--arch/x86/kvm/vmx.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 082cdb9011eb..2099b1495b57 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -419,7 +419,7 @@ struct nested_vmx {
419 /* 419 /*
420 * Cache of the guest's VMCS, existing outside of guest memory. 420 * Cache of the guest's VMCS, existing outside of guest memory.
421 * Loaded from guest memory during VMPTRLD. Flushed to guest 421 * Loaded from guest memory during VMPTRLD. Flushed to guest
422 * memory during VMXOFF, VMCLEAR, VMPTRLD. 422 * memory during VMCLEAR and VMPTRLD.
423 */ 423 */
424 struct vmcs12 *cached_vmcs12; 424 struct vmcs12 *cached_vmcs12;
425 /* 425 /*
@@ -7174,6 +7174,12 @@ static int nested_vmx_check_permission(struct kvm_vcpu *vcpu)
7174 return 1; 7174 return 1;
7175} 7175}
7176 7176
7177static void vmx_disable_shadow_vmcs(struct vcpu_vmx *vmx)
7178{
7179 vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL, SECONDARY_EXEC_SHADOW_VMCS);
7180 vmcs_write64(VMCS_LINK_POINTER, -1ull);
7181}
7182
7177static inline void nested_release_vmcs12(struct vcpu_vmx *vmx) 7183static inline void nested_release_vmcs12(struct vcpu_vmx *vmx)
7178{ 7184{
7179 if (vmx->nested.current_vmptr == -1ull) 7185 if (vmx->nested.current_vmptr == -1ull)
@@ -7184,9 +7190,7 @@ static inline void nested_release_vmcs12(struct vcpu_vmx *vmx)
7184 they were modified */ 7190 they were modified */
7185 copy_shadow_to_vmcs12(vmx); 7191 copy_shadow_to_vmcs12(vmx);
7186 vmx->nested.sync_shadow_vmcs = false; 7192 vmx->nested.sync_shadow_vmcs = false;
7187 vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL, 7193 vmx_disable_shadow_vmcs(vmx);
7188 SECONDARY_EXEC_SHADOW_VMCS);
7189 vmcs_write64(VMCS_LINK_POINTER, -1ull);
7190 } 7194 }
7191 vmx->nested.posted_intr_nv = -1; 7195 vmx->nested.posted_intr_nv = -1;
7192 7196
@@ -7209,12 +7213,14 @@ static void free_nested(struct vcpu_vmx *vmx)
7209 7213
7210 vmx->nested.vmxon = false; 7214 vmx->nested.vmxon = false;
7211 free_vpid(vmx->nested.vpid02); 7215 free_vpid(vmx->nested.vpid02);
7212 nested_release_vmcs12(vmx); 7216 vmx->nested.posted_intr_nv = -1;
7217 vmx->nested.current_vmptr = -1ull;
7213 if (vmx->nested.msr_bitmap) { 7218 if (vmx->nested.msr_bitmap) {
7214 free_page((unsigned long)vmx->nested.msr_bitmap); 7219 free_page((unsigned long)vmx->nested.msr_bitmap);
7215 vmx->nested.msr_bitmap = NULL; 7220 vmx->nested.msr_bitmap = NULL;
7216 } 7221 }
7217 if (enable_shadow_vmcs) { 7222 if (enable_shadow_vmcs) {
7223 vmx_disable_shadow_vmcs(vmx);
7218 vmcs_clear(vmx->vmcs01.shadow_vmcs); 7224 vmcs_clear(vmx->vmcs01.shadow_vmcs);
7219 free_vmcs(vmx->vmcs01.shadow_vmcs); 7225 free_vmcs(vmx->vmcs01.shadow_vmcs);
7220 vmx->vmcs01.shadow_vmcs = NULL; 7226 vmx->vmcs01.shadow_vmcs = NULL;