Skip to contentSkip to conversation

spi: dw: fix race between transfer IRQ handler and timeout handler

PATCH In review Peng Yang 2 participants 2 messages Jun 9 SPI

lore
Share & tools
lore

Peng Yang

author
#0 lore raw

PATCH v2 1/1 spi: dw: fix race between transfer IRQ handler and timeout handler

On SMP systems, dw_spi_handle_err() can be called from the SPI core kthread while the IRQ handler is still accessing the FIFO on another CPU. Resetting the chip via dw_spi_reset_chip() during an active FIFO read/write causes a bus error.

Fix this by calling disable_irq() before the chip reset, which masks the IRQ and waits for any in-flight handler to complete via synchronize_irq(). This ensures no handler is accessing the FIFO when the reset occurs.

Fixes 0b6bfad4cee4 ("spi: spi-dw: Remove extraneous locking")

---
v1 -> v2:
- Replace spinlock with disable_irq()/enable_irq() as suggested by Jonathan Chocron. This avoids touching the IRQ handler hot path entirely.

v1: https://lore.kernel.org/linux-spi/[email protected]/

 drivers/spi/spi-dw-core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/spi/spi-dw-core.c +2 -0
@@ -468,10 +468,12 @@ static inline void dw_spi_abort(struct spi_controller *ctlr)
 {
 	struct dw_spi *dws = spi_controller_get_devdata(ctlr);
 
 	if (dws->dma_mapped)
 		dws->dma_ops->dma_stop(dws);
 
+	disable_irq(dws->irq);
 	dw_spi_reset_chip(dws);
+	enable_irq(dws->irq);
 }
 
 static void dw_spi_handle_err(struct spi_controller *ctlr,
Signature · 1 line
2.40.1