From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46AF0606A31C for ; Mon, 30 Nov 2026 12:37:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256 header.s=default header.b=i97Qyh+7; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BwVypcLh Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 1A93280D88; Mon, 30 Nov 2026 12:37:56 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id ttwVErTzx4Sr; Mon, 30 Nov 2026 12:37:55 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp1.osuosl.org 5B24280D8C Authentication-Results: smtp1.osuosl.org; arc=none smtp.remote-ip=140.211.166.142 ARC-Seal: i=1; d=osuosl.org; s=arc; a=rsa-sha256; cv=none; t=1796042275; b=cHmMBKy1480aHQX2TjqA8JcCTAkUfExFZV7hevNqa9fijPEIMHSnvoNoAOkeoa6YHJuf /51IBxueUSQt59PzGn8E2ToKnEDFsovPksUF3SX/SqrDnP1SvKOpafdovazw0rR/77vnc AjZUoCMKrb487lkZus6xkzcLOaQiHSxvDfD1CTGVV3V5VSnEszHtq1Z85zscNnNCYnkZ9 e69FZmOlEycw6Eb7Nft6Kla/WgSrt3SFGlNmFtTOelcq0Pl8sHwmnH86OKJslWrBKEQzQ GEQf44m5rU7WitJWRG1oCbiC1NgIi6sjeQnxFyuM06KlXda31D3Y4a8DwzVs3SVGOvg== ARC-Message-Signature: i=1; d=osuosl.org; s=arc; a=rsa-sha256; c=relaxed/relaxed; t=1796042275; h=X-Comment:DKIM-Signature:X-Original-To:Delivered-To:Received: Received:X-Virus-Scanned:X-Spam-Flag:X-Spam-Score:X-Spam-Level: X-Spam-Status:Received:ARC-Filter:Received-SPF:Received:Received: Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding:X-BeenThere:X-Mailman-Version:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help: List-Subscribe:Errors-To; bh=IqUnybaBKLXaG+PAN/2isXsn5ciPicC+Ck/+NBew9+E=; b=qE3t6g1UUPiBRxiJV2Mshv6qKo2DsZdk/9W1icY9I8OT6UHKvk/i2SX7spBbRg1W9tJy XvtZUQ9BmuCELmJDNnglyq8iOuFxx59t3+wkSldL+MfRo6JAd/LKm3TTdjctBb6CB+jDc YkG2KwqGVcs1QYxMPlR1Fm5+/5uAqZ4GGySg3V68UVrXh/GFSDCsg6dIQ75WAcsE9QpKi dYRXYwWz9+l5HDROVAf7gQIov+ytD03OrHQFZtEu+1ztr2lkZsjHiezHJRBILKvEPkVqz aY7o42xtnMfvJpGPhkkYFG8uz5YBQaScV1AeAFzwqDVFWBIEEK4RxxfXqpX7Yg+nQYA== ARC-Authentication-Results: i=1; smtp1.osuosl.org; dmarc=pass header.from=kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BwVypcLh; arc=none smtp.remote-ip=140.211.166.142 X-Comment: SPF check N/A for local connections - client-ip=140.211.166.142; helo=lists1.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1796042275; bh=IqUnybaBKLXaG+PAN/2isXsn5ciPicC+Ck/+NBew9+E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=i97Qyh+7GQAY097UpNbi6JbEbBA5SVKy/uj0iTWlfWtQTL9FtL0E57ugHIhOBlSS2 c/T/FB6a1Fec3uDwdf9jtLmDXXu39RprZsVNVDxx61DIm6FACIlr6T7efut3Td6sRb HrCEZhaowRk8bJwa8pbBO3aa8HmK5HOL105HyAr0BmpV+6H+27QEoUC4Vv+RDFANNw g7l/Ivdkp7VVIta2Bwnl5pEStlvKMzJjukHM9DrKlwxdu7Pu17Kb1jB79zP2YJRMuA ywWopY0jcgfJMMfrkNh7KepKD/UQO9gEMNz66t5hAUIIgzLrsf9DJae3+qegCubmDc av7isgMVDbIlg== Received: from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142]) by smtp1.osuosl.org (Postfix) with ESMTP id 5B24280D8C; Mon, 30 Nov 2026 12:37:55 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists1.osuosl.org (Postfix) with ESMTP id 81E5C49D for ; Mon, 30 Nov 2026 12:37:53 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 683A280DA7 for ; Mon, 30 Nov 2026 12:37:53 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id RmeUkuVXVhSg for ; Mon, 30 Nov 2026 12:37:52 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp1.osuosl.org 9ECD780DA1 Authentication-Results: smtp1.osuosl.org; arc=none smtp.remote-ip="2600:3c0a:e001:78e:0:1991:8:25" Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2600:3c0a:e001:78e:0:1991:8:25; helo=sea.source.kernel.org; envelope-from=bjorn@kernel.org; receiver= Authentication-Results: smtp1.osuosl.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp1.osuosl.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BwVypcLh Received: from sea.source.kernel.org (sea.source.kernel.org [IPv6:2600:3c0a:e001:78e:0:1991:8:25]) by smtp1.osuosl.org (Postfix) with ESMTPS id 9ECD780DA1 for ; Mon, 30 Nov 2026 12:37:52 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 2A54D42B75; Mon, 30 Nov 2026 12:37:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67B0D1F00896; Mon, 30 Nov 2026 12:37:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796042272; bh=IqUnybaBKLXaG+PAN/2isXsn5ciPicC+Ck/+NBew9+E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BwVypcLhyQr0D/otHe+OzCJTSlCHG/yjA7cXaxSIxQ2wgvjgXsMIA/uHXkJwFXGdj WOdj/42zQIZidvRUovSiQjdm66Ra83yq0KUo8GdbYx6jX1lb0IIrvVnbU5klOw89Ry rmL+5qpW0Uih4hS8vA6oQxF08ftyTDNdr2CUAl6G1ZX7WrQJCgZhBC7q+PAUaVH9fb paiq9FPgu63RWzjBWJZbAPnWAhM8dT/IuD7NQqg49nIVlYTq1QsYZCCkB7viikvWtJ 9hEKL2MgsiZ59yK1nUgbapPYCj62uwEJc4SRs0HiqKavbX+srd5lM7pEHkheF9IYJE e0qRboFTX0cHg== From: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= To: Magnus Karlsson , Maciej Fijalkowski , Alexander Lobakin , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Simon Horman , Stanislav Fomichev , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , Tony Nguyen , Przemek Kitszel , intel-wired-lan@lists.osuosl.org, =?UTF-8?q?Cl=C3=A9ment=20Lecigne?= Subject: [PATCH net v2 1/4] libeth: xsk: Count each XDP_TX buffer on its own Date: Mon, 30 Nov 2026 13:37:32 +0100 Message-ID: <20261130123737.125432-2-bjorn@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261130123737.125432-1-bjorn@kernel.org> References: <20261130123737.125432-1-bjorn@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 libeth takes the number of buffers of an XSk XDP_TX frame from its shared info, and reports that many completed buffers to the driver. It reads the shared info when it flushes the bulk, not when it queues the frame. The shared info of a zero-copy buffer lives in the UMEM, which userspace may write at any time, so a rewritten count makes libeth report a wrong number. Once the last patch of this series moves the shared info into the buffer pool, the next multi-buffer frame of the same poll can overwrite it before the flush. A wrong number breaks the in-flight count of XDP_TX buffers that idpf keeps on its XSk queues, and idpf may then complete XDP_TX buffers as XSk xmit frames. Make libeth count each buffer on its own SQE. Head and fragments each count one completed buffer, and the head counts the packet. Stats stay the same for frames sent in full. Found by an AI agent while reviewing this code. Not triggered at runtime. Fixes: b3ad8450b4dc ("libeth: xsk: add XSk XDP_TX sending helpers") Signed-off-by: Björn Töpel --- include/net/libeth/tx.h | 8 +++++--- include/net/libeth/xdp.h | 9 ++++++++- include/net/libeth/xsk.h | 6 ++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/net/libeth/tx.h b/include/net/libeth/tx.h index c3db5c6f1641..a8cf03c8be71 100644 --- a/include/net/libeth/tx.h +++ b/include/net/libeth/tx.h @@ -22,7 +22,8 @@ * @LIBETH_SQE_XDP_XMIT: &xdp_frame, unmap and xdp_return_frame_bulk(), stats * @LIBETH_SQE_XDP_XMIT_FRAG: &xdp_frame frag, only unmap DMA * @LIBETH_SQE_XSK_TX: &libeth_xdp_buff on XSk queue, xsk_buff_free(), stats - * @LIBETH_SQE_XSK_TX_FRAG: &libeth_xdp_buff frag on XSk queue, xsk_buff_free() + * @LIBETH_SQE_XSK_TX_FRAG: &libeth_xdp_buff frag on XSk queue, xsk_buff_free(), + * stats */ enum libeth_sqe_type { LIBETH_SQE_EMPTY = 0U, @@ -50,9 +51,10 @@ enum libeth_sqe_type { * @xsk: XSk Rx frame from XDP_TX action * @dma: DMA address to unmap * @len: length of the mapped region to unmap - * @nr_frags: number of frags in the frame this buffer belongs to + * @nr_frags: number of frags in the frame this buffer belongs to, not for XSk * @packets: number of physical packets sent for this frame - * @bytes: number of physical bytes sent for this frame + * @bytes: number of physical bytes sent for this frame, or for this buffer + * on XSk * @priv: driver-private scratchpad */ struct libeth_sqe { diff --git a/include/net/libeth/xdp.h b/include/net/libeth/xdp.h index 898723ab62e8..66a3c4ec9967 100644 --- a/include/net/libeth/xdp.h +++ b/include/net/libeth/xdp.h @@ -1794,12 +1794,19 @@ __libeth_xdp_complete_tx(struct libeth_sqe *sqe, struct libeth_cq_pp *cp, switch (type) { case LIBETH_SQE_XDP_TX: case LIBETH_SQE_XDP_XMIT: - case LIBETH_SQE_XSK_TX: cp->xdp_tx -= sqe->nr_frags; cp->xss->packets++; cp->xss->bytes += sqe->bytes; break; + case LIBETH_SQE_XSK_TX: + cp->xss->packets++; + fallthrough; + case LIBETH_SQE_XSK_TX_FRAG: + /* One buffer per SQE, see libeth_xsk_tx_fill_buf() */ + cp->xdp_tx--; + cp->xss->bytes += sqe->bytes; + break; default: break; } diff --git a/include/net/libeth/xsk.h b/include/net/libeth/xsk.h index 249b1c740788..2cd4252a3445 100644 --- a/include/net/libeth/xsk.h +++ b/include/net/libeth/xsk.h @@ -129,6 +129,10 @@ libeth_xsk_tx_fill_buf(struct libeth_xdp_tx_frame frm, u32 i, sqe = &sq->sqes[i]; sqe->xsk = xdp; + /* Count each buffer on its own SQE. The shared info of the frame + * may change before the bulk is flushed. + */ + sqe->bytes = desc.len; if (!(desc.flags & LIBETH_XDP_TX_FIRST)) { sqe->type = LIBETH_SQE_XSK_TX_FRAG; @@ -136,8 +140,6 @@ libeth_xsk_tx_fill_buf(struct libeth_xdp_tx_frame frm, u32 i, } sqe->type = LIBETH_SQE_XSK_TX; - libeth_xdp_tx_fill_stats(sqe, &desc, - xdp_get_shared_info_from_buff(&xdp->base)); return desc; } -- 2.56.1