Skip to content

mtd: spi-nor: fix DMA-unsafe buffer issue between MTD and SPI

Cyrille Pitchen linux-devicetree linux-mtd linux-spi lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 22 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3mtd: spi-nor: add optional DMA-safe bounce buffer for data transferdrivers/mtd/devices/m25p80.c drivers/mtd/spi-nor/spi-nor.c include/linux/mtd/spi-nor.h+139 -910 replies
2/3dt-bindings: mtd: atmel-quadspi: add an optional property 'dmacap,memcpy'Documentation/devicetree/bindings/mtd/atmel-quadspi.txt+5 -06 replies
3/3mtd: atmel-quadspi: add support of DMA memcpy()drivers/mtd/spi-nor/atmel-quadspi.c+129 -30 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/3] mtd: spi-nor: fix DMA-unsafe buffer issue between MTD and SPI

Hi all,

this series tries to solve a long time issue of compatibility between the MTD and SPI sub-systems about whether we should use DMA-safe memory.

This issue is visible espcecially when using a UBI file-system on a SPI NOR memory accessed through a SPI controller behind the m25p80 driver.

The SPI sub-system has already implemented a work-around on its side, based on the spi_map_buf() function. However this function has its own limitation too. Especially, even if it builds a 'struct scatterlist' from a vmalloc'ed buffer, calling dma_map_sg() is still not safe on all architectures. Especially, on ARM cores using either VIPT or VIVT data caches, dma_map_sg() doesn't take the cache aliases issue into account. Then numerous crashes were reported for such architectures.

If think it's high time to provide a reliable solution. So let's try to work together!

The proposed solution here is based on an former series from Vignesh R and relies on a bounce buffer.

For this series, I will need some pieces of advice on how to implement a reliable [spi_nor_]is_dma_safe() function. The proposed implementation in patch 1 is based on the tests performed by spi_map_buf() but I was wondring whether it would be more cautious to consider:
DMA-safe <=> allocated by kmalloc'ed.

Actually, it's better using the bounce buffer when not needed than not using it when we should.

Also the bounce buffer solution in spi-nor is designed so it could be used as an helper so spi flash controller drivers other than m25p80.c could now easily add support to DMA transfers for (Fast) Read and/or Page Program operations.

I've implemented and tested it on a sama5d2 xplained board + Macronix mx25l25673g SPI NOR memory reading from and writing into some UBI file-system. I've also tested with mtd_debug to write then read back a raw data into the SPI NOR memory, later checking the data integrity with sha1sum.

For the atmel-quadspi.c driver, DMA memcpy() transfers are enabled only if the "dmacap,mempcy" boolean property is set in the device-tree. I found this name in some other device-trees already using it for a boolean property.

Best regards,

Cyrille

Cyrille Pitchen (3):
mtd: spi-nor: add optional DMA-safe bounce buffer for data transfer
dt-bindings: mtd: atmel-quadspi: add an optional property
'dmacap,memcpy'
mtd: atmel-quadspi: add support of DMA memcpy()

 .../devicetree/bindings/mtd/atmel-quadspi.txt      |   5 +
 drivers/mtd/devices/m25p80.c                       |   4 +-
 drivers/mtd/spi-nor/atmel-quadspi.c                | 132 +++++++++++++++++++-
 drivers/mtd/spi-nor/spi-nor.c                      | 136 +++++++++++++++++++--
 include/linux/mtd/spi-nor.h                        |   8 ++
 5 files changed, 273 insertions(+), 12 deletions(-)
Signature · 1 line
2.11.0