Browse Source

KVM: arm/arm64: vgic: Add missing irq_lock to vgic_mmio_read_pending

Our irq_is_pending() helper function accesses multiple members of the
vgic_irq struct, so we need to hold the lock when calling it.
Add that requirement as a comment to the definition and take the lock
around the call in vgic_mmio_read_pending(), where we were missing it
before.

Fixes: 96b298000db4 ("KVM: arm/arm64: vgic-new: Add PENDING registers handlers")
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Andre Przywara 7 years ago
parent
commit
62b06f8f42
2 changed files with 4 additions and 0 deletions
  1. 3 0
      virt/kvm/arm/vgic/vgic-mmio.c
  2. 1 0
      virt/kvm/arm/vgic/vgic.h

+ 3 - 0
virt/kvm/arm/vgic/vgic-mmio.c

@@ -113,9 +113,12 @@ unsigned long vgic_mmio_read_pending(struct kvm_vcpu *vcpu,
 	/* Loop over all IRQs affected by this read */
 	/* Loop over all IRQs affected by this read */
 	for (i = 0; i < len * 8; i++) {
 	for (i = 0; i < len * 8; i++) {
 		struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, intid + i);
 		struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, intid + i);
+		unsigned long flags;
 
 
+		spin_lock_irqsave(&irq->irq_lock, flags);
 		if (irq_is_pending(irq))
 		if (irq_is_pending(irq))
 			value |= (1U << i);
 			value |= (1U << i);
+		spin_unlock_irqrestore(&irq->irq_lock, flags);
 
 
 		vgic_put_irq(vcpu->kvm, irq);
 		vgic_put_irq(vcpu->kvm, irq);
 	}
 	}

+ 1 - 0
virt/kvm/arm/vgic/vgic.h

@@ -96,6 +96,7 @@
 /* we only support 64 kB translation table page size */
 /* we only support 64 kB translation table page size */
 #define KVM_ITS_L1E_ADDR_MASK		GENMASK_ULL(51, 16)
 #define KVM_ITS_L1E_ADDR_MASK		GENMASK_ULL(51, 16)
 
 
+/* Requires the irq_lock to be held by the caller. */
 static inline bool irq_is_pending(struct vgic_irq *irq)
 static inline bool irq_is_pending(struct vgic_irq *irq)
 {
 {
 	if (irq->config == VGIC_CONFIG_EDGE)
 	if (irq->config == VGIC_CONFIG_EDGE)