spi: Fix cache corruption due to DMA/PIO overlap
authorVincent Whitchurch <vincent.whitchurch@axis.com>
Tue, 27 Sep 2022 11:21:15 +0000 (13:21 +0200)
committerMark Brown <broonie@kernel.org>
Wed, 28 Sep 2022 11:54:05 +0000 (12:54 +0100)
commit0c17ba73c08ff2690c1eff8df374b6709eed55ce
treeb0c60feb122a9b47c76ab367a0263860cfd70390
parentf25723dcef4a38f6a39e17afeabd1adf6402230e
spi: Fix cache corruption due to DMA/PIO overlap

The SPI core DMA mapping support performs cache management once for the
entire message and not between transfers, and this leads to cache
corruption if a message has two or more RX transfers with both
transfers targeting the same cache line, and the controller driver
decides to handle one using DMA and the other using PIO (for example,
because one is much larger than the other).

Fix it by syncing before/after the actual transfers.  This also means
that we can skip the sync during the map/unmap of the message.

Fixes: 99adef310f68 ("spi: Provide core support for DMA mapping transfers")
Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
Link: https://lore.kernel.org/r/20220927112117.77599-3-vincent.whitchurch@axis.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi.c