From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.180.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796496054; b=Lpf8YQYlWT/PIz6j1uR+IIM9ZriIDInU2jxOf29qUzCoouAI8R8nWDJMks+ih14FMyJ4 tQRGD1CZbYAZtkmJunhliW8dB606N9ugsDZeM3MYDC0cvOP4Lhvz0qOyRDvXGaqXC9Yy+ kDZbrLAadqWlc3rvsdhoyyM699H0hg03fZvCzKa1bJrt7byqDxwtfOmDNspkieLuN0eTP QCafWjU+QxpbOlQPOPf3zS/rfaiMfv+QVXbcx6wLkrj7Osh8kIOBWlgEPuyrhjpLmIOef 3Zrs0Ep/Zfhi3zw5kjVwj+Gx4xdJE++gW8zyQ3TolVjZeQdflzlQcJ/wC4uG0kMyM2Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796496054; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:Date:From: To:Cc:Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To:X-Proofpoint-ORIG-GUID: X-Authority-Analysis:X-Proofpoint-Spam-Details-Enc: X-Proofpoint-Spam-Info:X-Proofpoint-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=kPy2R3Sz4B12UuAZnWUGAyNbysTSBQ+Jnv0oMOtvRus=; b=CrN7JQ0NexhxH8CiXpxqQQVe6Ma/DqVsdTYQFgyb0Uiv5M0RxAcsbSko++Qkazw/ynms ivJOH+iOizhRrb+DHIBVJJYqfZer/f1XFHj/BPw1MntbXtfr/4AKt1l8CYnr7ZndETF4w irxS7o0X5Z94B+W3PHPzqYbPVGlU0G7+915EVKTVVbSVpfpFM5ctSaoxwpMwQI6C3SeaF vQ3bPYJWeLQ4OF2AdQ/V4DmIbrLXrAoFMdm+45E2SdB7p1EslF8/WTyBdOv+poKDqgkOB M7URC2Wcd5g7p9mx51400o+4wXMzwxLdtZ4aZX5hSFYIllj305+GcZiOpeKGJ7Xd/jw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=WXDaxyK8; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b="N/zu0Bs0"; arc=none smtp.remote-ip=205.220.180.131 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (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 947C4606A322 for ; Sat, 5 Dec 2026 18:40:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 947C4606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=WXDaxyK8; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=N/zu0Bs0 Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B5GmgRp3960659 for ; Sat, 5 Dec 2026 18:40:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to; s=qcppdkim1; bh=kPy2R3Sz4B12UuAZnWUGAyNb ysTSBQ+Jnv0oMOtvRus=; b=WXDaxyK8c4M9/RIXCw46DM+iRqCEBrxE7uza88BT vkss6CYm6SKrG7EGurHd1AEKLz/oIDMluU30oqKQLgo9WJShW7vvqtd6Dus0ueFX W/exdZ2ujuCSKeArcsx+xMz+32IAY/wEbxhwDqWqAdroPXXpxLCPYJymOgmyJk1y UTKCq98cVT1UQE6065Hyr+DRbrXO4AnFq3gHYv2qFgMUHaowbj7XNac081QdUdIB Dd57u4X8JdZlx9sW/MegceP/6Kc1ho3gm+GzHx/1H+IPI/170w04CqStETHYysrx x2MGLlSLDSL3s9wPs/IkGrb2WtL1SugCIjv7+gNKbV+6YA== Received: from mail-vs1-f70.google.com (mail-vs1-f70.google.com [209.85.217.70]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4jcbpr1rb2-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Sat, 05 Dec 2026 18:40:52 +0000 (GMT) Received: by mail-vs1-f70.google.com with SMTP id ada2fe7eead31-7d2ec691518so2580826137.0 for ; Sat, 05 Dec 2026 10:40:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796496052; x=1797100852; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=kPy2R3Sz4B12UuAZnWUGAyNbysTSBQ+Jnv0oMOtvRus=; b=N/zu0Bs0QLAdW9tlO9BnSSrPKlH169sX2+ZP6P70/cl2dQSIsFd8SQwql6MSedk41Z 7YE/hOzFiYEXyPwp6JUxNgfuymOsMi0AY7FB4pyDFfeiVdFkOVqvZJ1AP4Bkim/kdPJn ZKT7xFM/oPB2WNB/yFxSL8yG7Hpx6SKfI/3g/7fljOfjDLcG5MkhOHjXlLKISsprqUYK rvKzE/M5Vp1ea7hQAn540Qi9MrHrowwGj3yvK3M/zAq8zhCEoU6XnS/akwnSTZ56fZRY J0gb2CJuwHfpzhuA5O+lv7gi6LnptuhxC3Vvtg5GjeDyFXLVglLJy8/+nCxcKHPnFz+0 qADw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796496052; x=1797100852; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=kPy2R3Sz4B12UuAZnWUGAyNbysTSBQ+Jnv0oMOtvRus=; b=FSIAQdipc4NHyA1f17epJo4SCClpUfJuKsQrEcqq3SULyXc0SI/cJ4TnNrhwW4Q7BH dmp+LBpwf82peNV3Iw5SY27UElzvbCmg0o3dtM+sAtZ+pj3y65cenxzGIEtvCOHGiNCw GEtmvxIlqC9H0dsG7dJiCwQHOjLTfANj3twN1jXPHrwsupyGEfCQHZQCISyJVAZ3/GQd y/0F8b6AMC06xKm5LZU6xzvWRubSyoe6wdhdcwLy6CsDjw3kPAmiU5zDdDJbzuGTzDl9 axWLcEnPg5OvyWx4T9CO5II3R9vVEWHGhMiSJnKhUt8LQsOSCfPHMEVg3xDzhhjjpkkr 6Y8Q== X-Forwarded-Encrypted: i=1; AL+hErH+7n7YBZjt5Wt7QxSQDdDCGWiVU3ecyB26JG6cFawNdEshxGr9WstdjfCbRu8jhwZ6/EA=@vger.kernel.org X-Gm-Message-State: AB4q+uGZ1ivyHjghEhPrvVRg+zqZ+1Zb1NZhpx/n6+w3DpGD32skWsnN 1+p+C3eimdmPms7FiMV9DwSSlVOrsLpIgAq8WXLNXWQ7y6IZms65CUBzoYXsMCDnhH89ragyQbz NeFIip3Uhl6Wl5hRRObWRjdlIhybaRJqPnIb0hBp2dtVebbKZDLuU3IU= X-Gm-Gg: AZFdTZf0cT7V9Q2Cvr6/TtCbAq/wedqzSqbV/MXPgzxSm+eWX4/rFR6poWcAEqGrua0 UEj+u34+PCtQtoy0LgTs0vrvAvtqHiTx896QII5yZs0m+IKGXWgk1PINFEaeLnyGHm2OcKpMtqE I+YzaSj/u4/g+2FPnz5d1rYkD9YzbKkAq0RMt3h35G8cHGFz1Q26gtPXqoh94jS3eXDwvZKjI6w oL0tcS4Szg61ME+wcm0abKrEqyNpwXvTSOOXUilluGD5bsrSPco3SvQn6mP3+HmnRh+fBDESHOZ gzEVKXHA2bklCYPMEV1/JNrWvdBfSb31VEfeXK6v15rIQm5beaeG1xcBPbpRytqxhOMva/DSitC fwoVsCoqbuZgeG1veYCXekku8YxtdvPyKmQWWh0xzuqfMH5bhB18g7PdYHEsx5g== X-Received: by 2002:a05:6102:292a:b0:7da:d26f:9667 with SMTP id ada2fe7eead31-7dad6a70ebamr6042876137.27.1796496051379; Sat, 05 Dec 2026 10:40:51 -0800 (PST) X-Received: by 2002:a05:6102:292a:b0:7da:d26f:9667 with SMTP id ada2fe7eead31-7dad6a70ebamr6042851137.27.1796496050666; Sat, 05 Dec 2026 10:40:50 -0800 (PST) Received: from localhost ([130.25.105.85]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d172f363b8sm12669869f8f.22.2026.12.05.10.40.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 10:40:49 -0800 (PST) Date: Sat, 5 Dec 2026 19:40:48 +0100 From: Lorenzo Bianconi To: netdev-bot+sashiko@kernel.org 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 Subject: Re: [PATCH net-next v14 5/5] net: stmmac: rework stmmac_rx to support XDP rx multi-buff Message-ID: References: <20261204-stmmac-rx-mb-v14-5-5506796fd39e@oss.qualcomm.com> <179646788378.3146.10539328034123068463@kernel.org> X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="sXVVRHr5CeQk1bdo" Content-Disposition: inline In-Reply-To: <179646788378.3146.10539328034123068463@kernel.org> X-Proofpoint-ORIG-GUID: UGe85WcW950QqjRK8nNmcUEsGGo73bpu X-Authority-Analysis: v=2.4 cv=Aup7T+9P c=1 sm=1 tr=0 ts=6b145ab4 cx=c_pps a=N1BjEkVkxJi3uNfLdpvX3g==:117 a=RcFDq6c+avmIvxkL9iwlxA==:17 a=pUM-KoujPXoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=3WHJM1ZQz_JShphwDgj5:22 a=9R54UkLUAAAA:8 a=EUspDBNiAAAA:8 a=hYnf4ff2e7B-5fyS3oAA:9 a=wPNLvfGTeEIA:10 a=yoNVfn2gE5osZWRYJ-gA:9 a=crWF4MFLhNY0qMRaF8an:22 a=YTcpBFlVQWkNscrzJ_Dz:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjA1MDA3NCBTYWx0ZWRfX9eXfEAhqFDfl CxvF9O6ARhO0HcfUVyXpnuvQ3knZcnqHBSRLrYHrEglA8sFVGU/czUMKU7utdBgFxYNr9RIYU/1 OCIdvqhSZvmIiNG9RSQIKYNO1lN73JqGAMtzrhqtwbPu0LW8McSsOy1lAhssJlN2hPXe4GA3NP1 wiS88gHbJf1jgEngvYTljqL46qKcrAFViWGLju3r3GOEhx/Cxe1t7lglFRL+l1egZZBHW98zdPH gSKhfVRIW6C6qm5MGaZ9603rKsW1ZFzQ+iRhkjS/cn7b4hFUh13X+9cjrBufTpaWXAG72IZq2sh RBf5zTJwsmyyR46K9sKV/EO20aBl5Cx+j2VlS4d/IZcumByBuBjVM77bqTYLFsnHh+XY98xxTBA YIHgV+3MEtAYV1V8U/YPUf3PZZf+bfIhdq8HTAW1h4UIqGuxnsY4yIyNuPu1qjxlz0oiRgReeUm CvooZOma3q/837lU/BQ== X-Proofpoint-Spam-Info: AW1haW4tMjYxMjA1MDA3NCBTYWx0ZWRfX/NEiFEfrwK0L vBrNLNHASGSdS+QG8oHSXHpkieQk8JgcVIoiYGY9ECfH664ElUFOvCYKWHvTFYu47FgYNdkkRJb Hz3yDdFBtZFTysxju0aurqOFpZSGV0k= X-Proofpoint-GUID: UGe85WcW950QqjRK8nNmcUEsGGo73bpu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-05_05,2026-12-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 spamscore=0 bulkscore=0 malwarescore=0 impostorscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2612040000 definitions=main-2612050074 --sXVVRHr5CeQk1bdo Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable > Thank you for your contribution! Sashiko AI review found 2 potential > issue(s) to consider. >=20 > Critical: 0 =B7 High: 0 (1) =B7 Medium: 1 =B7 Low: 1 >=20 > 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). >=20 > - [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() >=20 > Pre-existing issues: > - [High] Concurrent lockless page_pool direct recycling from a different > NAPI context. >=20 > -- >=20 > net: stmmac: rework stmmac_rx to support XDP rx multi-buff >=20 > 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. >=20 > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/driver= s/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 >=20 > [ ... ] >=20 > > @@ -2351,6 +2349,10 @@ static int __alloc_dma_rx_desc_resources(struct = stmmac_priv *priv, > > goto err_free_buf_pool; > > } > > =20 > > + rx_q->queue_index =3D queue; > > + rx_q->priv_data =3D priv; > > + rx_q->napi_skb_frag_size =3D PAGE_SIZE << pp_params.order; > > + > > if (priv->extend_desc) > > rx_q->dma_erx =3D addr; > > else > > @@ -2362,7 +2364,8 @@ static int __alloc_dma_rx_desc_resources(struct s= tmmac_priv *priv, > > else > > napi_id =3D ch->rx_napi.napi_id; > > =20 > > - ret =3D xdp_rxq_info_reg(&rx_q->xdp_rxq, priv->dev, queue, napi_id); > > + ret =3D __xdp_rxq_info_reg(&rx_q->xdp_rxq, priv->dev, queue, napi_id, > > + rx_q->napi_skb_frag_size); >=20 > [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? >=20 > stmmac_rx() attaches the buf2 payload as a fragment at offset 0: >=20 > if (!stmmac_build_xdp_frags(priv, rx_q, buf2_len, > buf->sec_page, 0, > dma_dir, &ctx.xdp)) { >=20 > 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. >=20 > 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. >=20 > If the program then returns XDP_TX, stmmac_xdp_xmit_xdpf() puts each > fragment into one descriptor and never checks the length: >=20 > int len =3D frag ? skb_frag_size(frag) : xdpf->len; > ... > stmmac_prepare_tx_desc(priv, desc, !i, len, false, ... >=20 > The descriptor helpers then mask the length to 14 bits: >=20 > dwmac4_rd_prepare_tx_desc(): > p->des2 |=3D cpu_to_le32(len & TDES2_BUFFER1_SIZE_MASK); >=20 > dwxgmac2_prepare_tx_desc(): > p->des2 |=3D cpu_to_le32(len & XGMAC_TDES2_B1L); >=20 > 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. >=20 > On 64K-page kernels the linear head could already hit this before this > patch. The fragment case is new. >=20 > Should frag_size be capped, or should stmmac_xdp_xmit_xdpf() reject > buffers over the hardware per-buffer limit? This issue is real, but it has not been introduced by this patch since we c= an have the same issue even on the head of the xdp_buff, not just on the fragm= ent. I think we should fix it with a dedicated patch. >=20 > [ ... ] >=20 > > @@ -6005,120 +6020,79 @@ static int stmmac_rx(struct stmmac_priv *priv,= int limit, u32 queue) >=20 > [ ... ] >=20 > > + ctx.desc =3D p; > > + ctx.ndesc =3D np; > > + > > + skb =3D stmmac_xdp_run_prog(priv, &ctx.xdp); > > + /* For Not XDP_PASS verdict */ > > + if (IS_ERR(skb)) { > > + unsigned int xdp_res =3D -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 |=3D xdp_res; > > + } > > goto next; > > } >=20 > [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. As pointed out by sashiko, this issue has not been introduced by this serie= s. >=20 > When an XDP_TX frame completes, stmmac_tx_clean() frees it with direct > recycling: >=20 > if (xdpf && > tx_q->tx_skbuff_dma[entry].buf_type =3D=3D STMMAC_TXBUF_T_XDP_TX)= { > xdp_return_frame_rx_napi(xdpf); > tx_q->xdpf[entry] =3D NULL; > } >=20 > This reaches the lockless alloc cache with allow_direct=3Dtrue: >=20 > xdp_return_frame_rx_napi() > __xdp_return(..., napi_direct=3Dtrue) > page_pool_put_full_netmem(pool, netmem, true) > page_pool_put_unrefed_netmem() > __page_pool_put_page() > page_pool_recycle_in_cache() >=20 > stmmac_tx_clean() runs from the TX NAPI (tx_napi or rxtx_napi) of the > queue that stmmac_xdp_xmit_back() picks: >=20 > queue =3D stmmac_xdp_get_tx_queue(priv, cpu); >=20 > 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. >=20 > 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. >=20 > 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. >=20 > With this patch, each XDP_TX completion now returns 1 + nr_frags pages > through that path instead of a single page. >=20 > [ ... ] >=20 > > @@ -6005,120 +6020,79 @@ static int stmmac_rx(struct stmmac_priv *priv,= int limit, u32 queue) > > buf2_len =3D stmmac_rx_buf2_len(priv, p, status, len); > > len +=3D buf2_len; > > =20 > > - /* 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 -=3D ETH_FCS_LEN; > > - > > - if (!skb) { > > - /* Each frame starts here: reset the FCS handling */ > > - fcs_stripped =3D 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); > > =20 > > - if (stmmac_xdp_is_enabled(priv) && !buf2_len) { > > - buf1_len -=3D ETH_FCS_LEN; > > - fcs_stripped =3D 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 =3D priv; > > - ctx.desc =3D p; > > - ctx.ndesc =3D np; > > - > > - skb =3D stmmac_xdp_run_prog(priv, &ctx.xdp); > > - /* For Not XDP_PASS verdict */ > > - if (IS_ERR(skb)) { > > - unsigned int xdp_res =3D -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 =3D NULL; > > + buf->page =3D 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 |=3D xdp_res; > > - buf->page =3D NULL; > > - goto next; > > - } > > - } > > - } > > - > > - if (!skb) { > > - unsigned int metasize; > > - > > - /* XDP program may expand or reduce tail */ > > - buf1_len =3D ctx.xdp.data_end - ctx.xdp.data; > > - > > - skb =3D 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 =3D NULL; > > - rx_dropped++; > > error =3D 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 =3D ctx.xdp.data - ctx.xdp.data_meta; > > - if (metasize) > > - skb_metadata_set(skb, metasize); > > - buf->page =3D 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 =3D NULL; > > } > > =20 > > 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 =3D 1; > > + } > > buf->sec_page =3D NULL; > > } > > + n_descs++; > > =20 > > -drain_data: > > if (likely(status & rx_not_ls)) > > goto read_again; > > - if (!skb) > > - goto next; > > =20 > > - /* Got entire packet into SKB. Finish it. */ > > + /* ACS is disabled; strip manually. */ > > + len -=3D ETH_FCS_LEN; > > + if (xdp_buff_shrink_tail(&ctx.xdp, ETH_FCS_LEN)) { > > + if (!error) > > + rx_dropped++; > > + error =3D 1; > > + } > > =20 > > - /* 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 =3D p; > > + ctx.ndesc =3D np; > > + > > + skb =3D stmmac_xdp_run_prog(priv, &ctx.xdp); > > + /* For Not XDP_PASS verdict */ > > + if (IS_ERR(skb)) { > > + unsigned int xdp_res =3D -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 |=3D xdp_res; > > + } > > goto next; > > } > > =20 > > + skb =3D 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); > > =20 > > if (priv->hw->hw_vlan_en) { >=20 > [Severity: Low] > Does the FCS strip here leave sinfo->xdp_frags_truesize stale when it > frees a trailing fragment? >=20 > 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. >=20 > 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. >=20 > If at least one fragment is left, xdp_build_skb_from_buff() then does: >=20 > tsize =3D sinfo->xdp_frags_truesize ? : nr_frags * xdp->frame_sz; >=20 > 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. >=20 > 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. >=20 > The impact is limited to socket receive buffer accounting. Nothing is > leaked or corrupted. >=20 > 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. As pointed out before, this is an issue already present in bpf_xdp_frags_shrink_tail(). This series is just moving the code in a helper routine to make it available to the drivers. We should post a dedicated fix= for it. Regards, Lorenzo >=20 > --=20 > Sashiko AI review =B7 https://netdev-ai.bots.linux.dev/sashiko/#/patchset= /20261204-stmmac-rx-mb-v14-0-5506796fd39e%40oss.qualcomm.com --sXVVRHr5CeQk1bdo Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQTquNwa3Txd3rGGn7Y6cBh0uS2trAUCaxRasAAKCRA6cBh0uS2t rII8AQCvfwOnxlBrqh58+47GkheHqFwQ92GW6ladJA5OWZg2YwD+KnqVxxWPdGXM WYWFVX8kwJCvF7BLaVCL1QxKG0FBaQY= =vtXs -----END PGP SIGNATURE----- --sXVVRHr5CeQk1bdo--