The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/2] spi: Fix DMA mapping ownership on partial map failure
@ 2026-08-05 15:14 Honghui Jiang
  2026-08-05 15:14 ` [PATCH 1/2] " Honghui Jiang
  2026-08-05 15:14 ` [PATCH 2/2] spi: Add KUnit coverage for DMA mapping error paths Honghui Jiang
  0 siblings, 2 replies; 8+ messages in thread
From: Honghui Jiang @ 2026-08-05 15:14 UTC (permalink / raw)
  To: broonie
  Cc: andy, andriy.shevchenko, fancer.lancer, linux-spi, linux-kernel,
	Honghui Jiang

__spi_map_msg() can fail after mapping only part of a message.  The
normal cleanup path may then act on stale mapped flags using a NULL or
stale DMA device, causing a NULL dereference or an extra unmap.

The core DMA mapping path is used by 28 in-tree SPI controllers.  The
bug remains reachable until a controller completes its first DMA-mapped
message, since cur_{tx,rx}_dma_dev are only set on success.  can_dma()
length checks may postpone that point well beyond probe.  A two-transfer
message with a mapped command followed by an unmappable static payload
reproduces the failure without memory pressure.

Patch 1 publishes the mapping devices before mapping starts and uses a
common unwind path for all failures.  Patch 2 adds KUnit coverage for
partial TX and RX mapping failures, successful map/unmap, and messages
which require no mapping.

Tested on v7.2-rc6 under x86_64 QEMU with KASAN.  All three cases that
previously oopsed complete cleanly after the fix, and the RX-only case
no longer issues an empty unmap.  DMA map/unmap counts changed from
3/4, 2/3 and 5/6 to 3/3, 2/2 and 5/5.

Two of the four KUnit cases fail without patch 1; all four pass with it.
Patch 1 also builds independently with x86_64_defconfig plus SPI.

Honghui Jiang (2):
  spi: Fix DMA mapping ownership on partial map failure
  spi: Add KUnit coverage for DMA mapping error paths

 drivers/spi/.kunitconfig      |   4 +
 drivers/spi/Kconfig           |  11 ++
 drivers/spi/spi.c             |  37 +++--
 drivers/spi/tests/spi_kunit.c | 301 ++++++++++++++++++++++++++++++++++
 4 files changed, 338 insertions(+), 15 deletions(-)
 create mode 100644 drivers/spi/.kunitconfig
 create mode 100644 drivers/spi/tests/spi_kunit.c


base-commit: 075b74841bd0065a3bda3440873c747938e69b68
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-08-08 17:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-05 15:14 [PATCH 0/2] spi: Fix DMA mapping ownership on partial map failure Honghui Jiang
2026-08-05 15:14 ` [PATCH 1/2] " Honghui Jiang
2026-08-06 19:34   ` Andy Shevchenko
2026-08-08 17:54     ` Honghui  Jiang
2026-08-05 15:14 ` [PATCH 2/2] spi: Add KUnit coverage for DMA mapping error paths Honghui Jiang
2026-08-05 21:57   ` Mark Brown
2026-08-06  4:20     ` 江宏辉 
2026-08-06 19:32     ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox