From: Peng Yang <pyangyyd@gmail.com>
To: Mark Brown <broonie@kernel.org>
Cc: Serge Semin <fancer.lancer@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 IRQ handler and error handler on SMP
Date: Mon, 8 Jun 2026 17:58:49 +0800 [thread overview]
Message-ID: <20260608095849.3446-1-pyangyyd@amazon.com> (raw)
In-Reply-To: <20260522095727.18307-1-pyangyyd@amazon.com>
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.
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.
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
@@ -486,10 +486,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
next prev parent reply other threads:[~2026-06-08 9:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-22 9:57 [PATCH] spi: dw: fix race between transfer IRQ handler and timeout handler Peng Yang
2026-05-25 14:32 ` Mark Brown
[not found] ` <TYRP286MB5365F4E370E3F4862A598B56A60B2@TYRP286MB5365.JPNP286.PROD.OUTLOOK.COM>
2026-05-26 11:33 ` Mark Brown
2026-05-27 8:20 ` Peng Yang
2026-06-08 9:58 ` Peng Yang [this message]
2026-06-08 13:10 ` [PATCH v2] spi: dw: fix race between IRQ handler and error handler on SMP Mark Brown
2026-06-09 23:07 ` 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=20260608095849.3446-1-pyangyyd@amazon.com \
--to=pyangyyd@gmail.com \
--cc=broonie@kernel.org \
--cc=fancer.lancer@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