Skip to contentSkip to conversation

KVM: arm64: vgic-debug: Don't put unmarked LPIs

PATCH Applied Zenghui Yu 3 participants 5 messages Aug 17, 2024 – Aug 19, 2024

Subsystems (2)
lore
Share & tools
lore

Zenghui Yu

author reviewer
#0 lore raw

PATCH 1/1 KVM: arm64: vgic-debug: Don't put unmarked LPIs

If there were LPIs being mapped behind our back (i.e., between .start() and .stop()), we would put them at iter_unmark_lpis() without checking if they were actually *marked*, which is obviously not good.

Switch to use the xa_for_each_marked() iterator to fix it.

Fixes 85d3ccc8b75b ("KVM: arm64: vgic-debug: Use an xarray mark for debug iterator")
---
 arch/arm64/kvm/vgic/vgic-debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/vgic/vgic-debug.c +1 -1
index bc74d06398ef..e1397ab2072a 100644
@@ -85,7 +85,7 @@ static void iter_unmark_lpis(struct kvm *kvm)
 	struct vgic_irq *irq;
 	unsigned long intid;
 
-	xa_for_each(&dist->lpi_xa, intid, irq) {
+	xa_for_each_marked(&dist->lpi_xa, intid, irq, LPI_XA_MARK_DEBUG_ITER) {
 		xa_clear_mark(&dist->lpi_xa, intid, LPI_XA_MARK_DEBUG_ITER);
 		vgic_put_irq(kvm, irq);
 	}
Signature · 1 line
2.33.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Zenghui Yu

If there were LPIs being mapped behind our back (i.e., between .start() and .stop()), we would put them at iter_unmark_lpis() without checking if they were actually *marked*, which is obviously not good.

Switch to use the xa_for_each_marked() iterator to fix it.

Fixes 85d3ccc8b75b ("KVM: arm64: vgic-debug: Use an xarray mark for debug iterator")
---
 arch/arm64/kvm/vgic/vgic-debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/vgic/vgic-debug.c +0 -0
index bc74d06398ef..e1397ab2072a 100644

arch/arm64/kvm/vgic/vgic-debug.c static void iter_unmark_lpis(struct kvm *kvm) · line 91

Quoted 8 lines
arch/arm64/kvm/vgic/vgic-debug.c +1 -1
@@ -85,7 +85,7 @@ static void iter_unmark_lpis(struct kvm *kvm)
 	struct vgic_irq *irq;
 	unsigned long intid;
 
-	xa_for_each(&dist->lpi_xa, intid, irq) {
+	xa_for_each_marked(&dist->lpi_xa, intid, irq, LPI_XA_MARK_DEBUG_ITER) {
 		xa_clear_mark(&dist->lpi_xa, intid, LPI_XA_MARK_DEBUG_ITER);
 		vgic_put_irq(kvm, irq);
 	}

Ouch. Nicely caught. I think this deserves a

With that,

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author reviewer
#2 lore raw
Quoted 31 lines · Marc Zyngier
Quoted 18 lines · Zenghui Yu

If there were LPIs being mapped behind our back (i.e., between .start() and .stop()), we would put them at iter_unmark_lpis() without checking if they were actually *marked*, which is obviously not good.

Switch to use the xa_for_each_marked() iterator to fix it.

Fixes 85d3ccc8b75b ("KVM: arm64: vgic-debug: Use an xarray mark for debug iterator")
---
 arch/arm64/kvm/vgic/vgic-debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/vgic/vgic-debug.c +0 -0
index bc74d06398ef..e1397ab2072a 100644

arch/arm64/kvm/vgic/vgic-debug.c static void iter_unmark_lpis(struct kvm *kvm) · line 91

Quoted 8 lines
arch/arm64/kvm/vgic/vgic-debug.c +1 -1
@@ -85,7 +85,7 @@ static void iter_unmark_lpis(struct kvm *kvm)
 	struct vgic_irq *irq;
 	unsigned long intid;
 
-	xa_for_each(&dist->lpi_xa, intid, irq) {
+	xa_for_each_marked(&dist->lpi_xa, intid, irq, LPI_XA_MARK_DEBUG_ITER) {
 		xa_clear_mark(&dist->lpi_xa, intid, LPI_XA_MARK_DEBUG_ITER);
 		vgic_put_irq(kvm, irq);
 	}

Ouch. Nicely caught. I think this deserves a

Quoted 1 line

Yup. I guess Oliver will help to add it when applying ;-)

Quoted 4 lines

With that,

Thanks!

Zenghui

#3 lore raw
Quoted 9 lines · Zenghui Yu
Quoted 8 lines · Marc Zyngier
Quoted 6 lines · Zenghui Yu

If there were LPIs being mapped behind our back (i.e., between .start() and .stop()), we would put them at iter_unmark_lpis() without checking if they were actually *marked*, which is obviously not good.

Switch to use the xa_for_each_marked() iterator to fix it.

Urgh, that's what I'd meant to do. Thanks for catching this Zenghui.

Quoted 22 lines
Quoted 22 lines
Quoted 11 lines
Fixes 85d3ccc8b75b ("KVM: arm64: vgic-debug: Use an xarray mark for debug iterator")
---
 arch/arm64/kvm/vgic/vgic-debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/vgic/vgic-debug.c +0 -0
index bc74d06398ef..e1397ab2072a 100644

arch/arm64/kvm/vgic/vgic-debug.c static void iter_unmark_lpis(struct kvm *kvm) · line 91

Quoted 8 lines
arch/arm64/kvm/vgic/vgic-debug.c +1 -1
@@ -85,7 +85,7 @@ static void iter_unmark_lpis(struct kvm *kvm)
 	struct vgic_irq *irq;
 	unsigned long intid;
 
-	xa_for_each(&dist->lpi_xa, intid, irq) {
+	xa_for_each_marked(&dist->lpi_xa, intid, irq, LPI_XA_MARK_DEBUG_ITER) {
 		xa_clear_mark(&dist->lpi_xa, intid, LPI_XA_MARK_DEBUG_ITER);
 		vgic_put_irq(kvm, irq);
 	}

Ouch. Nicely caught. I think this deserves a

Quoted 3 lines
Quoted 1 line

Yup. I guess Oliver will help to add it when applying ;-)

Indeed, I'll grab it here in a moment.

Quoted 5 lines
Quoted 4 lines

With that,

Thanks both!

Signature · 2 lines
Best,
Oliver
Applied
#4 lore raw
In reply to Zenghui Yu
Quoted 8 lines · Zenghui Yu

If there were LPIs being mapped behind our back (i.e., between .start() and .stop()), we would put them at iter_unmark_lpis() without checking if they were actually *marked*, which is obviously not good.

Switch to use the xa_for_each_marked() iterator to fix it.

[...]

Applied to kvmarm/fixes, thanks!

[1/1] KVM: arm64: vgic-debug: Don't put unmarked LPIs

      https://git.kernel.org/kvmarm/kvmarm/c/2240a50e6294

--
Best,
Oliver