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=1796499767; b=d/77OsUl+4YuFC8sObOeCYx5/62QHciphj3PmrioI72iRrn7P8zbUb0wQLRHBsfrg/Y9 Imnt0ov6i6EbxyXcTbUS2fA5dLeznMY5ErmPHwrEqJ0NNIgxfbZYtKqq8OHjWrfHtlHJe UGcyUxAeqbawg4tiCNm4LhbySV5GhvwzKcDDy1RI1gVXLgDdKJ+HyRpj9q/f7TaHbzSwS jJrAUDu+ancsKnGt+jO12aEbv/PvB1dYecPpghoTSb0M5KOZPml1+Vq+sWhV9IAPeUgb/ 719LJLsSjO4slga7teTPpWyBTfAlNdigEiR39DcsWrn1J3FPYzWAKLKE861yPSaGxNg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796499767; 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=LgZ+H34lopVEhT/vo4SXudVCuCaJSMjgFSUmPAgLb/8=; b=geytFKiSG+P6rOylvhrDiJ+kBhiCguOcCYG4aOjk60EleQOJOZUmb/6/UVoojgYz65iZ G7PQnvz9pXxr3pQvPKDBZc/fKV+Uen5iXOOpfpLamdr1oZfyVl2kGoMTVITSPOXteunLZ 3gmpI6gWcwRPpn2pH4gd1ONJSMtTWjI0SfNBtqj+F+lNJdEtf6iaTsSpLutGI7RrRiuLP 9/kSN0b28QJNUpHy35B03HMygExqQfDpzlHyZjnjr7DPpQ4+cLONZqsat1DWanc1JPov0 /7rOzGo+EKupGJnfIC+sU4fyYQ1Y/aokvszZhhOlvirM4uYBcrU/S7YRNop8vS9Obyg== 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=W8aEJjpg; 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 5D2A2606A330; Sat, 5 Dec 2026 19:42:47 +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=W8aEJjpg Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F3D51F0092B; Sat, 5 Dec 2026 19:42:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796499767; bh=LgZ+H34lopVEhT/vo4SXudVCuCaJSMjgFSUmPAgLb/8=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=W8aEJjpgLpqyPI7qhe36b4RXHJpI8IBhtD54ZEdR32dQYArFYMnGpmUVmb/47Ktmy YBXq/1OeFADtJe1/0/0qCzcaA676pkqAOrwG3a7wKxmwz1+Dqz/FUD6m8N70mi42EK L2De7YL/AgYU/ryXyHHbW47SpztnPJedHe0Tam+AQnUzY86SOP1D2lZm8Ll53Hd6nT PHwgcD2xIQnX1uKd7drO42fWU5FcH5t9SGs0anxa2xE1+i/flisCyZUbAsrYYE2t1B FyZN56lWk5Rm1BZChadrYSTJIYq06c57Y3BZNwjVPSqwVln9XlEOJ1sFZmhclR3ZYU lt047jo0SMCdw== Subject: Re: [PATCH net v6 2/2] xdp: Do not free ZC buffer when a frame redirect fails 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:44 +0000 Message-ID: <179649976493.3148.10047606663691842433@kernel.org> In-Reply-To: <20261204193929.1168874-3-maciej.fijalkowski@intel.com> References: <20261204193929.1168874-3-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 1 potential issue(s) to consider. Critical: 0 · High: 1 · Medium: 0 · Low: 0 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] On the zero-copy XDP_TX paths of i40e, ixgbe and icssg, the bug this patch fixes for xdp_do_redirect() is still there: a copied frame… -- xdp: Do not free ZC buffer when a frame redirect fails This patch adds __xdp_convert_zc_to_xdp_frame(), which takes a release flag. xdp_do_redirect() now uses it so that the zero-copy buffer is freed only after the copied frame has been redirected. If the redirect fails, the copy is returned with xdp_return_frame() and the XSk buffer is left to the driver. xdp_convert_zc_to_xdp_frame() still frees on success, for the zero-copy XDP_TX users. > diff --git a/net/core/xdp.c b/net/core/xdp.c > index 1d679e8fd6493..0466b1d62231e 100644 > --- a/net/core/xdp.c > +++ b/net/core/xdp.c [ ... ] > @@ -607,9 +608,23 @@ struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp) > xdpf->frame_sz = PAGE_SIZE; > xdpf->mem_type = MEM_TYPE_PAGE_ORDER0; > > - xsk_buff_free(xdp); > + if (release) > + xsk_buff_free(xdp); > + > return xdpf; > } > + > +/** > + * xdp_convert_zc_to_xdp_frame - copy an XSk buffer into a new &xdp_frame > + * @xdp: XSk buffer to copy, freed if the copy succeeds > + * > + * Return: new %MEM_TYPE_PAGE_ORDER0 frame, or %NULL if the data does not > + * fit into a page or the allocation fails. > + */ > +struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp) > +{ > + return __xdp_convert_zc_to_xdp_frame(xdp, true); > +} [Severity: High] The commit message says free-on-success is kept "for the zero-copy XDP_TX paths that rely on it, such as those of i40e, mlx5e and stmmac". The zero-copy XDP_TX paths in i40e, ixgbe and icssg seem to have the same leak of the copied page, and the same second xsk_buff_free(), that this patch fixes for xdp_do_redirect(). Is that right? In i40e the conversion frees the XSk buffer right away: drivers/net/ethernet/intel/i40e/i40e_txrx.c:i40e_xmit_xdp_tx_ring() { struct xdp_frame *xdpf = xdp_convert_buff_to_frame(xdp); if (unlikely(!xdpf)) return I40E_XDP_CONSUMED; return i40e_xmit_xdp_ring(xdpf, xdp_ring); } i40e_xmit_xdp_ring() can then fail without freeing or storing xdpf. One case is a full ring, and the DMA mapping error path is another: if (unlikely(I40E_DESC_UNUSED(xdp_ring) < 1 + nr_frags)) { xdp_ring->tx_stats.tx_busy++; return I40E_XDP_CONSUMED; } i40e_run_xdp_zc() passes the CONSUMED result to out_failure. Then i40e_handle_xdp_result_zc() frees the XSk buffer a second time: if (xdp_res == I40E_XDP_CONSUMED) { xsk_buff_free(xdp_buff); return; } Would this leak the dev_alloc_page() page from __xdp_convert_zc_to_xdp_frame() for every XDP_TX packet that is dropped this way? A full XDP Tx ring is a normal runtime condition, and remote senders can cause it. ixgbe looks the same. In ixgbe_run_xdp_zc()->ixgbe_xmit_xdp_ring(), a full ring or a DMA map error returns IXGBE_XDP_CONSUMED without freeing xdpf. ixgbe_clean_rx_irq_zc() then calls xsk_buff_free(bi->xdp) again. icssg looks the same too. In emac_run_xdp()->emac_xmit_xdp_frame(), a failure to allocate a descriptor, map the buffer or push it returns ICSSG_XDP_CONSUMED. prueth_xmit_free() does not free xdpf, and emac_rx_packet_zc() then calls xsk_buff_free(xdp) again. The second free is harmless only because xp_free() ignores a buffer that is already on the free list. The commit message makes the same argument for the redirect case. mlx5e_xmit_xdp_buff() and stmmac_xdp_xmit_back() call xdp_return_frame(xdpf) on failure and skip the second XSk free. So this looks specific to these three drivers. There seem to be two ways to fix these XDP_TX paths: - convert with __xdp_convert_zc_to_xdp_frame(xdp, false) and free the XSk buffer only after a successful transmit, as xdp_do_redirect() now does - call xdp_return_frame(xdpf) when the transmit fails and skip the caller's xsk_buff_free() Should one of these be applied? Also, should the commit message and the new kernel-doc stop presenting i40e as a correct user of the free-on-success contract? > EXPORT_SYMBOL_GPL(xdp_convert_zc_to_xdp_frame); > > /* Used by XDP_WARN macro, to avoid inlining WARN() in fast-path */ -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204193929.1168874-1-maciej.fijalkowski%40intel.com