dmaengine: xilinx_dma: MCDMA descriptor and metadata handling improvements
Subsystems (5)
v3 cover dmaengine: xilinx_dma: MCDMA descriptor and metadata handling improvements
This series improves the Xilinx AXI DMA and MCDMA driver's descriptor handling and metadata reporting. It fixes direction-specific descriptor field usage, ensures completion is based on the hardware completion bit (important with interrupt coalescing), and extends metadata handling to expose status and sideband fields alongside APP fields.
The axienet driver is updated to derive RX frame length from the standard dmaengine residue mechanism rather than descriptor APP fields, making it work on designs where the AXI4-Stream status/control interface is not present.
Changes in V3:
- Patch 1: Renamed subject, added static_assert for descriptor size, refactored residue calculation for clarity.
- Patch 2: Added Fixes tag, expanded commit message explaining interrupt coalescing scenario, simplified completion check logic.
- Patch 3: New patch - axienet now uses result->residue for RX length instead of APP metadata, removing dependency on status/control stream.
- Patch 4: Complete rewrite - metadata pointer now starts at status field (index 0) exposing status/sideband to clients; uses EOF descriptor; removed 'chan' field from descriptor struct.
- Dropped V2 patches 4/5 (dt-bindings) and 5/5 (xferred_bytes) as the approach changed to use standard residue mechanism.
Changes in V2:
- Rebased on the AXI DMA binding YAML conversion.
- Added xlnx,include-stscntrl-strm in the YAML binding.
- Clarified cover letter to reflect metadata behavior with and without APP fields.
https://lore.kernel.org/all/[email protected]/
Srinivas Neeli (3):
dmaengine: xilinx_dma: Fix MCDMA descriptor fields based on DMA
direction
dmaengine: xilinx_dma: Move descriptors to done list based on
completion bit
net: xilinx: axienet: Derive RX frame length from DMA residue
Suraj Gupta (1):
dmaengine: xilinx_dma: Extend metadata handling for AXI DMA and MCDMA
drivers/dma/xilinx/xilinx_dma.c | 85 ++++++++++++++++--- .../net/ethernet/xilinx/xilinx_axienet_main.c | 14 ++- 2 files changed, 76 insertions(+), 23 deletions(-)
--
2.25.1
PATCH v3 1/4 dmaengine: xilinx_dma: Fix MCDMA descriptor fields based on DMA direction
The MCDMA BD format differs between memory-to-device (MM2S) and device-to-memory (S2MM) directions, but the driver was using generic 'status' and 'sideband_status' fields for both. This led to incorrect residue calculations when the hardware updates direction-specific fields.
Refactor the descriptor structure to use unions with direction-specific field mappings, and update the residue calculation logic to select the correct status field based on DMA direction.
This matches the hardware descriptor layout and fixes incorrect residue reporting.
---
Changes in V3:
- Renamed subject from "for MM2S vs S2MM" to "based on DMA direction".
- Reworded commit message for clarity.
- Added XILINX_MCDMA_BD_HW_SIZE macro and static_assert to verify descriptor size at compile time.
- Refactored residue calculation to separate addition and subtraction operations for better readability.
Changes in V2:
- No change.
--- drivers/dma/xilinx/xilinx_dma.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +19 -7
@@ -223,6 +223,7 @@#define XILINX_MCDMA_IRQ_ERR_MASK BIT(7)#define XILINX_MCDMA_BD_EOP BIT(30)#define XILINX_MCDMA_BD_SOP BIT(31) +#define XILINX_MCDMA_BD_HW_SIZE 64/** * struct xilinx_vdma_desc_hw - Hardware Descriptor
@@ -277,8 +278,10 @@ struct xilinx_axidma_desc_hw {* @buf_addr_msb: MSB of Buffer address @0x0C * @rsvd: Reserved field @0x10 * @control: Control Information field @0x14 -* @status: Status field @0x18 -* @sideband_status: Status of sideband signals @0x1C +* @mm2s_ctrl_sideband: Sideband control info for mm2s @0x18 +* @s2mm_status: Status field for s2mm @0x18 +* @mm2s_status: Status field for mm2s @0x1C +* @s2mm_sideband_status: Sideband status for s2mm @0x1C * @app: APP Fields @0x20 - 0x30 */ struct xilinx_aximcdma_desc_hw {
@@ -288,10 +291,17 @@ struct xilinx_aximcdma_desc_hw {u32 buf_addr_msb;u32 rsvd;u32 control; -u32 status; -u32 sideband_status; +union { +u32 mm2s_ctrl_sideband; +u32 s2mm_status; + }; +union { +u32 mm2s_status; +u32 s2mm_sideband_status; + };u32 app[XILINX_DMA_NUM_APP_WORDS ]; }__aligned(64) ; +static_assert (sizeof (struct xilinx_aximcdma_desc_hw ) ==XILINX_MCDMA_BD_HW_SIZE );/** * struct xilinx_cdma_desc_hw - Hardware Descriptor
@@ -1015,9 +1025,11 @@ static u32 xilinx_dma_get_residue(struct xilinx_dma_chan *chan, struct xilinx_aximcdma_tx_segment, node); aximcdma_hw = &aximcdma_seg->hw; - residue += - (aximcdma_hw->control & chan->xdev->max_buffer_len) - - (aximcdma_hw->status & chan->xdev->max_buffer_len); + residue += aximcdma_hw->control & chan->xdev->max_buffer_len; +if (chan->direction ==DMA_DEV_TO_MEM ) + residue -= aximcdma_hw->s2mm_status & chan->xdev->max_buffer_len; +else + residue -= aximcdma_hw->mm2s_status & chan->xdev->max_buffer_len; } }
Signature · 1 line
2.25.1
Re: [PATCH V3 1/4] dmaengine: xilinx_dma: Fix MCDMA descriptor fields based on DMA direction
Quoted 9 lines
The MCDMA BD format differs between memory-to-device (MM2S) and device-to-memory (S2MM) directions, but the driver was using generic 'status' and '
sideband_status' fields for both. This led to incorrect residue calculations when the hardware updates direction-specific fields.Refactor the descriptor structure to use unions with direction-specific field mappings, and update the residue calculation logic to select the correct status field based on DMA direction.
Quoted 5 lines
This matches the hardware descriptor layout and fixes incorrect residue reporting.
Fixes 6ccd692bfb7f ("dmaengine: xilinx_dma: Add Xilinx AXI MCDMA Engine driver support")Signed-off-by Srinivas Neeli <[email protected]>
Thanks!
Quoted 75 lines
---
Changes in V3:
- Renamed subject from "for MM2S vs S2MM" to "based on DMA direction".
- Reworded commit message for clarity.
- AddedXILINX_MCDMA_BD_HW_SIZEmacro andstatic_assertto verify descriptor size at compile time.
- Refactored residue calculation to separate addition and subtraction operations for better readability.Changes in V2:
- No change.--- drivers/dma/xilinx/xilinx_dma.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)drivers/dma/xilinx/xilinx_dma.c +19
-7@@ -223,6 +223,7 @@#define XILINX_MCDMA_IRQ_ERR_MASK BIT(7)#define XILINX_MCDMA_BD_EOP BIT(30)#define XILINX_MCDMA_BD_SOP BIT(31) +#define XILINX_MCDMA_BD_HW_SIZE 64/** * struct xilinx_vdma_desc_hw - Hardware Descriptor @@ -277,8 +278,10 @@ struct xilinx_axidma_desc_hw {* @buf_addr_msb: MSB of Buffer address @0x0C * @rsvd: Reserved field @0x10 * @control: Control Information field @0x14 -* @status: Status field @0x18 -* @sideband_status: Status of sideband signals @0x1C +* @mm2s_ctrl_sideband: Sideband control info for mm2s @0x18 +* @s2mm_status: Status field for s2mm @0x18 +* @mm2s_status: Status field for mm2s @0x1C +* @s2mm_sideband_status: Sideband status for s2mm @0x1C * @app: APP Fields @0x20 - 0x30 */ struct xilinx_aximcdma_desc_hw {@@ -288,10 +291,17 @@ struct xilinx_aximcdma_desc_hw {u32 buf_addr_msb;u32 rsvd;u32 control; -u32 status; -u32 sideband_status; +union { +u32 mm2s_ctrl_sideband; +u32 s2mm_status; + }; +union { +u32 mm2s_status; +u32 s2mm_sideband_status; + };u32 app[XILINX_DMA_NUM_APP_WORDS ]; }__aligned(64) ; +static_assert (sizeof (struct xilinx_aximcdma_desc_hw ) ==XILINX_MCDMA_BD_HW_SIZE );/** * struct xilinx_cdma_desc_hw - Hardware Descriptor @@ -1015,9 +1025,11 @@ static u32 xilinx_dma_get_residue(struct xilinx_dma_chan *chan, struct xilinx_aximcdma_tx_segment, node); aximcdma_hw = &aximcdma_seg->hw; - residue += - (aximcdma_hw->control & chan->xdev->max_buffer_len) - - (aximcdma_hw->status & chan->xdev->max_buffer_len); + residue += aximcdma_hw->control & chan->xdev->max_buffer_len; +if (chan->direction ==DMA_DEV_TO_MEM ) + residue -= aximcdma_hw->s2mm_status & chan->xdev->max_buffer_len; +else + residue -= aximcdma_hw->mm2s_status & chan->xdev->max_buffer_len; } }
PATCH v3 2/4 dmaengine: xilinx_dma: Move descriptors to done list based on completion bit
In reply to Srinivas NeeliIn AXI MCDMA scatter-gather mode, xilinx_dma_complete_descriptor() walks the channel's active_list and unconditionally moves every entry to the done_list. The MCDMA IOC interrupt handler invokes this function on every interrupt-on-completion, but with interrupt coalescing (IRQThreshold > 1) an IOC interrupt may fire after only a subset of the queued descriptors have actually been processed by the hardware. As a result, descriptors whose completion bit is not yet set in the BD status were being reported as completed to client drivers.
Add a check for the descriptor completion bit before moving entries from the active list to the done list, using the appropriate direction- specific status field (s2mm_status for DMA_DEV_TO_MEM, mm2s_status for DMA_MEM_TO_DEV).
The MCDMA completion check is intentionally not guarded by chan->has_sg, unlike the AXIDMA branch above. AXI MCDMA only operates in scatter-gather mode (has_sg is always true), so the guard would always pass and is omitted. The completion bit is therefore checked unconditionally.
---
Changes in V3:
- Added Fixes tag.
- Expanded commit message to explain the interrupt coalescing scenario and why the has_sg guard is omitted for MCDMA.
- Changed local variable from 'bool completed' to 'u32 status' for cleaner status field access.
- Simplified completion check logic.
Changes in V2:
- No change.
--- drivers/dma/xilinx/xilinx_dma.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/dma/xilinx/xilinx_dma.c +11 -0
@@ -1784,6 +1784,17 @@ static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan) struct xilinx_axidma_tx_segment, node);if (!(seg->hw.status &XILINX_DMA_BD_COMP_MASK ) && chan->has_sg)break ; + }else if (chan->xdev->dma_config->dmatype ==XDMA_TYPE_AXIMCDMA ) { +struct xilinx_aximcdma_tx_segment *seg; +u32 status; + + seg =list_last_entry (&desc->segments, + struct xilinx_aximcdma_tx_segment, + node); + status = (chan->direction ==DMA_DEV_TO_MEM ) ? + seg->hw.s2mm_status : seg->hw.mm2s_status; +if (!(status &XILINX_DMA_BD_COMP_MASK )) +break ; }if (chan->has_sg && chan->xdev->dma_config->dmatype !=XDMA_TYPE_VDMA )
Signature · 1 line
2.25.1
Re: [PATCH V3 2/4] dmaengine: xilinx_dma: Move descriptors to done list based on completion bit
Quoted 1 line
In AXI MCDMA scatter-gather mode,
xilinx_dma_complete_descriptor()walks
avoid "scatter-gather" mode.
Quoted 13 lines
the channel's
active_listand unconditionally moves every entry to thedone_list. The MCDMA IOC interrupt handler invokes this function on every interrupt-on-completion, but with interrupt coalescing (IRQThreshold > 1) an IOC interrupt may fire after only a subset of the queued descriptors have actually been processed by the hardware. As a result, descriptors whose completion bit is not yet set in the BD status were being reported as completed to client drivers.Add a check for the descriptor completion bit before moving entries from the active list to the done list, using the appropriate direction- specific status field (
s2mm_statusforDMA_DEV_TO_MEM,mm2s_statusforDMA_MEM_TO_DEV).
Quoted 4 lines
The MCDMA completion check is intentionally not guarded by
chan->has_sg, unlike the AXIDMA branch above. AXI MCDMA only operates in scatter-gather mode (has_sgis always true), so the guard would always pass and is omitted. The completion bit is therefore checked unconditionally.
Not need to talk about has_sg check and compare it with AXIDMA but if you still prefer make it precise.
Once addressed , feel free to add.
Thanks!
Just a note that this change aligns with changes that were done in past for AXIDMA in commit 7bcdaa658102 dmaengine: xilinx_dma: Freeup active list based on descriptor completion bit
Quoted 40 lines
Fixes 6ccd692bfb7f ("dmaengine: xilinx_dma: Add Xilinx AXI MCDMA Engine driver support")Signed-off-by Srinivas Neeli <[email protected]>---
Changes in V3:
- Added Fixes tag.
- Expanded commit message to explain the interrupt coalescing scenario and why thehas_sgguard is omitted for MCDMA.
- Changed local variable from 'bool completed' to 'u32 status' for cleaner status field access.
- Simplified completion check logic.Changes in V2:
- No change.--- drivers/dma/xilinx/xilinx_dma.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/dma/xilinx/xilinx_dma.c +11
-0@@ -1784,6 +1784,17 @@ static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan) struct xilinx_axidma_tx_segment, node);if (!(seg->hw.status &XILINX_DMA_BD_COMP_MASK ) && chan->has_sg)break ; + }else if (chan->xdev->dma_config->dmatype ==XDMA_TYPE_AXIMCDMA ) { +struct xilinx_aximcdma_tx_segment *seg; +u32 status; + + seg =list_last_entry (&desc->segments, + struct xilinx_aximcdma_tx_segment, + node); + status = (chan->direction ==DMA_DEV_TO_MEM ) ? + seg->hw.s2mm_status : seg->hw.mm2s_status; +if (!(status &XILINX_DMA_BD_COMP_MASK )) +break ; }if (chan->has_sg && chan->xdev->dma_config->dmatype !=XDMA_TYPE_VDMA )
[email protected]
AI reviewRe: [PATCH V3 2/4] dmaengine: xilinx_dma: Move descriptors to done list based on completion bit
In reply to Srinivas NeeliThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Software state mismatch leading to hardware corruption and channel hang in AXI MCDMA. - [Medium]…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Software state mismatch leading to hardware corruption and channel hang in AXI MCDMA.
- [Medium] Missing read memory barrier (dma_rmb()) after checking the DMA completion flag in coherent memory. --
--- Patch [2]: [PATCH V3 2/4] dmaengine: xilinx_dma: Move descriptors to done list based on completion bit --- commit d59255ad1a6d4a4beb643022da1f9820716a0752
Author: Srinivas Neeli <[email protected]>
dmaengine: xilinx_dma: Move descriptors to done list based on completion bit
In AXI MCDMA scatter-gather mode, xilinx_dma_complete_descriptor() previously moved all active descriptors to the done list unconditionally. This commit adds a check for the descriptor completion bit before moving entries, handling scenarios where interrupt coalescing causes interrupts before all queued descriptors are processed.
Quoted 8 lines
drivers/dma/xilinx/xilinx_dma.c +0
-0@@ -1773,6 +1773,17 @@ static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan) struct xilinx_axidma_tx_segment, node);if (!(seg->hw.status &XILINX_DMA_BD_COMP_MASK ) && chan->has_sg)break ;
drivers/dma/xilinx/xilinx_dma.c static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan) · line 1785
Quoted 10 lines
drivers/dma/xilinx/xilinx_dma.c +10
-0+ }else if (chan->xdev->dma_config->dmatype ==XDMA_TYPE_AXIMCDMA ) { +struct xilinx_aximcdma_tx_segment *seg; +u32 status; + + seg =list_last_entry (&desc->segments, + struct xilinx_aximcdma_tx_segment, + node); + status = (chan->direction ==DMA_DEV_TO_MEM ) ? + seg->hw.s2mm_status : seg->hw.mm2s_status; +if (!(status &XILINX_DMA_BD_COMP_MASK ))
[Severity: Medium]
Is a read memory barrier needed after checking this completion status?
The CPU polls the s2mm_status or mm2s_status field in coherent memory to check the completion bit. Without a dma_rmb() here, could weakly ordered architectures speculatively execute subsequent descriptor reads out of order?
This might result in stale reads of the descriptor fields later on (for instance, during residue calculation) before the hardware has actually confirmed completion.
drivers/dma/xilinx/xilinx_dma.c static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan) · line 1797
Quoted 1 line
drivers/dma/xilinx/xilinx_dma.c +1
-0+break ;
[Severity: High]
Does breaking out early here create a state mismatch with the IRQ handler?
If this check breaks out leaving descriptors in the active list, the channel is technically still running. However, looking at the call chain, xilinx_mcdma_irq_handler() immediately forces the channel idle and starts a new transfer:
xilinx_mcdma_irq_handler() {
...
xilinx_dma_complete_descriptor(chan);
chan->idle = true;
chan->start_transfer(chan);
...
}This appears to bypass the idle safety check in xilinx_mcdma_start_transfer() and overwrite the CDESC hardware register while the DMA engine is actively processing the remaining active list. Could this software-splice new descriptors without establishing hardware links, leading to a permanent channel hang?
Quoted 3 lines
drivers/dma/xilinx/xilinx_dma.c +1
-0+ }if (chan->has_sg && chan->xdev->dma_config->dmatype !=XDMA_TYPE_VDMA )
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH V3 2/4] dmaengine: xilinx_dma: Move descriptors to done list based on completion bit
hi,
Quoted 38 lines · On 7/9/2026 3:41 PM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Software state mismatch leading to hardware corruption and channel hang in AXI MCDMA.
- [Medium] Missing read memory barrier (dma_rmb()) after checking the DMA completion flag in coherent memory. ----- Patch [2]: [PATCH V3 2/4] dmaengine:
xilinx_dma: Move descriptors to done list based on completion bit --- commitd59255ad1a6d4a4beb643022da1f9820716a0752
Author: Srinivas Neeli <[email protected]>dmaengine:
xilinx_dma: Move descriptors to done list based on completion bitIn AXI MCDMA scatter-gather mode,
xilinx_dma_complete_descriptor()previously moved all active descriptors to the done list unconditionally. This commit adds a check for the descriptor completion bit before moving entries, handling scenarios where interrupt coalescing causes interrupts before all queued descriptors are processed.Quoted 8 lines
drivers/dma/xilinx/xilinx_dma.c +0
-0@@ -1773,6 +1773,17 @@ static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan) struct xilinx_axidma_tx_segment, node);if (!(seg->hw.status &XILINX_DMA_BD_COMP_MASK ) && chan->has_sg)break ;drivers/dma/xilinx/xilinx_dma.c static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan) · line 1785
Quoted 10 lines
drivers/dma/xilinx/xilinx_dma.c +10
-0+ }else if (chan->xdev->dma_config->dmatype ==XDMA_TYPE_AXIMCDMA ) { +struct xilinx_aximcdma_tx_segment *seg; +u32 status; + + seg =list_last_entry (&desc->segments, + struct xilinx_aximcdma_tx_segment, + node); + status = (chan->direction ==DMA_DEV_TO_MEM ) ? + seg->hw.s2mm_status : seg->hw.mm2s_status; +if (!(status &XILINX_DMA_BD_COMP_MASK ))[Severity: Medium]
Is a read memory barrier needed after checking this completion status?
Quoted 8 lines
The CPU polls the
s2mm_statusormm2s_statusfield in coherent memory to check the completion bit. Without adma_rmb()here, could weakly ordered architectures speculatively execute subsequent descriptor reads out of order?This might result in stale reads of the descriptor fields later on (for instance, during residue calculation) before the hardware has actually confirmed completion.
The MCDMA descriptors are allocated using dma_alloc_coherent(), which provides cache-coherent memory between CPU and device.
On coherent DMA memory, the CPU sees device writes without requiring explicit barriers, so dma_rmb() is not needed here.
Quoted 17 lines
drivers/dma/xilinx/xilinx_dma.c static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan) · line 1797
Quoted 1 line
drivers/dma/xilinx/xilinx_dma.c +1
-0+break ;[Severity: High]
Does breaking out early here create a state mismatch with the IRQ handler?If this check breaks out leaving descriptors in the active list, the channel is technically still running. However, looking at the call chain,
xilinx_mcdma_irq_handler()immediately forces the channel idle and starts a new transfer:xilinx_mcdma_irq_handler() { ... xilinx_dma_complete_descriptor(chan); chan->idle = true; chan->start_transfer(chan); ... }
Quoted 5 lines
This appears to bypass the idle safety check in
xilinx_mcdma_start_transfer()and overwrite the CDESC hardware register while the DMA engine is actively processing the remaining active list. Could this software-splice new descriptors without establishing hardware links, leading to a permanent channel hang?
I believe this analysis was run against an older version of the driver. The list_empty() guard was added in a recent patch series:
https://lore.kernel.org/all/[email protected]/
The current code in xilinx_mcdma_irq_handler() has this protection:
xilinx_dma_complete_descriptor(chan);
if (list_empty(&chan->active_list)) {
chan->idle = true;
chan->start_transfer(chan);
}
When the completion check breaks early (leaving incomplete descriptors in active_list), the list won't be empty, so neither chan->idle = true nor start_transfer() will execute. The hardware state remains consistent.
Thanks
Neeli Srinivas
Quoted 6 lines
Quoted 4 lines
drivers/dma/xilinx/xilinx_dma.c +1
-0+ }if (chan->has_sg && chan->xdev->dma_config->dmatype !=XDMA_TYPE_VDMA )[ ... ]
PATCH v3 3/4 net: xilinx: axienet: Derive RX frame length from DMA residue
In reply to Srinivas NeeliThe dmaengine RX path determined the received frame length by reading APP word 4 of the DMA descriptor metadata, masking the lower 16 bits of app_metadata[LEN_APP].
This relies on the optional AXI4-Stream status/control interface being present in the design. The descriptor APP fields are only populated by the hardware when that interface is enabled. On designs without it the APP fields are not updated, so the length read back is invalid.
The AXI DMA engine already reports how many bytes it wrote into the buffer through the standard dmaengine residue mechanism (dmaengine_result.residue). The received frame length is therefore the posted buffer length minus the residue, which is independent of the status/control interface and correct across all designs, including multi-descriptor frames where the residue is summed over the chain.
Use result->residue to compute the RX frame length and drop the descriptor metadata lookup, which was only used for this purpose. The error path now uses the standard dmaengine_result.result status instead of the metadata pointer return value, and the now-unused LEN_APP macro is removed.
The transmit path is unaffected. It still passes APP metadata for checksum offload and derives its length from the skb.
---
Changes in V3:
- New patch in this series.
- This patch enables axienet to work on designs where the AXI4-Stream status/control interface is not present. By using the standard dmaengine residue mechanism, the driver no longer depends on APP fields being populated by hardware.
- This approach replaces the V2 xferred_bytes mechanism (V2 patch 5/5), making the dt-bindings patch (V2 patch 4/5) for xlnx,include-stscntrl-strm also unnecessary. Both V2 patches are dropped in this series.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +5 -9
@@ -53,7 +53,6 @@#define TX_BD_NUM_MAX 4096#define RX_BD_NUM_MAX 4096#define DMA_NUM_APP_WORDS 5 -#define LEN_APP 4#define RX_BUF_NUM_DEFAULT 128/* Must be shorter than length of ethtool_drvinfo.driver field to fit */
@@ -1159,29 +1158,26 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)static void axienet_dma_rx_cb (void *data,const struct dmaengine_result *result) {struct skbuf_dma_descriptor *skbuf_dma; -size_t meta_len, meta_max_len, rx_len;struct axienet_local *lp = data;struct sk_buff *skb; -u32 *app_metadata; +size_t rx_len;int i; skbuf_dma =axienet_get_rx_desc (lp, lp->rx_ring_tail++); skb = skbuf_dma->skb; - app_metadata =dmaengine_desc_get_metadata_ptr (skbuf_dma->desc, &meta_len, - &meta_max_len);dma_unmap_single (lp->dev, skbuf_dma->dma_address, lp->max_frm_size,DMA_FROM_DEVICE ); -if (IS_ERR (app_metadata)) { +if (result->result !=DMA_TRANS_NOERROR ) {if (net_ratelimit ()) -netdev_err (lp->ndev,"Failed to get RX metadata pointer\n" ); +netdev_err (lp->ndev,"RX DMA transfer failed\n" );dev_kfree_skb_any (skb); lp->ndev->stats.rx_dropped++; goto rx_submit; } -/* TODO: Derive app word index programmatically */ - rx_len = (app_metadata[LEN_APP ] &0xFFFF ); +/* Actual length = posted buffer length - residue. */ + rx_len = lp->max_frm_size - result->residue;skb_put (skb, rx_len); skb->protocol =eth_type_trans (skb, lp->ndev); skb->ip_summed =CHECKSUM_NONE ;
Signature · 1 line
2.25.1
Re: [PATCH V3 3/4] net: xilinx: axienet: Derive RX frame length from DMA residue
rephrase to - derive RX frame length from residue in dmaengine path
Quoted 3 lines
The dmaengine RX path determined the received frame length by reading APP word 4 of the DMA descriptor metadata, masking the lower 16 bits of app_metadata[LEN_APP].
Avoid above explanation and make commit description concise.>
Quoted 12 lines
This relies on the optional AXI4-Stream status/control interface being present in the design. The descriptor APP fields are only populated by the hardware when that interface is enabled. On designs without it the APP fields are not updated, so the length read back is invalid.
The AXI DMA engine already reports how many bytes it wrote into the buffer through the standard dmaengine residue mechanism (dmaengine_result.residue). The received frame length is therefore the posted buffer length minus the residue, which is independent of the status/control interface and correct across all designs, including multi-descriptor frames where the residue is summed over the chain.
Quoted 4 lines
Use
result->residueto compute the RX frame length and drop the descriptor metadata lookup, which was only used for this purpose. The error path now uses the standard dmaengine_result.result status instead of the metadata pointer return value, and the now-unusedLEN_APPmacro is removed.
now unused>
Quoted 3 lines
The transmit path is unaffected. It still passes APP metadata for checksum offload and derives its length from the skb.
Switching to dmaengine residue is better alternative but consider it as an enhancement. Drop the fixes tag. The non-dmaengine axienet RX path still derives frame length from APP field and it's a design assumption.
Quoted 63 lines
Fixes 6a91b846af85 ("net: axienet: Introduce dmaengine support")Signed-off-by Srinivas Neeli <[email protected]>---
Changes in V3:
- New patch in this series.
- This patch enables axienet to work on designs where the AXI4-Stream status/control interface is not present. By using the standard dmaengine residue mechanism, the driver no longer depends on APP fields being populated by hardware.
- This approach replaces the V2xferred_bytesmechanism (V2 patch 5/5), making the dt-bindings patch (V2 patch 4/5) for xlnx,include-stscntrl-strm also unnecessary. Both V2 patches are dropped in this series.--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)drivers/net/ethernet/xilinx/xilinx_axienet_main.c +5
-9@@ -53,7 +53,6 @@#define TX_BD_NUM_MAX 4096#define RX_BD_NUM_MAX 4096#define DMA_NUM_APP_WORDS 5 -#define LEN_APP 4#define RX_BUF_NUM_DEFAULT 128/* Must be shorter than length of ethtool_drvinfo.driver field to fit */ @@ -1159,29 +1158,26 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)static void axienet_dma_rx_cb (void *data,const struct dmaengine_result *result) {struct skbuf_dma_descriptor *skbuf_dma; -size_t meta_len, meta_max_len, rx_len;struct axienet_local *lp = data;struct sk_buff *skb; -u32 *app_metadata; +size_t rx_len;int i; skbuf_dma =axienet_get_rx_desc (lp, lp->rx_ring_tail++); skb = skbuf_dma->skb; - app_metadata =dmaengine_desc_get_metadata_ptr (skbuf_dma->desc, &meta_len, - &meta_max_len);dma_unmap_single (lp->dev, skbuf_dma->dma_address, lp->max_frm_size,DMA_FROM_DEVICE ); -if (IS_ERR (app_metadata)) { +if (result->result !=DMA_TRANS_NOERROR ) {if (net_ratelimit ()) -netdev_err (lp->ndev,"Failed to get RX metadata pointer\n" ); +netdev_err (lp->ndev,"RX DMA transfer failed\n" );dev_kfree_skb_any (skb); lp->ndev->stats.rx_dropped++; goto rx_submit; } -/* TODO: Derive app word index programmatically */ - rx_len = (app_metadata[LEN_APP ] &0xFFFF ); +/* Actual length = posted buffer length - residue. */ + rx_len = lp->max_frm_size - result->residue;skb_put (skb, rx_len); skb->protocol =eth_type_trans (skb, lp->ndev); skb->ip_summed =CHECKSUM_NONE ;
[email protected]
AI reviewRe: [PATCH V3 3/4] net: xilinx: axienet: Derive RX frame length from DMA residue
In reply to Srinivas NeeliThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Pending SKBs and DMA mappings are completely leaked during device stop when using dmaengine.
- [High] TX ring head/tail desynchronization on DMA mapping failure leads to use-after-free and double-free in the TX callback. --
--- Patch [3]: [PATCH V3 3/4] net: xilinx: axienet: Derive RX frame length from DMA residue --- commit 0ead77c343fc9310122738aba9dee99007a10e45
Author: Srinivas Neeli <[email protected]>
net: xilinx: axienet: Derive RX frame length from DMA residue
The dmaengine RX path previously determined the received frame length by reading APP word 4 of the DMA descriptor metadata. This patch updates the code to use the standard dmaengine residue mechanism instead, allowing the driver to work on designs without the AXI4-Stream status/control interface.
Quoted 12 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-1@@ -53,7 +53,6 @@#define TX_BD_NUM_MAX 4096#define RX_BD_NUM_MAX 4096#define DMA_NUM_APP_WORDS 5 -#define LEN_APP 4#define RX_BUF_NUM_DEFAULT 128/* Must be shorter than length of ethtool_drvinfo.driver field to fit */
[ ... ]
drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_stop() {
...
for (i = 0; i < TX_BD_NUM_MAX; i++)
kfree(lp->tx_skb_ring[i]);
kfree(lp->tx_skb_ring);
for (i = 0; i < RX_BUF_NUM_DEFAULT; i++)
kfree(lp->rx_skb_ring[i]);
kfree(lp->rx_skb_ring);
...
}[Severity: High]
This isn't a bug introduced by this patch, but are pending SKBs and DMA mappings leaked during device stop when using dmaengine?
The descriptor wrapper objects are freed here without first unmapping the associated DMA addresses or freeing the encapsulated SKBs.
Since the driver loses all pointers to previously allocated SKBs and their DMA mappings, could this exhaust IOMMU space and leak memory each time the interface is brought down?
drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_start_xmit_dmaengine() {
...
lp->tx_ring_head++;
sg_init_table(skbuf_dma->sgl, sg_len);
ret = skb_to_sgvec(skb, skbuf_dma->sgl, 0, skb->len);
if (ret < 0)
goto xmit_error_drop_skb;
ret = dma_map_sg(lp->dev, skbuf_dma->sgl, sg_len, DMA_TO_DEVICE);
if (!ret)
goto xmit_error_drop_skb;
...
}drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_dma_tx_cb() {
...
skbuf_dma = axienet_get_tx_desc(lp, lp->tx_ring_tail++);
len = skbuf_dma->skb->len;
txq = skb_get_tx_queue(lp->ndev, skbuf_dma->skb);
...
dev_consume_skb_any(skbuf_dma->skb);
...
}[Severity: High]
This is a pre-existing issue, but does this lead to a TX ring head and tail desynchronization on DMA mapping failure?
In axienet_start_xmit_dmaengine(), the tx_ring_head is advanced before the failure points, and the error path does not roll it back or submit a dummy descriptor.
If skb_to_sgvec() or dma_map_sg() fails, and a subsequent packet successfully completes, axienet_dma_tx_cb() will unconditionally increment tx_ring_tail.
Would it then incorrectly operate on the out-of-sync tail index, dereferencing and freeing the SKB pointer of the previously failed mapping?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH V3 3/4] net: xilinx: axienet: Derive RX frame length from DMA residue
Hi,
Quoted 87 lines · On 7/9/2026 3:41 PM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Pending SKBs and DMA mappings are completely leaked during device stop when using dmaengine.
- [High] TX ring head/tail desynchronization on DMA mapping failure leads to use-after-free and double-free in the TX callback. ----- Patch [3]: [PATCH V3 3/4] net: xilinx: axienet: Derive RX frame length from DMA residue --- commit
0ead77c343fc9310122738aba9dee99007a10e45
Author: Srinivas Neeli <[email protected]>net: xilinx: axienet: Derive RX frame length from DMA residue
The dmaengine RX path previously determined the received frame length by reading APP word 4 of the DMA descriptor metadata. This patch updates the code to use the standard dmaengine residue mechanism instead, allowing the driver to work on designs without the AXI4-Stream status/control interface.
Quoted 12 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-1@@ -53,7 +53,6 @@#define TX_BD_NUM_MAX 4096#define RX_BD_NUM_MAX 4096#define DMA_NUM_APP_WORDS 5 -#define LEN_APP 4#define RX_BUF_NUM_DEFAULT 128/* Must be shorter than length of ethtool_drvinfo.driver field to fit */ [ ... ]
drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_stop() { ... for (i = 0; i < TX_BD_NUM_MAX; i++) kfree(lp->tx_skb_ring[i]); kfree(lp->tx_skb_ring); for (i = 0; i < RX_BUF_NUM_DEFAULT; i++) kfree(lp->rx_skb_ring[i]); kfree(lp->rx_skb_ring); ... }[Severity: High]
This isn't a bug introduced by this patch, but are pending SKBs and DMA mappings leaked during device stop when using dmaengine?The descriptor wrapper objects are freed here without first unmapping the associated DMA addresses or freeing the encapsulated SKBs.
Since the driver loses all pointers to previously allocated SKBs and their DMA mappings, could this exhaust IOMMU space and leak memory each time the interface is brought down?
drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_start_xmit_dmaengine() { ... lp->tx_ring_head++; sg_init_table(skbuf_dma->sgl, sg_len); ret = skb_to_sgvec(skb, skbuf_dma->sgl, 0, skb->len); if (ret < 0) goto xmit_error_drop_skb; ret = dma_map_sg(lp->dev, skbuf_dma->sgl, sg_len, DMA_TO_DEVICE); if (!ret) goto xmit_error_drop_skb; ... }drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_dma_tx_cb() { ... skbuf_dma = axienet_get_tx_desc(lp, lp->tx_ring_tail++); len = skbuf_dma->skb->len; txq = skb_get_tx_queue(lp->ndev, skbuf_dma->skb); ... dev_consume_skb_any(skbuf_dma->skb); ... }[Severity: High]
This is a pre-existing issue, but does this lead to a TX ring head and tail desynchronization on DMA mapping failure?In
axienet_start_xmit_dmaengine(), thetx_ring_headis advanced before the failure points, and the error path does not roll it back or submit a dummy descriptor.
Quoted 5 lines
If
skb_to_sgvec()ordma_map_sg()fails, and a subsequent packet successfully completes,axienet_dma_tx_cb()will unconditionally incrementtx_ring_tail.Would it then incorrectly operate on the out-of-sync tail index, dereferencing and freeing the SKB pointer of the previously failed mapping?
Both issues identified (SKB/DMA cleanup in axienet_stop and TX ring head/tail desync) are valid pre-existing concerns in the dmaengine path, not introduced by this patch.
I will address these in a separate patch series.
Thanks,
Neeli Srinivas
PATCH v3 4/4 dmaengine: xilinx_dma: Extend metadata handling for AXI DMA and MCDMA
In reply to Srinivas NeeliFrom: Suraj Gupta <[email protected]>
xilinx_dma_get_metadata_ptr() exposed only the descriptor APP fields. Both AXI DMA and AXI MCDMA descriptors carry a status word with the transfer status, and AXI MCDMA additionally carries an AXI4-Stream sideband status word holding TID, TDEST and TUSER that clients may need. Extend the metadata handling to expose these.
The returned pointer now starts at the descriptor status word for both AXI DMA and AXI MCDMA. As the descriptor words are contiguous, the client sees the status at index 0, followed for AXI MCDMA by the sideband status (TID/TDEST/TUSER) at index 1 and the APP fields, or for AXI DMA by the APP fields directly. The payload length is derived from the field sizes.
This changes the get_metadata_ptr() contract for AXI DMA. The pointer now starts at the status word of the last (EOF) descriptor instead of the APP fields of the first, and the payload grows from 20 to 24 bytes. A client reading app[0] now reads the status word. No in-tree consumer is affected, as the axienet driver reads the RX frame length from result->residue rather than the APP fields. Reading the EOF descriptor is also correct, as the hardware writes the status and APP fields there.
The index 0 and 1 layout described above is for the AXI MCDMA receive (S2MM) direction, which is where metadata is consumed. On the transmit (MM2S) direction the same descriptor words hold different fields.
The probe logic is extended to read xlnx,axistream-connected for MCDMA, and xilinx_mcdma_prep_slave_sg() attaches metadata_ops when an AXI Stream interface is present, so MCDMA clients can use the metadata API in the same way as AXI DMA clients.
---
Changes in V3:
- Renamed subject to include "AXI DMA and MCDMA" (was "AXI MCDMA" only).
- Complete rewrite of commit message and implementation.
- Metadata pointer now returns status field at index 0 instead of APP fields, exposing status and sideband information to clients.
- Changed from list_first_entry to list_last_entry to return the EOF descriptor where hardware writes status and APP fields.
- Added explicit handling for both AXIDMA and MCDMA types with proper payload length calculation.
- Added WARN_ON_ONCE for unsupported DMA types.
- Removed the 'chan' field from struct xilinx_dma_tx_descriptor (was added in V2) as it's no longer needed; channel is obtained from tx->chan instead.
- Dropped V2 patches 4/5 (dt-bindings xlnx,include-stscntrl-strm) and 5/5 (xferred_bytes support) as the approach changed to use residue.
Changes in V2:
- Added support for MCDMA metadata handling alongside AXIDMA.
- Added 'chan' field to struct xilinx_dma_tx_descriptor.
--- drivers/dma/xilinx/xilinx_dma.c | 48 ++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 7 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +41 -7
@@ -651,18 +651,48 @@ static inline void xilinx_aximcdma_buf(struct xilinx_dma_chan *chan,* @tx: async transaction descriptor * @payload_len: metadata payload length * @max_len: metadata max length -* Return: The app field pointer. +* +* The returned pointer starts at the descriptor status word for both AXI DMA +* and AXI MCDMA. As the descriptor words are contiguous, the client sees the +* status at index 0, followed for AXI MCDMA by the sideband status +* (TID/TDEST/TUSER) at index 1 and the APP fields from index 2, or for AXI DMA +* by the APP fields from index 1. These fields are populated by the hardware on +* the End-Of-Frame descriptor, so the pointer is taken from there. +* +* Return: Pointer to the descriptor status field. */ static void *xilinx_dma_get_metadata_ptr (struct dma_async_tx_descriptor *tx,size_t *payload_len,size_t *max_len) {struct xilinx_dma_tx_descriptor *desc =to_dma_tx_descriptor (tx); -struct xilinx_axidma_tx_segment *seg; +struct xilinx_dma_chan *chan =to_xilinx_chan (tx->chan); + +if (chan->xdev->dma_config->dmatype ==XDMA_TYPE_AXIMCDMA ) { +struct xilinx_aximcdma_tx_segment *seg = +list_last_entry (&desc->segments, + struct xilinx_aximcdma_tx_segment, node); + +/* [0] = status, [1] = sideband (TID/TDEST/TUSER), [2..] = app */ + *max_len = *payload_len =sizeof (seg->hw.s2mm_status) + +sizeof (seg->hw.s2mm_sideband_status) + +sizeof (seg->hw.app); +return &seg->hw.s2mm_status; + } + +if (chan->xdev->dma_config->dmatype ==XDMA_TYPE_AXIDMA ) { +struct xilinx_axidma_tx_segment *seg = +list_last_entry (&desc->segments, + struct xilinx_axidma_tx_segment, node); + +/* [0] = status, [1..] = app */ + *max_len = *payload_len =sizeof (seg->hw.status) + +sizeof (seg->hw.app); +return &seg->hw.status; + } - *max_len = *payload_len =sizeof (u32) *XILINX_DMA_NUM_APP_WORDS ; - seg =list_first_entry (&desc->segments, - struct xilinx_axidma_tx_segment, node); -return seg->hw.app; +/* Only AXIDMA and MCDMA attach metadata_ops today. */ +WARN_ON_ONCE (1 ); +return ERR_PTR (-EINVAL ); }static struct dma_descriptor_metadata_ops xilinx_dma_metadata_ops = {
@@ -2639,6 +2669,9 @@ xilinx_mcdma_prep_slave_sg(struct dma_chan *dchan, struct scatterlist *sgl, segment->hw.control |=XILINX_MCDMA_BD_EOP ; } +if (chan->xdev->has_axistream_connected) + desc->async_tx.metadata_ops = &xilinx_dma_metadata_ops; +return &desc->async_tx; error:
@@ -3287,7 +3320,8 @@ static int xilinx_dma_probe(struct platform_device *pdev)dma_set_max_seg_size (xdev->dev, xdev->max_buffer_len); -if (xdev->dma_config->dmatype ==XDMA_TYPE_AXIDMA ) { +if (xdev->dma_config->dmatype ==XDMA_TYPE_AXIDMA || + xdev->dma_config->dmatype ==XDMA_TYPE_AXIMCDMA ) { xdev->has_axistream_connected =of_property_read_bool (node,"xlnx,axistream-connected" ); }
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH V3 4/4] dmaengine: xilinx_dma: Extend metadata handling for AXI DMA and MCDMA
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Modifying chan->free_seg_list without holding chan->lock causes linked list corruption. --
--- Patch [4]: [PATCH V3 4/4] dmaengine: xilinx_dma: Extend metadata handling for AXI DMA and MCDMA --- commit 7c1e9fcfa16f54b84c1fd0328dc790510cde97be
Author: Suraj Gupta <[email protected]>
dmaengine: xilinx_dma: Extend metadata handling for AXI DMA and MCDMA
This commit extends metadata handling for AXI DMA and MCDMA to expose status and sideband information. The metadata pointer now starts at the descriptor status word instead of the APP fields, and probe logic is updated to attach metadata_ops when an AXI Stream interface is present.
Quoted 4 lines
drivers/dma/xilinx/xilinx_dma.c +0
-0
[ ... ]
Quoted 11 lines
drivers/dma/xilinx/xilinx_dma.c +3
-0@@ -2623,6 +2653,9 @@ xilinx_mcdma_prep_slave_sg(struct dma_chan *dchan, struct scatterlist *sgl, segment->hw.control |=XILINX_MCDMA_BD_EOP ; } +if (chan->xdev->has_axistream_connected) + desc->async_tx.metadata_ops = &xilinx_dma_metadata_ops; +return &desc->async_tx; error:
xilinx_dma_free_tx_descriptor(chan, desc);
[Severity: High]
This isn't a bug introduced by this patch, but does this error path corrupt the channel's free segment list?
When xilinx_mcdma_prep_slave_sg() encounters an error, it calls xilinx_dma_free_tx_descriptor() without holding chan->lock. This eventually cascades to xilinx_mcdma_free_tx_segment() and xilinx_dma_free_tx_segment(), which add the segment back to chan->free_seg_list:
xilinx_mcdma_free_tx_segment()
list_add_tail(&segment->node, &chan->free_seg_list);
If another CPU core concurrently calls xilinx_aximcdma_alloc_tx_segment(), which acquires chan->lock to remove items from this same list, could this unprotected modification lead to linked list corruption?
This unprotected error path also appears to be present in xilinx_dma_tx_submit() when chan->cyclic is true.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH V3 4/4] dmaengine: xilinx_dma: Extend metadata handling for AXI DMA and MCDMA
Hi,
Quoted 44 lines · On 7/9/2026 3:41 PM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Modifyingchan->free_seg_listwithout holdingchan->lockcauses linked list corruption. ----- Patch [4]: [PATCH V3 4/4] dmaengine:
xilinx_dma: Extend metadata handling for AXI DMA and MCDMA --- commit7c1e9fcfa16f54b84c1fd0328dc790510cde97be
Author: Suraj Gupta <[email protected]>dmaengine:
xilinx_dma: Extend metadata handling for AXI DMA and MCDMAThis commit extends metadata handling for AXI DMA and MCDMA to expose status and sideband information. The metadata pointer now starts at the descriptor status word instead of the APP fields, and probe logic is updated to attach
metadata_opswhen an AXI Stream interface is present.Quoted 4 lines
drivers/dma/xilinx/xilinx_dma.c +0
-0[ ... ]
Quoted 11 lines
drivers/dma/xilinx/xilinx_dma.c +3
-0@@ -2623,6 +2653,9 @@ xilinx_mcdma_prep_slave_sg(struct dma_chan *dchan, struct scatterlist *sgl, segment->hw.control |=XILINX_MCDMA_BD_EOP ; } +if (chan->xdev->has_axistream_connected) + desc->async_tx.metadata_ops = &xilinx_dma_metadata_ops; +return &desc->async_tx; error:xilinx_dma_free_tx_descriptor(chan, desc);[Severity: High]
This isn't a bug introduced by this patch, but does this error path corrupt the channel's free segment list?When
xilinx_mcdma_prep_slave_sg()encounters an error, it callsxilinx_dma_free_tx_descriptor()without holdingchan->lock. This eventually cascades toxilinx_mcdma_free_tx_segment()andxilinx_dma_free_tx_segment(), which add the segment back tochan->free_seg_list:
xilinx_mcdma_free_tx_segment()
Quoted 8 lines
list_add_tail(&segment->node, &chan->free_seg_list);If another CPU core concurrently calls
xilinx_aximcdma_alloc_tx_segment(), which acquireschan->lockto remove items from this same list, could this unprotected modification lead to linked list corruption?This unprotected error path also appears to be present in
xilinx_dma_tx_submit()whenchan->cyclicis true.
The locking issue with free_seg_list modification is a valid pre-existing concern, not introduced by this patch.
I'll address this in a separate patch series along with the other pre-existing issues identified in this review.
Thanks,
Neeli Srinivas
Re: [PATCH V3 4/4] dmaengine: xilinx_dma: Extend metadata handling for AXI DMA and MCDMA
In reply to Srinivas NeeliQuoted 22 lines
From: Suraj Gupta <[email protected]>
xilinx_dma_get_metadata_ptr()exposed only the descriptor APP fields. Both AXI DMA and AXI MCDMA descriptors carry a status word with the transfer status, and AXI MCDMA additionally carries an AXI4-Stream sideband status word holding TID, TDEST and TUSER that clients may need. Extend the metadata handling to expose these.The returned pointer now starts at the descriptor status word for both AXI DMA and AXI MCDMA. As the descriptor words are contiguous, the client sees the status at index 0, followed for AXI MCDMA by the sideband status (TID/TDEST/TUSER) at index 1 and the APP fields, or for AXI DMA by the APP fields directly. The payload length is derived from the field sizes.
This changes the
get_metadata_ptr()contract for AXI DMA. The pointer now starts at the status word of the last (EOF) descriptor instead of the APP fields of the first, and the payload grows from 20 to 24 bytes. A client reading app[0] now reads the status word. No in-tree consumer is affected, as the axienet driver reads the RX frame length fromresult->residuerather than the APP fields. Reading the EOF descriptor is also correct, as the hardware writes the status and APP fields there.
Quoted 8 lines
The index 0 and 1 layout described above is for the AXI MCDMA receive (S2MM) direction, which is where metadata is consumed. On the transmit (MM2S) direction the same descriptor words hold different fields.
The probe logic is extended to read xlnx,axistream-connected for MCDMA, and
xilinx_mcdma_prep_slave_sg()attachesmetadata_opswhen an AXI Stream interface is present, so MCDMA clients can use the metadata API in the same way as AXI DMA clients.
Nit - make the commit description precise.>
Quoted 48 lines
Signed-off-by Suraj Gupta <[email protected]>Co-developed-by Srinivas Neeli <[email protected]>Signed-off-by Srinivas Neeli <[email protected]>---
Changes in V3:
- Renamed subject to include "AXI DMA and MCDMA" (was "AXI MCDMA" only).
- Complete rewrite of commit message and implementation.
- Metadata pointer now returns status field at index 0 instead of APP fields, exposing status and sideband information to clients.
- Changed fromlist_first_entrytolist_last_entryto return the EOF descriptor where hardware writes status and APP fields.
- Added explicit handling for both AXIDMA and MCDMA types with proper payload length calculation.
- AddedWARN_ON_ONCEfor unsupported DMA types.
- Removed the 'chan' field from structxilinx_dma_tx_descriptor(was added in V2) as it's no longer needed; channel is obtained fromtx->chaninstead.
- Dropped V2 patches 4/5 (dt-bindings xlnx,include-stscntrl-strm) and 5/5 (xferred_bytessupport) as the approach changed to use residue.Changes in V2:
- Added support for MCDMA metadata handling alongside AXIDMA.
- Added 'chan' field to structxilinx_dma_tx_descriptor.--- drivers/dma/xilinx/xilinx_dma.c | 48 ++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 7 deletions(-)drivers/dma/xilinx/xilinx_dma.c +9
-1@@ -651,18 +651,48 @@ static inline void xilinx_aximcdma_buf(struct xilinx_dma_chan *chan,* @tx: async transaction descriptor * @payload_len: metadata payload length * @max_len: metadata max length -* Return: The app field pointer. +* +* The returned pointer starts at the descriptor status word for both AXI DMA +* and AXI MCDMA. As the descriptor words are contiguous, the client sees the +* status at index 0, followed for AXI MCDMA by the sideband status +* (TID/TDEST/TUSER) at index 1 and the APP fields from index 2, or for AXI DMA +* by the APP fields from index 1. These fields are populated by the hardware on +* the End-Of-Frame descriptor, so the pointer is taken from there. +* +* Return: Pointer to the descriptor status field. */ static void *xilinx_dma_get_metadata_ptr (struct dma_async_tx_descriptor *tx,size_t *payload_len,size_t *max_len)
drivers/dma/xilinx/xilinx_dma.c static inline void xilinx_aximcdma_buf(struct xilinx_dma_chan *chan, · line 674
Quoted 10 lines
drivers/dma/xilinx/xilinx_dma.c +7
-1{struct xilinx_dma_tx_descriptor *desc =to_dma_tx_descriptor (tx); -struct xilinx_axidma_tx_segment *seg; +struct xilinx_dma_chan *chan =to_xilinx_chan (tx->chan); + +if (chan->xdev->dma_config->dmatype ==XDMA_TYPE_AXIMCDMA ) { +struct xilinx_aximcdma_tx_segment *seg = +list_last_entry (&desc->segments, + struct xilinx_aximcdma_tx_segment, node); +
This func is common for MCDMA s2mm and mm2s channel. Please make it generic to address both.
Quoted 15 lines
drivers/dma/xilinx/xilinx_dma.c +15
-0+/* [0] = status, [1] = sideband (TID/TDEST/TUSER), [2..] = app */ + *max_len = *payload_len =sizeof (seg->hw.s2mm_status) + +sizeof (seg->hw.s2mm_sideband_status) + +sizeof (seg->hw.app); +return &seg->hw.s2mm_status; + } + +if (chan->xdev->dma_config->dmatype ==XDMA_TYPE_AXIDMA ) { +struct xilinx_axidma_tx_segment *seg = +list_last_entry (&desc->segments, + struct xilinx_axidma_tx_segment, node); + +/* [0] = status, [1..] = app */ + *max_len = *payload_len =sizeof (seg->hw.status) + +sizeof (seg->hw.app);
drivers/dma/xilinx/xilinx_dma.c static inline void xilinx_aximcdma_buf(struct xilinx_dma_chan *chan, · line 695
Quoted 10 lines
drivers/dma/xilinx/xilinx_dma.c +5
-4+return &seg->hw.status; + } - *max_len = *payload_len =sizeof (u32) *XILINX_DMA_NUM_APP_WORDS ; - seg =list_first_entry (&desc->segments, - struct xilinx_axidma_tx_segment, node); -return seg->hw.app; +/* Only AXIDMA and MCDMA attach metadata_ops today. */ +WARN_ON_ONCE (1 ); +return ERR_PTR (-EINVAL );
We are registering metadata ops for MCDMA and AXI DMA so when is this error condition going to happen?
Quoted 23 lines
drivers/dma/xilinx/xilinx_dma.c +5
-1}static struct dma_descriptor_metadata_ops xilinx_dma_metadata_ops = {@@ -2639,6 +2669,9 @@ xilinx_mcdma_prep_slave_sg(struct dma_chan *dchan, struct scatterlist *sgl, segment->hw.control |=XILINX_MCDMA_BD_EOP ; } +if (chan->xdev->has_axistream_connected) + desc->async_tx.metadata_ops = &xilinx_dma_metadata_ops; +return &desc->async_tx; error:@@ -3287,7 +3320,8 @@ static int xilinx_dma_probe(struct platform_device *pdev)dma_set_max_seg_size (xdev->dev, xdev->max_buffer_len); -if (xdev->dma_config->dmatype ==XDMA_TYPE_AXIDMA ) { +if (xdev->dma_config->dmatype ==XDMA_TYPE_AXIDMA || + xdev->dma_config->dmatype ==XDMA_TYPE_AXIMCDMA ) { xdev->has_axistream_connected =of_property_read_bool (node,"xlnx,axistream-connected" ); }