mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-28 12:53:14 +01:00
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 <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
This commit is contained in:
1 parent
cff540ebef
commit
bf672720e8
1 file changed
+7
-3
+7
-3
@@ -10203,9 +10203,13 @@ static int kvm_check_and_inject_events(struct kvm_vcpu *vcpu,
|
||||
if (r < 0)
|
||||
goto out;
|
||||
if (r) {
|
||||
kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu), false);
|
||||
static_call(kvm_x86_inject_irq)(vcpu, false);
|
||||
WARN_ON(static_call(kvm_x86_interrupt_allowed)(vcpu, true) < 0);
|
||||
int irq = kvm_cpu_get_interrupt(vcpu);
|
||||
|
||||
if (!WARN_ON_ONCE(irq == -1)) {
|
||||
kvm_queue_interrupt(vcpu, irq, false);
|
||||
static_call(kvm_x86_inject_irq)(vcpu, false);
|
||||
WARN_ON(static_call(kvm_x86_interrupt_allowed)(vcpu, true) < 0);
|
||||
}
|
||||
}
|
||||
if (kvm_cpu_has_injectable_intr(vcpu))
|
||||
static_call(kvm_x86_enable_irq_window)(vcpu);
|
||||
|
||||
Reference in new issue
Block a user