From nobody Fri Apr 10 04:21:49 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 9D0203D6CBA; Wed, 4 Mar 2026 18:23:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772648640; cv=none; b=H6eaOoMFa28MnYpwAP+YKLGTNjWCzynnWPbqd5b4Nu9c60TLJiVDo9NKVbNRzk1EUgK/R2Png97EEhYkMsjYNePc82lK11kbGtLi8v9K3QNziTdVOPlyu++sGLEQW0D7/KyKsAaO+GNIEOHR64qglungLj81W82M649BzhVALlA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772648640; c=relaxed/simple; bh=lR/31OvnWqMELBpLtLx85N3MW+LVO6QwM8QgYOp7nE8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kh9PdMIpiqo3MAUcLibDeGJFhCNZQNf8MbYFhHBu72X7M+kTntjUwjNQQgKJhJHJ2s7+w6RpFjvmYTUsxooupcBAWa7R7NL4cfHY6KVy/N7hX22kNd11ntruJEkulcPqvrQtHE0KycNd0zDSw2IWYZomK5Pw8VDAwye/HbzPhBE= 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=QRmtLtd6; arc=none smtp.client-ip=185.246.85.4 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="QRmtLtd6" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 3F6FD4E4253B; Wed, 4 Mar 2026 18:23:57 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 0EFA95FF5C; Wed, 4 Mar 2026 18:23:57 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 88D69103695E4; Wed, 4 Mar 2026 19:23:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1772648635; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=RKXDnQhH/EddQZ2g7wQh6dP4jPVhKwjH602UOlRULfw=; b=QRmtLtd6yNacCp3C5YfPQVPMScn9eMWoazFBrrXJSRIZIzH50TOP8K4mZ/n2ETSyD+OCbQ Y4feizNQs9UTZPIa8qoWQvkOboXZVF/T7sVUr21sJ6Yo23MM5YqaNc3g91z5w0jxMoeXi2 BRuvNMDOzPA4n5wBcyrhc73xZYb/02imyzlpy6trkCrnlE/L2tlq1vxe4W+hbW/qy8eHPF jtjQ4r9gn9wmcksp3ROVYIX03Ki7CN4n83EQKSpHlHieRTH6pgEFdsjH7K6Z3nd5VZTyXv xLxKTRFCWN7WVIkaFNSt0cwHbpu/nMbVLnYC6AUpME7MmPGQgtoqXlY5xXSMDA== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Wed, 04 Mar 2026 19:23:45 +0100 Subject: [PATCH net-next 2/8] net: macb: account for stats in Rx XDP codepaths 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: <20260304-macb-xsk-v1-2-3d036076abf5@bootlin.com> References: <20260304-macb-xsk-v1-0-3d036076abf5@bootlin.com> In-Reply-To: <20260304-macb-xsk-v1-0-3d036076abf5@bootlin.com> To: Nicolas Ferre , Claudiu Beznea , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Stanislav Fomichev , Richard Cochran Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@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?= X-Mailer: b4 0.14.3 X-Last-TLS-Session-Version: TLSv1.3 gem_xdp_run() returns an action. Wrt stats, we land in three different cases: - Packet is handed to the stack (XDP_PASS), turns into an SKB and gets accounted for below in gem_rx(). No fix here. - Packet is dropped (XDP_DROP|ABORTED), we must increment the dropped counter. Missing; add it. - Packet is passed along (XDP_TX|REDIRECT), we must increment bytes & packets counters. Missing; add it. Along the way, use local variables to store rx_bytes, rx_packets and rx_dropped. Then increase stats only once at the end of gem_rx(). This is simpler because all three stats must modified on a per interface and per queue basis. Signed-off-by: Th=C3=A9o Lebrun --- drivers/net/ethernet/cadence/macb_main.c | 47 +++++++++++++++++++++++-----= ---- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/etherne= t/cadence/macb_main.c index ab73d1a522c2..1aa90499343a 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -1627,6 +1627,7 @@ static u32 gem_xdp_run(struct macb_queue *queue, void= *buff_head, static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, int budget) { + unsigned int packets =3D 0, dropped =3D 0, bytes =3D 0; struct skb_shared_info *shinfo; struct macb *bp =3D queue->bp; struct macb_dma_desc *desc; @@ -1669,8 +1670,7 @@ static int gem_rx(struct macb_queue *queue, struct na= pi_struct *napi, if (unlikely(!buff_head)) { dev_err_ratelimited(&bp->pdev->dev, "inconsistent Rx descriptor chain\n"); - bp->dev->stats.rx_dropped++; - queue->stats.rx_dropped++; + dropped++; break; } =20 @@ -1700,11 +1700,29 @@ static int gem_rx(struct macb_queue *queue, struct = napi_struct *napi, if (last_frame) { ret =3D gem_xdp_run(queue, buff_head, &data_len, &headroom, addr - gem_rx_pad(bp)); - if (ret =3D=3D XDP_REDIRECT) - xdp_flush =3D true; =20 - if (ret !=3D XDP_PASS) - goto next_frame; + switch (ret) { + /* continue to SKB handling codepath */ + case XDP_PASS: + break; + + /* dropped packet cases */ + case XDP_ABORTED: + case XDP_DROP: + dropped++; + queue->rx_buff[entry] =3D NULL; + continue; + + /* redirect/tx cases */ + case XDP_REDIRECT: + xdp_flush =3D true; + fallthrough; + case XDP_TX: + packets++; + bytes +=3D data_len; + queue->rx_buff[entry] =3D NULL; + continue; + } } =20 queue->skb =3D napi_build_skb(buff_head, gem_total_rx_buffer_size(bp)); @@ -1743,10 +1761,8 @@ static int gem_rx(struct macb_queue *queue, struct n= api_struct *napi, =20 /* now everything is ready for receiving packet */ if (last_frame) { - bp->dev->stats.rx_packets++; - queue->stats.rx_packets++; - bp->dev->stats.rx_bytes +=3D queue->skb->len; - queue->stats.rx_bytes +=3D queue->skb->len; + packets++; + bytes +=3D queue->skb->len; =20 queue->skb->protocol =3D eth_type_trans(queue->skb, bp->dev); skb_checksum_none_assert(queue->skb); @@ -1769,7 +1785,6 @@ static int gem_rx(struct macb_queue *queue, struct na= pi_struct *napi, queue->skb =3D NULL; } =20 -next_frame: queue->rx_buff[entry] =3D NULL; continue; =20 @@ -1784,11 +1799,17 @@ static int gem_rx(struct macb_queue *queue, struct = napi_struct *napi, virt_to_head_page(buff_head), false); =20 - bp->dev->stats.rx_dropped++; - queue->stats.rx_dropped++; + dropped++; queue->rx_buff[entry] =3D NULL; } =20 + bp->dev->stats.rx_packets +=3D packets; + queue->stats.rx_packets +=3D packets; + bp->dev->stats.rx_dropped +=3D dropped; + queue->stats.rx_dropped +=3D dropped; + bp->dev->stats.rx_bytes +=3D bytes; + queue->stats.rx_bytes +=3D bytes; + if (xdp_flush) xdp_do_flush(); =20 --=20 2.53.0