You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Title: DMA buffer ring handling broken: head_idx not incremented in rp1_pio_sm_xfer_data()
Description:
There is a critical issue in the rp1_pio_sm_xfer_data() function related to DMA buffer management.
Currently, the function allocates and uses a buffer from the internal DMA ring via:
dbi=&dma->bufs[dma->head_idx % dma->buf_count];
However, after submitting the DMA transfer, the head_idx is never incremented. As a result:
Every transfer reuses the same buffer (typically bufs[0]).
Only the first transfer works correctly.
Subsequent DMA transfers appear to fail silently (or overwrite data in-flight).
The buf_sem semaphore eventually blocks further transfers, since the ring never advances.
This breaks multi-buffer DMA handling and causes subtle data loss and transfer hangs.
Suggested Fix:
Increment head_idx after a successful DMA submission:
ret=dmaengine_submit(desc);
if (ret<0) {
dev_err(dev, "dmaengine_submit failed (%d)\n", ret);
returnret;
}
dma_async_issue_pending(dma->chan);
/* Add this line to advance the ring */dma->head_idx++;
return0;
The corresponding tail_idx++ already occurs in the DMA completion callback, so this fix restores proper ring behavior.
Impact:
This bug causes:
DMA transfers after the first one to fail silently.
Potential data corruption due to buffer reuse.
System hangs if the ring fills and buffers never recycle.
Steps to reproduce the behaviour
just analyze the code ; the callback is doing the tail_idx++ but for the head no increase is done.
i tried to use my driver wich includes the rp1-pio driver with a ping pong buffer scenario and reading data from the second buffer results in 0 reads.
Hmm, yes. The in-kernel API has been barely used, so I'm disappointed but not hugely surprised. I'll take a look at the rest of the code in this area, but a fix will be merged ASAP.
Activity
pelwell commentedon Jun 23, 2025
Hmm, yes. The in-kernel API has been barely used, so I'm disappointed but not hugely surprised. I'll take a look at the rest of the code in this area, but a fix will be merged ASAP.
pa3gsb commentedon Jun 23, 2025
I understand; no problem. I did the change and my ping-pong dma transfer started to work.
Nice you are so quick in responding and willing to update the code.
Really appreciated.
misc: rp1-pio: Don't just reuse the same DMA buf
pelwell commentedon Jun 23, 2025
There - I think that should be fixed now. If you wait about 40 minutes for these autobuilds (https://github.com/raspberrypi/linux/actions/runs/15826180099) to complete, you should be able to install a trial build using
sudo rpi-update rpi-6.12.y.Thanks for the clear bug report - I'll take a look at your piolib API issue next.
pa3gsb commentedon Jun 23, 2025
This works for me. Tnx.
misc: rp1-pio: Don't just reuse the same DMA buf
misc: rp1-pio: Don't just reuse the same DMA buf
misc: rp1-pio: Don't just reuse the same DMA buf
misc: rp1-pio: Don't just reuse the same DMA buf
misc: rp1-pio: Don't just reuse the same DMA buf
misc: rp1-pio: Don't just reuse the same DMA buf
misc: rp1-pio: Don't just reuse the same DMA buf
misc: rp1-pio: Don't just reuse the same DMA buf
misc: rp1-pio: Don't just reuse the same DMA buf
160 remaining items
misc: Add RP1 PIO driver
misc: Add RP1 PIO driver
misc: Add RP1 PIO driver
misc: Add RP1 PIO driver
misc: Add RP1 PIO driver
misc: Add RP1 PIO driver
misc: Add RP1 PIO driver
misc: Add RP1 PIO driver
misc: Add RP1 PIO driver
misc: Add RP1 PIO driver
misc: Add RP1 PIO driver
misc: Add RP1 PIO driver
misc: Add RP1 PIO driver
misc: Add RP1 PIO driver
misc: Add RP1 PIO driver