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
Subject: Re: [PATCH net v6 2/2] xdp: Do not free ZC buffer when a frame redirect fails
Date: Sat, 05 Dec 2026 19:42:44 +0000 [thread overview]
Message-ID: <179649976493.3148.10047606663691842433@kernel.org> (raw)
In-Reply-To: <20261204193929.1168874-3-maciej.fijalkowski@intel.com>
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
prev parent reply other threads:[~2026-12-05 19:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 19:39 [PATCH net v6 0/2] xsk, xdp: fix ZC buffer double free on failed redirect Maciej Fijalkowski
2026-12-04 19:39 ` [PATCH net v6 1/2] xsk: Do not free ZC Rx buffer when the Rx ring is full Maciej Fijalkowski
2026-12-05 19:42 ` netdev-bot+sashiko
2026-12-04 19:39 ` [PATCH net v6 2/2] xdp: Do not free ZC buffer when a frame redirect fails Maciej Fijalkowski
2026-12-05 19:42 ` netdev-bot+sashiko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179649976493.3148.10047606663691842433@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=hangbin.liu@linux.dev \
--cc=hawk@kernel.org \
--cc=hramamurthy@google.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=joshwash@google.com \
--cc=jtollet@cisco.com \
--cc=kerneljasonxing@gmail.com \
--cc=kuba@kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=marcin.knap@vecima.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=sgoutham@marvell.com \
--cc=song@kernel.org \
--cc=toke@redhat.com \
--cc=willemb@google.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox