* [PATCH] KVM: arm64: vgic: Use list_del_rcu() when flushing pending LPIs
@ 2026-06-04 21:16 Hyunwoo Kim
2026-06-05 5:47 ` Oliver Upton
0 siblings, 1 reply; 3+ messages in thread
From: Hyunwoo Kim @ 2026-06-04 21:16 UTC (permalink / raw)
To: maz, oupton, joey.gouly, seiden, suzuki.poulose, yuzenghui,
catalin.marinas, will, Sascha.Bischoff, jic23
Cc: linux-arm-kernel, kvmarm, imv4bel
vgic_v3_fold_lr_state() walks the ap_list from last_lr_irq without holding
the ap_list_lock, relying on vgic_irq being freed via kfree_rcu() and on
interrupts being disabled. vgic_flush_pending_lpis() removes entries with
list_del(), which clobbers a node's next pointer, so when another vCPU
disables LPIs via GICR_CTLR the walk can follow the clobbered next pointer
from a removed node, or from the node that last_lr_irq points to.
Remove entries with list_del_rcu() so that the next pointer stays valid
until the walk completes.
Fixes: 3cfd59f81e0f ("KVM: arm64: GICv3: Handle LR overflow when EOImode==0")
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
---
arch/arm64/kvm/vgic/vgic.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm64/kvm/vgic/vgic.c b/arch/arm64/kvm/vgic/vgic.c
index 1e9fe8764584d..73efc0f95bfb1 100644
--- a/arch/arm64/kvm/vgic/vgic.c
+++ b/arch/arm64/kvm/vgic/vgic.c
@@ -204,7 +204,7 @@ void vgic_flush_pending_lpis(struct kvm_vcpu *vcpu)
list_for_each_entry_safe(irq, tmp, &vgic_cpu->ap_list_head, ap_list) {
if (irq_is_lpi(vcpu->kvm, irq->intid)) {
raw_spin_lock(&irq->irq_lock);
- list_del(&irq->ap_list);
+ list_del_rcu(&irq->ap_list);
irq->vcpu = NULL;
raw_spin_unlock(&irq->irq_lock);
deleted |= vgic_put_irq_norelease(vcpu->kvm, irq);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: arm64: vgic: Use list_del_rcu() when flushing pending LPIs
2026-06-04 21:16 [PATCH] KVM: arm64: vgic: Use list_del_rcu() when flushing pending LPIs Hyunwoo Kim
@ 2026-06-05 5:47 ` Oliver Upton
2026-06-05 8:17 ` Marc Zyngier
0 siblings, 1 reply; 3+ messages in thread
From: Oliver Upton @ 2026-06-05 5:47 UTC (permalink / raw)
To: Hyunwoo Kim
Cc: maz, joey.gouly, seiden, suzuki.poulose, yuzenghui,
catalin.marinas, will, Sascha.Bischoff, jic23, linux-arm-kernel,
kvmarm
Hi Hyunwoo,
On Fri, Jun 05, 2026 at 06:16:08AM +0900, Hyunwoo Kim wrote:
> vgic_v3_fold_lr_state() walks the ap_list from last_lr_irq without holding
> the ap_list_lock, relying on vgic_irq being freed via kfree_rcu() and on
> interrupts being disabled. vgic_flush_pending_lpis() removes entries with
> list_del(), which clobbers a node's next pointer, so when another vCPU
> disables LPIs via GICR_CTLR the walk can follow the clobbered next pointer
> from a removed node, or from the node that last_lr_irq points to.
>
> Remove entries with list_del_rcu() so that the next pointer stays valid
> until the walk completes.
>
> Fixes: 3cfd59f81e0f ("KVM: arm64: GICv3: Handle LR overflow when EOImode==0")
> Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
Changing only one of the writer paths to use the rculist helpers does
not make the ap_list an rculist. Insertions are not RCU-safe, nor are
deleations from vgic_prune_ap_list().
And TBH, the real bug here is the fact that vgic_v3_fold_lr_state() isn't
taking the ap_list_lock.
Thanks,
Oliver
> ---
> arch/arm64/kvm/vgic/vgic.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm64/kvm/vgic/vgic.c b/arch/arm64/kvm/vgic/vgic.c
> index 1e9fe8764584d..73efc0f95bfb1 100644
> --- a/arch/arm64/kvm/vgic/vgic.c
> +++ b/arch/arm64/kvm/vgic/vgic.c
> @@ -204,7 +204,7 @@ void vgic_flush_pending_lpis(struct kvm_vcpu *vcpu)
> list_for_each_entry_safe(irq, tmp, &vgic_cpu->ap_list_head, ap_list) {
> if (irq_is_lpi(vcpu->kvm, irq->intid)) {
> raw_spin_lock(&irq->irq_lock);
> - list_del(&irq->ap_list);
> + list_del_rcu(&irq->ap_list);
> irq->vcpu = NULL;
> raw_spin_unlock(&irq->irq_lock);
> deleted |= vgic_put_irq_norelease(vcpu->kvm, irq);
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: arm64: vgic: Use list_del_rcu() when flushing pending LPIs
2026-06-05 5:47 ` Oliver Upton
@ 2026-06-05 8:17 ` Marc Zyngier
0 siblings, 0 replies; 3+ messages in thread
From: Marc Zyngier @ 2026-06-05 8:17 UTC (permalink / raw)
To: Oliver Upton
Cc: Hyunwoo Kim, joey.gouly, seiden, suzuki.poulose, yuzenghui,
catalin.marinas, will, Sascha.Bischoff, jic23, linux-arm-kernel,
kvmarm
On Fri, 05 Jun 2026 06:47:17 +0100,
Oliver Upton <oupton@kernel.org> wrote:
>
> Hi Hyunwoo,
>
> On Fri, Jun 05, 2026 at 06:16:08AM +0900, Hyunwoo Kim wrote:
> > vgic_v3_fold_lr_state() walks the ap_list from last_lr_irq without holding
> > the ap_list_lock, relying on vgic_irq being freed via kfree_rcu() and on
> > interrupts being disabled. vgic_flush_pending_lpis() removes entries with
> > list_del(), which clobbers a node's next pointer, so when another vCPU
> > disables LPIs via GICR_CTLR the walk can follow the clobbered next pointer
> > from a removed node, or from the node that last_lr_irq points to.
> >
> > Remove entries with list_del_rcu() so that the next pointer stays valid
> > until the walk completes.
> >
> > Fixes: 3cfd59f81e0f ("KVM: arm64: GICv3: Handle LR overflow when EOImode==0")
> > Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
>
> Changing only one of the writer paths to use the rculist helpers does
> not make the ap_list an rculist. Insertions are not RCU-safe, nor are
> deleations from vgic_prune_ap_list().
>
> And TBH, the real bug here is the fact that vgic_v3_fold_lr_state() isn't
> taking the ap_list_lock.
Yup, that'd be more sensible. I need to convince myself that there is
no possible path from vgic_v*_fold_lr() to vgic_irq_queue_unlock(),
because that one does actually acquire that lock.
M.
--
Jazz isn't dead. It just smells funny.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-05 8:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-04 21:16 [PATCH] KVM: arm64: vgic: Use list_del_rcu() when flushing pending LPIs Hyunwoo Kim
2026-06-05 5:47 ` Oliver Upton
2026-06-05 8:17 ` Marc Zyngier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox