[PATCH v2 0/5] irqchip/riscv-imsic: Fix vector lifetime during IRQ migration

From: Zhanpeng Zhang

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


An IRQ move in the RISC-V IMSIC leaves a source vector on the old CPU
and a destination on the new CPU. The old CPU finishes the move from
its local sync path, which can run after the affinity change returns.

The host panicked on Linux 6.18 while a guest was running fio against
a VFIO passthrough device:

Unable to handle kernel NULL pointer dereference at virtual address 0000000000000010
irq_can_move_in_process_context+0x10/0x38
__imsic_local_sync+0x170/0x298
imsic_local_sync_all+0x7a/0xc8
imsic_handle_irq+0x2a/0x118

At the fault, a0 (the irq_data argument) was NULL. Commit 896f8e436f99
("irqchip/riscv-imsic: Special handling for non-atomic device MSI update")
introduced the failing lookup in v6.15. One teardown sequence
consistent with this trace is:

1. An IRQ moves from CPU A to CPU B. CPU A still has the move pending.
2. IRQ teardown returns CPU B's destination ID to the vector matrix
and the IRQ core releases the descriptor.
3. CPU A runs local sync and follows the old move link. The IRQ data
lookup can return NULL, and pending MSI forwarding can target an
ID that is already available for reuse.

CPU offlining has a separate path to a stale move. Forced completion
can return the source ID without clearing its forward link or dirty
bit. The outgoing CPU later runs local sync with the source IRQ
number already cleared.

There is also a window between reading the Linux IRQ number in the
IMSIC chained handler and looking up its descriptor. IRQ teardown
must wait for that reader before the core can reuse the IRQ number.

This series cancels the move during teardown and finishes pending
moves during CPU offlining. It then fixes completion tracking,
drains IMSIC dispatch before IRQ reuse, and uses the temporary MSI
ID recorded at affinity change to handle pending MSIs.

Changes since v1:
- Split the teardown, CPU offline, move tracking, dispatch lifetime
and temporary MSI changes into reviewable steps.
- Skip cleared IRQ mappings from the first teardown change and keep a
disabled ID reserved while another live move uses it temporarily.
- Describe the failure paths and why each change is needed.

v1: https://lore.kernel.org/r/20261202114905.1357-2-zhangzhanpeng.jasper@xxxxxxxxxxxxx

Zhanpeng Zhang (5):
irqchip/riscv-imsic: Cancel pending vector moves on IRQ teardown
irqchip/riscv-imsic: Complete pending vector moves on the outgoing CPU
irqchip/riscv-imsic: Wait for the matching vector move
irqchip/riscv-imsic: Finish vector retirement before IRQ reuse
irqchip/riscv-imsic: Use the recorded temporary MSI ID at completion

drivers/irqchip/irq-riscv-imsic-early.c | 5 +-
drivers/irqchip/irq-riscv-imsic-platform.c | 5 +-
drivers/irqchip/irq-riscv-imsic-state.c | 224 ++++++++++++++++++++++++-----
drivers/irqchip/irq-riscv-imsic-state.h | 6 +-
4 files changed, 204 insertions(+), 36 deletions(-)


base-commit: 693c2e04e3f1d4c59af236e1211b7b8cb165a790