Skip to content

Commit 5bd90b0

Browse files
author
Marc Zyngier
committed
KVM: vgic-v4: Track the number of VLPIs per vcpu
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 <[email protected]> Reviewed-by: Zenghui Yu <[email protected]> Reviewed-by: Christoffer Dall <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9090825 commit 5bd90b0

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

include/linux/irqchip/arm-gic-v4.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ struct its_vm {
3232
struct its_vpe {
3333
struct page *vpt_page;
3434
struct its_vm *its_vm;
35+
/* per-vPE VLPI tracking */
36+
atomic_t vlpi_count;
3537
/* Doorbell interrupt */
3638
int irq;
3739
irq_hw_number_t vpe_db_lpi;

virt/kvm/arm/vgic/vgic-init.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu)
203203

204204
INIT_LIST_HEAD(&vgic_cpu->ap_list_head);
205205
raw_spin_lock_init(&vgic_cpu->ap_list_lock);
206+
atomic_set(&vgic_cpu->vgic_v3.its_vpe.vlpi_count, 0);
206207

207208
/*
208209
* Enable and configure all SGIs to be edge-triggered and

virt/kvm/arm/vgic/vgic-its.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,10 @@ static int update_affinity(struct vgic_irq *irq, struct kvm_vcpu *vcpu)
360360
if (ret)
361361
return ret;
362362

363+
if (map.vpe)
364+
atomic_dec(&map.vpe->vlpi_count);
363365
map.vpe = &vcpu->arch.vgic_cpu.vgic_v3.its_vpe;
366+
atomic_inc(&map.vpe->vlpi_count);
364367

365368
ret = its_map_vlpi(irq->host_irq, &map);
366369
}

virt/kvm/arm/vgic/vgic-v4.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ int kvm_vgic_v4_set_forwarding(struct kvm *kvm, int virq,
309309

310310
irq->hw = true;
311311
irq->host_irq = virq;
312+
atomic_inc(&map.vpe->vlpi_count);
312313

313314
out:
314315
mutex_unlock(&its->its_lock);
@@ -342,6 +343,7 @@ int kvm_vgic_v4_unset_forwarding(struct kvm *kvm, int virq,
342343

343344
WARN_ON(!(irq->hw && irq->host_irq == virq));
344345
if (irq->hw) {
346+
atomic_dec(&irq->target_vcpu->arch.vgic_cpu.vgic_v3.its_vpe.vlpi_count);
345347
irq->hw = false;
346348
ret = its_unmap_vlpi(virq);
347349
}

0 commit comments

Comments
 (0)