[PATCH] kvm: fix irq route entries exceed gsi count 1024

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Create a new msi route entry needs 3 steps:
1) find out an unused gsi number from the gsi bitmap, and flush the msi route entries if the counter of used irq route entries equals global gsi count 1024 in function kvm_irqchip_get_virq.
2) add the new msi route entry and increase the counter of used irq route entries in function kvm_add_routing_entry.
3) commit the new msi route entry to kvm module in function kvm_irqchip_commit_routes. Especially, the kvm module will check the counter of used irq route entries again here. If the counter exceeds KVM_MAX_IRQ_ROUTES, which is same as the global gsi count 1024, will trigger assertion failure.

This procedure has some problem in one corner case.
For example, if the current counter of used irq route entries is 1023, and want to create a new msi route entry, will succeed finding an unused gsi number without flushing the msi route entries in step 1). However, an assertion failure will pop up in step 3), because the counter of used irq route entries is increased in step 2) and now is 1024.

This patch fix this BUG by flushing the msi route entries when try to get the last irq route entry.

Signed-off-by: Wei Tang <tangwei@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Xiubo Li <lixiubo@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Zhuoyu Zhang <zhangzhuoyu@xxxxxxxxxxxxxxxxxxxx>
---
 kvm-all.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kvm-all.c b/kvm-all.c
index bd9e764..9048f85 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1115,7 +1115,7 @@ static int kvm_irqchip_get_virq(KVMState *s)
      * number can succeed even though a new route entry cannot be added.
      * When this happens, flush dynamic MSI entries to free IRQ route entries.
      */
-    if (!kvm_direct_msi_allowed && s->irq_routes->nr == s->gsi_count) {
+    if (!kvm_direct_msi_allowed && s->irq_routes->nr == s->gsi_count - 1) {
         kvm_flush_dynamic_msi_routes(s);
     }
 
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux