Skip to content

Commit bf67272

Browse files
Maxim Levitskybonzini
authored andcommitted
KVM: x86: check the kvm_cpu_get_interrupt result before using it
The code was blindly assuming that kvm_cpu_get_interrupt never returns -1 when there is a pending interrupt. While this should be true, a bug in KVM can still cause this. If -1 is returned, the code before this patch was converting it to 0xFF, and 0xFF interrupt was injected to the guest, which results in an issue which was hard to debug. Add WARN_ON_ONCE to catch this case and skip the injection if this happens again. Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> Message-Id: <20230726135945.260841-4-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent cff540e commit bf67272

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

arch/x86/kvm/x86.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10203,9 +10203,13 @@ static int kvm_check_and_inject_events(struct kvm_vcpu *vcpu,
1020310203
if (r < 0)
1020410204
goto out;
1020510205
if (r) {
10206-
kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu), false);
10207-
static_call(kvm_x86_inject_irq)(vcpu, false);
10208-
WARN_ON(static_call(kvm_x86_interrupt_allowed)(vcpu, true) < 0);
10206+
int irq = kvm_cpu_get_interrupt(vcpu);
10207+
10208+
if (!WARN_ON_ONCE(irq == -1)) {
10209+
kvm_queue_interrupt(vcpu, irq, false);
10210+
static_call(kvm_x86_inject_irq)(vcpu, false);
10211+
WARN_ON(static_call(kvm_x86_interrupt_allowed)(vcpu, true) < 0);
10212+
}
1020910213
}
1021010214
if (kvm_cpu_has_injectable_intr(vcpu))
1021110215
static_call(kvm_x86_enable_irq_window)(vcpu);

0 commit comments

Comments
 (0)