Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] virtio_net: race between virtnet_rx_watchdog() and RX queue
  pause/reset
--

commit fd9c9353e0dbe0759e73fd91a8963232b76ecc1c
Author: Longjun Tang <[email protected]>

virtio_net: add stalls per-queue statistic

This commit adds a per-queue RX stalls statistic to virtio_net and exposes
it via ethtool when NAPI poll recovers a stalled RX queue.

> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 7f21fe4f96a2b..0b95fa10734d2 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c

[ ... ]

> @@ -3005,6 +3007,12 @@ static int virtnet_receive(struct receive_queue *rq, 
> int budget,
>               u64_stats_add(item, u64_stats_read(src));
>       }
>  
> +     /* Count a stall recovered by this poll. */
> +     if (rq->watchdog.stalled) {
> +             u64_stats_inc(&rq->stats.stalls);
> +             rq->watchdog.stalled = false;
> +     }

[Severity: Medium]
Can virtnet_rx_watchdog() race with an RX queue resize or reset while the
interface is up, causing a use-after-free on the vring and false
rq->stats.stalls increments?

Commit "virtio_net: introduce an RX queue watchdog for stuck detection"
starts vi->rx_watchdog in virtnet_open() and only stops it in
virtnet_close().  When virtnet_rx_resize() or virtnet_rq_bind_xsk_pool()
pauses an active RX queue via virtnet_rx_pause(), it disables NAPI and DIM
but does not stop or synchronize with vi->rx_watchdog:

CPU0                                  CPU1 (<softirq>)
virtnet_rx_resize()
  virtnet_rx_pause(vi, rq)
  virtqueue_resize(rq->vq, ...)
                                      virtnet_rx_watchdog()
                                        last_used =
                                          virtqueue_get_last_used_idx(...)
    vring_free(&vq->vq)
                                        virtqueue_poll(rq->vq, last_used)
                                          <-- use-after-free

In addition, virtqueue_resize() and virtqueue_reset() reset
vq->last_used_idx, but neither path calls
virtnet_rx_watchdog_init_queue(rq).  Any stale rq->watchdog.last_used or
rq->watchdog.stalled state persists across the reset and causes
virtnet_receive() to falsely increment rq->stats.stalls after the queue is
resumed.

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

Reply via email to