Linux SPI subsystem development
 help / color / mirror / Atom feed
From: Joseph CT Chan <jctchan@gmail.com>
To: Mark Brown <broonie@kernel.org>
Cc: linux-spi@vger.kernel.org, David Lechner <dlechner@baylibre.com>,
	Bart Van Assche <bvanassche@acm.org>,
	Joseph CT Chan <josephctchan@google.com>
Subject: [PATCH v3 0/2] spi: unoptimize message when queuing it fails
Date: Fri, 13 Nov 2026 02:03:50 +0000	[thread overview]
Message-ID: <20261113020352.1741295-1-jctchan@gmail.com> (raw)

From: Joseph CT Chan <josephctchan@google.com>

Hi Mark,

spi_async() and spi_sync() optimize a message before they queue it. If
queuing fails, the message is never finalized, so the split transfers
and the controller's optimize state leak and the message stays marked
as optimized. This happens with -EBUSY while another device holds
spi_bus_lock() (for example mmc_spi), with a stopped queue, and with an
error from a legacy transfer() callback. Patch 1 unoptimizes the message
on those error paths, and patch 2 adds KUnit tests for them.

Tested with KUnit using --kunitconfig=drivers/spi on ARCH=um and on
x86_64 under QEMU: the 7 new cases and the 4 existing DMA cases pass
with patch 1, and the 3 queue error cases fail without it. Not tested
on hardware.

Changes in v3:
- Rebased on spi/for-7.5.
- Patch 2: include drivers/spi/tests unconditionally from
  drivers/spi/Makefile instead of adding a second conditional line, as
  you suggested.
- Patch 2: add the test to the existing drivers/spi/.kunitconfig, which
  also runs the DMA tests, instead of adding a new one.

Changes in v2:
- Split out of the v1 14-patch series, as David suggested.
- Patch 1: added David's Reviewed-by.
- Patch 2: inject errors through the fake controller's transfer()
  callback instead of mem_ops, use designated initializers, and trim
  the comments.
- Moved the AI assistance note from an Assisted-by tag into the commit
  message.

v2: https://lore.kernel.org/linux-spi/20261103224753.3610049-1-jctchan@gmail.com/
v1: https://lore.kernel.org/all/20261102163023.2574632-1-jctchan@gmail.com/

Walkthrough of the bug and the tests:
https://gist.github.com/joectchan/9a14b5e6facb75058ebc5a6ff1757131

Please consider this patch series for the next merge window.

Thanks,
Joseph

Joseph CT Chan (2):
  spi: unoptimize message when queuing it fails
  spi: add KUnit tests for message optimize state on queue errors

 drivers/spi/.kunitconfig           |   1 +
 drivers/spi/Kconfig                |  13 ++
 drivers/spi/Makefile               |   2 +-
 drivers/spi/spi.c                  |   7 +
 drivers/spi/tests/Makefile         |   1 +
 drivers/spi/tests/spi-core-kunit.c | 262 +++++++++++++++++++++++++++++
 6 files changed, 285 insertions(+), 1 deletion(-)
 create mode 100644 drivers/spi/tests/spi-core-kunit.c


base-commit: 281521f809f6a6ff406d082293faf1ed3bbfd949
-- 
2.56.0.506.g506a7eabc5-goog


             reply	other threads:[~2026-11-13  2:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13  2:03 Joseph CT Chan [this message]
2026-11-13  2:03 ` [PATCH v3 1/2] spi: unoptimize message when queuing it fails Joseph CT Chan
2026-11-13  2:03 ` [PATCH v3 2/2] spi: add KUnit tests for message optimize state on queue errors Joseph CT Chan

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=20261113020352.1741295-1-jctchan@gmail.com \
    --to=jctchan@gmail.com \
    --cc=broonie@kernel.org \
    --cc=bvanassche@acm.org \
    --cc=dlechner@baylibre.com \
    --cc=josephctchan@google.com \
    --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