Skip to content

Commit

Permalink
KVM: SVM: Fix nested VM-Exit on #GP interception handling
Browse files Browse the repository at this point in the history
Fix the interpreation of nested_svm_vmexit()'s return value when
synthesizing a nested VM-Exit after intercepting an SVM instruction while
L2 was running.  The helper returns '0' on success, whereas a return
value of '0' in the exit handler path means "exit to userspace".  The
incorrect return value causes KVM to exit to userspace without filling
the run state, e.g. QEMU logs "KVM: unknown exit, hardware reason 0".

Fixes: 14c2bf8 ("KVM: SVM: Fix #GP handling for doubly-nested virtualization")
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20210224005627.657028-1-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Sean Christopherson authored and Paolo Bonzini committed Feb 25, 2021
1 parent 67b45af commit 2df8d38
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions arch/x86/kvm/svm/svm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2211,15 +2211,20 @@ static int emulate_svm_instr(struct kvm_vcpu *vcpu, int opcode)
[SVM_INSTR_VMSAVE] = vmsave_interception,
};
struct vcpu_svm *svm = to_svm(vcpu);
int ret;

if (is_guest_mode(vcpu)) {
svm->vmcb->control.exit_code = guest_mode_exit_codes[opcode];
svm->vmcb->control.exit_info_1 = 0;
svm->vmcb->control.exit_info_2 = 0;

return nested_svm_vmexit(svm);
} else
return svm_instr_handlers[opcode](svm);
/* Returns '1' or -errno on failure, '0' on success. */
ret = nested_svm_vmexit(svm);
if (ret)
return ret;
return 1;
}
return svm_instr_handlers[opcode](svm);
}

/*
Expand Down

0 comments on commit 2df8d38

Please sign in to comment.