On Thu, Nov 12, 2026 at 01:45:56PM -0500, Vincent Choiniere wrote:

...

> @@ -424,6 +429,78 @@ void ice_prep_tx_hang_report(struct ice_pf *pf, struct 
> ice_tx_ring *tx_ring,
>       buf->vsi_num = vsi_num;
>       buf->head = head;
>       buf->intr = intr;
> +     buf->queue = tx_ring->q_index;
> +     buf->next_to_clean = tx_ring->next_to_clean;
> +     buf->next_to_use = tx_ring->next_to_use;
> +}
> +
> +/**
> + * ice_tx_hang_snapshot - copy the timed-out queue's ring at report time
> + * @pf: PF on which the Tx hang was detected
> + * @tx_ring: ring saved by ice_tx_timeout(), possibly stale
> + * @ev: event to fill in
> + *
> + * The saved ring may have been freed or replaced since the timeout (e.g. by
> + * ethtool -G or -L), and a freed ring may be reused for another queue. Use 
> it
> + * only if the timeout was on the PF VSI, that VSI is up and the timed-out
> + * queue still maps to it. Those paths, and the reset paths, replace or free
> + * the rings under RTNL or from the service task itself, so with RTNL held 
> the
> + * accesses below are to live memory for them. The ring may still have been
> + * reset in place since the timeout (e.g. by ethtool -G or an MTU change); as
> + * before, its state is read when the report is generated. Driver removal and
> + * devlink reload tear the VSIs down before the service task is stopped and 
> are
> + * not covered here. ice_clean_tx_irq() may still run and free the skb at
> + * next_to_clean at any time, so only the pointer value is recorded and the 
> skb
> + * itself is never dereferenced.
> + */
> +static void ice_tx_hang_snapshot(struct ice_pf *pf, struct ice_tx_ring 
> *tx_ring,
> +                              struct ice_tx_hang_event *ev)
> +{
> +     struct ice_vsi *vsi = ice_get_main_vsi(pf);
> +     struct ice_q_vector *q_vector;
> +     struct ice_tx_buf *tx_buf;
> +     u16 ntc, ntu;
> +     void *desc;
> +     u32 size;
> +
> +     ASSERT_RTNL();
> +
> +     if (!tx_ring || !vsi || !vsi->tx_rings ||
> +         test_bit(ICE_VSI_DOWN, vsi->state))
> +             return;
> +
> +     if (ev->vsi_num != vsi->vsi_num || ev->queue >= vsi->num_txq ||
> +         vsi->tx_rings[ev->queue] != tx_ring)
> +             return;
> +
> +     q_vector = tx_ring->q_vector;
> +     if (!q_vector || !tx_ring->desc || !tx_ring->tx_buf || !tx_ring->count)
> +             return;
> +
> +     size = tx_ring->count * sizeof(struct ice_tx_desc);
> +     desc = kvmalloc(size, GFP_KERNEL);
> +     if (!desc)
> +             return;
> +
> +     ntc = READ_ONCE(tx_ring->next_to_clean);
> +     ntu = READ_ONCE(tx_ring->next_to_use);
> +
> +     if (ntc < tx_ring->count) {

Sorry to nit-pick, but I wonder if it would be nicer to move the kvmalloc()
call and associated error checking be moved here...

> +             tx_buf = &tx_ring->tx_buf[ntc];
> +             if (tx_buf->type == ICE_TX_BUF_SKB)
> +                     ev->skb_ptr = READ_ONCE(tx_buf->skb);
> +
> +             memcpy(desc, tx_ring->desc, size);
> +             ev->next_to_clean = ntc;
> +             ev->next_to_use = ntu;
> +             strscpy(ev->irq_name, q_vector->name);
> +             ev->desc_ptr = tx_ring->desc;
> +             ev->dma = tx_ring->dma;
> +             ev->desc_size = size;
> +             ev->desc = desc;
> +     } else {
> +             kvfree(desc);

... and remove the else arm of the condition.

> +     }
>  }

And further, the sense of the condition could be reversed, saving some
indentation:

        if (ntc >= tx_ring->count)
                return

        desc = kvmalloc(size, GFP_KERNEL);
        if (!desc)
                return;

        tx_buf = &tx_ring->tx_buf[ntc];
        if (tx_buf->type == ICE_TX_BUF_SKB)
                ev->skb_ptr = READ_ONCE(tx_buf->skb);

        memcpy(desc, tx_ring->desc, size);
        ev->next_to_clean = ntc;
        ev->next_to_use = ntu;
        strscpy(ev->irq_name, q_vector->name);
        ev->desc_ptr = tx_ring->desc;
        ev->dma = tx_ring->dma;
        ev->desc_size = size;
        ev->desc = desc;

Regardless, this looks good to me.

Reviewed-by: Simon Horman <[email protected]>

Reply via email to