Skip to content

Commit

Permalink
KVM: x86: Exit to userspace when kvm_check_nested_events fails
Browse files Browse the repository at this point in the history
If kvm_check_nested_events fails due to raising an
EXIT_REASON_INTERNAL_ERROR, propagate it to userspace
immediately, even if the vCPU would otherwise be sleeping.
This happens for example when the posted interrupt descriptor
points outside guest memory.

Fixes: 966eefb ("KVM: nVMX: Disable vmcs02 posted interrupts if vmcs12 PID isn't mappable")
Cc: stable@vger.kernel.org
Reported-by: Jim Mattson <jmattson@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
bonzini committed Aug 20, 2021
1 parent dafe1ca commit 680c7e3
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -9762,10 +9762,14 @@ static inline int vcpu_block(struct kvm *kvm, struct kvm_vcpu *vcpu)
return 1;
}

static inline bool kvm_vcpu_running(struct kvm_vcpu *vcpu)
static inline int kvm_vcpu_running(struct kvm_vcpu *vcpu)
{
if (is_guest_mode(vcpu))
kvm_check_nested_events(vcpu);
int r;
if (is_guest_mode(vcpu)) {
r = kvm_check_nested_events(vcpu);
if (r < 0 && r != -EBUSY)
return r;
}

return (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE &&
!vcpu->arch.apf.halted);
Expand All @@ -9780,12 +9784,16 @@ static int vcpu_run(struct kvm_vcpu *vcpu)
vcpu->arch.l1tf_flush_l1d = true;

for (;;) {
if (kvm_vcpu_running(vcpu)) {
r = vcpu_enter_guest(vcpu);
} else {
r = vcpu_block(kvm, vcpu);
r = kvm_vcpu_running(vcpu);
if (r < 0) {
r = 0;
break;
}

if (r)
r = vcpu_enter_guest(vcpu);
else
r = vcpu_block(kvm, vcpu);
if (r <= 0)
break;

Expand Down

0 comments on commit 680c7e3

Please sign in to comment.