Re: [v5 1/3] KVM: setup empty irq routing when create vm

From: Christian Borntraeger

Date: Mon May 04 2026 - 08:50:45 EST


Am 17.04.26 um 12:19 schrieb Paolo Bonzini:
On 4/17/26 11:36, Christian Borntraeger wrote:


         irq_rt = srcu_dereference_check(kvm->irq_routing, &kvm- >irq_srcu,
                                         lockdep_is_held(&kvm- >irq_lock));
         if (irq_rt && gsi < irq_rt->nr_rt_entries) {  <---------

Hmm, I guess I misread the code and the problem is likely not this.
Let me have another look.

It makes sense anyway, together with a similar extra element in
kvm_set_irq_routing():


Turns out that the bisect was wrong. the increased cpu consumption came from
commit aeb1b22a3ac8e94c791f06f16e921384794771fa ("KVM: Enable halt polling shrink parameter by default")
which kind of makes sense.


@Paolo, shall I do a patch with 0 nr_rt_entries anyway as discussed or shall we
drop this?




diff --git a/virt/kvm/irqchip.c b/virt/kvm/irqchip.c
index 462c70621247..c3e4fbbfed94 100644
--- a/virt/kvm/irqchip.c
+++ b/virt/kvm/irqchip.c
@@ -178,11 +178,9 @@ int kvm_set_irq_routing(struct kvm *kvm,
     for (i = 0; i < nr; ++i) {
         if (ue[i].gsi >= KVM_MAX_IRQ_ROUTES)
             return -EINVAL;
-        nr_rt_entries = max(nr_rt_entries, ue[i].gsi);
+        nr_rt_entries = max(nr_rt_entries + 1, ue[i].gsi);
     }

-    nr_rt_entries += 1;
-
     new = kzalloc_flex(*new, map, nr_rt_entries, GFP_KERNEL_ACCOUNT);
     if (!new)
         return -ENOMEM;
@@ -246,11 +244,11 @@ int kvm_init_irq_routing(struct kvm *kvm)
     struct kvm_irq_routing_table *new;
     int chip_size;

-    new = kzalloc_flex(*new, map, 1, GFP_KERNEL_ACCOUNT);
+    new = kzalloc_flex(*new, map, 0, GFP_KERNEL_ACCOUNT);
     if (!new)
         return -ENOMEM;

-    new->nr_rt_entries = 1;
+    new->nr_rt_entries = 0;

     chip_size = sizeof(int) * KVM_NR_IRQCHIPS * KVM_IRQCHIP_NUM_PINS;
     memset(new->chip, -1, chip_size);

Paolo