From: sashiko-bot@kernel.org
To: "Longjun Tang" <lange_tang@163.com>
Cc: virtualization@lists.linux.dev,
"Michael S. Tsirkin" <mst@redhat.com>,
"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH v2 2/3] virtio_net: introduce an RX queue watchdog for stuck detection
Date: Sat, 21 Nov 2026 07:18:58 +0000 [thread overview]
Message-ID: <sashiko-outbox-226757@kernel.org> (raw)
In-Reply-To: <20261120071826.198604-3-lange_tang@163.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] virtio_net: virtnet_rx_watchdog() races with
virtqueue_resize() and reset
- [Low] virtio_net: unsynchronized watchdog init in virtnet_set_queues()
--
commit 093ca3617532e988a9fe20901b18a2e6a86aca17
Author: Longjun Tang <tanglongjun@kylinos.cn>
virtio_net: introduce an RX queue watchdog for stuck detection
This commit adds a per-device 1 Hz watchdog timer that checks active RX
queues for 5-second consumption stalls and reschedules NAPI when a queue
is stuck with a non-zero backlog.
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 1cd64f9e12e74..7f21fe4f96a2b 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
[ ... ]
> @@ -3090,6 +3106,74 @@ static int virtnet_poll(struct napi_struct *napi, int budget)
> return received;
> }
>
> +/*
> + * An RX queue is stalled if it has a backlog but makes no progress and
> + * gets no new interrupt for VIRTNET_RX_WATCHDOG_TIMEO seconds, usually
> + * because an interrupt was lost. Mark it stalled and reschedule NAPI to
> + * drain the ring and refill the buffers.
> + */
> +static void virtnet_rx_watchdog(struct timer_list *t)
> +{
> + struct virtnet_info *vi = timer_container_of(vi, t, rx_watchdog);
> + unsigned long timeout = VIRTNET_RX_WATCHDOG_TIMEO * HZ;
> + int i;
> +
> + for (i = 0; i < vi->curr_queue_pairs; i++) {
> + struct receive_queue *rq = &vi->rq[i];
> + u16 last_used = virtqueue_get_last_used_idx(rq->vq);
> + u16 calls = rq->calls;
> + bool backlog = virtqueue_poll(rq->vq, last_used);
[Severity: Medium]
Can virtnet_rx_watchdog() race with virtqueue_resize() or
virtqueue_reset() and read freed vring memory?
When an RX ring is resized via virtnet_rx_resize() (or reset for AF_XDP in
virtnet_rq_bind_xsk_pool()) while the interface is up, virtnet_rx_pause()
disables NAPI and cancels DIM, but vi->rx_watchdog keeps firing:
drivers/net/virtio_net.c:virtnet_rx_pause() {
bool running = netif_running(vi->dev);
if (running) {
virtnet_napi_disable(rq);
virtnet_cancel_dim(vi, &rq->dim);
}
}
Inside virtqueue_resize_split() and virtqueue_resize_packed(),
vring_free() frees the old vring before virtqueue_vring_attach_split() or
virtqueue_vring_attach_packed() installs the new ring pointers:
CPU0 CPU1 (<softirq>)
virtnet_rx_resize()
virtnet_rx_pause(vi, rq)
virtqueue_resize(rq->vq, ...)
vring_free(&vq->vq)
virtnet_rx_watchdog()
last_used =
virtqueue_get_last_used_idx(...)
virtqueue_poll(rq->vq, last_used)
<-- use-after-free
virtqueue_init(vq, ...)
virtqueue_vring_attach_split(...)
On packed virtqueues, if virtnet_rx_resize() shrinks the ring and
virtnet_rx_watchdog() reads last_used from the old ring right before
virtqueue_init() resets vq->last_used_idx and attaches the smaller
descriptor array, virtqueue_poll_packed() also indexes
vq->packed.vring.desc[used_idx] out of bounds.
In addition, both virtqueue_resize() and virtqueue_reset() reset
vq->last_used_idx in virtqueue_init(), but virtnet_rx_resume() does not
call virtnet_rx_watchdog_init_queue(rq) to resynchronize rq->watchdog.
[ ... ]
> @@ -3839,7 +3926,14 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
> if (vi->has_rss)
> vi->rss_trailer.max_tx_vq = cpu_to_le16(queue_pairs);
> succ:
> + if (dev->flags & IFF_UP) {
> + /* Init new queues */
> + for (int i = old_queue_pairs; i < queue_pairs; i++)
> + virtnet_rx_watchdog_init_queue(&vi->rq[i]);
> + }
> +
> vi->curr_queue_pairs = queue_pairs;
[Severity: Low]
Can virtnet_rx_watchdog() observe the updated vi->curr_queue_pairs before
the rq->watchdog fields initialized by virtnet_rx_watchdog_init_queue()?
virtnet_set_queues() runs while vi->rx_watchdog is active and uses plain
stores to initialize rq->watchdog and update vi->curr_queue_pairs. By the
time execution reaches the succ label, the CVQ command has already allowed
the device to steer RX packets to the new queues:
CPU0 CPU1 (<softirq>)
virtnet_set_queues()
virtnet_rx_watchdog_init_queue(rq)
rq->watchdog.last_used = ...
rq->watchdog.calls = ...
vi->curr_queue_pairs = queue_pairs
virtnet_rx_watchdog()
i < vi->curr_queue_pairs
time_after(jiffies,
rq->watchdog.jiffies + timeout)
<-- stale jiffies, false stall
rq->watchdog.jiffies = jiffies
If a newly activated queue already has a buffer in its used ring and
virtnet_rx_watchdog() reads a stale rq->watchdog.jiffies (0 from initial
allocation or an old timestamp from before the queue count was lowered),
it logs a false RX stall warning and marks rq->watchdog.stalled. If
vi->curr_queue_pairs is lowered and raised again while
virtnet_rx_watchdog() is mid-loop, both functions can also read and write
rq->watchdog concurrently.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120071826.198604-1-lange_tang@163.com?part=2
next prev parent reply other threads:[~2026-11-21 7:18 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 7:18 [PATCH v2 0/3] virtio_net: introduce an RX queue watchdog for stuck detection Longjun Tang
2026-11-20 7:18 ` [PATCH v2 1/3] virtio: add virtqueue_get_last_used_idx() helper Longjun Tang
2026-11-20 17:43 ` Michael S. Tsirkin
2026-11-21 7:18 ` sashiko-bot
2026-11-20 7:18 ` [PATCH v2 2/3] virtio_net: introduce an RX queue watchdog for stuck detection Longjun Tang
2026-11-21 7:18 ` sashiko-bot [this message]
2026-11-20 7:18 ` [PATCH v2 3/3] virtio_net: add stalls per-queue statistic Longjun Tang
2026-11-21 7:18 ` sashiko-bot
2026-11-20 17:45 ` [PATCH v2 0/3] virtio_net: introduce an RX queue watchdog for stuck detection Michael S. Tsirkin
2026-11-24 8:41 ` Lange Tang
2026-11-21 8:27 ` Jiaming Fan
2026-11-24 8:43 ` Lange Tang
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=sashiko-outbox-226757@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=eperezma@redhat.com \
--cc=lange_tang@163.com \
--cc=mst@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=virtualization@lists.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