From: sashiko-bot@kernel.org
To: "Markus Klotzbuecher" <mk@mkio.de>
Cc: dmaengine@vger.kernel.org, vkoul@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH] spi: omap2-mcspi: skip the TX drain wait in duplex
Date: Wed, 25 Nov 2026 16:50:45 +0000 [thread overview]
Message-ID: <sashiko-outbox-233780@kernel.org> (raw)
In-Reply-To: <20261125162045.1222271-1-mk@mkio.de>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] spi: omap2-mcspi: broken non-FIFO DMA handling in
omap2_mcspi_tx_duplex()
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] spi: omap2-mcspi: race condition in omap2_mcspi_set_dma_req()
[1]
--
commit be820d0974cd0a480f2639f996cc447a021feacc
Author: Markus Klotzbuecher <mk@mkio.de>
spi: omap2-mcspi: skip the TX drain wait in duplex
This commit skips DMA_PREP_INTERRUPT and the TX completion wait for host
full-duplex DMA transfers, clearing the TX DMA request after RX DMA
completes instead of in the TX callback.
Link: https://lore.kernel.org/r/20220822091531.27827-1-vaishnav.a@ti.com [1]
> diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
> index 061d50c65dfd0..1eaa86c8d892e 100644
> --- a/drivers/spi/spi-omap2-mcspi.c
> +++ b/drivers/spi/spi-omap2-mcspi.c
> @@ -413,6 +413,18 @@ static void omap2_mcspi_tx_callback(void *data)
> complete(&mcspi_dma->dma_tx_completion);
> }
>
> +/*
> + * In host full duplex the RX completion proves that every TX word was
> + * shifted out, so TX needs neither a callback nor k3-udma's peer drain
> + * check, which it defers to a kworker.
> + */
> +static bool omap2_mcspi_tx_duplex(struct spi_device *spi,
> + struct spi_transfer *xfer)
> +{
> + return xfer->tx_buf && xfer->rx_buf &&
> + !spi_controller_is_target(spi->controller);
> +}
[Severity: Medium]
Should omap2_mcspi_tx_duplex() also require mcspi->fifo_depth > 0?
When the transfer exceeds OMAP2_MCSPI_MAX_FIFOWCNT on controllers with
max_xfer_len == 0, omap2_mcspi_set_fifo() disables the FIFO and sets
mcspi->fifo_depth = 0. In that mode, omap2_mcspi_rx_dma() only transfers
elements - 1 words via DMA, disables the channel after dma_rx_completion,
polls OMAP2_MCSPI_CHSTAT_RXS for the last word, and re-enables the channel:
drivers/spi/spi-omap2-mcspi.c:omap2_mcspi_rx_dma() {
...
omap2_mcspi_set_enable(spi, 0);
elements = word_count - 1;
if (!mcspi_wait_for_reg_bit(chstat_reg, OMAP2_MCSPI_CHSTAT_RXS)) {
...
} else {
dev_err(&spi->dev, "DMA RX last word empty\n");
*count -= mcspi_bytes_per_word(word_len);
}
omap2_mcspi_set_enable(spi, 1);
return 0;
}
Without omap2_mcspi_tx_callback() clearing OMAP2_MCSPI_CHCONF_DMAW when
the last TX word is written, omap2_mcspi_rx_dma() re-enables the channel
while DMAW is still set and TX0 is empty, asserting a spurious TX DMA
request before omap2_mcspi_txrx_dma() clears DMAW.
In addition, if the last word has not shifted out when
omap2_mcspi_rx_dma() disables the channel after elements - 1 RX words, the
RXS poll times out, decrements *count, and returns 0.
omap2_mcspi_txrx_dma() then returns 0 without waiting for
dma_tx_completion or calling dmaengine_terminate_sync(mcspi_dma->dma_tx),
and omap2_mcspi_transfer_one() returns -EIO on count != t->len, allowing
the SPI core to unmap xfer->tx_sg while the TX DMA channel is still active.
[ ... ]
> @@ -672,6 +689,8 @@ static int omap2_mcspi_txrx_dma(struct spi_device *spi,
> &rx_submitted, &dma_started);
> if (ret)
> goto out;
> + if (omap2_mcspi_tx_duplex(spi, xfer))
> + omap2_mcspi_set_dma_req(spi, 0, 0);
[Severity: High]
This problem wasn't introduced by this patch, but nothing serializes
[1] the read-modify-write of the cached CHCONF0 register in
omap2_mcspi_set_dma_req() when RX and TX DMA completion callbacks run
concurrently on target full-duplex transfers:
CPU0 CPU1
omap2_mcspi_rx_callback() omap2_mcspi_tx_callback()
omap2_mcspi_set_dma_req(..., 1, 0) omap2_mcspi_set_dma_req(..., 0, 0)
l = mcspi_cached_chconf0(spi);
l = mcspi_cached_chconf0(spi);
l &= ~OMAP2_MCSPI_CHCONF_DMAR;
l &= ~OMAP2_MCSPI_CHCONF_DMAW;
mcspi_write_chconf0(spi, l);
mcspi_write_chconf0(spi, l);
<-- overwrites DMAR clear
Can this lost update leave OMAP2_MCSPI_CHCONF_DMAR or
OMAP2_MCSPI_CHCONF_DMAW enabled in CHCONF0 and hang subsequent DMA
transfers?
[1] https://sashiko.dev/#/bug/linux-53ef0b8a-76a9-4654-bac2-e99f1ecedc21
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125162045.1222271-1-mk@mkio.de?part=1
prev parent reply other threads:[~2026-11-25 16:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 16:20 [PATCH] spi: omap2-mcspi: skip the TX drain wait in duplex Markus Klotzbuecher
2026-11-25 16:50 ` sashiko-bot [this message]
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=sashiko-outbox-233780@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=mk@mkio.de \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vkoul@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.