Linux SPI subsystem development
 help / color / mirror / Atom feed
From: Peng Yang <pyangyyd@gmail.com>
To: Mark Brown <broonie@kernel.org>
Cc: Serge Semin <fancer.lansen@gmail.com>,
	Jonathan Chocron <jonnyc@amazon.com>,
	linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	pyangyyd@amazon.com, pyangyyd@gmail.com
Subject: [PATCH v2] spi: dw: fix race between transfer IRQ handler and timeout handler
Date: Tue,  9 Jun 2026 18:29:55 +0800	[thread overview]
Message-ID: <20260609102956.2811-1-pyangyyd@amazon.com> (raw)

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")
Signed-off-by: Peng Yang <pyangyyd@amazon.com>
Suggested-by: Jonathan Chocron <jonnyc@amazon.com>
---
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/20260522095727.18307-1-pyangyyd@amazon.com/

 drivers/spi/spi-dw-core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c
--- a/drivers/spi/spi-dw-core.c
+++ b/drivers/spi/spi-dw-core.c
@@ -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,
-- 
2.40.1


             reply	other threads:[~2026-06-09 10:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09 10:29 Peng Yang [this message]
2026-06-09 21:28 ` [PATCH v2] spi: dw: fix race between transfer IRQ handler and timeout handler Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260609102956.2811-1-pyangyyd@amazon.com \
    --to=pyangyyd@gmail.com \
    --cc=broonie@kernel.org \
    --cc=fancer.lansen@gmail.com \
    --cc=jonnyc@amazon.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=pyangyyd@amazon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox