Commit 9a2a05b9 authored by Paolo Bonzini's avatar Paolo Bonzini

KVM: nVMX: clean up nested_release_vmcs12 and code around it

Make nested_release_vmcs12 idempotent.
Tested-by: default avatarWanpeng Li <wanpeng.li@linux.intel.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 4fa7734c
...@@ -6109,8 +6109,14 @@ static int nested_vmx_check_permission(struct kvm_vcpu *vcpu) ...@@ -6109,8 +6109,14 @@ static int nested_vmx_check_permission(struct kvm_vcpu *vcpu)
static inline void nested_release_vmcs12(struct vcpu_vmx *vmx) static inline void nested_release_vmcs12(struct vcpu_vmx *vmx)
{ {
u32 exec_control; u32 exec_control;
if (vmx->nested.current_vmptr == -1ull)
return;
/* current_vmptr and current_vmcs12 are always set/reset together */
if (WARN_ON(vmx->nested.current_vmcs12 == NULL))
return;
if (enable_shadow_vmcs) { if (enable_shadow_vmcs) {
if (vmx->nested.current_vmcs12 != NULL) {
/* copy to memory all shadowed fields in case /* copy to memory all shadowed fields in case
they were modified */ they were modified */
copy_shadow_to_vmcs12(vmx); copy_shadow_to_vmcs12(vmx);
...@@ -6120,9 +6126,10 @@ static inline void nested_release_vmcs12(struct vcpu_vmx *vmx) ...@@ -6120,9 +6126,10 @@ static inline void nested_release_vmcs12(struct vcpu_vmx *vmx)
vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_control); vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_control);
vmcs_write64(VMCS_LINK_POINTER, -1ull); vmcs_write64(VMCS_LINK_POINTER, -1ull);
} }
}
kunmap(vmx->nested.current_vmcs12_page); kunmap(vmx->nested.current_vmcs12_page);
nested_release_page(vmx->nested.current_vmcs12_page); nested_release_page(vmx->nested.current_vmcs12_page);
vmx->nested.current_vmptr = -1ull;
vmx->nested.current_vmcs12 = NULL;
} }
/* /*
...@@ -6133,12 +6140,9 @@ static void free_nested(struct vcpu_vmx *vmx) ...@@ -6133,12 +6140,9 @@ static void free_nested(struct vcpu_vmx *vmx)
{ {
if (!vmx->nested.vmxon) if (!vmx->nested.vmxon)
return; return;
vmx->nested.vmxon = false; vmx->nested.vmxon = false;
if (vmx->nested.current_vmptr != -1ull) {
nested_release_vmcs12(vmx); nested_release_vmcs12(vmx);
vmx->nested.current_vmptr = -1ull;
vmx->nested.current_vmcs12 = NULL;
}
if (enable_shadow_vmcs) if (enable_shadow_vmcs)
free_vmcs(vmx->nested.current_shadow_vmcs); free_vmcs(vmx->nested.current_shadow_vmcs);
/* Unpin physical memory we referred to in current vmcs02 */ /* Unpin physical memory we referred to in current vmcs02 */
...@@ -6175,11 +6179,8 @@ static int handle_vmclear(struct kvm_vcpu *vcpu) ...@@ -6175,11 +6179,8 @@ static int handle_vmclear(struct kvm_vcpu *vcpu)
if (nested_vmx_check_vmptr(vcpu, EXIT_REASON_VMCLEAR, &vmptr)) if (nested_vmx_check_vmptr(vcpu, EXIT_REASON_VMCLEAR, &vmptr))
return 1; return 1;
if (vmptr == vmx->nested.current_vmptr) { if (vmptr == vmx->nested.current_vmptr)
nested_release_vmcs12(vmx); nested_release_vmcs12(vmx);
vmx->nested.current_vmptr = -1ull;
vmx->nested.current_vmcs12 = NULL;
}
page = nested_get_page(vcpu, vmptr); page = nested_get_page(vcpu, vmptr);
if (page == NULL) { if (page == NULL) {
...@@ -6521,9 +6522,8 @@ static int handle_vmptrld(struct kvm_vcpu *vcpu) ...@@ -6521,9 +6522,8 @@ static int handle_vmptrld(struct kvm_vcpu *vcpu)
skip_emulated_instruction(vcpu); skip_emulated_instruction(vcpu);
return 1; return 1;
} }
if (vmx->nested.current_vmptr != -1ull)
nested_release_vmcs12(vmx);
nested_release_vmcs12(vmx);
vmx->nested.current_vmptr = vmptr; vmx->nested.current_vmptr = vmptr;
vmx->nested.current_vmcs12 = new_vmcs12; vmx->nested.current_vmcs12 = new_vmcs12;
vmx->nested.current_vmcs12_page = page; vmx->nested.current_vmcs12_page = page;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment