KVM: arm64: vgic: Use new IRQ type helpers in vgic_try_get_irq_ref()
PATCH 1/1 KVM: arm64: vgic: Use new IRQ type helpers in vgic_try_get_irq_ref()
Commit eb8bce08ecb1 ("KVM: arm64: gic: Introduce interrupt type helpers") introduced GICv3/v5-aware helpers to distinguish PPIs, SGIs, SPIs, and LPIs.
However unlike vgic_put_irq(), vgic_try_get_irq_ref() wasn't updated and is still using irq->intid < VGIC_MIN_LPI to detect LPIs. Although vGICv5 paths aren't referencing vgic_try_get_irq_ref() at the moment, let's still do the correct thing and use the new irq_is_lpi() to avoid future bugs.
---
This caught my attention while looking at:
https://lore.kernel.org/kvmarm/[email protected]/
The ITS translation cache look up calls vgic_try_get_irq_ref(). The logic irq->intid < VGIC_MIN_LPI is wrong for GICv5, but since GICv5 vgic_irq->intid have the IRQ type encoded in the top bits the comparison yields correct results by coincidence.
arch/arm64/kvm/vgic/vgic-its.c | 6 +++--- arch/arm64/kvm/vgic/vgic-v4.c | 2 +- arch/arm64/kvm/vgic/vgic.c | 8 ++++---- arch/arm64/kvm/vgic/vgic.h | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-)
arch/arm64/kvm/vgic/vgic-its.c +3 -3
@@ -111,7 +111,7 @@ static struct vgic_irq *vgic_add_lpi(struct kvm *kvm, u32 intid,* check that we don't add a second list entry with the same LPI. */ oldirq =xa_load (&dist->lpi_xa, intid); -if (vgic_try_get_irq_ref (oldirq)) { +if (vgic_try_get_irq_ref (kvm, oldirq)) {/* Someone was faster with adding this LPI, lets use that. */ kfree (irq); irq = oldirq;
@@ -560,7 +560,7 @@ static struct vgic_irq *vgic_its_check_cache(struct kvm *kvm, phys_addr_t db,rcu_read_lock (); irq =xa_load (&its->translation_cache, cache_key); -if (!vgic_try_get_irq_ref (irq)) +if (!vgic_try_get_irq_ref (kvm, irq)) irq =NULL ;rcu_read_unlock ();
@@ -584,7 +584,7 @@ static void vgic_its_cache_translation(struct kvm *kvm, struct vgic_its *its,* its_lock, as the ITE (and the reference it holds) cannot be freed. */ lockdep_assert_held (&its->its_lock); -vgic_get_irq_ref (irq); +vgic_get_irq_ref (kvm, irq); old =xa_store (&its->translation_cache, cache_key, irq,GFP_KERNEL_ACCOUNT );
arch/arm64/kvm/vgic/vgic-v4.c +1 -1
@@ -524,7 +524,7 @@ static struct vgic_irq *__vgic_host_irq_get_vlpi(struct kvm *kvm, int host_irq)if (!irq->hw || irq->host_irq != host_irq)continue ; -if (!vgic_try_get_irq_ref (irq)) +if (!vgic_try_get_irq_ref (kvm, irq))return NULL ;return irq;
arch/arm64/kvm/vgic/vgic.c +4 -4
@@ -71,7 +71,7 @@ static struct vgic_irq *vgic_get_lpi(struct kvm *kvm, u32 intid)rcu_read_lock (); irq =xa_load (&dist->lpi_xa, intid); -if (!vgic_try_get_irq_ref (irq)) +if (!vgic_try_get_irq_ref (kvm, irq)) irq =NULL ;rcu_read_unlock ();
@@ -507,7 +507,7 @@ bool vgic_queue_irq_unlock(struct kvm *kvm, struct vgic_irq *irq,* now in the ap_list. This is safe as the caller must already hold a * reference on the irq. */ -vgic_get_irq_ref (irq); +vgic_get_irq_ref (kvm, irq);list_add_tail (&irq->ap_list, &vcpu->arch.vgic_cpu.ap_list_head); irq->vcpu = vcpu;
@@ -817,7 +817,7 @@ static void vgic_prune_ap_list(struct kvm_vcpu *vcpu)* This interrupt looks like it has to be migrated, * make sure it is kept alive while locks are dropped. */ -vgic_get_irq_ref (irq); +vgic_get_irq_ref (vcpu->kvm, irq);raw_spin_unlock (&irq->irq_lock);raw_spin_unlock (&vgic_cpu->ap_list_lock);
@@ -1049,7 +1049,7 @@ static void vgic_flush_lr_state(struct kvm_vcpu *vcpu)if (likely (vgic_target_oracle (irq) == vcpu)) {vgic_populate_lr (vcpu, irq, count++);if (count == kvm_vgic_global_state.nr_lr) { -vgic_get_irq_ref (irq); +vgic_get_irq_ref (vcpu->kvm, irq); *host_data_ptr (last_lr_irq) = irq; } }
arch/arm64/kvm/vgic/vgic.h +4 -4
@@ -320,20 +320,20 @@ void vgic_v2_put(struct kvm_vcpu *vcpu);void vgic_v2_save_state (struct kvm_vcpu *vcpu);void vgic_v2_restore_state (struct kvm_vcpu *vcpu); -static inline bool vgic_try_get_irq_ref (struct vgic_irq *irq) +static inline bool vgic_try_get_irq_ref (struct kvm *kvm,struct vgic_irq *irq) {if (!irq)return false; -if (irq->intid <VGIC_MIN_LPI ) +if (!irq_is_lpi (kvm, irq->intid))return true;return refcount_inc_not_zero (&irq->refcount); } -static inline void vgic_get_irq_ref (struct vgic_irq *irq) +static inline void vgic_get_irq_ref (struct kvm *kvm,struct vgic_irq *irq) { -WARN_ON_ONCE (!vgic_try_get_irq_ref (irq)); +WARN_ON_ONCE (!vgic_try_get_irq_ref (kvm, irq)); }void vgic_v3_fold_lr_state (struct kvm_vcpu *vcpu);
Signature · 1 line
2.43.0