From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: Magnus Karlsson <magnus.karlsson@gmail.com>
Cc: Magnus Karlsson <magnus.karlsson@intel.com>,
<netdev@vger.kernel.org>, <sdf@fomichev.me>,
<davem@davemloft.net>, <edumazet@kernel.org>, <kuba@kernel.org>,
<pabeni@redhat.com>, <horms@kernel.org>, <bjorn@kernel.org>,
<kerneljasonxing@gmail.com>, <intel-wired-lan@lists.osuosl.org>,
<anthony.l.nguyen@intel.com>, <przemyslaw.kitszel@intel.com>,
<jacob.e.keller@intel.com>
Subject: Re: [PATCH net-next 3/5] xsk: ice: add USO zero-copy support
Date: Mon, 23 Nov 2026 10:04:01 +0100 [thread overview]
Message-ID: <awQBgefjtxMdZYWg@boxer> (raw)
In-Reply-To: <CAJ8uoz2tKthHN6MHUJoixtjzkGqJR0ukdJCWRG0_2_J11PN_uw@mail.gmail.com>
On Mon, Nov 23, 2026 at 09:40:37AM +0100, Magnus Karlsson wrote:
> On Fri, 20 Nov 2026 at 15:22, Maciej Fijalkowski
> <maciej.fijalkowski@intel.com> wrote:
> >
> > On Thu, Nov 19, 2026 at 05:53:38PM +0100, Magnus Karlsson wrote:
> > > Add UDP Segmentation Offload (USO) for AF_XDP zero-copy and implement
> > > it in the ice driver. Drivers advertise support with tmo_supports_uso,
> > > which is reported to user space as the tx-uso-zc netdev XSK feature.
> > >
> > > The core exports xsk_tx_uso_parse() and xsk_tx_uso_prepare_headers() for
> > > drivers, which snapshot, validate and prepare the packet header, and
> > > xsk_tx_invalid_descs() for accounting dropped requests. Drivers without
> > > tmo_supports_uso keep handling a USO request as invalid metadata, so
> > > xsk_tx_metadata_request() ignores the packet's metadata. As in copy
> > > mode, requests that produce more than one datagram also need
> > > NETIF_F_GSO_UDP_L4 on the device.
> > >
> > > Packet headers are copied into kernel-owned memory before they are
> > > validated and handed to the NIC, so that user space cannot change them
> > > afterwards. ice keeps a DMA-mapped header slot for every two
> > > descriptors of the XDP Tx ring, as a USO packet takes at least a
> > > context and a header descriptor. The slots hold only header bytes and
> > > are allocated page by page to avoid a large contiguous
> > > allocation. They belong to the ring: they are allocated when a pool
> > > that can carry USO requests is assigned to the ring, and freed with
> > > the ring. They therefore follow XDP attach and detach, ring rebuilds
> > > and netdev unregistration rather than the pool. Only the copied header
> > > bytes are synced for the device. With fewer XDP rings than CPUs,
> > > queues share XDP rings and would share their slots, so no slots are
> > > allocated and USO requests are ignored for now, though support for
> > > this could be added as a separate patch set in the future. tx-uso-zc
> > > is still reported in this case, as documented. The slots are only
> > > set up when an XDP program is attached. If they cannot be allocated
> > > when a ring is reconfigured, the ring keeps its pool without USO and a
> > > warning is logged, while a bind fails.
> > >
> > > When the slots exist, ice_xmit_zc() processes descriptors one packet
> > > at a time. A USO packet gets a context and a header descriptor, then
> > > shares the data-descriptor loop with ordinary packets. The Tx budget
> > > reserves worst-case descriptors per packet. The per-packet path is used
> > > for every pool with a Tx metadata area that can carry USO requests,
> > > whether or not it sends them. Other pools keep the existing batched
> > > fast path. Both paths share the budget, tail, stats and wakeup
> > > handling. If the Tx ring cannot hold a maximum-size packet in this
> > > worst case, such a packet could never be peeked and Tx would stall, so
> > > no header slots are allocated, USO requests are ignored and a warning
> > > is logged. The pool flag is not cleared, as the pool may still fall
> > > back to copy mode. This is only possible when PAGE_SIZE is 64K and the
> > > Tx ring is set to its minimum size.
> > >
> > > Packets that exceed the hardware limits are dropped and counted in
> > > tx_invalid_descs through the new xsk_tx_invalid_descs() helper. Their
> > > completions are deferred behind in-flight descriptors to keep the
> > > completion ring in order. Packets without USO are dropped as well if
> > > they would exceed the eight buffers, which is possible when chunks
> > > larger than a data descriptor are split. A batch from the shared-umem
> > > fallback can end inside a packet. That packet is dropped, and so is
> > > its remainder in the next batch.
> > >
> > > On completion, a buffer of the existing fast path still stands for one
> > > completion, so that path writes nothing to tx_buf[] and struct
> > > ice_tx_buf keeps its size. Buffers of the USO path carry an explicit
> > > completion count in a union with fields that zero-copy rings do not use.
> > > USO header slots, deferred drops and buffers split into several
> > > descriptors are tracked with a per-ring counter, so ordinary traffic
> > > keeps the fast cleanup path. The header slot of a context descriptor is
> > > found from its position in the ring.
> > >
> > > The descriptors are built with the descriptor builders that the
> > > previous patch added for ice_tso().
> > >
> > > Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
> > > +/* Returns the number of packets queued on the ring. */
> > > +static u32 ice_xmit_zc_metadata(struct ice_tx_ring *ring, struct xsk_buff_pool *pool,
> > > + u32 count, unsigned int *total_bytes)
> > > +{
> > > + struct xdp_desc *descs = pool->tx_descs;
> > > + u32 i = 0, packets = 0;
> > > +
> > > + /* Drop the rest of a packet whose start was dropped in an earlier batch. */
> > > + if (unlikely(ring->xsk_drain)) {
> > > + while (i < count && ring->xsk_drain)
> > > + ring->xsk_drain = !xsk_is_eop_desc(&descs[i++]);
> > > + ice_xsk_drop_packet(ring, pool, i);
> > > + }
> > > +
> > > + while (i < count) {
> > > + u32 cmd = 0, offset = 0, skip = 0, slot_offset;
> > > + u32 len = descs[i].len, nr = 1;
> > > + struct ice_xsk_uso_page *page;
> > > + struct xsk_tx_uso_info info;
> > > + int uso;
> > > +
> > > + while (!xsk_is_eop_desc(&descs[i + nr - 1]) && i + nr < count)
> > > + len += descs[i + nr++].len;
> > > + /* The shared-umem fallback can end a batch inside a packet. */
> >
> > No, it can not... or at least the intent was not to. the shared umem
> > fallback has been written in a way that it also calls
> > xskq_cons_read_desc_batch() which is supposed *not* to expose incomplete
> > multi-buffer packet.
> >
> > Is that a special case where you don't set XDP_USE_SG but packets are not
> > linear due to USO, or what?
> >
> > I wouldn't like to propagate the draining disease down to drivers. We've
> > put enough of convoluted code onto layer above, let us address it there if
> > there's something missing?
>
> You are right. This should not be here in the driver. I will fix it in
> the core instead.
>
> At some point we really need to simplify the skb multi-buffer path.
> Always gives me a headache.
skb mbuf is not a victim here :P regardless I agree on rewrite.
>
> > I'm gonna cut the review here and keep the comments I had so far.
> >
> > > + if (unlikely(!xsk_is_eop_desc(&descs[i + nr - 1]))) {
> > > + ice_xsk_drop_packet(ring, pool, nr);
> > > + ring->xsk_drain = true;
> > > + break;
> > > + }
> > > + page = ice_xsk_uso_slot(ring, ring->next_to_use, &slot_offset);
> > > + uso = xsk_tx_uso_parse(pool, &descs[i], nr, &info,
> > > + page->addr + slot_offset + NET_IP_ALIGN);
> > > + if (uso < 0 || (!uso && !ice_xsk_bufs_fit(pool, &descs[i], nr)) ||
> > > + (uso && ice_xsk_xmit_uso_hdr(ring, &descs[i], nr, &info,
> > > + &cmd, &offset))) {
> > > + ice_xsk_drop_packet(ring, pool, nr);
> > > + i += nr;
> > > + continue;
> > > + }
> > > + if (uso) {
> > > + skip = info.header_len;
> > > + *total_bytes += (info.gso_segs - 1) * skip;
> > > + packets += info.gso_segs - 1;
> > > + }
> > > + ice_xsk_xmit_descs(ring, pool, &descs[i], nr, skip, cmd, offset);
> > > + *total_bytes += len;
> > > + packets++;
> > > + i += nr;
> > > + }
> > > + return packets;
> > > +}
> > > +
> > > +/**
> > > + * ice_xsk_setup_metadata - register AF_XDP Tx metadata operations
> > > + * @netdev: net_device
> > > + */
> > > +void ice_xsk_setup_metadata(struct net_device *netdev)
> > > +{
> > > + static const struct xsk_tx_metadata_ops ops = {
> > > + .tmo_supports_uso = true,
> > > + };
> > > +
> > > + netdev->xsk_tx_metadata_ops = &ops;
> > > +}
> > > +
> > > /**
> > > * ice_xmit_zc - take entries from XSK Tx ring and place them onto HW Tx ring
> > > * @xdp_ring: XDP ring to produce the HW Tx descriptors on
> > > @@ -801,9 +1222,9 @@ static void ice_fill_tx_hw_ring(struct ice_tx_ring *xdp_ring,
> > > bool ice_xmit_zc(struct ice_tx_ring *xdp_ring, struct xsk_buff_pool *xsk_pool)
> > > {
> > > struct xdp_desc *descs = xsk_pool->tx_descs;
> > > - u32 nb_pkts, nb_processed = 0;
> > > + u32 nb_pkts, nb_processed = 0, packets;
> > > unsigned int total_bytes = 0;
> > > - int budget;
> > > + u32 budget, cost = 1;
> > >
> > > ice_clean_xdp_irq_zc(xdp_ring, xsk_pool);
> > >
> > > @@ -811,26 +1232,38 @@ bool ice_xmit_zc(struct ice_tx_ring *xdp_ring, struct xsk_buff_pool *xsk_pool)
> > > !netif_running(xdp_ring->vsi->netdev))
> > > return true;
> > >
> > > - budget = ICE_DESC_UNUSED(xdp_ring);
> > > - budget = min_t(u16, budget, ICE_RING_QUARTER(xdp_ring));
> > > + /* Reserve worst-case descriptors for each potential USO packet. */
> > > + if (xdp_ring->xsk_uso_pages)
> > > + cost = ice_xsk_uso_desc_cost(xsk_pool);
> > > + budget = min_t(u32, ICE_DESC_UNUSED(xdp_ring) / cost,
> > > + ICE_RING_QUARTER(xdp_ring));
> > >
> > > nb_pkts = xsk_tx_peek_release_desc_batch(xsk_pool, budget);
> > > if (!nb_pkts)
> > > return true;
> > >
> > > - if (xdp_ring->next_to_use + nb_pkts >= xdp_ring->count) {
> > > - nb_processed = xdp_ring->count - xdp_ring->next_to_use;
> > > - ice_fill_tx_hw_ring(xdp_ring, xsk_pool, descs, nb_processed,
> > > - &total_bytes);
> > > - xdp_ring->next_to_use = 0;
> > > - }
> > > + if (xdp_ring->xsk_uso_pages) {
> > > + packets = ice_xmit_zc_metadata(xdp_ring, xsk_pool, nb_pkts,
> >
> > nit: could we stick to 'pkts'
> >
> > > + &total_bytes);
> > > + } else {
> > > + if (xdp_ring->next_to_use + nb_pkts >= xdp_ring->count) {
> > > + nb_processed = xdp_ring->count - xdp_ring->next_to_use;
> > > + ice_fill_tx_hw_ring(xdp_ring, xsk_pool, descs, nb_processed,
> > > + &total_bytes);
> > > + xdp_ring->next_to_use = 0;
> > > + }
> > >
> > > - ice_fill_tx_hw_ring(xdp_ring, xsk_pool, &descs[nb_processed],
> > > - nb_pkts - nb_processed, &total_bytes);
> > > + ice_fill_tx_hw_ring(xdp_ring, xsk_pool, &descs[nb_processed],
> > > + nb_pkts - nb_processed, &total_bytes);
> > > + packets = nb_pkts;
> > > + }
> > >
> > > - ice_set_rs_bit(xdp_ring);
> > > - ice_xdp_ring_update_tail(xdp_ring);
> > > - ice_update_tx_ring_stats(xdp_ring, nb_pkts, total_bytes);
> > > + /* Metadata packets may all have been dropped. */
> > > + if (packets) {
> > > + ice_set_rs_bit(xdp_ring);
> > > + ice_xdp_ring_update_tail(xdp_ring);
> > > + ice_update_tx_ring_stats(xdp_ring, packets, total_bytes);
> > > + }
> > >
> > > if (xsk_uses_need_wakeup(xsk_pool))
> > > xsk_set_tx_need_wakeup(xsk_pool);
> > > @@ -939,12 +1372,7 @@ void ice_xsk_clean_xdp_ring(struct ice_tx_ring *xdp_ring)
> > > while (ntc != ntu) {
> > > struct ice_tx_buf *tx_buf = &xdp_ring->tx_buf[ntc];
> > >
> > > - if (tx_buf->type == ICE_TX_BUF_XSK_TX) {
> > > - tx_buf->type = ICE_TX_BUF_EMPTY;
> > > - xsk_buff_free(tx_buf->xdp);
> > > - } else {
> > > - xsk_frames++;
> > > - }
> > > + xsk_frames += ice_clean_xsk_buf(xdp_ring, tx_buf);
> > >
> > > ntc++;
> > > if (ntc >= xdp_ring->count)
> >
> > I think we could pull out core enablement for zc uso out of this patch
> > maybe?
>
> What do you mean with "core" here? Core as in AF_XDP core, or
> preparatory stuff to the ice driver?
I meant xsk core as preceding patch and ice changes here would only play
in its own mud + make use of introduced api before. This would reduce size
of this patch.
next prev parent reply other threads:[~2026-11-23 9:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 16:53 [PATCH net-next 0/5] xsk: ice: USO support for AF_XDP Magnus Karlsson
2026-11-19 16:53 ` [PATCH net-next 1/5] xsk: add USO support for skb path Magnus Karlsson
2026-11-19 18:47 ` Maciej Fijalkowski
2026-11-20 8:55 ` Magnus Karlsson
2026-11-20 11:43 ` Maciej Fijalkowski
2026-11-20 17:22 ` Stanislav Fomichev
2026-11-23 8:52 ` Magnus Karlsson
2026-11-19 16:53 ` [PATCH net-next 2/5] ice: add Tx descriptor builders and header length check Magnus Karlsson
2026-11-20 11:59 ` Maciej Fijalkowski
2026-11-19 16:53 ` [PATCH net-next 3/5] xsk: ice: add USO zero-copy support Magnus Karlsson
2026-11-20 14:22 ` Maciej Fijalkowski
2026-11-23 8:40 ` Magnus Karlsson
2026-11-23 9:04 ` Maciej Fijalkowski [this message]
2026-11-19 16:53 ` [PATCH net-next 4/5] xsk: add KUnit tests for AF_XDP USO header helpers Magnus Karlsson
2026-11-19 16:53 ` [PATCH net-next 5/5] selftests: net: add AF_XDP USO test Magnus Karlsson
2026-11-19 19:05 ` Maciej Fijalkowski
2026-11-20 8:35 ` Magnus Karlsson
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=awQBgefjtxMdZYWg@boxer \
--to=maciej.fijalkowski@intel.com \
--cc=anthony.l.nguyen@intel.com \
--cc=bjorn@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=jacob.e.keller@intel.com \
--cc=kerneljasonxing@gmail.com \
--cc=kuba@kernel.org \
--cc=magnus.karlsson@gmail.com \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=sdf@fomichev.me \
/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