Article View: linux.kernel.netdev
Article #13098[PATCH 2/3] virtio_net: introduce an RX queue watchdog for stuck detection
From: Longjun Tang
Date: Mon, 09 Nov 2026 09:43
Date: Mon, 09 Nov 2026 09:43
200 lines
14640 bytes
14640 bytes
From: Longjun Tang <tanglongjun@kylinos.cn>
The backend raises an interrupt after adding buffers to the used ring,
and the hypervisor injects it. If one is lost (e.g., a transient KVM
failure), NAPI will not be scheduled and the driver stops consuming
buffers. The ring eventually fills up, the backend stops notifying, and
the queue is left permanently stuck.
Add a per-device watchdog that scans the RX queues once per second and
detects a queue that has a non-zero backlog while making no consumption
progress and receiving no new interrupt for rx_watchdog_timeo seconds
(default 5, 0 disables it). On detection, reschedule NAPI.
Signed-off-by: Longjun Tang <tanglongjun@kylinos.cn>
---
drivers/net/virtio_net.c | 104 +++++++++++++++++++++++++++++++++++++++
1 file changed, 104 insertions(+)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index dd2c41ef6fbe..ec7c248080c5 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -36,6 +36,10 @@ module_param(csum, bool, 0444);
module_param(gso, bool, 0444);
module_param(napi_tx, bool, 0644);
+/* RX queue stall timeout in seconds; 0 disables the watchdog. */
+static unsigned int rx_watchdog_timeo = 5;
+module_param(rx_watchdog_timeo, uint, 0644);
+
#define VIRTIO_OFFLOAD_MAP_MIN 46
#define VIRTIO_OFFLOAD_MAP_MAX 47
#define VIRTIO_FEATURES_MAP_MIN 65
@@ -318,6 +322,13 @@ struct send_queue {
dma_addr_t xsk_hdr_dma_addr;
};
+struct virtnet_rq_watchdog {
+ u16 last_used;
+ u16 calls;
+ unsigned long jiffies;
+ bool stalled;
+};
+
/* Internal representation of a receive virtqueue */
struct receive_queue {
/* Virtqueue associated with this receive_queue */
@@ -332,6 +343,9 @@ struct receive_queue {
/* The number of rx notifications */
u16 calls;
+ /* RX watchdog state. */
+ struct virtnet_rq_watchdog watchdog;
+
/* Is dynamic interrupt moderation enabled? */
bool dim_enabled;
@@ -443,6 +457,9 @@ struct virtnet_info {
/* Work struct for setting rx mode */
struct work_struct rx_mode_work;
+ /* RX watchdog timer for stuck detection */
+ struct timer_list rx_watchdog;
+
/* Does the affinity hint is set for virtqueues? */
bool affinity_hint_set;
@@ -3067,6 +3084,80 @@ 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 rx_watchdog_timeo seconds, usually because
+ * an interrupt was lost. Mark it stalled and reschedule NAPI to drain
+ * the ring, 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 = rx_watchdog_timeo * HZ;
+ int i;
+
+ if (!rx_watchdog_timeo)
+ return;
+
+ 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);
+ bool progress = last_used != rq->watchdog.last_used;
+
+ if (!backlog || progress || calls != rq->watchdog.calls) {
+ rq->watchdog.last_used = last_used;
+ rq->watchdog.calls = calls;
+ rq->watchdog.jiffies = jiffies;
+ continue;
+ }
+
+ if (time_after(jiffies, rq->watchdog.jiffies + timeout)) {
+ unsigned int stall_ms =
+ jiffies_to_msecs(jiffies - rq->watchdog.jiffies);
+
+ netdev_warn(vi->dev,
+ "RX queue %u stalled for %u ms, rescheduling NAPI\n",
+ i, stall_ms);
+
+ rq->watchdog.stalled = true;
+ virtqueue_napi_schedule(&rq->napi, rq->vq);
+
+ /* Rate-limit to one event per timeout. */
+ rq->watchdog.jiffies = jiffies;
+ }
+ }
+
+ mod_timer(&vi->rx_watchdog, jiffies + HZ);
+}
+
+static void virtnet_rx_watchdog_init_queue(struct receive_queue *rq)
+{
+ rq->watchdog.last_used = virtqueue_get_last_used_idx(rq->vq);
+ rq->watchdog.calls = rq->calls;
+ rq->watchdog.jiffies = jiffies;
+ rq->watchdog.stalled = false;
+}
+
+static void virtnet_rx_watchdog_start(struct virtnet_info *vi)
+{
+ int i;
+
+ if (!rx_watchdog_timeo)
+ return;
+
+ for (i = 0; i < vi->curr_queue_pairs; i++)
+ virtnet_rx_watchdog_init_queue(&vi->rq[i]);
+
+ mod_timer(&vi->rx_watchdog, jiffies + HZ);
+}
+
+static void virtnet_rx_watchdog_stop(struct virtnet_info *vi)
+{
+ timer_delete_sync(&vi->rx_watchdog);
+}
+
static void virtnet_disable_queue_pair(struct virtnet_info *vi, int qp_index)
{
virtnet_napi_tx_disable(&vi->sq[qp_index]);
@@ -3230,6 +3321,8 @@ static int virtnet_open(struct net_device *dev)
netif_carrier_on(dev);
}
+ virtnet_rx_watchdog_start(vi);
+
return 0;
err_enable_qp:
@@ -3759,6 +3852,7 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
struct virtio_net_rss_config_trailer old_rss_trailer;
struct net_device *dev = vi->dev;
struct scatterlist sg;
+ u16 old_queue_pairs = vi->curr_queue_pairs;
if (!vi->has_cvq || !virtio_has_feature(vi->vdev, VIRTIO_NET_F_MQ))
return 0;
@@ -3816,7 +3910,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;
+
if (dev->flags & IFF_UP) {
local_bh_disable();
for (int i = 0; i < vi->curr_queue_pairs; ++i)
@@ -3832,6 +3933,8 @@ static int virtnet_close(struct net_device *dev)
struct virtnet_info *vi = netdev_priv(dev);
int i;
+ virtnet_rx_watchdog_stop(vi);
+
/* Prevent the config change callback from changing carrier
* after close
*/
@@ -6900,6 +7003,7 @@ static int virtnet_probe(struct virtio_device *vdev)
INIT_WORK(&vi->config_work, virtnet_config_changed_work);
INIT_WORK(&vi->rx_mode_work, virtnet_rx_mode_work);
disable_work(&vi->rx_mode_work);
+ timer_setup(&vi->rx_watchdog, virtnet_rx_watchdog, 0);
if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF)) {
vi->mergeable_rx_bufs = true;
--
2.51.0
Technical Details
Message-ID:
<20261109094310.103979-3-lange_tang@163.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359181-linux-kernel-netdev=dewy.ruReferences:
<20261109094310.103979-1-lange_tang@163.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359181-linux-kernel-netdev=dewy.ru From: lange_tang@163.com (Longjun Tang) Newsgroups: linux.kernel.netdev Subject: [PATCH 2/3] virtio_net: introduce an RX queue watchdog for stuck detection Date: Mon, 9 Nov 2026 17:43:09 +0800 Organization: Usenet Network Message-ID: <20261109094310.103979-3-lange_tang@163.com> References: <20261109094310.103979-1-lange_tang@163.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="320251"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:ThKBkHrNWt9H33bDObzjBlfx3Eg= sha256:RlBANc1nc6MoOY75/tTESqhTXDqxekIxlGa9X5b114Q= sha1:U684ncztppMr78pDCsbf/4xBlis= sha256:MJbDlIYibmUIpt9R/uu46Jz4iIciAwpABtcvrJSMc40= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id C032C11376B; Mon, 9 Nov 2026 12:47:26 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.148 X-Spam-Status: No, score=-3.148 tagged_above=-9999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=163.com X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vIBOqByq2_Vm; Mon, 9 Nov 2026 12:47:17 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-359181-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=163.com X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 8B8A5113768; Mon, 9 Nov 2026 12:47:06 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 425CD605440; Mon, 9 Nov 2026 09:43:47 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794217426; b=yrRgqBFX3z+NyAxhlc+Rhexh8pK7rerpSP3rumQHfEKl3TTIRwwtQK4sVEfUXfQY0bOA mTLgtadlkJr7DOEbJ86tpdCk6S8edHslvjwJmC0kKJS4hTGonsx2H8SVZU9BPOxYALBzy H0+d2kz0RP/AxYaFpIKL7K1AFRIlMwN+d5C4cbWz/liyNGe3xup6ikhcgeu929bjMsNSZ 5VsoRO9Wqch9Dyxm58FgOMHERSntGE9Kkiqk+mtlBR0BY9+eA4F3otwXEWZ0omS/iex0U G2Agw4Wy0jusz2dAhrcxX26A+cIl+BSFAeWzj+BSzQmOsjqfF/8vA21KUJ6n1VUyVJA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794217426; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:From:To: Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=ptywGNiTNVGUFGqPa/Yt2XRlNd43/CqRk5k+EWi/QvA=; b=XrUMj6BIj/RH5VAhCaQF7cEkk8ywhLCINr711vITdwN10tXIP+DexWlYFZX/LTNAY1Tl /MAVY57qLc1y/aqFef5J9hbJGUL2H/XhqkRbLUHc2ORrlP+hYwBm42G8/jKCbZoCwD43M devikLzJ9bLbj47i6vTF8WW5JMg70vKAKvTNWTgTpQ7BoHP1wA7a0kw0bSI8Qtt6Ctks+ 8LteppsE6ENcCKaIPsEZwKXGsscQ9hR9OIoDuKYUN9CdPCrM30qU/Z4LSTrUeBdWaLC7c FcxDhkDF5fbB0THGCCphQFFqqZTzNWndrT0TbUL4PMDfv76FQyJXCX/7vTDY2+hVZgA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=YvyQ3QrE; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18D31606A335; Mon, 9 Nov 2026 09:43:46 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=YvyQ3QrE X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.5 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794217425; b=F9SeKEaVUQe9G5V4/nM/3QTOMGJ1U3L/tAg2tNwDvvY4XKxVgOEr3Ro1Cjcx2CqR1QT3 kH/Yq98iybxK+eAZeKOCK0VGRRRmniIMRXNQKQRIM1gqWbWKzYilkdYwGj9D4Wxw5x/vf cgAbrTHPwQeOWxSmiYwNBGyXmuB6gn6braZ+XCgJsbodFmSsdPPBIMBD/lxKVyN2/w6s7 oHoEKlgDnccsKQC4qyynj8HpJdt0a/5MdevDKhVdq0tsgI+7RLhQyKqo+XOQ/mR1qyl39 DhkU0M3b3uGW3W1D5k/Azr0BMydxjXBZ8cbS7F0zRXwhAcOi6lTK/cNkISq9GMCb/Hg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794217425; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=ptywGNiTNVGUFGqPa/Yt2XRlNd43/CqRk5k+EWi/QvA=; b=uh4O1ODunORMED8pzAi65ASpbz+PzaDTwqgy3FZ5ncqO51euA7r6et6QuBauGCWT0Mw7 RRHt/syEbjrfSKPbhYsglprydk8wj8sHXDXWzNPOS41FOvpUWS/j7Gcw8tbZzggil0vk2 uldS07q3s/0ixmobNELph59tTKIjKKAWZvyvqlH0ZsCL9vh2QUKh6bC4d0SvoBr3fVECf fNRYQXEWFA5cc8xmoQGG8E2zNaresG3GDCX5rDnGUU2dnKB1p30jU03EfaN8Rj3IieFH+ 8uwlTfbdjmFoaevNjzSvQ6QSj2fYYGJ1Yew9+zp1mbGpHKX8oCS4jjbdkzPrd0wGKdQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=YvyQ3QrE; arc=none smtp.remote-ip=220.197.31.5 X-Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83CB2606A321 for <netdev@vger.kernel.org>; Mon, 9 Nov 2026 09:43:43 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 83CB2606A321 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=pt ywGNiTNVGUFGqPa/Yt2XRlNd43/CqRk5k+EWi/QvA=; b=YvyQ3QrEJw43EnS0jU DnzH28ti8cFUkYD6WlAauNaL/MvD5Ux4hvDEKd7Fthue2HavPOHQ7RpX52KYxppv 2ojoQINtHMV6ZoWZl4ZKAfSQid/a6I1sMortaWdw0LCZRF0AXIkY9P4Hw0UdOo5e UXu4MUWVrUhV84emMD39G7dEE= X-Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g0-2 (Coremail) with SMTP id _____wBHJCGvlfFq58sxGQ--.4049S4; Mon, 09 Nov 2026 17:43:13 +0800 (CST) X-Cc: xuanzhuo@linux.alibaba.com, virtualization@lists.linux.dev, netdev@vger.kernel.org, tanglongjun@kylinos.cn X-Mailer: git-send-email 2.25.1 X-In-Reply-To: <20261109094310.103979-1-lange_tang@163.com> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-CM-TRANSID: _____wBHJCGvlfFq58sxGQ--.4049S4 X-Coremail-Antispam: 1Uf129KBjvJXoW3Jr4DJFWUZr4fKrW7KF4DJwb_yoWxGF4xpF W3Aw15trW8tr4xuayxJ397XF13KrykXry7GrWfK398uFs8Kr1rZFn2kry5Ga9Y9FZ3Jr17 Xr4kt3yfK3yv9rJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j3-B_UUUUU= X-CM-SenderInfo: 5odqwvxbwd0wi6rwjhhfrp/xtbC4hKo1mrxlbJX9QAA3Q