* [PATCH 0/2] kvm: minor cleanups in kvm_close and kvm_irqchip_release_virq
@ 2026-05-09 2:45 Bin Guo
2026-05-09 2:45 ` [PATCH 1/2] kvm: remove redundant check in kvm_close Bin Guo
2026-05-09 2:45 ` [PATCH 2/2] kvm: fix kvm_irqchip_release_virq loop after swap-remove Bin Guo
0 siblings, 2 replies; 3+ messages in thread
From: Bin Guo @ 2026-05-09 2:45 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, kvm
Two small cleanups in kvm-all.c:
- Patch 1 removes a redundant null/fd check in kvm_close() that
can never be true once the early-return guard at function entry
has already passed.
- Patch 2 fixes an off-by-one in kvm_irqchip_release_virq(): after
a swap-remove the newly placed entry at the same index was never
re-examined, so a duplicate GSI could be silently left in the
routing table.
Bin Guo (2):
kvm: remove redundant check in kvm_close
kvm: fix kvm_irqchip_release_virq loop after swap-remove
accel/kvm/kvm-all.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
--
2.50.1 (Apple Git-155)
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] kvm: remove redundant check in kvm_close
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 ` Bin Guo
2026-05-09 2:45 ` [PATCH 2/2] kvm: fix kvm_irqchip_release_virq loop after swap-remove Bin Guo
1 sibling, 0 replies; 3+ messages in thread
From: Bin Guo @ 2026-05-09 2:45 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, kvm
In kvm_close(), the condition `!kvm_state || kvm_state->fd == -1` is
checked at the function entry, causing an early return if either is
true. Later in the function, the same condition is redundantly checked
again before closing vmfd and fd.
Remove the redundant second check since it can never be true at that
point.
Signed-off-by: Bin Guo <guobin@linux.alibaba.com>
---
accel/kvm/kvm-all.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 92af42503b..70bc2c86a2 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -769,12 +769,11 @@ void kvm_close(void)
cpu->kvm_vcpu_stats_fd = -1;
}
- if (kvm_state && kvm_state->fd != -1) {
- close(kvm_state->vmfd);
- kvm_state->vmfd = -1;
- close(kvm_state->fd);
- kvm_state->fd = -1;
- }
+ close(kvm_state->vmfd);
+ kvm_state->vmfd = -1;
+ close(kvm_state->fd);
+ kvm_state->fd = -1;
+
kvm_state = NULL;
}
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] kvm: fix kvm_irqchip_release_virq loop after swap-remove
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
1 sibling, 0 replies; 3+ messages in thread
From: Bin Guo @ 2026-05-09 2:45 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, kvm
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)
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-09 2:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/2] kvm: fix kvm_irqchip_release_virq loop after swap-remove Bin Guo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox