From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796467886; b=nqZ9GTkJcQCJna5eCPTmq3pFDEMXWziZAx7Iq49bBKoHb0aNebCLuf411WHpKl4JcV8T 3ebs2CZ8eOUnxb7aUdRyadblIDU8Bv5/nmYSDUTkjOJuyDub+Dtsbz/QJaPv20wAQNQsf k5PWixwEoYj9y4ZgiO6hhLpfFSnQ9nw+fl/WeUgmI5oC9kvMF5BaUslCJ3khvDJNQYoct kvntdMkAqtE4WSotKDKJnOmFGagTi0d/9qZJ4UuEfZrq5kHubYILfANuz1Tr5+IyS6H8p 2zPsMjhWORAxIEp79/4/GdkNuCZ7ZwtFiEPR/hodxEyoIbAJOMN0jsTXknYGyt+WFjQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796467886; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=e5o2SC1IH5aQSqc3UelwIIueTXO8MR1oz+C4oX5w0BU=; b=Ua80ATUiIpg3R7liYNRU+itBIk5La/BImbu1BnZW10Yn8CLuYgwAECLEog7sApz8jHGn QWaRdkMtBVDGCdFOAZ6je5+9ZfhbHsCvtgfHr5P7LZjl56mYdB9JPyjp2UI2Y4xHt7X5O qupx6O8aaUZQfe3vrYc+uWesBCHTQ7KiqvNBpCz4zNl/JShL/f5/OjGJTpbFNAYUWX4te w7ww+YmUN+fPzWNffxqBVgKorlUExVCcWTXhxr0pOO+wFAtqc0kUztIuo5ZjV56NQlY85 b4KB/2ngRb6+MCykp+TcHvY2d3SGfu652TVVOlSIDi7wTDBofiqs77f2ta3r5cVWNXg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JcnromjL; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8228D606A322; Sat, 5 Dec 2026 10:51:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JcnromjL Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37EB61F00936; Sat, 5 Dec 2026 10:51:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796467886; bh=e5o2SC1IH5aQSqc3UelwIIueTXO8MR1oz+C4oX5w0BU=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=JcnromjLXScb3v9kDMF9GBXmXy2mBlizupFJrvfNO5oziZrbUUgt2/G4oNSC0iVLj tqu5DfnZjxnfmwoeKA+shmcr1F78odQpkvNw3f69cYDBV0KEJBwCCmQxFKug4Ku6hS MdjLovhG9p0plOvT+QoJgaN1XjafNwTqHeCK02zpPHDPxfZAykLdtPsxTJ7V20NNWT LNu1mDorJYFpG8IzaajLCFOUejKgSVE8ajd91DJk+Oj/ebbcSjZKSyTgta+2alD65W Df4n/4OIbWjM2S/gCdXkbw2eZHdChE9e/um17nbRMyXjAlDz5L53hsWl8SvlEdksbS oiD6Iuqux0mDg== Subject: Re: [PATCH net-next v14 5/5] net: stmmac: rework stmmac_rx to support XDP rx multi-buff From: netdev-bot+sashiko@kernel.org To: lorenzo.bianconi@oss.qualcomm.com Cc: maxime.chevallier@bootlin.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me, Jose.Abreu@synopsys.com, boon.leong.ong@intel.com, horms@kernel.org, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev, matthew.gerlach@altera.com, boon.khai.ng@altera.com, linux@armlinux.org.uk, willemb@google.com, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org, nb@tipi-net.de Date: Sat, 05 Dec 2026 10:51:23 +0000 Message-ID: <179646788378.3146.10539328034123068463@kernel.org> In-Reply-To: <20261204-stmmac-rx-mb-v14-5-5506796fd39e@oss.qualcomm.com> References: <20261204-stmmac-rx-mb-v14-5-5506796fd39e@oss.qualcomm.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 0 · High: 0 (1) · Medium: 1 · Low: 1 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] TX descriptor buffer-length field overflow on XDP_TX of a tail-grown fragment. - [Low] net: stmmac: stale xdp_frags_truesize after xdp_buff_shrink_tail() Pre-existing issues: - [High] Concurrent lockless page_pool direct recycling from a different NAPI context. -- net: stmmac: rework stmmac_rx to support XDP rx multi-buff This commit reworks stmmac_rx() to collect every descriptor of a frame in an xdp_buff kept in rx_q->state, so the XDP program sees the whole frame, including any fragments. Fragmented frames only go to programs loaded with BPF_F_XDP_HAS_FRAGS, and the skb is built with xdp_build_skb_from_buff(). The xdp_rxq is now registered with the page_pool page size as frag_size, so bpf_xdp_adjust_tail() can grow fragments. > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > index c429cb9e1ccbe..0edc92d5fb306 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c [ ... ] > @@ -2351,6 +2349,10 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv, > goto err_free_buf_pool; > } > > + rx_q->queue_index = queue; > + rx_q->priv_data = priv; > + rx_q->napi_skb_frag_size = PAGE_SIZE << pp_params.order; > + > if (priv->extend_desc) > rx_q->dma_erx = addr; > else > @@ -2362,7 +2364,8 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv, > else > napi_id = ch->rx_napi.napi_id; > > - ret = xdp_rxq_info_reg(&rx_q->xdp_rxq, priv->dev, queue, napi_id); > + ret = __xdp_rxq_info_reg(&rx_q->xdp_rxq, priv->dev, queue, napi_id, > + rx_q->napi_skb_frag_size); [Severity: Medium] Registering a frag_size here turns on bpf_xdp_frags_increase_tail() for this rxq. Can a frags-capable program now grow a fragment beyond what a single TX descriptor can describe? stmmac_rx() attaches the buf2 payload as a fragment at offset 0: if (!stmmac_build_xdp_frags(priv, rx_q, buf2_len, buf->sec_page, 0, dma_dir, &ctx.xdp)) { This happens on any core with buf2 capability (GMAC4/XGMAC), not only with SPH. GMAC4 also sets GMAC_CONFIG_JE, so frames longer than dma_buf_sz can use buf2 or several descriptors even at MTU 1500. With frag_size equal to PAGE_SIZE << order, bpf_xdp_adjust_tail() can grow the last fragment to the full page_pool page. That is 16384 bytes on 16K-page kernels and up to about 64K on 64K-page kernels. If the program then returns XDP_TX, stmmac_xdp_xmit_xdpf() puts each fragment into one descriptor and never checks the length: int len = frag ? skb_frag_size(frag) : xdpf->len; ... stmmac_prepare_tx_desc(priv, desc, !i, len, false, ... The descriptor helpers then mask the length to 14 bits: dwmac4_rd_prepare_tx_desc(): p->des2 |= cpu_to_le32(len & TDES2_BUFFER1_SIZE_MASK); dwxgmac2_prepare_tx_desc(): p->des2 |= cpu_to_le32(len & XGMAC_TDES2_B1L); Wouldn't a 16384-byte fragment be programmed as a 0-byte buffer, and larger ones wrap modulo 16K? The descriptor would then disagree with the mapped length and with the total frame length in TDES3. That could put truncated or malformed frames on the wire, or cause TX DMA errors. On 64K-page kernels the linear head could already hit this before this patch. The fragment case is new. Should frag_size be capped, or should stmmac_xdp_xmit_xdpf() reject buffers over the hardware per-buffer limit? [ ... ] > @@ -6005,120 +6020,79 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) [ ... ] > + ctx.desc = p; > + ctx.ndesc = np; > + > + skb = stmmac_xdp_run_prog(priv, &ctx.xdp); > + /* For Not XDP_PASS verdict */ > + if (IS_ERR(skb)) { > + unsigned int xdp_res = -PTR_ERR(skb); > + > + if (xdp_res & STMMAC_XDP_CONSUMED) { > + __xdp_return_buff(&ctx.xdp, true); > + rx_dropped++; > + } else if (xdp_res & (STMMAC_XDP_TX | > + STMMAC_XDP_REDIRECT)) { > + xdp_status |= xdp_res; > + } > goto next; > } [Severity: High] This isn't a bug introduced by this patch. However, now that multi-buffer frames can reach XDP_TX, the patch seems to make an existing page_pool race worse. When an XDP_TX frame completes, stmmac_tx_clean() frees it with direct recycling: if (xdpf && tx_q->tx_skbuff_dma[entry].buf_type == STMMAC_TXBUF_T_XDP_TX) { xdp_return_frame_rx_napi(xdpf); tx_q->xdpf[entry] = NULL; } This reaches the lockless alloc cache with allow_direct=true: xdp_return_frame_rx_napi() __xdp_return(..., napi_direct=true) page_pool_put_full_netmem(pool, netmem, true) page_pool_put_unrefed_netmem() __page_pool_put_page() page_pool_recycle_in_cache() stmmac_tx_clean() runs from the TX NAPI (tx_napi or rxtx_napi) of the queue that stmmac_xdp_xmit_back() picks: queue = stmmac_xdp_get_tx_queue(priv, cpu); That queue is cpu % tx_queues, so it need not be the RX queue that owns the page_pool. Even when the queue matches, tx_napi and rx_napi are separate napi_structs and do not exclude each other. At the same time, the owning RX NAPI can run on another CPU. It pops from the same alloc cache in stmmac_rx_refill(). It also pushes to it through __xdp_return_buff(&ctx.xdp, true) and page_pool_put_full_page(..., true). Those RX paths do not take the netdev TX queue lock that stmmac_tx_clean() holds. Can interleaved updates of pool->alloc.count and pool->alloc.cache[] give the same page to two RX descriptors, or lose a page? This looks reachable with per-channel MSI RX/TX IRQs on different CPUs, with the TX coalesce hrtimer, or with threaded NAPI. With this patch, each XDP_TX completion now returns 1 + nr_frags pages through that path instead of a single page. [ ... ] > @@ -6005,120 +6020,79 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) > buf2_len = stmmac_rx_buf2_len(priv, p, status, len); > len += buf2_len; > > - /* Drop the packet if it is split over buf1 and buf2 on a > - * single descriptor if the interface is running in XDP mode. > - */ > - if (unlikely(stmmac_xdp_is_enabled(priv) && buf2_len)) { > - rx_dropped++; > - goto next; > - } > - > - /* ACS is disabled; strip manually. */ > - if (likely(!(status & rx_not_ls))) > - len -= ETH_FCS_LEN; > - > - if (!skb) { > - /* Each frame starts here: reset the FCS handling */ > - fcs_stripped = false; > - > + if (!n_descs) { > dma_sync_single_for_cpu(priv->device, buf->addr, > buf1_len, dma_dir); > net_prefetch(page_address(buf->page) + > buf->page_offset); > > - if (stmmac_xdp_is_enabled(priv) && !buf2_len) { > - buf1_len -= ETH_FCS_LEN; > - fcs_stripped = true; > - } > - > xdp_init_buff(&ctx.xdp, bufsz, &rx_q->xdp_rxq); > xdp_prepare_buff(&ctx.xdp, page_address(buf->page), > buf->page_offset, buf1_len, true); > - > - ctx.priv = priv; > - ctx.desc = p; > - ctx.ndesc = np; > - > - skb = stmmac_xdp_run_prog(priv, &ctx.xdp); > - /* For Not XDP_PASS verdict */ > - if (IS_ERR(skb)) { > - unsigned int xdp_res = -PTR_ERR(skb); > - > - if (xdp_res & STMMAC_XDP_CONSUMED) { > - page_pool_recycle_direct(rx_q->page_pool, > - virt_to_head_page(ctx.xdp.data)); > - buf->page = NULL; > + buf->page = NULL; > + } else if (buf1_len) { > + if (!stmmac_build_xdp_frags(priv, rx_q, buf1_len, > + buf->page, > + buf->page_offset, > + dma_dir, &ctx.xdp)) { > + if (!error) > rx_dropped++; > - goto next; > - } else if (xdp_res & (STMMAC_XDP_TX | > - STMMAC_XDP_REDIRECT)) { > - xdp_status |= xdp_res; > - buf->page = NULL; > - goto next; > - } > - } > - } > - > - if (!skb) { > - unsigned int metasize; > - > - /* XDP program may expand or reduce tail */ > - buf1_len = ctx.xdp.data_end - ctx.xdp.data; > - > - skb = napi_build_skb(page_address(buf->page), > - rx_q->napi_skb_frag_size); > - if (!skb) { > - page_pool_recycle_direct(rx_q->page_pool, > - buf->page); > - buf->page = NULL; > - rx_dropped++; > error = 1; > - goto drain_data; > } > - > - /* XDP program may adjust header */ > - skb_reserve(skb, > - ctx.xdp.data - ctx.xdp.data_hard_start); > - skb_put(skb, buf1_len); > - skb_mark_for_recycle(skb); > - > - metasize = ctx.xdp.data - ctx.xdp.data_meta; > - if (metasize) > - skb_metadata_set(skb, metasize); > - buf->page = NULL; > - } else if (buf1_len) { > - dma_sync_single_for_cpu(priv->device, buf->addr, > - buf1_len, dma_dir); > - skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, > - buf->page, buf->page_offset, buf1_len, > - priv->dma_conf.dma_buf_sz); > buf->page = NULL; > } > > if (buf2_len) { > - dma_sync_single_for_cpu(priv->device, buf->sec_addr, > - buf2_len, dma_dir); > - skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, > - buf->sec_page, 0, buf2_len, > - priv->dma_conf.dma_buf_sz); > + if (!stmmac_build_xdp_frags(priv, rx_q, buf2_len, > + buf->sec_page, 0, > + dma_dir, &ctx.xdp)) { > + if (!error) > + rx_dropped++; > + error = 1; > + } > buf->sec_page = NULL; > } > + n_descs++; > > -drain_data: > if (likely(status & rx_not_ls)) > goto read_again; > - if (!skb) > - goto next; > > - /* Got entire packet into SKB. Finish it. */ > + /* ACS is disabled; strip manually. */ > + len -= ETH_FCS_LEN; > + if (xdp_buff_shrink_tail(&ctx.xdp, ETH_FCS_LEN)) { > + if (!error) > + rx_dropped++; > + error = 1; > + } > > - /* Remove FCS if needed */ > - if (!fcs_stripped && pskb_trim(skb, len)) { > - dev_kfree_skb_any(skb); > - rx_dropped++; > + if (unlikely(error)) > + goto error_free_frag; > + > + ctx.desc = p; > + ctx.ndesc = np; > + > + skb = stmmac_xdp_run_prog(priv, &ctx.xdp); > + /* For Not XDP_PASS verdict */ > + if (IS_ERR(skb)) { > + unsigned int xdp_res = -PTR_ERR(skb); > + > + if (xdp_res & STMMAC_XDP_CONSUMED) { > + __xdp_return_buff(&ctx.xdp, true); > + rx_dropped++; > + } else if (xdp_res & (STMMAC_XDP_TX | > + STMMAC_XDP_REDIRECT)) { > + xdp_status |= xdp_res; > + } > goto next; > } > > + skb = xdp_build_skb_from_buff(&ctx.xdp); > + if (!skb) { > + rx_dropped++; > + goto error_free_frag; > + } > + > + /* Got entire packet into SKB. Finish it. */ > stmmac_get_rx_hwtstamp(priv, p, np, skb); > > if (priv->hw->hw_vlan_en) { [Severity: Low] Does the FCS strip here leave sinfo->xdp_frags_truesize stale when it frees a trailing fragment? stmmac_build_xdp_frags() attaches every fragment with xdp_buff_add_frag(..., xdp->frame_sz). That makes __xdp_buff_add_frag() add one full page_pool allocation to sinfo->xdp_frags_truesize for each fragment. Sometimes the last buffer of a multi-buffer frame holds only 1 to 4 of the FCS bytes. In that case xdp_buff_shrink_tail() goes through xdp_frags_shrink_tail(), which returns that page to the pool and updates sinfo->nr_frags and sinfo->xdp_frags_size. It never decrements sinfo->xdp_frags_truesize, though. If at least one fragment is left, xdp_build_skb_from_buff() then does: tsize = sinfo->xdp_frags_truesize ? : nr_frags * xdp->frame_sz; So skb->truesize is overcharged by xdp->frame_sz for a page the skb no longer owns. That is 4K up to 64K, depending on page size and pool order. This path runs for every non-XSK RX frame, whether or not an XDP program is loaded. Before this patch, the FCS was removed with pskb_trim(). That goes through skb_condense(), which recomputed truesize whenever the remaining frag data fit in the head tailroom. So regular stmmac RX traffic did not see this before. The impact is limited to socket receive buffer accounting. Nothing is leaked or corrupted. Every stmmac fragment has the same truesize. Would it be enough to pass 0 as truesize to xdp_buff_add_frag(), and let xdp_build_skb_from_buff() fall back to nr_frags * xdp->frame_sz from the post-shrink nr_frags? Or should xdp_frags_shrink_tail() subtract the truesize of the fragments it frees? bpf_xdp_adjust_tail() shares that helper and seems to have the same omission. -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-stmmac-rx-mb-v14-0-5506796fd39e%40oss.qualcomm.com