From: Peng Yang <pyangyyd@gmail.com>
To: Mark Brown <broonie@kernel.org>
Cc: Serge Semin <fancer.lancer@gmail.com>,
linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
pyangyyd@gmail.com
Subject: Re: [PATCH] spi: dw: fix race between transfer IRQ handler and timeout handler
Date: Wed, 27 May 2026 16:20:42 +0800 [thread overview]
Message-ID: <20260527082042.3746-1-pyangyyd@amazon.com> (raw)
In-Reply-To: <d08e1763-1130-48ef-9804-22e708c6e8f2@sirena.org.uk>
On Mon, May 26, 2026 at ..., Mark Brown wrote:
> Please don't top post, reply in line with needed context.
Apologies for the format, fixing it here.
> Please fix your mail client to word wrap within paragraphs at
> something substantially less than 80 columns.
Will do.
> That doesn't mean that's the only possible thing that could race.
I've traced through the code paths during my debug. The only
race path is in IRQ mode, where handle_err() calls
dw_spi_reset_chip() from the SPI core kthread while the IRQ
handler is still servicing FIFO interrupts on another CPU.
Poll mode returns 0 so the kthread never sleeps and
handle_err can't be reached concurrently.
DMA mode has its own transfer handler that doesn't access
the FIFO directly.
> What happens if between checking the interrupt status and
> handling the FIFOs we call dw_spi_handle_err()? The next
> transfer could be started, updating the buffer pointers and
> lengths in dw_spi_transfer_one() but that doesn't exclude
> the interrupt handler.
Looking at spi_transfer_one_message(), handle_err() and the
next transfer_one() are called sequentially from the same
kthread:
transfer_one() -> spi_transfer_wait() -> timeout ->
handle_err() -> spi_finalize_current_message() ->
next transfer_one()
A new transfer cannot start until handle_err() returns and
spi_finalize_current_message() completes, so buffer pointers
won't be updated concurrently.
If reset happens between checking irq_status and taking the
lock, dw_reader/dw_writer will see an empty FIFO (max=0)
and exit without accessing DR.
> That's also already an issue, but it's complicated by the
> thin locking windows.
I think this case is safe because the kthread serializes
handle_err and the next transfer_one sequentially, so the
buffer pointers can't be updated while the IRQ handler is
still running.
Please let me know if I'm missing something here.
Best Regards,
Peng Yang
next prev parent reply other threads:[~2026-05-27 8:21 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 [this message]
2026-06-08 9:58 ` [PATCH v2] spi: dw: fix race between IRQ handler and error handler on SMP Peng Yang
2026-06-08 13:10 ` 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=20260527082042.3746-1-pyangyyd@amazon.com \
--to=pyangyyd@gmail.com \
--cc=broonie@kernel.org \
--cc=fancer.lancer@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@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