Re: [PATCH v6 0/7] dmaengine: dw-axi-dmac: fix termination and pause acknowledgment
From: James Hilliard
Date: Mon Nov 16 2026 - 22:19:52 EST
On Mon, Nov 16, 2026 at 7:43 PM Mitch Barnett <mitch@xxxxxxxxxxxxxxxx> wrote:
>
> Hi James,
>
> Thank you for incorporating the descriptor-callback lifetime and IRQ/channel-reuse fixes in v6.
>
> We've continued investigating the remaining STOP/ABORT safety question on our Raspberry Pi 5 (RP1) test system, particularly the lifetime of client-owned ALSA PCM buffers after unsuccessful DMA termination.
>
> We've completed several additional investigations against Raspberry Pi Linux 6.18.50, pinned at cff533aec2fa601846766b32ff57204e0a61bed7:
>
> 1. DMAengine/ALSA STOP contract (V24R33): Eight source-executed host tests passed. A simulated dmaengine_terminate_async() failure (-ETIMEDOUT) is not propagated by snd_dmaengine_pcm_trigger(). The snd_dmaengine_pcm_sync_stop() path returns success after callback synchronization without independently verifying hardware quiescence.
>
> 2. ALSA buffer lifetime (V24R34/V24R35): Twelve further source-executed host cases passed. The pinned ALSA core can release managed dynamic buffers despite an hw_free error. Preallocated buffers can be detached and subsequently reused. This exposes a potential client-memory lifetime problem independently of the DMA driver's descriptor pool.
>
> 3. Live RP1 configuration (V24R36–V24R39): Read-only inspection confirmed the HiFiBerry Digi sound card bound through snd-rpi-wm8804 and designware-i2s. The live I²S1 device tree contains TX/RX DMA mappings and no I²S interrupt property. However, its PCM streams do not expose the expected prealloc entries, and we're still reconciling the effective PCM component and allocator.
>
> These are source-level tests and read-only hardware configuration checks. We have not reproduced a client-buffer use-after-free on RP1 hardware.
>
> We've also prepared an isolated combination incorporating Raspberry Pi's per-channel ABORT implementation (PR #7654). It compiles against our matching kernel source, but we have deliberately not installed or exercised it on the hardware.
>
> Our remaining concern is that retaining DMA descriptors does not establish that independently owned PCM pages are safe to release. The Synopsys DW_axi_dmac documentation cautions that an ABORT does not necessarily complete outstanding AXI transactions.
I checked the corresponding mainline paths. Mainline currently warns on
a termination timeout, frees the descriptors and returns success. The v6
change retains those descriptors and returns the error, but that does
not protect a client buffer if the caller ignores the error and proceeds
with cleanup. The final channel-resource release path also still needs
to account for unsuccessful termination.
This is a remaining limitation of the failed-stop handling, rather than
a problem introduced by the descriptor-retention change.
>
> Could you or the other DMAengine maintainers clarify two points?
>
> 1. Hardware quiescence: Is there an RP1-specific hardware condition, or supported controller recovery sequence, that positively guarantees all outstanding DMA transactions have completed after a failed STOP followed by ABORT? In particular, does this account for in-flight AXI/PCIe writes and the shared DMA master?
I cannot confirm an RP1-specific guarantee. The 1.02a databook also
appears internally inconsistent: section 2.15.5 on page 92 describes
completing initiated AXI transfers before reporting the channel aborted,
whereas the CH1_ABORT description on page 178 explicitly warns that
those transfers might not have completed.
That needs clarification before relying on CH_EN clearing after ABORT
as permission to release memory. Mainline does not currently use ABORT,
so the software lifetime issue exists independently of that mechanism.
>
> 2. Client-buffer ownership: If no such guarantee exists, what would be the preferred upstream approach to preventing ALSA from freeing or reusing DMA-addressable PCM memory after an unrecoverable termination failure? Would this require a coordinated DMAengine/ALSA fail-closed mechanism, including the HW_FREE, error-cleanup, close, and device-removal paths?
The DMAengine synchronize contract already requires transfers to have
stopped, as well as callbacks to have finished. DW AXI currently only
calls vchan_synchronize(), which cannot establish hardware quiescence
after termination has failed.
Simply propagating the error through snd_dmaengine_pcm_trigger() would
not be sufficient: the PCM core ignores the STOP return value, and
managed-buffer cleanup proceeds even when hw_free returns an error.
A provider recovery path that guarantees the hardware has stopped
before synchronization returns could avoid introducing new PCM buffer
ownership rules. If that guarantee cannot be provided and cleanup is
allowed to continue, retaining only the descriptor pool is insufficient:
the client buffers and their DMA mappings must also remain valid, with
reuse and removal covered as well.
>
> We're holding off on forced STOP/ABORT testing until we can establish a defensible memory-lifetime contract.
>
> Any guidance on the hardware guarantee or appropriate upstream design would be greatly appreciated.
>
> Thanks again for your work on this.
>
> Kind regards,
> Mitch Barnett
> Accurate Sound
>
> References:
>
> Raspberry Pi per-channel ABORT implementation:
> https://github.com/raspberrypi/linux/pull/7654
>
> Pinned Raspberry Pi kernel source:
> https://github.com/raspberrypi/linux/tree/cff533aec2fa601846766b32ff57204e0a61bed7
>
> ________________________________________
> From: James Hilliard <james.hilliard1@xxxxxxxxx>
> Sent: Sunday, November 15, 2026 10:00 PM
> To: Eugeniy Paltsev <Eugeniy.Paltsev@xxxxxxxxxxxx>; Vinod Koul <vkoul@xxxxxxxxxx>; Frank Li <Frank.Li@xxxxxxxxxx>; Sergey Khimich <serghox@xxxxxxxxx>; Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>; Sia Jee Heng <jee.heng.sia@xxxxxxxxx>
> Cc: Mitch Barnett <mitch@xxxxxxxxxxxxxxxx>; dmaengine@xxxxxxxxxxxxxxx <dmaengine@xxxxxxxxxxxxxxx>; linux-kernel@xxxxxxxxxxxxxxx <linux-kernel@xxxxxxxxxxxxxxx>; James Hilliard <james.hilliard1@xxxxxxxxx>; stable@xxxxxxxxxxxxxxx <stable@xxxxxxxxxxxxxxx>; Wang YuWei <1973615295@xxxxxx>
> Subject: [PATCH v6 0/7] dmaengine: dw-axi-dmac: fix termination and pause acknowledgment
>
> Keep cyclic mode in each descriptor so failed preparation and queued
> work cannot change the completion handling of another transfer.
>
> Use the layout-aware channel enable check during termination and retain
> transfer resources when the channel does not stop. Preserve suspension
> status for the pause and resume paths, including acknowledgments that
> arrive after a polling timeout or during another channel's interrupt.
>
> Keep a pending pause across cyclic segment completion and resume the
> segment only after the client releases the pause. Track the active
> descriptor until completion so queued work cannot reissue it while its
> interrupt is pending.
>
> Retain terminated descriptors until their callbacks have drained, including
> cyclic descriptors that error handling has moved to the completed list.
> Serialize interrupt status collection with channel reuse so an old event
> cannot complete a replacement transfer.
>
> This series uses the shared virt-dma descriptor-retirement helper [0].
>
> [0] https://lore.kernel.org/r/20261115-submit-sun4i-dma-callback-lifetime-v1-v2-1-fb7d258702f8@xxxxxxxxx/
>
> Assisted-by: Codex:gpt-6-astra
> Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
> ---
> Changes in v6:
> - Retain descriptors through callback synchronization using the posted
> virt-dma helper, covering pending, executing and error-completed cyclic
> callbacks raised in Mitch's follow-up.
> - Serialize interrupt status collection with channel reuse and clear old
> completion and error status after successful termination.
> - Link to v5: https://patch.msgid.link/20261113-submit-dw-axi-dma-stop-pause-v1-v5-0-8523a27b5788@xxxxxxxxx
>
> Changes in v5:
> - Use a positive enabled-channel condition in the suspend-status helper,
> following Andy's review.
> - Initialize the resume result immediately before its first use.
> - Separate the lock-protected channel bitfields from the preceding fields.
> - Link to v4: https://patch.msgid.link/20261112-submit-dw-axi-dma-stop-pause-v1-v4-0-3ebc24b243db@xxxxxxxxx
>
> Changes in v4:
> - Add a preparatory fix for cyclic mode leaking between transfers,
> following Sashiko's review. Store the mode in each descriptor so
> failed preparation, error recovery and queued work cannot change
> another transfer's completion handling.
> - Link to v3: https://patch.msgid.link/20261110-submit-dw-axi-dma-stop-pause-v1-v3-0-35fdfba8b61d@xxxxxxxxx
>
> Changes in v3:
> - Wrap the atomic polling calls by argument group and correct their
> continuation indentation, following Andy's review.
> - Move the termination return-value check simplification into the
> channel-enable polling patch.
> - Separate the pause-loop conversion to atomic polling from the
> pending-request and cyclic-restart changes.
> - Annotate the suspend-wait helper with its channel-lock requirement.
> - Pack the lock-protected flags into existing padding while keeping
> cyclic separately writable, following Andy's review.
> - Link to v2: https://patch.msgid.link/20261109-submit-dw-axi-dma-stop-pause-v1-v2-0-64adc48df793@xxxxxxxxx
>
> Changes in v2:
> - Use readx_poll_timeout_atomic() for the single-argument status helpers
> and express the termination polling interval and timeout in milliseconds,
> following Andy's review.
> - Track pending suspend requests separately from confirmed suspension so
> resume can handle acknowledgments received after a pause timeout.
> - Use the atomic polling helper, including its final status check, and
> report -EAGAIN if resume cannot yet cancel a pending suspend request.
> - Defer cyclic restart while paused and track the active descriptor until
> completion, preventing resume or issue_pending from reissuing it.
> - Reset pause state on successful termination and channel allocation;
> clear stale status when starting a new descriptor.
> - Link to v1: https://patch.msgid.link/20261108-submit-dw-axi-dma-stop-pause-v1-v1-0-c48ec19e9ee4@xxxxxxxxx
>
> To: Eugeniy Paltsev <Eugeniy.Paltsev@xxxxxxxxxxxx>
> To: Vinod Koul <vkoul@xxxxxxxxxx>
> To: Frank Li <Frank.Li@xxxxxxxxxx>
> To: Sergey Khimich <serghox@xxxxxxxxx>
> To: Sia Jee Heng <jee.heng.sia@xxxxxxxxx>
> To: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> Cc: dmaengine@xxxxxxxxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
>
> ---
> James Hilliard (7):
> dmaengine: dw-axi-dmac: keep cyclic mode in the descriptor
> dmaengine: dw-axi-dmac: poll the correct enable bit during termination
> dmaengine: dw-axi-dmac: retain descriptors when termination times out
> dmaengine: dw-axi-dmac: use atomic polling for suspend acknowledgment
> dmaengine: dw-axi-dmac: preserve pending pause requests
> dmaengine: dw-axi-dmac: retain descriptors until callbacks drain
> dmaengine: dw-axi-dmac: serialize interrupt status with channel reuse
>
> drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 183 +++++++++++++++++--------
> drivers/dma/dw-axi-dmac/dw-axi-dmac.h | 10 +-
> 2 files changed, 130 insertions(+), 63 deletions(-)
> ---
> base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
> base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/dmaengine.git fixes
> change-id: 20261108-submit-dw-axi-dma-stop-pause-v1-c93f1e767169
> prerequisite-patch-id: fc343480330da5ff95e5271997fa71107977c2b8
>
> Best regards,
> --
> James Hilliard <james.hilliard1@xxxxxxxxx>