mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Markus Klotzbuecher <mk@mkio.de>
To: Mark Brown <broonie@kernel.org>
Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-omap@vger.kernel.org,
	Sahaj Chaudhari <sahaj123.sc@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] spi: omap2-mcspi: lock the DMA request bit updates
Date: Wed, 25 Nov 2026 17:13:40 +0100	[thread overview]
Message-ID: <20261125161340.1218564-1-mk@mkio.de> (raw)

omap2_mcspi_set_dma_req() does an unlocked read-modify-write of the
cached CHCONF value to set or clear DMAR/DMAW. On full-duplex DMA
transfers the RX and TX completion callbacks both call it to clear
their own bit. The callbacks are invoked from the per-channel dmaengine
tasklets, which can run concurrently on different CPUs. One of them
can then write back a stale copy that still has the other's bit set.

DMAR or DMAW then stays set in the cached value and is written back by
every later CHCONF update. With a stale DMAR, the next PIO transfer
times out waiting for RXS and the next RX DMA completes early.

Protect the read-modify-write in omap2_mcspi_set_dma_req() with a
spinlock. All other CHCONF updates run in the transfer thread while no
DMA callback is pending, so only this helper needs the lock.

Tested on a TI AM625 with linux-stable 6.18 PREEMPT_RT, a device on
McSPI2 CS1 at 50 MHz and four spidev transfers per cycle, the larger
ones via DMA. An instrumented kernel that flags stale DMAR/DMAW on PIO
entry reported more than 720 stale bit events and DMA transfer errors
in 15 minutes without this change, and none over an 11.5 hour soak
with it.

Fixes: 53741ed8f0a3 ("spi: omap2-mcspi: add DMA engine support")
Cc: stable@vger.kernel.org
Signed-off-by: Markus Klotzbuecher <mk@mkio.de>
---
Tested on 6.18.y with commit c126e07bde21 ("spi: omap2-mcspi: handle
DMA setup failures"); omap2_mcspi_set_dma_req() and the DMA callbacks
are the same on spi for-next. Compile-tested on spi for-next.

 drivers/spi/spi-omap2-mcspi.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index 061d50c65dfd..b1d3b8447d0b 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -118,6 +118,8 @@ struct omap2_mcspi_regs {
 
 struct omap2_mcspi {
 	struct completion	txdone;
+	/* serializes the DMAR/DMAW read-modify-write of the cached chconf */
+	spinlock_t		chconf_lock;
 	struct spi_controller	*ctlr;
 	/* Virtual base address of the controller */
 	void __iomem		*base;
@@ -205,8 +207,11 @@ static inline int mcspi_bytes_per_word(int word_len)
 static void omap2_mcspi_set_dma_req(const struct spi_device *spi,
 		int is_read, int enable)
 {
+	struct omap2_mcspi *mcspi = spi_controller_get_devdata(spi->controller);
+	unsigned long flags;
 	u32 l, rw;
 
+	spin_lock_irqsave(&mcspi->chconf_lock, flags);
 	l = mcspi_cached_chconf0(spi);
 
 	if (is_read) /* 1 is read, 0 write */
@@ -220,6 +225,7 @@ static void omap2_mcspi_set_dma_req(const struct spi_device *spi,
 		l &= ~rw;
 
 	mcspi_write_chconf0(spi, l);
+	spin_unlock_irqrestore(&mcspi->chconf_lock, flags);
 }
 
 static void omap2_mcspi_set_enable(const struct spi_device *spi, int enable)
@@ -1630,6 +1636,7 @@ static int omap2_mcspi_probe(struct platform_device *pdev)
 	mcspi->base += regs_offset;
 
 	mcspi->dev = &pdev->dev;
+	spin_lock_init(&mcspi->chconf_lock);
 
 	INIT_LIST_HEAD(&mcspi->ctx.cs);
 

base-commit: 266ae6df1980a5a5c58735ae114ae62a2acad8db
-- 
2.53.0



                 reply	other threads:[~2026-11-25 16:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261125161340.1218564-1-mk@mkio.de \
    --to=mk@mkio.de \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=sahaj123.sc@gmail.com \
    --cc=stable@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®