From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: James Clark <james.clark@linaro.org>
Cc: Vladimir Oltean <olteanv@gmail.com>,
Mark Brown <broonie@kernel.org>,
linux-spi@vger.kernel.org, imx@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/4] spi: spi-fsl-dspi: Clear completion counter before initiating transfer
Date: Wed, 11 Jun 2025 00:01:47 +0300 [thread overview]
Message-ID: <20250610210147.kwuwwjtcl36hrxjc@skbuf> (raw)
In-Reply-To: <9852a22a-1a09-4559-9775-2ccbb44c43c0@linaro.org>
On Tue, Jun 10, 2025 at 04:41:04PM +0100, James Clark wrote:
> On 10/06/2025 12:34 pm, Vladimir Oltean wrote:
> > On Mon, Jun 09, 2025 at 04:32:38PM +0100, James Clark wrote:
> > > In target mode, extra interrupts can be received between the end of a
> > > transfer and halting the module if the host continues sending more data.
> >
> > Presumably you mean not just any extra interrupts can be received, but
> > specifically CMDTCF, since that triggers the complete(&dspi->xfer_done)
> > call. Other interrupt sources are masked in XSPI mode and should be
> > irrelevant.
>
> Yes complete(&dspi->xfer_done) is called so CMDTCF is set. For example in
> one case of underflow I get SPI_SR = 0xca8b0450, which is these flags:
>
> TCF, TXRXS, TFUF, TFFF, CMDTCF, RFOF, RFDF, CMDFFF
>
> Compared to a successful transfer I get 0xc2830330:
>
> TCF, TXRXS, TFFF, CMDTCF, RFDF, CMDFFF
Ok, so my new question would be: if CMDTCF is set, presumably it means a
command was transferred. What command was transferred, and who put data
in the FIFO for it?
Because the answer to the above is AFAIU "no one", I guess the driver
should ignore CMDTCF when TFUF (TX FIFO underflow) is set; I consider
that to be the logic bug. You are also doing that in patch 4/4, except
you still call complete() for some reason. If you don't call complete(),
there is no reason to fend against spurious completions.
I think I would prefer seeing more deliberate decisions in the driver,
it helps if things don't just work by coincidence.
> > > If the interrupt from this occurs after the reinit_completion() then the
> > > completion counter is left at a non-zero value. The next unrelated
> > > transfer initiated by userspace will then complete immediately without
> > > waiting for the interrupt or writing to the RX buffer.
> > >
> > > Fix it by resetting the counter before the transfer so that lingering
> > > values are cleared. This is done after clearing the FIFOs and the
> > > status register but before the transfer is initiated, so no interrupts
> > > should be received at this point resulting in other race conditions.
> >
> > Sorry, I don't have a lot of experience with the target mode, and when I
> > introduced the XSPI FIFO mode, I didn't take target mode into consideration.
> >
> > The question is, does the module support XSPI FIFO writes in target
> > mode? In the LS1028A reference manual, I see PUSHR_SLAVE has the upper
> > 16 bits (for the command) hidden, specifically there is no CTAS field
> > there that would point to one of the CTARE0/CTARE1 registers.
> > Cross-checking with the S32G3 RM, I see nothing fundamentally different.
> >
> > I am surprised, given this fact, that the CMDTCF interrupt would fire at
> > all in target mode.
>
> It's working in my testing where I've forced it to XSPI mode instead of DMA
> mode on S32G3. I assume the command is blank because in target mode CTAR0
> (aka CTAR0_SLAVE) is always used regardless of the frame.
>
> CTARE0 isn't explicitly relabeled like CTAR0, but this paragraph states that
> CTARE0 is used:
>
> 50.4.3.2 Slave mode
>
> ... The SPI Slave mode transfer attributes are configured in the CTAR0
> and CTARE0 registers ...
That's an interesting piece of data which I wasn't aware of, thanks.
> Any transfers smaller than the FIFO are working in interrupt mode, although
> larger ones are problematic because there isn't enough time to reload the
> FIFOs while the host is still sending (hence the error I added in patch 4).
>
> Polling mode isn't working at all because it has a timeout which gets hit
> and returns -ETIMEDOUT before the host sends anything. Although I added the
> check there for consistency and for catching host mode errors.
>
> > >
> > > Fixes: 4f5ee75ea171 ("spi: spi-fsl-dspi: Replace interruptible wait queue with a simple completion")
> >
> > To be clear, if you ran 'git bisect' to track down this issue, it
> > wouldn't have pointed you to this commit, would it?
>
> I didn't test it no, but I did assume that the wake_up_interruptible() that
> got replaced wasn't vulnerable to this same issue. Because the spurious
> wake_up_interruptible() would be "lost", and a fresh one from the next
> transfer would have been required to proceed past the
> wait_event_interruptible().
>
> Whereas wait_for_completion() is just a counter so it has the memory problem
> explained in the commit message.
Why would a spurious wake_up_interruptible() be lost? Is it because of
the dspi->waitflags condition not becoming 1? It would also become 1...
next prev parent reply other threads:[~2025-06-10 21:01 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-09 15:32 [PATCH 0/4] spi: spi-fsl-dspi: Target mode improvements James Clark
2025-06-09 15:32 ` [PATCH 1/4] spi: spi-fsl-dspi: Clear completion counter before initiating transfer James Clark
2025-06-10 11:34 ` Vladimir Oltean
2025-06-10 15:41 ` James Clark
2025-06-10 21:01 ` Vladimir Oltean [this message]
2025-06-10 21:31 ` Vladimir Oltean
2025-06-11 9:12 ` James Clark
2025-06-09 15:32 ` [PATCH 2/4] spi: spi-fsl-dspi: Use non-coherent memory for DMA James Clark
2025-06-10 8:26 ` Arnd Bergmann
2025-06-10 9:03 ` James Clark
2025-06-10 15:15 ` Frank Li
2025-06-10 15:46 ` James Clark
2025-06-13 15:56 ` David Laight
2025-06-10 15:48 ` Arnd Bergmann
2025-06-10 15:56 ` Frank Li
2025-06-11 9:01 ` Vladimir Oltean
2025-06-12 11:05 ` James Clark
2025-06-12 11:15 ` Vladimir Oltean
2025-06-12 14:14 ` James Clark
2025-06-12 14:23 ` Vladimir Oltean
2025-06-12 14:28 ` James Clark
2025-06-12 14:31 ` Vladimir Oltean
2025-06-12 14:35 ` James Clark
2025-06-12 14:36 ` Vladimir Oltean
2025-06-12 15:36 ` James Clark
2025-06-12 15:37 ` James Clark
2025-06-12 14:43 ` Mark Brown
2025-06-12 15:47 ` James Clark
2025-06-12 15:51 ` Vladimir Oltean
2025-06-12 15:40 ` Arnd Bergmann
2025-06-12 11:15 ` Arnd Bergmann
2025-06-09 15:32 ` [PATCH 3/4] spi: spi-fsl-dspi: Increase DMA buffer size James Clark
2025-06-09 15:32 ` [PATCH 4/4] spi: spi-fsl-dspi: Report FIFO overflows as errors James Clark
2025-06-10 21:52 ` Vladimir Oltean
2025-06-11 14:40 ` James Clark
2025-06-11 14:56 ` Vladimir Oltean
2025-06-11 15:00 ` James Clark
2025-06-30 11:40 ` [PATCH 0/4] spi: spi-fsl-dspi: Target mode improvements Mark Brown
2025-06-30 12:23 ` James Clark
2025-06-30 12:25 ` Mark Brown
2025-06-30 12:36 ` James Clark
2025-06-30 12:40 ` Mark Brown
2025-06-30 12:54 ` James Clark
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=20250610210147.kwuwwjtcl36hrxjc@skbuf \
--to=vladimir.oltean@nxp.com \
--cc=broonie@kernel.org \
--cc=imx@lists.linux.dev \
--cc=james.clark@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=olteanv@gmail.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