🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
5 messages
5 total messages Started by Longjun Tang Fri, 20 Nov 2026 07:18
[PATCH v2 0/3] virtio_net: introduce an RX queue watchdog for stuck detection
#19672
Author: Longjun Tang
Date: Fri, 20 Nov 2026 07:18
71 lines
11033 bytes
Hi Michael, Kuba,

I once ran into a problem where the virtio_net receive queue became
permanently stuck.

The virtio_net RX path relies on backend interrupt notifications.
The backend(vhost_net/vhost-user) appends buffers to the used ring
and then notifies the guest, relying on the hypervisor(KVM) to inject
the interrupt. On receiving it, virtio_net schedules NAPI, drains the
used ring and refills descriptors.

If the hypervisor fails to inject the interrupt(e.g. a transient KVM
failure), the guest never schedules NAPI, so it neither consumes buffers
nor returns descriptors. The backend keeps appending until the ring is full,
then stops and, with no free descriptors left, also stops sending
notifications. Both sides now wait for the other, and the RX queue is
permanently stuck.

The root cause is the lost interrupt in the hypervisor, and the proper
fix belongs there. Nevertheless, I believe virtio_net needs a way to
observe and diagnose it. Today, once a queue hangs, there is no signal
to the operator that anything is wrong: the RX path has no equivalent of
the TX watchdog (ndo_tx_timeout). This series lets virtio_net detect and
recover a stuck RX queue.


Implementation
--------------

Patch 1 exposes last_used_idx through a new helper, which is used by both
the split and the packed ring and denotes the position the driver has
last consumed. Together with the existing virtqueue_poll(), it lets a
driver ask whether the device has produced buffers that the driver has
not consumed yet ("backlog").

Patch 2 adds a per-device RX watchdog that scans all RX queues once per
second. A queue is considered stuck when, for 5 seconds, all of the
following hold simultaneously:
  - the queue has a non-zero backlog (unconsumed buffers);
  - the driver makes no consumption progress (last_used unchanged);
  - no new interrupt arrives (rq->calls unchanged).
On detection it logs a warning, rate-limited to once per timeout, and
reschedules NAPI, which drains the ring and refills the descriptors,
so the queue recovers.

Patch 3 adds a per-queue stalls statistic, exposed via ethtool -S, so
the number of stuck events can be observed per queue.

questions and comments are welcome.

Thanks!
Lange

Changes in v2:
- 1/3: fix the kdoc.
- 2/3: drop the module parameter, use a fixed 5s timeout.
- 3/3: rename rx_timeouts to stalls.

Longjun Tang (3):
  virtio: add virtqueue_get_last_used_idx() helper
  virtio_net: introduce an RX queue watchdog for stuck detection
  virtio_net: add stalls per-queue statistic

 drivers/net/virtio_net.c     | 105 +++++++++++++++++++++++++++++++++++
 drivers/virtio/virtio_ring.c |  18 +++++-
 include/linux/virtio.h       |   2 +
 3 files changed, 123 insertions(+), 2 deletions(-)

-- 
2.25.1
Re: [PATCH v2 0/3] virtio_net: introduce an RX queue watchdog for stuck detection
#20092
Author: "Jiaming Fan"
Date: Sat, 21 Nov 2026 08:27
15 lines
17983 bytes
Hi Longjun,

I don't think this reasoning holds. You saw an RX stall, but that
doesn't mean it was caused by a lost interrupt. Masking the interrupt
injection only creates the same symptom, it doesn't reproduce what
happened in production.

Michael posted a patch for a similar RX stall recently:
https://lore.kernel.org/netdev/ad74886a8429a862c00d1e42f1dc746f2924b75f.1795108341.git.mst@redhat.com/

So did your guest have IRQ deferral enabled (napi_defer_hard_irqs and
gro_flush_timeout)? If so, you may have hit the race Michael fixed. It
stalls the queue the same way without losing any interrupt.
Re:Re: [PATCH v2 0/3] virtio_net: introduce an RX queue watchdog for stuck detection
#21611
Author: "Lange Tang"
Date: Tue, 24 Nov 2026 08:41
66 lines
13703 bytes
At 2026-11-21 01:45:22, "Michael S. Tsirkin" <mst@redhat.com> wrote:
>On Fri, Nov 20, 2026 at 03:18:23PM +0800, Longjun Tang wrote:
>> Hi Michael, Kuba,
>> 
>> I once ran into a problem where the virtio_net receive queue became
>> permanently stuck.
>> 
>> The virtio_net RX path relies on backend interrupt notifications.
>> The backend(vhost_net/vhost-user) appends buffers to the used ring
>> and then notifies the guest, relying on the hypervisor(KVM) to inject
>> the interrupt. On receiving it, virtio_net schedules NAPI, drains the
>> used ring and refills descriptors.
>> 
>> If the hypervisor fails to inject the interrupt(e.g. a transient KVM
>> failure), the guest never schedules NAPI, so it neither consumes buffers
>> nor returns descriptors. The backend keeps appending until the ring is full,
>> then stops and, with no free descriptors left, also stops sending
>> notifications. Both sides now wait for the other, and the RX queue is
>> permanently stuck.
>> 
>> The root cause is the lost interrupt in the hypervisor, and the proper
>> fix belongs there. Nevertheless, I believe virtio_net needs a way to
>> observe and diagnose it. Today, once a queue hangs, there is no signal
>> to the operator that anything is wrong: the RX path has no equivalent of
>> the TX watchdog (ndo_tx_timeout). This series lets virtio_net detect and
>> recover a stuck RX queue.
>> 
>
>Why virtio net specifically?

Compared to a physical NIC, the interrupt injection path of virtio net is 
longer: host backend (QEMU/vhost-user, here OVS-DPDK) -> eventfd -> irqfd ->
injected into the vCPU by KVM. This path loses interrupts more easily than a 
physical NIC. On bare metal the interrupt is a single hardware hop and stays 
pending until taken, so it cannot be missed.

>
>
>> Implementation
>> --------------
>> 
>> Patch 1 exposes last_used_idx through a new helper, which is used by both
>> the split and the packed ring and denotes the position the driver has
>> last consumed. Together with the existing virtqueue_poll(), it lets a
>> driver ask whether the device has produced buffers that the driver has
>> not consumed yet ("backlog").
>> 
>> Patch 2 adds a per-device RX watchdog that scans all RX queues once per
>> second. A queue is considered stuck when, for 5 seconds, all of the
>> following hold simultaneously:
>>   - the queue has a non-zero backlog (unconsumed buffers);
>
>
>what does unconsumed mean?

That the driver has not taken the completed buffers out of the queue yet:
the device has published a completion (virtqueue_poll() is true) but the 
driver has not consumed it. 

>
>>   - the driver makes no consumption progress (last_used unchanged);
>>   - no new interrupt arrives (rq->calls unchanged).
>> On detection it logs a warning, rate-limited to once per timeout, and
>> reschedules NAPI, which drains the ring and refills the descriptors,
>> so the queue recovers.
>> 
>> Patch 3 adds a per-queue stalls statistic, exposed via ethtool -S, so
>> the number of stuck events can be observed per queue.
>
>
>
>> questions and comments are welcome.
>> 
>> Thanks!
>> Lange
>> 
>> Changes in v2:
>> - 1/3: fix the kdoc.
>> - 2/3: drop the module parameter, use a fixed 5s timeout.
>> - 3/3: rename rx_timeouts to stalls.
>> 
>> Longjun Tang (3):
>>   virtio: add virtqueue_get_last_used_idx() helper
>>   virtio_net: introduce an RX queue watchdog for stuck detection
>>   virtio_net: add stalls per-queue statistic
>> 
>>  drivers/net/virtio_net.c     | 105 +++++++++++++++++++++++++++++++++++
>>  drivers/virtio/virtio_ring.c |  18 +++++-
>>  include/linux/virtio.h       |   2 +
>>  3 files changed, 123 insertions(+), 2 deletions(-)
>> 
>> -- 
>> 2.25.1
Re:Re: [PATCH v2 0/3] virtio_net: introduce an RX queue watchdog for stuck detection
#21613
Author: "Lange Tang"
Date: Tue, 24 Nov 2026 08:43
25 lines
10582 bytes
At 2026-11-21 16:27:27, "Jiaming Fan" <fan.jiaming@hotmail.com> wrote:
>Hi Longjun,
>
>I don't think this reasoning holds. You saw an RX stall, but that
>doesn't mean it was caused by a lost interrupt. Masking the interrupt
>injection only creates the same symptom, it doesn't reproduce what
>happened in production.

A lost interrupt is enough to stall the RX queue, and this can be seen 
from the code: the ring is only drained from the notification path,
vring_interrupt() -> skb_recv_done() -> virtqueue_napi_schedule() ->
virtnet_poll(). If that notification is lost, the used ring is not drained,
buffers are never returned, the device runs out of descriptors and stops
publishing, so no further notification comes. The queue stays stuck.

>
>Michael posted a patch for a similar RX stall recently:
>https://lore.kernel.org/netdev/ad74886a8429a862c00d1e42f1dc746f2924b75f.1795108341.git.mst@redhat.com/
>
>So did your guest have IRQ deferral enabled (napi_defer_hard_irqs and
>gro_flush_timeout)? If so, you may have hit the race Michael fixed. It
>stalls the queue the same way without losing any interrupt.

I looked at Michael's patch and my case does not match it: at the time 
of the stall the callbacks were enabled, and IRQ deferral was not enabled
(napi_defer_hard_irqs = 0, gro_flush_timeout = 0).
Re:Re: [PATCH v2 0/3] virtio_net: introduce an RX queue watchdog for stuck detection
#22280
Author: "Jiaming Fan"
Date: Wed, 25 Nov 2026 03:41
24 lines
18680 bytes
> If that notification is lost, the used ring is not drained,
> buffers are never returned, the device runs out of descriptors and stops
> publishing, so no further notification comes. The queue stays stuck.

I agree that a lost interrupt can stall the RX queue. The point is a basic one of logic: A -> B does not mean B -> A.
Observing a stall does not establish that an interrupt was lost.
At least in the earlier messages, I didn't see evidence that an interrupt was actually lost in production.
You explained what would happen *if* the notification was lost, not how you determined that it was.

> I looked at Michael's patch and my case does not match it: at the time
> of the stall the callbacks were enabled, and IRQ deferral was not enabled
> (napi_defer_hard_irqs = 0, gro_flush_timeout = 0).

I appreciate the clarification. That addresses the IRQ deferral scenario I suggested.

Adding a watchdog may only take a few lines of code, but once it's in, we have to account for it whenever the queue changes state, including when it is stopped, reset, or resized.
That's a long-term maintenance cost.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads