* [PATCH net-next v2] net: xilinx: axienet: Derive RX frame length from residue in dmaengine path
@ 2026-11-23 16:42 Srinivas Neeli
2026-11-24 5:39 ` Gupta, Suraj
2026-11-24 16:46 ` netdev-bot+sashiko
0 siblings, 2 replies; 3+ messages in thread
From: Srinivas Neeli @ 2026-11-23 16:42 UTC (permalink / raw)
To: radhey.shyam.pandey, andrew+netdev, davem, edumazet, kuba,
pabeni, michal.simek, horms
Cc: netdev, linux-arm-kernel, linux-kernel, git
The dmaengine RX path derived the received frame length from the descriptor
APP metadata. That only works when the optional AXI4-Stream status/control
interface is present, because the hardware populates the APP fields solely
when that interface is enabled. On designs without it 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. Compute the RX frame
length as the posted buffer length minus result->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.
Drop the descriptor metadata lookup, which was only used for this purpose.
Detect a failed transfer from dmaengine_result.result instead of the
metadata pointer return value, and remove the now unused LEN_APP macro.
The transmit path is unaffected. It still passes APP metadata for checksum
offload and derives its length from the skb.
Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
Signed-off-by: Srinivas Neeli <srinivas.neeli@amd.com>
---
Changes in v2:
- Refresh the patch against next-20261120 to address the reported
git am failure. No intended change to the RX logic.
base-commit: 909ef7a9a30fa139e69e555e3606680f5cca7726
Apply failure reported in:
https://lore.kernel.org/lkml/20261123140311.GB31322@horms.kernel.org/
This patch was originally posted as part of the MCDMA series and can
be applied independently of the other patches in that series.
https://lore.kernel.org/lkml/20260818174151.1608971-4-srinivas.neeli@amd.com/
---
drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
index 7e83c4b5f193..5b4998e2ca14 100644
--- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
+++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
@@ -55,7 +55,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 */
@@ -1219,30 +1218,27 @@ 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);
skbuf_dma->skb = NULL;
- 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;
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v2] net: xilinx: axienet: Derive RX frame length from residue in dmaengine path
2026-11-23 16:42 [PATCH net-next v2] net: xilinx: axienet: Derive RX frame length from residue in dmaengine path Srinivas Neeli
@ 2026-11-24 5:39 ` Gupta, Suraj
2026-11-24 16:46 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: Gupta, Suraj @ 2026-11-24 5:39 UTC (permalink / raw)
To: Srinivas Neeli, radhey.shyam.pandey, andrew+netdev, davem,
edumazet, kuba, pabeni, michal.simek, horms
Cc: netdev, linux-arm-kernel, linux-kernel, git
On 11/23/2026 10:12 PM, Srinivas Neeli wrote:
> The dmaengine RX path derived the received frame length from the descriptor
> APP metadata. That only works when the optional AXI4-Stream status/control
> interface is present, because the hardware populates the APP fields solely
> when that interface is enabled. On designs without it 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. Compute the RX frame
> length as the posted buffer length minus result->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.
>
> Drop the descriptor metadata lookup, which was only used for this purpose.
> Detect a failed transfer from dmaengine_result.result instead of the
> metadata pointer return value, and remove the now unused LEN_APP macro.
>
> The transmit path is unaffected. It still passes APP metadata for checksum
> offload and derives its length from the skb.
>
> Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
> Signed-off-by: Srinivas Neeli <srinivas.neeli@amd.com>
Reviewed-by: Suraj Gupta <suraj.gupta2@amd.com>
Thanks!
Suraj
> ---
> Changes in v2:
> - Refresh the patch against next-20261120 to address the reported
> git am failure. No intended change to the RX logic.
> base-commit: 909ef7a9a30fa139e69e555e3606680f5cca7726
>
> Apply failure reported in:
> https://lore.kernel.org/lkml/20261123140311.GB31322@horms.kernel.org/
>
> This patch was originally posted as part of the MCDMA series and can
> be applied independently of the other patches in that series.
> https://lore.kernel.org/lkml/20260818174151.1608971-4-srinivas.neeli@amd.com/
> ---
> drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 14 +++++---------
> 1 file changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> index 7e83c4b5f193..5b4998e2ca14 100644
> --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> @@ -55,7 +55,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 */
> @@ -1219,30 +1218,27 @@ 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);
> skbuf_dma->skb = NULL;
>
> - 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;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v2] net: xilinx: axienet: Derive RX frame length from residue in dmaengine path
2026-11-23 16:42 [PATCH net-next v2] net: xilinx: axienet: Derive RX frame length from residue in dmaengine path Srinivas Neeli
2026-11-24 5:39 ` Gupta, Suraj
@ 2026-11-24 16:46 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 16:46 UTC (permalink / raw)
To: srinivas.neeli
Cc: radhey.shyam.pandey, andrew+netdev, davem, edumazet, kuba,
pabeni, michal.simek, horms, netdev, linux-arm-kernel,
linux-kernel, git
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The commit message says the residue-based length is "correct
across all designs, including multi-descriptor frames".
- [Medium] The commit message says that summing the residue over the
chain gives the correct length for multi-descriptor frames.
- [Low] This patch fixes a real, user-visible RX failure in the dmaengine
path of axienet_dma_rx_cb()…
--
net: xilinx: axienet: Derive RX frame length from residue in dmaengine path
This commit changes axienet_dma_rx_cb() so that the dmaengine RX path
computes the received frame length as the posted buffer length minus
result->residue. Previously the length came from the APP4 descriptor
metadata word. It also detects failed transfers through
dmaengine_result.result and removes the unused LEN_APP macro.
> diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> index 7e83c4b5f1931..5b4998e2ca148 100644
> --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
[ ... ]
> @@ -1219,30 +1218,27 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
> static void axienet_dma_rx_cb(void *data, const struct dmaengine_result *result)
> {
[ ... ]
> - /* 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;
[Severity: Low]
This fixes a receive failure that users can see. Should it carry a Fixes:
tag and go through net rather than net-next?
The line being replaced came in with commit 6a91b846af85 ("net: axienet:
Introduce dmaengine support"). On designs without the status/control
stream, the old code had two failure modes.
If the channel has no metadata_ops, dmaengine_desc_get_metadata_ptr()
returns ERR_PTR(-ENOTSUPP) and every frame is dropped here:
if (IS_ERR(app_metadata)) {
...
dev_kfree_skb_any(skb);
lp->ndev->stats.rx_dropped++;
goto rx_submit;
}
Before commit 8bbceba7dc5090, that ERR_PTR was dereferenced instead.
If metadata_ops is present but the status stream is absent, the invalid
APP4 value is passed straight to skb_put().
The stable trees that carry the dmaengine RX path won't pick this up unless
it has something like:
Fixes: 6a91b846af85 ("net: axienet: Introduce dmaengine support")
> skb_put(skb, rx_len);
> skb->protocol = eth_type_trans(skb, lp->ndev);
[Severity: Medium]
The commit message says the residue-based length is "correct across all
designs, including multi-descriptor frames where the residue is summed over
the chain". Does that hold for a frame longer than one posted RX buffer?
axienet_rx_submit_desc() posts each skb as its own dmaengine descriptor
with a single sg entry:
sg_dma_len(skbuf_dma->sgl) = lp->max_frm_size;
dma_rx_desc = dmaengine_prep_slave_sg(lp->rx_chan, skbuf_dma->sgl,
1, DMA_DEV_TO_MEM,
xilinx_dma_get_residue() only sums the segments of that one descriptor:
residue += (axidma_hw->control & chan->xdev->max_buffer_len) -
(axidma_hw->status & chan->xdev->max_buffer_len);
So the residue is never summed across the several descriptors that make up
one frame.
When the MTU is above 1500, axienet_device_reset() sets max_frm_size to
mtu + VLAN_ETH_HLEN + XAE_TRL_SIZE and enables XAE_OPTION_JUMBO. No maximum
receive frame length is programmed into the MAC.
If the MAC then accepts frames longer than max_frm_size, any L2 peer can
send one. For example, a double-tagged frame at MTU size is mtu + 26 bytes.
AXI DMA S2MM fills the current BD without EOF and continues into the next
BD, which belongs to the next descriptor and the next skb:
first callback: residue == 0, so a truncated max_frm_size frame is
passed to __netif_rx()
second callback: rx_len == remainder, so eth_type_trans() parses bytes
from the sender's payload as a new Ethernet header
Could a remote peer use this to inject a frame with its own choice of MAC
addresses, ethertype and VLAN tag, getting past hardware MAC filtering and
VLAN separation?
If the remainder is shorter than ETH_HLEN, eth_skb_pull_mac() silently
fails and the short skb is still passed up the stack.
axienet_dma_rx_cb() never checks XAXIDMA_BD_STS_RXSOF_MASK or
XAXIDMA_BD_STS_RXEOF_MASK, and dmaengine_result does not carry them.
The missing SOF/EOF handling predates this patch. Before it, APP4 on the
EOF BD held the full frame length, so skb_put() hit skb_over_panic(). With
this change the same input instead becomes silent frame splitting.
Should buffers that don't carry both SOF and EOF be dropped? Alternatively,
could the MAC's accepted frame size be limited to max_frm_size?
[Severity: Medium]
A related case can happen inside a single descriptor. Is the summed
residue still correct when the dmaengine provider splits the single RX sg
into several BDs?
xilinx_dma_prep_slave_sg() caps each hardware BD at xdev->max_buffer_len
through xilinx_dma_calc_copysize(). max_buffer_len comes from
xlnx,sg-length-width, which can be 8 to 26 bits.
Nothing in axienet checks lp->max_frm_size against that per-BD limit. Two
examples where one descriptor ends up with several BDs:
width 13 (8191) with MTU 9000 (max_frm_size 9022)
width 10 (1023) with the default 1522 byte max_frm_size
AXI DMA S2MM ends a BD at TLAST and starts each packet in a new BD. The
legacy axienet_rx_poll() relies on the same behaviour.
xilinx_dma_complete_descriptor() only checks the last segment:
if (!(seg->hw.status & XILINX_DMA_BD_COMP_MASK) && chan->has_sg)
break;
With a frame A shorter than BD0, the sequence would be:
frame A lands in BD0, and the descriptor stays pending
frame B lands in BD1, which is the same skb at offset BD0-size
BD1 completes, and the residue sum gives rx_len = len(A) + len(B)
Would axienet_dma_rx_cb() then deliver frame A followed by len(B) bytes of
stale buffer data, and lose frame B? If B is longer than BD1, it spills
into the next descriptor as described above.
The old APP4 method was also wrong here, because it reported B's length
from the last BD. However, the commit message explicitly says the
summed-residue case is handled correctly.
> skb->ip_summed = CHECKSUM_NONE;
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123164251.48234-1-srinivas.neeli%40amd.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-24 16:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 16:42 [PATCH net-next v2] net: xilinx: axienet: Derive RX frame length from residue in dmaengine path Srinivas Neeli
2026-11-24 5:39 ` Gupta, Suraj
2026-11-24 16:46 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®