Skip to content

Commit d51e1d3

Browse files
Maxim Levitskybonzini
authored andcommitted
KVM: nVMX: Sync unsync'd vmcs02 state to vmcs12 on migration
Even when we are outside the nested guest, some vmcs02 fields may not be in sync vs vmcs12. This is intentional, even across nested VM-exit, because the sync can be delayed until the nested hypervisor performs a VMCLEAR or a VMREAD/VMWRITE that affects those rarely accessed fields. However, during KVM_GET_NESTED_STATE, the vmcs12 has to be up to date to be able to restore it. To fix that, call copy_vmcs02_to_vmcs12_rare() before the vmcs12 contents are copied to userspace. Fixes: 7952d76 ("KVM: nVMX: Sync rarely accessed guest fields only when needed") Reviewed-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> Message-Id: <20210114205449.8715-2-mlevitsk@redhat.com> Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent d95df95 commit d51e1d3

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

arch/x86/kvm/vmx/nested.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6077,11 +6077,14 @@ static int vmx_get_nested_state(struct kvm_vcpu *vcpu,
60776077
if (is_guest_mode(vcpu)) {
60786078
sync_vmcs02_to_vmcs12(vcpu, vmcs12);
60796079
sync_vmcs02_to_vmcs12_rare(vcpu, vmcs12);
6080-
} else if (!vmx->nested.need_vmcs12_to_shadow_sync) {
6081-
if (vmx->nested.hv_evmcs)
6082-
copy_enlightened_to_vmcs12(vmx);
6083-
else if (enable_shadow_vmcs)
6084-
copy_shadow_to_vmcs12(vmx);
6080+
} else {
6081+
copy_vmcs02_to_vmcs12_rare(vcpu, get_vmcs12(vcpu));
6082+
if (!vmx->nested.need_vmcs12_to_shadow_sync) {
6083+
if (vmx->nested.hv_evmcs)
6084+
copy_enlightened_to_vmcs12(vmx);
6085+
else if (enable_shadow_vmcs)
6086+
copy_shadow_to_vmcs12(vmx);
6087+
}
60856088
}
60866089

60876090
BUILD_BUG_ON(sizeof(user_vmx_nested_state->vmcs12) < VMCS12_SIZE);

0 commit comments

Comments
 (0)