Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] ice: xsk: missing descriptor count check in ice_xsk_bufs_fit()
  and USO parse
- [High] ice: xsk: XDP ring mismatch in ice_tx_xsk_pool() frees active
  USO DMA slots
--

commit fb6d44af668d56b22c97560cb76b6bdaca838144
Author: Magnus Karlsson <[email protected]>

xsk: ice: add USO zero-copy support

This commit adds UDP Segmentation Offload (USO) support for AF_XDP
zero-copy transmission and implements it in the ice driver using per-ring
DMA-mapped header slots.

> diff --git a/drivers/net/ethernet/intel/ice/ice.h 
> b/drivers/net/ethernet/intel/ice/ice.h
> index 432da05c48c08..e19929b37e110 100644
> --- a/drivers/net/ethernet/intel/ice/ice.h
> +++ b/drivers/net/ethernet/intel/ice/ice.h
> @@ -833,16 +833,24 @@ static inline void ice_rx_xsk_pool(struct ice_rx_ring 
> *ring)
>   * carries a pointer to one of these XDP rings for its own purposes, such as
>   * handling XDP_TX action, therefore we can piggyback here on the
>   * rx_ring->xdp_ring assignment that was done during XDP rings 
> initialization.
> + * The ring must be stopped, as its USO header slots are matched to the pool.
> + * If they cannot be allocated, the ring keeps the pool without USO.
>   */
>  static inline void ice_tx_xsk_pool(struct ice_vsi *vsi, u16 qid)
>  {
> +     struct xsk_buff_pool *pool;
>       struct ice_tx_ring *ring;
>  
>       ring = vsi->rx_rings[qid]->xdp_ring;
>       if (!ring)
>               return;
>  
> -     WRITE_ONCE(ring->xsk_pool, ice_get_xp_from_qid(vsi, qid));
> +     pool = ice_get_xp_from_qid(vsi, qid);
> +     if (ice_xsk_cfg_uso_slots(ring, pool))
> +             netdev_warn(vsi->netdev,
> +                         "Failed to allocate USO header buffers, USO 
> requests on queue %u are ignored\n",
> +                         qid);
> +     WRITE_ONCE(ring->xsk_pool, pool);
>  }

[Severity: High]
Can ice_tx_xsk_pool() free ring->xsk_uso_pages while the ring is still
active and holds in-flight ICE_TX_BUF_XSK_USO descriptors?

When a queue vector has more than one XDP ring (vsi->num_q_vectors <
vsi->num_xdp_txq, for example after reducing queues with ethtool -L),
ice_map_xdp_rings() prepends multiple XDP rings to q_vector->tx, so
vsi->rx_rings[qid]->xdp_ring is not vsi->xdp_rings[qid].  On pool teardown,
ice_xsk_pool_setup() calls ice_qp_dis() and ice_qp_ena(), but ice_qp_dis()
and ice_qp_clean_rings() stop and clean vsi->xdp_rings[qid]:

drivers/net/ethernet/intel/ice/ice_base.c:ice_qp_clean_rings() {
        ice_clean_tx_ring(vsi->tx_rings[q_idx]);
        if (vsi->xdp_rings)
                ice_clean_tx_ring(vsi->xdp_rings[q_idx]);
        ice_clean_rx_ring(vsi->rx_rings[q_idx]);
}

ice_qp_ena() then calls ice_tx_xsk_pool() -> ice_xsk_cfg_uso_slots(ring,
NULL) -> ice_xsk_free_uso_slots() on the unstopped
vsi->rx_rings[qid]->xdp_ring.  This frees the noncoherent DMA pages while
hardware is still transmitting from them, and zeroes
ring->xsk_uso_slots_per_page and ring->xsk_uso_pages so the next
ice_clean_xsk_buf() -> ice_xsk_uso_slot() divides by zero and dereferences
NULL.

Also, when a pool is disabled while the VSI is down, ice_xsk_pool_setup()
skips ice_qp_ena(), and ice_xsk_pool_disable() does not free the USO slots
that ice_xsk_pool_enable() allocated on vsi->rx_rings[qid]->xdp_ring.

> diff --git a/drivers/net/ethernet/intel/ice/ice_xsk.c 
> b/drivers/net/ethernet/intel/ice/ice_xsk.c
> index 0c1ce3e86a45b..7fa1127480b66 100644
> --- a/drivers/net/ethernet/intel/ice/ice_xsk.c
> +++ b/drivers/net/ethernet/intel/ice/ice_xsk.c
[ ... ]
> +/* A buffer longer than one data descriptor is split, so a packet without USO
> + * can then need more data descriptors than the hardware allows.
> + */
> +static bool ice_xsk_bufs_fit(const struct xsk_buff_pool *pool,
> +                          const struct xdp_desc *descs, u32 nr)
> +{
> +     u32 buffers = 0, i;
> +
> +     if (likely(pool->chunk_size <= ICE_MAX_DATA_PER_TXD_ALIGNED))
> +             return true;
> +     for (i = 0; i < nr; i++)
> +             buffers += DIV_ROUND_UP(descs[i].len,
> +                                     ICE_MAX_DATA_PER_TXD_ALIGNED);
> +     return buffers <= ICE_MAX_BUF_TXD;
> +}

[Severity: High]
Can a multi-descriptor packet on the shared-UMEM fallback path bypass the
ICE_MAX_BUF_TXD limit here?

When multiple sockets share a UMEM without XDP_UMEM_SG_FLAG,
xsk_tx_peek_release_desc_batch() falls back to
xsk_tx_peek_release_fallback(), which peeks descriptors through
xsk_tx_peek_desc() without enforcing pool->xdp_zc_max_segs on
XDP_PKT_CONTD chains.  ice_xmit_zc_metadata() gathers up to count
descriptors into one packet of nr descriptors.  When pool->chunk_size <=
ICE_MAX_DATA_PER_TXD_ALIGNED, ice_xsk_bufs_fit() returns true without
checking nr <= ICE_MAX_BUF_TXD, so ice_xsk_xmit_descs() emits more than 8
data descriptors for a single non-USO packet and triggers a hardware MDD
event on the Tx queue.

For USO packets on the same fallback path, neither xsk_tx_uso_parse() nor
ice_xsk_uso_fits() checks nr <= pool->xdp_zc_max_segs (ice_xsk_uso_fits()
resets buffers = 1 at each segment boundary), allowing a USO packet to
exceed xdp-zc-max-segs descriptors.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=3

Reply via email to