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=1796499765; b=gMxWXEz4uVYICBnercTcxTEg4rUYcXX0/bxsALAOkgwCtOXr1ywvoc81rllZLX/54n3A U5z2M4PqgUY1EQ52jkkxxa/scHtktCjng2eUFPPluhnAuScr+w/vq8ajqKTaEsPGIioJ5 cS7RH7y+ivTvJSMEDGOd8WMsCOpZkulDZWqoWxsaSB4n1XJz3ZnRoc2ofnnGONs1/Y/wO m3pb+dKcvfudHw8NPes/ECi6YSBW1242CcTCV2t7aWc0KBWkxA+yIMHmYc9Z6YslBNuvL /d6kIx6Gfk7bNea24CJFFMKsYGzGF8UQXSSJpOVyMy64CpeoHspsjPiuC7FEh2k79Uw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796499765; 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=RvBMYokT53hJt1IyOs1/zaFqFhmt/4sE8O/9qvytI3A=; b=hb39mF9YO+DWdz75WekO/GqUyaRt3mHWQjULn4XCDtioOxxIhp4jY4RIyITybNBfVJM7 nZGcAFh1zqkehS6mtMtjEm2Zo2pF4Z3pRHieAaYdXd9GplM70J8OQM74CWsPCiJbMB76M XSy+e6kZmcN90t1ZE4hbS5aMf4tTjjzTf6BOKV3KSouQp95KKR0iwLKyTX6Qkdxo3teSx dZXyRjThSGLPiApety8kA/jYwzWWELCpYvy16/ZwZP7RN/uDjOqEl/cZUDWr4b4yjc5op AckMc8tsfWmeprzFq4Ubc0BB9NTvE5P542FhetCgr3MIB8elFpaOjGqi+0ALJK9Ecbg== 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=NXMIn+eC; 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 303DC606A31F; Sat, 5 Dec 2026 19:42:44 +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=NXMIn+eC Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CB891F0092B; Sat, 5 Dec 2026 19:42:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796499764; bh=RvBMYokT53hJt1IyOs1/zaFqFhmt/4sE8O/9qvytI3A=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=NXMIn+eCHW2HoWemPRRwypIhQ3aFHxiXl7oItFLm77JbaK//bxqWei0Q0DYrMOsYy WCQOIHNqIKyOLm1pH5XHkgnb2OmgXT/CfbmUoVUMB56E23o19Hs10/HBkhflRURq05 euWIQ4sze1LzjGtAmX54fAKGq9F9CJlxksVBdwjjKzpFPfUtBs00aeRh8W82d6VpWN 079faepAu69WcuSajGbN5g7NfUvKllbtwRFKOndX/EyMGV/phI8zNqF5LY00FAAohM rQB3gxHZzeSkCpLCfmWyb//Vsn9HnLssX90OpxzQt+aayXaq2Hbm2Uo+8M6b1UrX2n KV4EeGURYlvUA== Subject: Re: [PATCH net v6 1/2] xsk: Do not free ZC Rx buffer when the Rx ring is full From: netdev-bot+sashiko@kernel.org To: maciej.fijalkowski@intel.com Cc: netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com, magnus.karlsson@intel.com, sdf@fomichev.me, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, jtollet@cisco.com, willemb@google.com, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, bpf@vger.kernel.org, bjorn@kernel.org, kerneljasonxing@gmail.com, marcin.knap@vecima.com, joshwash@google.com, hramamurthy@google.com, sgoutham@marvell.com, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev, toke@redhat.com, hangbin.liu@linux.dev Date: Sat, 05 Dec 2026 19:42:42 +0000 Message-ID: <179649976273.3148.10281043057398500708@kernel.org> In-Reply-To: <20261204193929.1168874-2-maciej.fijalkowski@intel.com> References: <20261204193929.1168874-2-maciej.fijalkowski@intel.com> X-sashiko-severity: High 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 (1) · High: 1 (1) · Medium: 0 · 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). - [High] The patch relies on ixgbe's XDP_EXIT retry path to handle the retained buffer correctly, but that retry reuses stale xdp_buff state. - [Low] The commit message lists the drivers that break because xsk_rcv_zc() freed the buffer on -ENOBUFS, and names ixgbe as the one… Pre-existing issues: - [Critical] In otx2_xdp_rcv_pkt_handler(), the non-XSK (page pool) XDP_REDIRECT failure path releases the receive page and then returns… - [High] In otx2_xdp_rcv_pkt_handler(), when pool->xsk_pool is set, the code runs the program on xsk_buff and does `goto handle_xdp_verdict`… -- xsk: Do not free ZC Rx buffer when the Rx ring is full This patch stops xsk_rcv_zc() from freeing the zero-copy buffer when the XSK Rx ring is full. The buffer now stays with the driver that called xdp_do_redirect(). It also updates i40e, ice, gve DQO and octeontx2, which relied on the core freeing the buffer, so that they free it themselves. > A failed xdp_do_redirect() leaves the buffer owned by the caller, so > the driver releases it as well. That is harmless when the driver frees > it right away, as i40e, ice, igc, stmmac, idpf and most others do: > xp_free() ignores a buffer that is already on the pool free list. It > breaks when the driver releases or uses the buffer later, after it may > have been reallocated: [ ... ] > - ixgbe keeps the buffer in the ring on its need_wakeup -ENOBUFS > (XDP_EXIT) path and runs XDP on it again on the next poll. [Severity: Low] Should igb be listed next to ixgbe here? igb_run_xdp_zc() returns IGB_XDP_EXIT on -ENOBUFS when need_wakeup is enabled. igb_clean_rx_irq_zc() then handles it the same way ixgbe does: drivers/net/ethernet/intel/igb/igb_xsk.c:igb_clean_rx_irq_zc() { ... } else if (xdp_res == IGB_XDP_EXIT) { failure = true; break; ... } ntc is not advanced and rx_buffer_info_zc[ntc] is not cleared, so the same xdp_buff goes through XDP again on the next poll. Before this patch, that buffer was already on the pool free list. The core change in xsk_rcv_zc() fixes igb without any driver change. The changelog doesn't say so, though, and it suggests igb is one of "most others" that free the buffer right away. Could igb be added to the list of affected drivers? [ ... ] > diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c > index 90af9b9044aa0..6d10c132f61cb 100644 > --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c > +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c > @@ -1555,7 +1555,8 @@ static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf, > *need_xdp_flush = true; > return true; > } > - return false; > + xsk_buff_free(xsk_buff); > + return true; > } [Severity: High] This is a pre-existing issue, but this patch is fixing the XSK verdict handling in otx2_xdp_rcv_pkt_handler(). What happens with XDP_TX and XDP_PASS on the XSK path? The XSK branch jumps to the verdict without initializing the local struct xdp_buff xdp: if (pool->xsk_pool) { xsk_buff = pool->xdp[--cq->rbpool->xdp_top]; ... xsk_buff->data_end = xsk_buff->data + cqe->sg.seg_size; act = bpf_prog_run_xdp(prog, xsk_buff); goto handle_xdp_verdict; } The verdict cases still use xdp, though: case XDP_PASS: *metasize = xdp.data - xdp.data_meta; break; case XDP_TX: ... xdpf = xdp_convert_buff_to_frame(&xdp); xdp_convert_buff_to_frame() dereferences xdp->rxq->mem.type immediately. xdp.rxq is uninitialized stack memory, or NULL with INIT_STACK_ALL_ZERO. Can an XDP_TX verdict on an AF_XDP zero-copy queue oops in NAPI context here? xsk_buff is also never converted or released on that path. For XDP_PASS, metasize comes from uninitialized stack memory, and the caller passes it to skb_metadata_set(). > > err = xdp_do_redirect(pfvf->netdev, &xdp, prog); [Severity: Critical] This isn't a bug introduced by this patch, but the non-XSK branch just below seems to have the same problem the commit message describes for octeontx2 ("returns false on a failed redirect, so the caller goes on to build an skb from the freed buffer"): err = xdp_do_redirect(pfvf->netdev, &xdp, prog); if (!err) { *need_xdp_flush = true; return true; } otx2_dma_unmap_page(pfvf, iova, pfvf->rbsize, DMA_FROM_DEVICE); xdpf = xdp_convert_buff_to_frame(&xdp); xdp_return_frame(xdpf); break; ... return false; The page is unmapped and returned through xdp_return_frame(), and then the function returns false. otx2_rcv_pkt_handler() treats false as XDP_PASS: if (pfvf->xdp_prog) if (otx2_xdp_rcv_pkt_handler(pfvf, pfvf->xdp_prog, cqe, cq, &metasize, need_xdp_flush)) return; skb = napi_get_frags(napi); ... if (otx2_skb_add_frag(pfvf, skb, *seg_addr, seg_size[seg], parse, cq->cq_idx)) cq->pool_ptrs++; Does this attach the already freed page to an skb and pass it to GRO? cq->pool_ptrs also gets incremented a second time. This looks reachable whenever __xdp_do_redirect_frame() fails, for example when a devmap or ifindex target is down or has no ndo_xdp_xmit. Should this branch also return true after releasing the page? The later patch in this series doesn't touch this driver either. > diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c > index 48a835e535188..933a13a19a781 100644 > --- a/net/xdp/xsk.c > +++ b/net/xdp/xsk.c > @@ -224,21 +224,15 @@ static int xsk_rcv_zc(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len) > struct list_head *xskb_list; > u32 contd = 0; > u32 num_desc; > - int err; > > - if (likely(!frags)) { > - err = __xsk_rcv_zc(xs, xskb, len, contd); > - if (err) > - goto err; > - return 0; > - } > + if (likely(!frags)) > + return __xsk_rcv_zc(xs, xskb, len, contd); [Severity: High] Now that the buffer stays with the driver, ixgbe's XDP_EXIT retry becomes the normal path whenever the XSK Rx ring is full. Does that retry start from a clean xdp_buff? drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c:ixgbe_clean_rx_irq_zc() { ... bi->xdp->data_end = bi->xdp->data + size; xsk_buff_dma_sync_for_cpu(bi->xdp); xdp_res = ixgbe_run_xdp_zc(adapter, rx_ring, bi->xdp); if (likely(xdp_res & (IXGBE_XDP_TX | IXGBE_XDP_REDIR))) { xdp_xmit |= xdp_res; } else if (xdp_res == IXGBE_XDP_EXIT) { failure = true; break; ... } On the next poll only data_end is recomputed. data and data_meta keep whatever the previous program run left in them. igb resets them with xsk_buff_set_size(). Suppose the program calls bpf_xdp_adjust_head() with a positive offset N before redirecting. data then moves forward by N on every retry, and data_end moves with it, so this check in bpf_xdp_adjust_head() keeps passing: if (unlikely(data < data_start || data > xdp->data_end - ETH_HLEN)) return -EINVAL; After a single retry, user space would get the packet shifted by N bytes, with N trailing bytes the hardware never wrote. If the Rx ring stays full for enough polls, can [data, data_end) move past the end of the UMEM chunk? The program could then read and write the neighbouring chunk. When the redirect finally succeeds, in aligned mode xp_get_handle() takes the descriptor address from xskb->xdp.data - pool->addrs. That address could then point into another chunk, so the same frame would be handed to user space twice. Would ixgbe need an xsk_buff_set_size() style reset before it runs XDP again, as igb does? The later patch in this series ("xdp: Do not free ZC buffer when a frame redirect fails") doesn't seem to touch ixgbe. [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204193929.1168874-1-maciej.fijalkowski%40intel.com