Skip to content

Commit f2c7ef3

Browse files
Maxim Levitskybonzini
authored andcommitted
KVM: nSVM: cancel KVM_REQ_GET_NESTED_STATE_PAGES on nested vmexit
It is possible to exit the nested guest mode, entered by svm_set_nested_state prior to first vm entry to it (e.g due to pending event) if the nested run was not pending during the migration. In this case we must not switch to the nested msr permission bitmap. Also add a warning to catch similar cases in the future. Fixes: a7d5c7c ("KVM: nSVM: delay MSR permission processing to first nested VM run") Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> Message-Id: <20210107093854.882483-2-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 56fe28d commit f2c7ef3

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

arch/x86/kvm/svm/nested.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ static bool nested_svm_vmrun_msrpm(struct vcpu_svm *svm)
199199
static bool svm_get_nested_state_pages(struct kvm_vcpu *vcpu)
200200
{
201201
struct vcpu_svm *svm = to_svm(vcpu);
202+
202203
if (!nested_svm_vmrun_msrpm(svm)) {
203204
vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
204205
vcpu->run->internal.suberror =
@@ -595,6 +596,8 @@ int nested_svm_vmexit(struct vcpu_svm *svm)
595596
svm->nested.vmcb12_gpa = 0;
596597
WARN_ON_ONCE(svm->nested.nested_run_pending);
597598

599+
kvm_clear_request(KVM_REQ_GET_NESTED_STATE_PAGES, &svm->vcpu);
600+
598601
/* in case we halted in L2 */
599602
svm->vcpu.arch.mp_state = KVM_MP_STATE_RUNNABLE;
600603

arch/x86/kvm/vmx/nested.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4442,6 +4442,8 @@ void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason,
44424442
/* trying to cancel vmlaunch/vmresume is a bug */
44434443
WARN_ON_ONCE(vmx->nested.nested_run_pending);
44444444

4445+
kvm_clear_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu);
4446+
44454447
/* Service the TLB flush request for L2 before switching to L1. */
44464448
if (kvm_check_request(KVM_REQ_TLB_FLUSH_CURRENT, vcpu))
44474449
kvm_vcpu_flush_tlb_current(vcpu);

arch/x86/kvm/x86.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8789,7 +8789,9 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
87898789

87908790
if (kvm_request_pending(vcpu)) {
87918791
if (kvm_check_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu)) {
8792-
if (unlikely(!kvm_x86_ops.nested_ops->get_nested_state_pages(vcpu))) {
8792+
if (WARN_ON_ONCE(!is_guest_mode(vcpu)))
8793+
;
8794+
else if (unlikely(!kvm_x86_ops.nested_ops->get_nested_state_pages(vcpu))) {
87938795
r = 0;
87948796
goto out;
87958797
}

0 commit comments

Comments
 (0)