* [PATCH net v3 0/2] Drop in-flight Tx SKBs on MACB close
@ 2026-06-17 9:17 Théo Lebrun
2026-06-17 9:17 ` [PATCH net v3 1/2] net: macb: give reasons for Tx SKB kfree Théo Lebrun
2026-06-17 9:17 ` [PATCH net v3 2/2] net: macb: drop in-flight Tx SKBs on close Théo Lebrun
0 siblings, 2 replies; 5+ messages in thread
From: Théo Lebrun @ 2026-06-17 9:17 UTC (permalink / raw)
To: Nicolas Ferre, Claudiu Beznea, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Haavard Skinnemoen,
Jeff Garzik, Conor Dooley
Cc: Paolo Valerio, Nicolai Buchwitz, netdev, linux-kernel,
Vladimir Kondratiev, Gregory CLEMENT, Benoît Monin,
Tawfik Bayouk, Thomas Petazzoni, Maxime Chevallier,
Théo Lebrun, stable
The first patch is here to allow giving a drop reason.
We dissociate consumed packets from dropped ones that way.
Second patch is the main one: it drops unsent packets on close.
MACB driver forgot freeing its SKBs (and associated DMA mappings).
---
Changes in v3:
- Drop stats fixing. A proper fix deserves its own net-next refactoring
series to migrate to netdev_stat_ops (ynltool uAPI), which will come
in later. We keep the tx_dropped++ because they are safe as every
other context is disabled when macb_free_consistent() is called.
- Rebased to latest net/main (406e8a651a7b), nothing to report.
- Link to v2: https://patch.msgid.link/20260428-macb-drop-tx-v2-0-647f5199d8df@bootlin.com
Changes in v2:
- Increment tx_dropped stat once per SKB, not once per frame.
- Reset tx_head & tx_tail to avoid keeping stalled cursors.
- Fix SKB dropped reasons throughout by adding the reason as parameter
to macb_tx_unmap(). This is a new patch. Then the drop-all-on-close
fix can use this ability to report we are not consuming SKBs.
- Add increment to stats->tx_dropped on DMA mapping failure and
tx_error_task. Done as separate patches (3 and 4).
- Rebase upon net/main @ 46f74a3f7d57, nothing to report.
- Link to v1: https://patch.msgid.link/20260424-macb-drop-tx-v1-1-b3ecb787d84d@bootlin.com
To: Nicolas Ferre <nicolas.ferre@microchip.com>
To: Claudiu Beznea <claudiu.beznea@tuxon.dev>
To: Andrew Lunn <andrew+netdev@lunn.ch>
To: "David S. Miller" <davem@davemloft.net>
To: Eric Dumazet <edumazet@google.com>
To: Jakub Kicinski <kuba@kernel.org>
To: Paolo Abeni <pabeni@redhat.com>
To: Haavard Skinnemoen <hskinnemoen@atmel.com>
To: Jeff Garzik <jeff@garzik.org>
To: Conor Dooley <conor.dooley@microchip.com>
Cc: Paolo Valerio <pvalerio@redhat.com>
Cc: Nicolai Buchwitz <nb@tipi-net.de>
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
Cc: Gregory CLEMENT <gregory.clement@bootlin.com>
Cc: Benoît Monin <benoit.monin@bootlin.com>
Cc: Tawfik Bayouk <tawfik.bayouk@mobileye.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Maxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
---
Théo Lebrun (2):
net: macb: give reasons for Tx SKB kfree
net: macb: drop in-flight Tx SKBs on close
drivers/net/ethernet/cadence/macb_main.c | 46 +++++++++++++++++++++++++-------
1 file changed, 37 insertions(+), 9 deletions(-)
---
base-commit: 712927eaa34199bb62cf370af591c0550ba977de
change-id: 20260423-macb-drop-tx-f9ce72720d05
Best regards,
--
Théo Lebrun <theo.lebrun@bootlin.com>
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH net v3 1/2] net: macb: give reasons for Tx SKB kfree 2026-06-17 9:17 [PATCH net v3 0/2] Drop in-flight Tx SKBs on MACB close Théo Lebrun @ 2026-06-17 9:17 ` Théo Lebrun 2026-06-17 9:49 ` Nicolai Buchwitz 2026-06-17 9:17 ` [PATCH net v3 2/2] net: macb: drop in-flight Tx SKBs on close Théo Lebrun 1 sibling, 1 reply; 5+ messages in thread From: Théo Lebrun @ 2026-06-17 9:17 UTC (permalink / raw) To: Nicolas Ferre, Claudiu Beznea, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Haavard Skinnemoen, Jeff Garzik, Conor Dooley Cc: Paolo Valerio, Nicolai Buchwitz, netdev, linux-kernel, Vladimir Kondratiev, Gregory CLEMENT, Benoît Monin, Tawfik Bayouk, Thomas Petazzoni, Maxime Chevallier, Théo Lebrun, stable Using dev_consume_skb_any() marks the drop reason as SKB_CONSUMED every time we free a Tx SKB. Instead, replace by SKB_DROP_REASON_NOT_SPECIFIED when packet has been dropped without sending. It is not precise but at least differs from SKB_CONSUMED and is used by many drivers for their error codepaths through dev_kfree_skb_{any,irq}(). Pass a reason around rather than call dev_consume_skb_any() or dev_kfree_skb_any() because macb_tx_unmap() is called for cleanup in all cases. macb_tx_error_task() is made complex because some SKBs encountered have been successfully sent. Fixes: 89e5785fc8a6 ("[PATCH] Atmel MACB ethernet driver") Cc: stable@vger.kernel.org Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com> --- drivers/net/ethernet/cadence/macb_main.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index a12aa21244e8..9caae1ef52b1 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -1201,7 +1201,8 @@ static int macb_halt_tx(struct macb *bp) bp, TSR); } -static void macb_tx_unmap(struct macb *bp, struct macb_tx_skb *tx_skb, int budget) +static void macb_tx_unmap(struct macb *bp, struct macb_tx_skb *tx_skb, + int budget, enum skb_drop_reason reason) { if (tx_skb->mapping) { if (tx_skb->mapped_as_page) @@ -1214,7 +1215,7 @@ static void macb_tx_unmap(struct macb *bp, struct macb_tx_skb *tx_skb, int budge } if (tx_skb->skb) { - dev_consume_skb_any(tx_skb->skb); + dev_kfree_skb_any_reason(tx_skb->skb, reason); tx_skb->skb = NULL; } } @@ -1297,7 +1298,8 @@ static void macb_tx_error_task(struct work_struct *work) * Free transmit buffers in upper layer. */ for (tail = queue->tx_tail; tail != queue->tx_head; tail++) { - u32 ctrl; + enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED; + u32 ctrl; desc = macb_tx_desc(queue, tail); ctrl = desc->ctrl; @@ -1307,7 +1309,10 @@ static void macb_tx_error_task(struct work_struct *work) if (ctrl & MACB_BIT(TX_USED)) { /* skb is set for the last buffer of the frame */ while (!skb) { - macb_tx_unmap(bp, tx_skb, 0); + /* The reason parameter is unused because it + * only matters when skb is valid. + */ + macb_tx_unmap(bp, tx_skb, 0, SKB_CONSUMED); tail++; tx_skb = macb_tx_skb(queue, tail); skb = tx_skb->skb; @@ -1326,6 +1331,7 @@ static void macb_tx_error_task(struct work_struct *work) bp->dev->stats.tx_bytes += skb->len; queue->stats.tx_bytes += skb->len; bytes += skb->len; + reason = SKB_CONSUMED; } } else { /* "Buffers exhausted mid-frame" errors may only happen @@ -1339,7 +1345,7 @@ static void macb_tx_error_task(struct work_struct *work) desc->ctrl = ctrl | MACB_BIT(TX_USED); } - macb_tx_unmap(bp, tx_skb, 0); + macb_tx_unmap(bp, tx_skb, 0, reason); } netdev_tx_completed_queue(netdev_get_tx_queue(bp->dev, queue_index), @@ -1458,7 +1464,7 @@ static int macb_tx_complete(struct macb_queue *queue, int budget) } /* Now we can safely release resources */ - macb_tx_unmap(bp, tx_skb, budget); + macb_tx_unmap(bp, tx_skb, budget, SKB_CONSUMED); /* skb is set only for the last buffer of the frame. * WARNING: at this point skb has been freed by @@ -2357,7 +2363,11 @@ static unsigned int macb_tx_map(struct macb *bp, for (i = queue->tx_head; i != tx_head; i++) { tx_skb = macb_tx_skb(queue, i); - macb_tx_unmap(bp, tx_skb, 0); + /* The reason parameter is unused, tx_skb->skb has not yet + * been assigned. Parent caller is responsible for freeing + * the SKB. + */ + macb_tx_unmap(bp, tx_skb, 0, SKB_DROP_REASON_NOT_SPECIFIED); } return -ENOMEM; -- 2.54.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net v3 1/2] net: macb: give reasons for Tx SKB kfree 2026-06-17 9:17 ` [PATCH net v3 1/2] net: macb: give reasons for Tx SKB kfree Théo Lebrun @ 2026-06-17 9:49 ` Nicolai Buchwitz 0 siblings, 0 replies; 5+ messages in thread From: Nicolai Buchwitz @ 2026-06-17 9:49 UTC (permalink / raw) To: Théo Lebrun Cc: Nicolas Ferre, Claudiu Beznea, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Haavard Skinnemoen, Jeff Garzik, Conor Dooley, Paolo Valerio, netdev, linux-kernel, Vladimir Kondratiev, Gregory CLEMENT, Benoît Monin, Tawfik Bayouk, Thomas Petazzoni, Maxime Chevallier, stable On 17.6.2026 11:17, Théo Lebrun wrote: > Using dev_consume_skb_any() marks the drop reason as SKB_CONSUMED every > time we free a Tx SKB. Instead, replace by > SKB_DROP_REASON_NOT_SPECIFIED > when packet has been dropped without sending. > > It is not precise but at least differs from SKB_CONSUMED and is used by > many drivers for their error codepaths through > dev_kfree_skb_{any,irq}(). > > Pass a reason around rather than call dev_consume_skb_any() or > dev_kfree_skb_any() because macb_tx_unmap() is called for cleanup in > all cases. > > macb_tx_error_task() is made complex because some SKBs encountered have > been successfully sent. > > Fixes: 89e5785fc8a6 ("[PATCH] Atmel MACB ethernet driver") > Cc: stable@vger.kernel.org > Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com> > --- Looks like my r-b from v2 was lost, but here it goes again :) Reviewed-by: Nicolai Buchwitz <nb@tipi-net.de> Thanks, Nicolai ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net v3 2/2] net: macb: drop in-flight Tx SKBs on close 2026-06-17 9:17 [PATCH net v3 0/2] Drop in-flight Tx SKBs on MACB close Théo Lebrun 2026-06-17 9:17 ` [PATCH net v3 1/2] net: macb: give reasons for Tx SKB kfree Théo Lebrun @ 2026-06-17 9:17 ` Théo Lebrun 2026-06-17 9:49 ` Nicolai Buchwitz 1 sibling, 1 reply; 5+ messages in thread From: Théo Lebrun @ 2026-06-17 9:17 UTC (permalink / raw) To: Nicolas Ferre, Claudiu Beznea, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Haavard Skinnemoen, Jeff Garzik, Conor Dooley Cc: Paolo Valerio, Nicolai Buchwitz, netdev, linux-kernel, Vladimir Kondratiev, Gregory CLEMENT, Benoît Monin, Tawfik Bayouk, Thomas Petazzoni, Maxime Chevallier, Théo Lebrun, stable The MACB driver has since forever leaked the outgoing SKBs that have not yet been marked as completed. They live in queue->tx_skb which gets freed without remorse nor checking. macb_free_consistent() gets called in a few codepaths, but only close will trigger the added expressions. In macb_open() and macb_alloc_consistent() failure cases, tx_skb just got allocated and is empty. Use the new macb_tx_unmap() prototype to report our error as SKB_DROP_REASON_NOT_SPECIFIED rather than SKB_CONSUMED which makes it sound like no error occurred. Equivalent to dev_kfree_skb_any(). Fixes: 89e5785fc8a6 ("[PATCH] Atmel MACB ethernet driver") Cc: stable@vger.kernel.org Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com> --- drivers/net/ethernet/cadence/macb_main.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 9caae1ef52b1..5a2500bd59a6 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -2678,8 +2678,26 @@ static void macb_free_consistent(struct macb *bp) dma_free_coherent(dev, size, bp->queues[0].rx_ring, bp->queues[0].rx_ring_dma); for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { - kfree(queue->tx_skb); - queue->tx_skb = NULL; + if (queue->tx_skb) { + unsigned int dropped = 0, tail; + + for (tail = queue->tx_tail; tail != queue->tx_head; + tail++) { + if (macb_tx_skb(queue, tail)->skb) + dropped++; + macb_tx_unmap(bp, macb_tx_skb(queue, tail), 0, + SKB_DROP_REASON_NOT_SPECIFIED); + } + + queue->stats.tx_dropped += dropped; + bp->dev->stats.tx_dropped += dropped; + + kfree(queue->tx_skb); + queue->tx_skb = NULL; + } + + queue->tx_head = 0; + queue->tx_tail = 0; queue->tx_ring = NULL; queue->rx_ring = NULL; } -- 2.54.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net v3 2/2] net: macb: drop in-flight Tx SKBs on close 2026-06-17 9:17 ` [PATCH net v3 2/2] net: macb: drop in-flight Tx SKBs on close Théo Lebrun @ 2026-06-17 9:49 ` Nicolai Buchwitz 0 siblings, 0 replies; 5+ messages in thread From: Nicolai Buchwitz @ 2026-06-17 9:49 UTC (permalink / raw) To: Théo Lebrun Cc: Nicolas Ferre, Claudiu Beznea, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Haavard Skinnemoen, Jeff Garzik, Conor Dooley, Paolo Valerio, netdev, linux-kernel, Vladimir Kondratiev, Gregory CLEMENT, Benoît Monin, Tawfik Bayouk, Thomas Petazzoni, Maxime Chevallier, stable On 17.6.2026 11:17, Théo Lebrun wrote: > The MACB driver has since forever leaked the outgoing SKBs that > have not yet been marked as completed. They live in queue->tx_skb > which gets freed without remorse nor checking. > > macb_free_consistent() gets called in a few codepaths, but only > close will trigger the added expressions. In macb_open() and > macb_alloc_consistent() failure cases, tx_skb just got allocated > and is empty. > > Use the new macb_tx_unmap() prototype to report our error as > SKB_DROP_REASON_NOT_SPECIFIED rather than SKB_CONSUMED which makes it > sound like no error occurred. Equivalent to dev_kfree_skb_any(). > > Fixes: 89e5785fc8a6 ("[PATCH] Atmel MACB ethernet driver") > Cc: stable@vger.kernel.org > Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com> > --- > [...] Reviewed-by: Nicolai Buchwitz <nb@tipi-net.de> Thanks, Nicolai ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-06-17 9:49 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-06-17 9:17 [PATCH net v3 0/2] Drop in-flight Tx SKBs on MACB close Théo Lebrun 2026-06-17 9:17 ` [PATCH net v3 1/2] net: macb: give reasons for Tx SKB kfree Théo Lebrun 2026-06-17 9:49 ` Nicolai Buchwitz 2026-06-17 9:17 ` [PATCH net v3 2/2] net: macb: drop in-flight Tx SKBs on close Théo Lebrun 2026-06-17 9:49 ` Nicolai Buchwitz
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox