mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1] KVM: arm64: vgic: Use new IRQ type helpers in vgic_try_get_irq_ref()
@ 2026-11-04 21:22 Wei-Lin Chang
  0 siblings, 0 replies; only message in thread
From: Wei-Lin Chang @ 2026-11-04 21:22 UTC (permalink / raw)
  To: linux-arm-kernel, kvmarm, linux-kernel
  Cc: Marc Zyngier, Oliver Upton, Fuad Tabba, Joey Gouly,
	Steffen Eiden, Suzuki K Poulose, Zenghui Yu, Catalin Marinas,
	Will Deacon, Mark Rutland, Carlos López, Eric Auger,
	Sascha Bischoff, Jackie Liu, Jonathan Cameron, Wei-Lin Chang

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.

Signed-off-by: Wei-Lin Chang <weilin.chang@arm.com>
---
This caught my attention while looking at:
https://lore.kernel.org/kvmarm/20261102194454.4086911-9-sascha.bischoff@arm.com/
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(-)

diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c
index 5ce485485a11..9d3dfb0e525e 100644
--- a/arch/arm64/kvm/vgic/vgic-its.c
+++ b/arch/arm64/kvm/vgic/vgic-its.c
@@ -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);
 
diff --git a/arch/arm64/kvm/vgic/vgic-v4.c b/arch/arm64/kvm/vgic/vgic-v4.c
index 1b7623f098e2..95b82a153134 100644
--- a/arch/arm64/kvm/vgic/vgic-v4.c
+++ b/arch/arm64/kvm/vgic/vgic-v4.c
@@ -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;
diff --git a/arch/arm64/kvm/vgic/vgic.c b/arch/arm64/kvm/vgic/vgic.c
index fe09ada32262..e1072b819245 100644
--- a/arch/arm64/kvm/vgic/vgic.c
+++ b/arch/arm64/kvm/vgic/vgic.c
@@ -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;
 				}
 			}
diff --git a/arch/arm64/kvm/vgic/vgic.h b/arch/arm64/kvm/vgic/vgic.h
index 71c481ddd98d..fe7b508ce172 100644
--- a/arch/arm64/kvm/vgic/vgic.h
+++ b/arch/arm64/kvm/vgic/vgic.h
@@ -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);
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-04 21:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04 21:22 [PATCH v1] KVM: arm64: vgic: Use new IRQ type helpers in vgic_try_get_irq_ref() Wei-Lin Chang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®