KVM: vgic-v4: Track the number of VLPIs per vcpu
authorMarc Zyngier <maz@kernel.org>
Thu, 7 Nov 2019 16:04:11 +0000 (16:04 +0000)
committerMarc Zyngier <maz@kernel.org>
Fri, 8 Nov 2019 11:13:24 +0000 (11:13 +0000)
In order to find out whether a vcpu is likely to be the target of
VLPIs (and to further optimize the way we deal with those), let's
track the number of VLPIs a vcpu can receive.

This gets implemented with an atomic variable that gets incremented
or decremented on map, unmap and move of a VLPI.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Zenghui Yu <yuzenghui@huawei.com>
Reviewed-by: Christoffer Dall <christoffer.dall@arm.com>
Link: https://lore.kernel.org/r/20191107160412.30301-2-maz@kernel.org
include/linux/irqchip/arm-gic-v4.h
virt/kvm/arm/vgic/vgic-init.c
virt/kvm/arm/vgic/vgic-its.c
virt/kvm/arm/vgic/vgic-v4.c

index ab1396a..5dbcfc6 100644 (file)
@@ -32,6 +32,8 @@ struct its_vm {
 struct its_vpe {
        struct page             *vpt_page;
        struct its_vm           *its_vm;
+       /* per-vPE VLPI tracking */
+       atomic_t                vlpi_count;
        /* Doorbell interrupt */
        int                     irq;
        irq_hw_number_t         vpe_db_lpi;
index 6f50c42..b3c5de4 100644 (file)
@@ -203,6 +203,7 @@ int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu)
 
        INIT_LIST_HEAD(&vgic_cpu->ap_list_head);
        raw_spin_lock_init(&vgic_cpu->ap_list_lock);
+       atomic_set(&vgic_cpu->vgic_v3.its_vpe.vlpi_count, 0);
 
        /*
         * Enable and configure all SGIs to be edge-triggered and
index 2be6b66..98c7360 100644 (file)
@@ -360,7 +360,10 @@ static int update_affinity(struct vgic_irq *irq, struct kvm_vcpu *vcpu)
                if (ret)
                        return ret;
 
+               if (map.vpe)
+                       atomic_dec(&map.vpe->vlpi_count);
                map.vpe = &vcpu->arch.vgic_cpu.vgic_v3.its_vpe;
+               atomic_inc(&map.vpe->vlpi_count);
 
                ret = its_map_vlpi(irq->host_irq, &map);
        }
index 0965fb0..46f8755 100644 (file)
@@ -309,6 +309,7 @@ int kvm_vgic_v4_set_forwarding(struct kvm *kvm, int virq,
 
        irq->hw         = true;
        irq->host_irq   = virq;
+       atomic_inc(&map.vpe->vlpi_count);
 
 out:
        mutex_unlock(&its->its_lock);
@@ -342,6 +343,7 @@ int kvm_vgic_v4_unset_forwarding(struct kvm *kvm, int virq,
 
        WARN_ON(!(irq->hw && irq->host_irq == virq));
        if (irq->hw) {
+               atomic_dec(&irq->target_vcpu->arch.vgic_cpu.vgic_v3.its_vpe.vlpi_count);
                irq->hw = false;
                ret = its_unmap_vlpi(virq);
        }