Skip to content

Commit 138d73b

Browse files
diandersbroonie
authored andcommitted
spi: spi-qcom-qspi: Fallback to PIO for xfers that aren't multiples of 4 bytes
The Qualcomm QSPI driver appears to require that any reads using DMA are a mutliple of 4 bytes. If this isn't true then the controller will clobber any extra bytes in memory following the last word. Let's detect this and falback to PIO. This fixes problems reported by slub_debug=FZPUA, which would complain about "kmalloc Redzone overwritten". One such instance said: 0xffffff80c29d541a-0xffffff80c29d541b @offset=21530. First byte 0x0 instead of 0xcc Allocated in mtd_kmalloc_up_to+0x98/0xac age=36 cpu=3 pid=6658 Tracing through what was happening I saw that, while we often did DMA tranfers of 0x1000 bytes, sometimes we'd end up doing ones of 0x41a bytes. Those 0x41a byte transfers were the problem. NOTE: a future change will enable the SPI "mem ops" to help avoid this case, but it still seems good to add the extra check in the transfer. Fixes: b5762d9 ("spi: spi-qcom-qspi: Add DMA mode support") Signed-off-by: Douglas Anderson <[email protected]> Reviewed-by: Vijaya Krishna Nivarthi <[email protected]> Reviewed-by: Bjorn Andersson <[email protected]> Link: https://lore.kernel.org/r/20230725110226.1.Ia2f980fc7cd0b831e633391f0bb1272914d8f381@changeid Signed-off-by: Mark Brown <[email protected]>
1 parent 916a4ed commit 138d73b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/spi/spi-qcom-qspi.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,22 @@ static int qcom_qspi_setup_dma_desc(struct qcom_qspi *ctrl,
357357

358358
for (i = 0; i < sgt->nents; i++) {
359359
dma_ptr_sg = sg_dma_address(sgt->sgl + i);
360+
dma_len_sg = sg_dma_len(sgt->sgl + i);
360361
if (!IS_ALIGNED(dma_ptr_sg, QSPI_ALIGN_REQ)) {
361362
dev_warn_once(ctrl->dev, "dma_address not aligned to %d\n", QSPI_ALIGN_REQ);
362363
return -EAGAIN;
363364
}
365+
/*
366+
* When reading with DMA the controller writes to memory 1 word
367+
* at a time. If the length isn't a multiple of 4 bytes then
368+
* the controller can clobber the things later in memory.
369+
* Fallback to PIO to be safe.
370+
*/
371+
if (ctrl->xfer.dir == QSPI_READ && (dma_len_sg & 0x03)) {
372+
dev_warn_once(ctrl->dev, "fallback to PIO for read of size %#010x\n",
373+
dma_len_sg);
374+
return -EAGAIN;
375+
}
364376
}
365377

366378
for (i = 0; i < sgt->nents; i++) {

0 commit comments

Comments
 (0)