* [PATCH] KVM: x86: Handle -1 return from kvm_cpu_get_interrupt
@ 2026-07-12 9:00 Deepanshu Kartikey
2026-07-13 13:14 ` Sean Christopherson
0 siblings, 1 reply; 2+ messages in thread
From: Deepanshu Kartikey @ 2026-07-12 9:00 UTC (permalink / raw)
To: seanjc, pbonzini, tglx, mingo, bp, dave.hansen, x86, hpa
Cc: kvm, linux-kernel, Deepanshu Kartikey,
syzbot+9dcd0a11dc9703a49511
kvm_check_and_inject_events() checks for a pending PIC
interrupt using kvm_cpu_has_injectable_intr() and then
fetches it using kvm_cpu_get_interrupt(). These two
operations are not atomic with respect to vpic->output.
Between the check and fetch, another thread running on
a different CPU can call kvm_pic_read_irq() which sets
output=0 before taking pic_lock(), making it immediately
visible to all other threads:
Thread A: kvm_cpu_has_injectable_intr() reads output=1
Thread B: kvm_pic_read_irq() sets output=0 before lock
Thread A: kvm_cpu_get_interrupt() reads output=0
Thread A: returns -1, WARN_ON_ONCE fires
The -1 return is a valid result indicating another thread
already consumed the interrupt between the check and fetch.
Replace WARN_ON_ONCE with a graceful goto out to handle
this race condition correctly.
Reported-by: syzbot+9dcd0a11dc9703a49511@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?extid=9dcd0a11dc9703a49511
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
arch/x86/kvm/x86.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index afcac1042947..36bf479a1164 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10797,11 +10797,11 @@ static int kvm_check_and_inject_events(struct kvm_vcpu *vcpu,
if (r) {
int irq = kvm_cpu_get_interrupt(vcpu);
- if (!WARN_ON_ONCE(irq == -1)) {
- kvm_queue_interrupt(vcpu, irq, false);
- kvm_x86_call(inject_irq)(vcpu, false);
- WARN_ON(kvm_x86_call(interrupt_allowed)(vcpu, true) < 0);
- }
+ if (irq == -1)
+ goto out;
+ kvm_queue_interrupt(vcpu, irq, false);
+ kvm_x86_call(inject_irq)(vcpu, false);
+ WARN_ON(kvm_x86_call(interrupt_allowed)(vcpu, true) < 0);
}
if (kvm_cpu_has_injectable_intr(vcpu))
kvm_x86_call(enable_irq_window)(vcpu);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] KVM: x86: Handle -1 return from kvm_cpu_get_interrupt
2026-07-12 9:00 [PATCH] KVM: x86: Handle -1 return from kvm_cpu_get_interrupt Deepanshu Kartikey
@ 2026-07-13 13:14 ` Sean Christopherson
0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2026-07-13 13:14 UTC (permalink / raw)
To: Deepanshu Kartikey
Cc: pbonzini, tglx, mingo, bp, dave.hansen, x86, hpa, kvm,
linux-kernel, syzbot+9dcd0a11dc9703a49511
On Sun, Jul 12, 2026, Deepanshu Kartikey wrote:
> kvm_check_and_inject_events() checks for a pending PIC
> interrupt using kvm_cpu_has_injectable_intr() and then
> fetches it using kvm_cpu_get_interrupt(). These two
> operations are not atomic with respect to vpic->output.
>
> Between the check and fetch, another thread running on
> a different CPU can call kvm_pic_read_irq() which sets
> output=0 before taking pic_lock(), making it immediately
> visible to all other threads:
>
> Thread A: kvm_cpu_has_injectable_intr() reads output=1
> Thread B: kvm_pic_read_irq() sets output=0 before lock
> Thread A: kvm_cpu_get_interrupt() reads output=0
> Thread A: returns -1, WARN_ON_ONCE fires
>
> The -1 return is a valid result indicating another thread
> already consumed the interrupt between the check and fetch.
> Replace WARN_ON_ONCE with a graceful goto out to handle
> this race condition correctly.
>
> Reported-by: syzbot+9dcd0a11dc9703a49511@syzkaller.appspotmail.com
> Link: https://syzkaller.appspot.com/bug?extid=9dcd0a11dc9703a49511
Already being handled, thanks!
https://lore.kernel.org/all/86078441-92eb-4461-b823-7d3539ac5859@mail.kernel.org
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-13 13:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-12 9:00 [PATCH] KVM: x86: Handle -1 return from kvm_cpu_get_interrupt Deepanshu Kartikey
2026-07-13 13:14 ` Sean Christopherson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox