From: Hao Zhang <hao_zhang_kdev@163.com>
To: "seanjc@google.com" <seanjc@google.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"Huang, Kai" <kai.huang@intel.com>
Subject: [PATCH v5 1/6] KVM: x86: ioapic: Update remote_irr only after successful delivery
Date: Wed, 12 Aug 2026 16:32:28 +0800 [thread overview]
Message-ID: <anwvnBuFNqKBthtZ@192.168.1.215> (raw)
In-Reply-To: <anwugm-oU0v1VM-t@192.168.1.215>
From: Hao Zhang <zhanghao1@kylinos.cn>
The I/O APIC sets remote_irr for level-triggered interrupts that have
been accepted by a local APIC and are waiting for an EOI.
ioapic_service() currently treats any non-zero return from
kvm_irq_delivery_to_apic() as successful delivery. But negative return
values are failures, not successful delivery. Setting remote_irr after
such a failed delivery leaves the pin blocked forever waiting for an EOI
that will never be generated.
The bug dates back to commit 4925663a079c ("KVM: Report IRQ injection
status to userspace."), which made ioapic_service() preserve and return
the delivery result, initialized the result to -1, but kept using
"ret != 0" as the condition for setting remote_irr. As a result, any
negative delivery failure that reaches this path is incorrectly treated
as a delivered level-triggered interrupt.
Update remote_irr only when the delivery result is positive, i.e. when
at least one local APIC accepted the interrupt.
Fixes: 4925663a079c ("KVM: Report IRQ injection status to userspace.")
Reviewed-by: Kai Huang <kai.huang@intel.com>
Signed-off-by: Hao Zhang <zhanghao1@kylinos.cn>
---
arch/x86/kvm/ioapic.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c
index 757667fb2bfa..24a7cc3b8b7e 100644
--- a/arch/x86/kvm/ioapic.c
+++ b/arch/x86/kvm/ioapic.c
@@ -491,7 +491,7 @@ static int ioapic_service(struct kvm_ioapic *ioapic, int irq, bool line_status)
} else
ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe);
- if (ret && irqe.trig_mode == IOAPIC_LEVEL_TRIG)
+ if (ret > 0 && irqe.trig_mode == IOAPIC_LEVEL_TRIG)
entry->fields.remote_irr = 1;
return ret;
--
2.15.0
next prev parent reply other threads:[~2026-08-12 8:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-12 8:27 [PATCH v5 0/6] KVM: x86: Fix IOAPIC remote_irr and irr_delivered handling Hao Zhang
2026-08-12 8:32 ` Hao Zhang [this message]
2026-08-12 8:34 ` [PATCH v5 2/6] KVM: selftests: Verify failed IOAPIC delivery preserves state Hao Zhang
2026-08-12 8:35 ` [PATCH v5 3/6] KVM: x86: ioapic: Preserve irr_delivered for duplicate edge interrupts Hao Zhang
2026-08-12 8:52 ` sashiko-bot
2026-08-12 8:37 ` [PATCH v5 4/6] KVM: selftests: Verify duplicate edge preserves IOAPIC state Hao Zhang
2026-08-12 8:39 ` [PATCH v5 5/6] KVM: x86: ioapic: Clear irr_delivered on level-triggered RTE Hao Zhang
2026-08-12 8:41 ` [PATCH v5 6/6] KVM: selftests: Verify edge-to-level clears IOAPIC state Hao Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=anwvnBuFNqKBthtZ@192.168.1.215 \
--to=hao_zhang_kdev@163.com \
--cc=kai.huang@intel.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox