Skip to content

Commit 05f4d4f

Browse files
committed
KVM: arm64: vgic: Use atomics to count LPIs
Switch to using atomics for LPI accounting, allowing vgic_irq references to be dropped in parallel. Reviewed-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 9880835 commit 05f4d4f

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

arch/arm64/kvm/vgic/vgic-debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static void print_dist_state(struct seq_file *s, struct vgic_dist *dist)
149149
seq_printf(s, "vgic_model:\t%s\n", v3 ? "GICv3" : "GICv2");
150150
seq_printf(s, "nr_spis:\t%d\n", dist->nr_spis);
151151
if (v3)
152-
seq_printf(s, "nr_lpis:\t%d\n", dist->lpi_list_count);
152+
seq_printf(s, "nr_lpis:\t%d\n", atomic_read(&dist->lpi_count));
153153
seq_printf(s, "enabled:\t%d\n", dist->enabled);
154154
seq_printf(s, "\n");
155155

arch/arm64/kvm/vgic/vgic-its.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static struct vgic_irq *vgic_add_lpi(struct kvm *kvm, u32 intid,
9696
goto out_unlock;
9797
}
9898

99-
dist->lpi_list_count++;
99+
atomic_inc(&dist->lpi_count);
100100

101101
out_unlock:
102102
raw_spin_unlock_irqrestore(&dist->lpi_list_lock, flags);
@@ -346,7 +346,7 @@ int vgic_copy_lpi_list(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 **intid_ptr)
346346
* command). If coming from another path (such as enabling LPIs),
347347
* we must be careful not to overrun the array.
348348
*/
349-
irq_count = READ_ONCE(dist->lpi_list_count);
349+
irq_count = atomic_read(&dist->lpi_count);
350350
intids = kmalloc_array(irq_count, sizeof(intids[0]), GFP_KERNEL_ACCOUNT);
351351
if (!intids)
352352
return -ENOMEM;

arch/arm64/kvm/vgic/vgic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void __vgic_put_lpi_locked(struct kvm *kvm, struct vgic_irq *irq)
123123
return;
124124

125125
xa_erase(&dist->lpi_xa, irq->intid);
126-
dist->lpi_list_count--;
126+
atomic_dec(&dist->lpi_count);
127127

128128
kfree(irq);
129129
}

include/kvm/arm_vgic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,10 @@ struct vgic_dist {
273273
*/
274274
u64 propbaser;
275275

276-
/* Protects the lpi_list and the count value below. */
276+
/* Protects the lpi_list. */
277277
raw_spinlock_t lpi_list_lock;
278278
struct xarray lpi_xa;
279-
int lpi_list_count;
279+
atomic_t lpi_count;
280280

281281
/* LPI translation cache */
282282
struct list_head lpi_translation_cache;

0 commit comments

Comments
 (0)