From: Bin Guo <guobin@linux.alibaba.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, kvm@vger.kernel.org
Subject: [PATCH 2/2] kvm: fix kvm_irqchip_release_virq loop after swap-remove
Date: Sat, 9 May 2026 10:45:39 +0800 [thread overview]
Message-ID: <20260509024539.90998-3-guobin@linux.alibaba.com> (raw)
In-Reply-To: <20260509024539.90998-1-guobin@linux.alibaba.com>
In kvm_irqchip_release_virq(), when an entry matching the target GSI is
found, the code removes it by swapping in the last entry:
s->irq_routes->nr--;
*e = s->irq_routes->entries[s->irq_routes->nr];
However, the loop then increments `i` unconditionally, which means the
newly-swapped entry at position `i` is never re-checked. If that entry
also has `gsi == virq`, it will be skipped and left in the routing
table.
Fix this by decrementing `i` after the swap, so the same index is
re-examined in the next iteration.
Signed-off-by: Bin Guo <guobin@linux.alibaba.com>
---
accel/kvm/kvm-all.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 70bc2c86a2..3c5b62c97e 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -2278,6 +2278,7 @@ void kvm_irqchip_release_virq(KVMState *s, int virq)
if (e->gsi == virq) {
s->irq_routes->nr--;
*e = s->irq_routes->entries[s->irq_routes->nr];
+ i--;
}
}
clear_gsi(s, virq);
--
2.50.1 (Apple Git-155)
prev parent reply other threads:[~2026-05-09 2:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-09 2:45 [PATCH 0/2] kvm: minor cleanups in kvm_close and kvm_irqchip_release_virq Bin Guo
2026-05-09 2:45 ` [PATCH 1/2] kvm: remove redundant check in kvm_close Bin Guo
2026-05-09 2:45 ` Bin Guo [this message]
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=20260509024539.90998-3-guobin@linux.alibaba.com \
--to=guobin@linux.alibaba.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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