From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (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 92FD2606A322 for ; Thu, 3 Dec 2026 09:57:13 +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=uc2U7bh5; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ghr5G08Q Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 75C7160AC1; Thu, 3 Dec 2026 09:57:13 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id evZKTuj-ps_1; Thu, 3 Dec 2026 09:57:12 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp3.osuosl.org C04A5616E1 Authentication-Results: smtp3.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=1796291832; b=dysm9BSh2E7Q5dfvLIWdFfZs+DeSOXvLF82mZYpjXIjs6Fz9/Jld455MfeLNRFHPot9/ aUIOmZIY0i93f7zDJqkzua16DPu2BJAWJSQxcJlr0/LvUfDTnW1DWfsAADzK+FKPyywVy d677Nx12saLhyHvUBZfP3WVhT6momfsItYwtnim0GRFcCsIaJsEGKsTz8Y8uzake/Ux2F T0uNIOdJEk5pNu2ir9NSQ0+sO57IKwLThUT49UvG013HesxMW8gIrmYRLXYP7uEz7Z2/N 1f2a1ATkL5dgCQyUxIZIq0g+cqzUPxyV0VRyEWxLa/ZSyAA8QLUnILdiAx8Ht6tVjHA== ARC-Message-Signature: i=1; d=osuosl.org; s=arc; a=rsa-sha256; c=relaxed/relaxed; t=1796291832; 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=VVgJwXjWbkKs9rJANwOtc47eei1r02tMn+JLoe7b6zY=; b=J3TyBu8yA0HwX58OsClQuyr2ddRSZukaN/mtewwVm6bnArtN/iL1Ntn5oI8KJCytKnL8 NsKF+TWWvFm+BZAtJdSoxn9Dc+Ut9c2uB5SdALyhQCJiBzXb4f0kk6A1KUsdnlsZ9NI1K fKe4io8QjK9y0amlwU/3SfEGPmFKia0MvJRki4RNdDD4YawE8jPdz+fynryYkZG85BXqP yum5lIrM2hTYwGZcLnopjNbyFHo8M3nCtH53zJRzsPnfjPK9ijepdnL6XyWezMT3Se58K 01Vqhvb+ztlLE93JEfSI601x5aH8Q46pzJ8Z54ywA/67uqcylZ7GT4KJafEGdziGSlw== ARC-Authentication-Results: i=1; smtp3.osuosl.org; 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=1796291832; bh=VVgJwXjWbkKs9rJANwOtc47eei1r02tMn+JLoe7b6zY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=uc2U7bh53mupc329xkzhL/lueBfPWHuHKTT7DfFjUABWqlwGx9d0YtP4TsYrggUji wcB8Fg4Rr3O+7MVmRkVVo8OPUizKymoyuwGpSHyCkeD5Y+PTfHf2q3I0uz7jpC1xuC F7lCrovcTJRZEPAlFxeTCcvn4ukHxSEDUgoP7v9xIZeYP8ti89wWeTlJJLnRVrFgoq HiBf8O2tG8OkFGGtWWI7SNAEM2FWnhbzlzNhAvgWQZEnWMgrJK30F5AHVSeIueCSE3 6qW1Tpmy1CYwcnJDbpz18Nq77cztKVJXiD3iQbe4Mr74Fh58VoWNlVV+ch1JIFt6rc b5+v6rovbXdew== Received: from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142]) by smtp3.osuosl.org (Postfix) with ESMTP id C04A5616E1; Thu, 3 Dec 2026 09:57:12 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists1.osuosl.org (Postfix) with ESMTP id 2809A2FF for ; Thu, 3 Dec 2026 09:57:11 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 0EA4685EB4 for ; Thu, 3 Dec 2026 09:57:11 +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 t_B_jg6b8_lp for ; Thu, 3 Dec 2026 09:57:10 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp1.osuosl.org 586BB85E96 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, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ghr5G08Q 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 586BB85E96 for ; Thu, 3 Dec 2026 09:57:09 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id C109343EB5; Thu, 3 Dec 2026 09:57:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D8571F000C1; Thu, 3 Dec 2026 09:57:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796291829; bh=VVgJwXjWbkKs9rJANwOtc47eei1r02tMn+JLoe7b6zY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ghr5G08QtCmQM9aEUsDv8HoD4tHAazaEOpk4fKofV1SnBlwUDozdKVsZElaOpZ3Qp cJ6Jo59ZkUCq3MjclqOOtIgOOxBXPfcshZeLfzuy5RHehsdCWAXwLnNWHTRxzfVZ0h frfwRWPzhpfgWVJaKStGhEhVKB0AukD79P7DTI6rirB22tAk5jK6ghW1vquv5z52ow vTdTu0/6TmHY5aJS+PiiEiWCmm3CCjZbeJUXzau6Wvd03RLzJWgB1BHcFyAyVAfQGF vZxz44VrHxid94CZsbWxQCx3FGZ5ArTIR4v/2Ptku355RIg2KVxvtwDKogzm7bGz3r OlFWzG7S+me3w== 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 , Andrew Lunn , Tony Nguyen , Przemek Kitszel , 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 , intel-wired-lan@lists.osuosl.org, =?UTF-8?q?Cl=C3=A9ment=20Lecigne?= , Michal Swiatkowski , Sriram Yagnaraman , Kurt Kanzenbach Subject: [PATCH net v3 1/4] libeth: xsk: Count each XDP_TX buffer on its own Date: Thu, 3 Dec 2026 10:56:42 +0100 Message-ID: <20261203095647.3448925-2-bjorn@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261203095647.3448925-1-bjorn@kernel.org> References: <20261203095647.3448925-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_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") Acked-by: Alexander Lobakin 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.53.1-Meta