[PATCH v2 3/5] irqchip/riscv-imsic: Wait for the matching vector move

From: Zhanpeng Zhang

Date: Thu Dec 03 2026 - 07:32:28 EST


The destination keeps move_prev until its local sync observes that
the old CPU has completed the move. In the meantime, the source ID
can be recycled and begin a move for a different IRQ. A non-NULL
move_next then makes the destination wait for an unrelated move.

Wait only while the source still points to this destination. Order
the old CPU's MSI writes before publishing completion and pair that
publication with the destination's acquire load.

Fixes: 0f67911e821c ("irqchip/riscv-imsic: Separate next and previous pointers in IMSIC vector")

Signed-off-by: Zhanpeng Zhang <zhangzhanpeng.jasper@xxxxxxxxxxxxx>
---
drivers/irqchip/irq-riscv-imsic-state.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c
index 07e703989..cc27fd624 100644
--- a/drivers/irqchip/irq-riscv-imsic-state.c
+++ b/drivers/irqchip/irq-riscv-imsic-state.c
@@ -192,10 +192,10 @@ static bool __imsic_local_sync(struct imsic_local_priv *lpriv)
mvec = READ_ONCE(vec->move_prev);
if (mvec) {
/*
- * If the old vector has not been updated then
- * try again in the next sync-up call.
+ * The old slot may have been reused for another IRQ.
*/
- if (READ_ONCE(mvec->move_next)) {
+ /* Pair with the old CPU publishing move completion. */
+ if (smp_load_acquire(&mvec->move_next) == vec) {
ret = false;
continue;
}
@@ -238,7 +238,10 @@ static bool __imsic_local_sync(struct imsic_local_priv *lpriv)
writel_relaxed(mvec->local_id, mlocal->msi_va);
}

- WRITE_ONCE(vec->move_next, NULL);
+ /* Order the retriggers before publishing completion. */
+ wmb();
+ /* Pair with the destination checking move_next. */
+ smp_store_release(&vec->move_next, NULL);
imsic_vector_free(vec);
}