From nobody Sat Jun 20 19:58:33 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3175330B51E for ; Wed, 17 Jun 2026 09:17:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781687871; cv=none; b=tCDY960UNXgsJjXQfgjEpl0zAnnoyl3pizNrjNfgl9EYiU1Lo8CvOpcLB7j+C6dmIWWGhvk9XRcYYComM+cMmcKSZ1vT6sqU6Ii0WPGx+OTGFNwe/wPgyMVUTBWo50Y8NoFyvDv5d21Gr91agcWXtOxibyStPvCvuHkLm0ZwgAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781687871; c=relaxed/simple; bh=dAGm4PiwWs80ZnheUKD2LU5YAlmFHcW8oMdB+VthDOQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jNdux0cmCuZ1mKFjXUg66iWfS1yb6Npo4nK2rA+ReiZn0zK1sAcOefH4kIIaDxuVcb5nULvZ8iu2VZtHBD0xZHLLirNNqfXvIXRsGP3hYwfwAtjwiLvwC9sWs8tABI44Eb2dw+KzVbu+U5J44BEPbmjawupnqiA22yJRdYHSYGE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=OwRxlSgt; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="OwRxlSgt" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 784191A3964; Wed, 17 Jun 2026 09:17:47 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 44B58601AA; Wed, 17 Jun 2026 09:17:47 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 9F496106CA34E; Wed, 17 Jun 2026 11:17:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1781687866; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=+0AqFZZvY0X0WypoYom4SAfWrYqe9FmXmaw/Ruojua0=; b=OwRxlSgtA7X9jK4+a/Ru9tHlDjG2YqNEmcUMawRKfQBsjnIGYczrsLd384l2o31yYDkamX ec5YjD94KnI7l5N/BEFLR8AGqlfIEYUCkWAsy96X3uVwdubFD7pEKWXTht5T4xzySTjx1W 99aX7P6I81tXKbNku4+vEuiv17QU6bdnmYjRcGr/OS0fgmKxXOUrtVmG4BRQdkAIaObN4X FqCy54a7kzGmzKId5OA1m3wOw1HSx/Ie/OrLqbwBlykuLywiOktQxi0oZb8EW6acSaRiDZ m/cbYmEuiFqmdKbm9GwP5gkl71tnfDsAIR9bG3JXLcokaoZ8CbIPvdj7QW76gw== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Wed, 17 Jun 2026 11:17:29 +0200 Subject: [PATCH net v3 1/2] net: macb: give reasons for Tx SKB kfree Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260617-macb-drop-tx-v3-1-d4c7e57d890b@bootlin.com> References: <20260617-macb-drop-tx-v3-0-d4c7e57d890b@bootlin.com> In-Reply-To: <20260617-macb-drop-tx-v3-0-d4c7e57d890b@bootlin.com> 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@vger.kernel.org, linux-kernel@vger.kernel.org, Vladimir Kondratiev , Gregory CLEMENT , =?utf-8?q?Beno=C3=AEt_Monin?= , Tawfik Bayouk , Thomas Petazzoni , Maxime Chevallier , =?utf-8?q?Th=C3=A9o_Lebrun?= , stable@vger.kernel.org X-Mailer: b4 0.15.2 X-Last-TLS-Session-Version: TLSv1.3 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=C3=A9o Lebrun Reviewed-by: Nicolai Buchwitz --- 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/etherne= t/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); } =20 -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 mac= b_tx_skb *tx_skb, int budge } =20 if (tx_skb->skb) { - dev_consume_skb_any(tx_skb->skb); + dev_kfree_skb_any_reason(tx_skb->skb, reason); tx_skb->skb =3D NULL; } } @@ -1297,7 +1298,8 @@ static void macb_tx_error_task(struct work_struct *wo= rk) * Free transmit buffers in upper layer. */ for (tail =3D queue->tx_tail; tail !=3D queue->tx_head; tail++) { - u32 ctrl; + enum skb_drop_reason reason =3D SKB_DROP_REASON_NOT_SPECIFIED; + u32 ctrl; =20 desc =3D macb_tx_desc(queue, tail); ctrl =3D desc->ctrl; @@ -1307,7 +1309,10 @@ static void macb_tx_error_task(struct work_struct *w= ork) 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 =3D macb_tx_skb(queue, tail); skb =3D tx_skb->skb; @@ -1326,6 +1331,7 @@ static void macb_tx_error_task(struct work_struct *wo= rk) bp->dev->stats.tx_bytes +=3D skb->len; queue->stats.tx_bytes +=3D skb->len; bytes +=3D skb->len; + reason =3D SKB_CONSUMED; } } else { /* "Buffers exhausted mid-frame" errors may only happen @@ -1339,7 +1345,7 @@ static void macb_tx_error_task(struct work_struct *wo= rk) desc->ctrl =3D ctrl | MACB_BIT(TX_USED); } =20 - macb_tx_unmap(bp, tx_skb, 0); + macb_tx_unmap(bp, tx_skb, 0, reason); } =20 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) } =20 /* Now we can safely release resources */ - macb_tx_unmap(bp, tx_skb, budget); + macb_tx_unmap(bp, tx_skb, budget, SKB_CONSUMED); =20 /* 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 =3D queue->tx_head; i !=3D tx_head; i++) { tx_skb =3D macb_tx_skb(queue, i); =20 - 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); } =20 return -ENOMEM; --=20 2.54.0 From nobody Sat Jun 20 19:58:33 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D31763876BA for ; Wed, 17 Jun 2026 09:17:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781687872; cv=none; b=qBgQOe/8CVNDdlGZGl9BimKp/hrdbZ+Y/6DGdQNJNB3CVAsmWmQ4hyJdsBST+edTdX+6N1aHeGMks2ZgF78GODsWgNVyRPP8hX0SPmvnu0BSH85vB8Sgq1VQCkSdgw8+Z7wQJz0ay/YZKMSwbig61PBWEvo/fZfGmAdmCE5qQyU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781687872; c=relaxed/simple; bh=1jBDxYXWJq8oVg4cfwRSFslEeHBgkTsITO5M9rYbr1Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tCg0Ky3fvIJc+G/AQhzZz5vi3unmS21xNSU4+fl1DHcx75zNsubkGNJ6cooTj8gOypiLl8arcrRwrOJvOiExFYGX6Xr9ZbtXDl52wY/FzTC4ZDRNaV0Isiz35gr/UjF0HJCXIISy3q1t98h9MA2a3qeicZ628ec9iq/wjOb6EDA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Qm0iVjU4; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Qm0iVjU4" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 77C9B1A395A; Wed, 17 Jun 2026 09:17:49 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 46A8A601AA; Wed, 17 Jun 2026 09:17:49 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 804AA106CA350; Wed, 17 Jun 2026 11:17:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1781687868; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=G9FpCeKi3Ynv/LOiUy9epKx2SW5IzmteIiDj38KugCY=; b=Qm0iVjU4OMdghsQmnsSO/ZVglUuAgnSWOLaEln7sLb0stSd5BiwNTG+skRE5W6v3NM36gN WIQOk93EJD4sv52sOkRdC9HVawr/X7IFU80SnCCXq1PazwZhwep1i9OgCmhKP2wFB1zGoc GB13r44Stdt2gEgUmPQ9q0Wc/7qHoUm4h4m7TiaNtiWtbj3eNC2ZzwF+EPWwbb8ePFfN8N qvNsINoO3ALOm5y1vsJVXflVV2fQT8s76IUjL/6eSGp0JF40a4ibAL/sMhj9QEPcn3N5yL O/b+AA+zriz0OkqoSBxJne3TuK/MHTD9n+4MLuAli8RdO4XGmVqJ6ApiAWzEfQ== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Wed, 17 Jun 2026 11:17:30 +0200 Subject: [PATCH net v3 2/2] net: macb: drop in-flight Tx SKBs on close Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260617-macb-drop-tx-v3-2-d4c7e57d890b@bootlin.com> References: <20260617-macb-drop-tx-v3-0-d4c7e57d890b@bootlin.com> In-Reply-To: <20260617-macb-drop-tx-v3-0-d4c7e57d890b@bootlin.com> 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@vger.kernel.org, linux-kernel@vger.kernel.org, Vladimir Kondratiev , Gregory CLEMENT , =?utf-8?q?Beno=C3=AEt_Monin?= , Tawfik Bayouk , Thomas Petazzoni , Maxime Chevallier , =?utf-8?q?Th=C3=A9o_Lebrun?= , stable@vger.kernel.org X-Mailer: b4 0.15.2 X-Last-TLS-Session-Version: TLSv1.3 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=C3=A9o Lebrun Reviewed-by: Nicolai Buchwitz --- 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/etherne= t/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); =20 for (q =3D 0, queue =3D bp->queues; q < bp->num_queues; ++q, ++queue) { - kfree(queue->tx_skb); - queue->tx_skb =3D NULL; + if (queue->tx_skb) { + unsigned int dropped =3D 0, tail; + + for (tail =3D queue->tx_tail; tail !=3D 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 +=3D dropped; + bp->dev->stats.tx_dropped +=3D dropped; + + kfree(queue->tx_skb); + queue->tx_skb =3D NULL; + } + + queue->tx_head =3D 0; + queue->tx_tail =3D 0; queue->tx_ring =3D NULL; queue->rx_ring =3D NULL; } --=20 2.54.0