[PATCH v2 2/5] irqchip/riscv-imsic: Complete pending vector moves on the outgoing CPU
From: Zhanpeng Zhang
Date: Thu Dec 03 2026 - 07:32:20 EST
When a CPU is going offline, forced move completion can return the
source vector to the matrix before running its pending local sync.
This clears the vector's IRQ number while leaving its move_next link
and dirty bit set. The outgoing CPU then runs local sync and can look
up irq_data for IRQ 0 when checking the temporary MSI target.
Run local sync on the outgoing CPU if the source still points to the
same destination. This forwards any pending MSIs and clears the link
before returning the ID to the matrix. Drop the destination's reverse
link after releasing the source CPU's lock.
Fixes: 51611130d57d ("irqchip/riscv-imsic: Implement irq_force_complete_move() for IMSIC")
Signed-off-by: Zhanpeng Zhang <zhangzhanpeng.jasper@xxxxxxxxxxxxx>
---
drivers/irqchip/irq-riscv-imsic-state.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c
index 453591443..07e703989 100644
--- a/drivers/irqchip/irq-riscv-imsic-state.c
+++ b/drivers/irqchip/irq-riscv-imsic-state.c
@@ -377,18 +377,23 @@ void imsic_vector_unmask(struct imsic_vector *vec)
void imsic_vector_force_move_cleanup(struct imsic_vector *vec)
{
+ struct imsic_vector *prev = READ_ONCE(vec->move_prev);
struct imsic_local_priv *lpriv;
- struct imsic_vector *mvec;
unsigned long flags;
- lpriv = per_cpu_ptr(imsic->lpriv, vec->cpu);
+ if (!prev)
+ return;
+
+ /* The caller runs on the old CPU and serializes affinity changes. */
+ lpriv = this_cpu_ptr(imsic->lpriv);
raw_spin_lock_irqsave(&lpriv->lock, flags);
+ if (prev->move_next == vec)
+ __imsic_local_sync(lpriv);
+ raw_spin_unlock_irqrestore(&lpriv->lock, flags);
- mvec = READ_ONCE(vec->move_prev);
+ lpriv = per_cpu_ptr(imsic->lpriv, vec->cpu);
+ raw_spin_lock_irqsave(&lpriv->lock, flags);
WRITE_ONCE(vec->move_prev, NULL);
- if (mvec)
- imsic_vector_free(mvec);
-
raw_spin_unlock_irqrestore(&lpriv->lock, flags);
}