Article View: linux.kernel.netdev
Article #19663Re:Re: [PATCH 2/3] virtio_net: introduce an RX queue watchdog for stuck detection
From: "Lange Tang"
Date: Fri, 20 Nov 2026 07:14
Date: Fri, 20 Nov 2026 07:14
123 lines
18221 bytes
18221 bytes
At 2026-11-13 06:51:46, "Michael S. Tsirkin" <mst@redhat.com> wrote:
>On Mon, Nov 09, 2026 at 05:43:09PM +0800, Longjun Tang wrote:
>> 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
>
>No module params pls. This is not a sane UAPI.
Dropped in v2; the timeout is now a fixed 5s constant.
>
>> @@ -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:
<7158076d.5a7a.1a1f7ce82d5.Coremail.lange_tang@163.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367732-linux-kernel-netdev=dewy.ruReferences:
<20261109094310.103979-1-lange_tang@163.com> <20261109094310.103979-3-lange_tang@163.com> <20261112175123-mutt-send-email-mst@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367732-linux-kernel-netdev=dewy.ru
From: lange_tang@163.com ("Lange Tang")
Newsgroups: linux.kernel.netdev
Subject: Re:Re: [PATCH 2/3] virtio_net: introduce an RX queue watchdog for
stuck detection
Date: Fri, 20 Nov 2026 15:14:28 +0800 (CST)
Organization: Usenet Network
Message-ID: <7158076d.5a7a.1a1f7ce82d5.Coremail.lange_tang@163.com>
References: <20261109094310.103979-1-lange_tang@163.com>
<20261109094310.103979-3-lange_tang@163.com>
<20261112175123-mutt-send-email-mst@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=GBK
Content-Transfer-Encoding: base64
Injection-Info: usenet.network;
logging-data="3091626"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:zXxBu2tXQS+pFlcxEAoMxagCSzE= sha256:fWl9f7Tc28DyRBmJgTSx98vNRx/wq5BLtbxm/Nx5mVc=
sha1:Br+933SS/D9gGuv7+ilxGtYusKA= sha256:p8Ea93adGoOllLgVpBklRkfHjr6MPrEx8oI17GfYm7k=
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 A0B4C1158E2; Fri, 20 Nov 2026 10:15:21 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, 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] 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 5slkLLH-E1pL;
Fri, 20 Nov 2026 10:15:14 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-367732-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id B84E01158E3; Fri, 20 Nov 2026 10:15:05 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id DCF1D66201; Fri, 20 Nov 2026 07:15:02 +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=1795158902;
b=Vn05zOWmcS7YU+NVh1zDBNZN7kAWG+84L5xuOs5YaHguDMGOH4gy7VPkHLgd1br6mcKD
3MRTtdfyTBaPIMnw6902IHI2impJM7VqBW4xzONuMXW8fUHvw2/ays2nPU++viy5ozMnS
SUETEazZb3OSyDVyxwqmQCJ6A9qrvpkC/vnCl76fMG2NPApfeIDIzJYWGqyO+8ys5usWG
AFwxyO0cinU3PtGWtn9iOqRkV9/S22JOf004rjwB9it9UID4UEnaMw2/NObSlWaWNTyPe
JiQCsz1S/7Mz5K2+vndwBrYmOXS/vGHSvh6J47XcrtnSsSIPu3fSbtlWjAzqxczj/2Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795158902;
h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Date:From:To:Cc:
Subject:X-Priority:X-Mailer:In-Reply-To:References:X-NTES-SC:
Content-Transfer-Encoding:Content-Type:X-Mailing-List:List-Id:
List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
Precedence:MIME-Version:Message-ID:X-Coremail-Locale:X-CM-TRANSID:
X-CM-SenderInfo:X-Coremail-Antispam;
bh=yMb4y4ic9DcyyykxkiIHneI0onsh6rE3fLC/W+8P3us=;
b=VB7nLPj/+x60nkto3f66Ha97itNN3eT8Ih+3xcUJDGWogPOwS3bcd8iDQkf1lrfGZm9r
TpaqZ9P4cFQXGx4p6jZE004ZNosMFjP2vOq7stolmaI0NRthhCqZWoQQrVd8jf5DGgRGS
fwsKNlO0lKgjW8XsPbb+UixCH32dtEpN9D6u1Ns2Pw/LeOACpruYrEA8q4v1NgIhm1q9q
q77iAIxpaRHDlbHUCtxogJefEztE9yK5qZFCBivaM/9TNdcWHTKd0Uhs7rO82aVjMWpCk
vLTycoUWCkurJ4RPM4HUuemNkGeXMBmIglIq/Cf9M3iKTwcFv3G0YkyDErrjiHZE4Vw==
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=GUHZcepy;
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 A2A17606A330;
Fri, 20 Nov 2026 07:15:02 +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=GUHZcepy
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=117.135.210.5
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1795158901;
b=GrjPGdY2jQz5dBbF9Sql/hCy32s64j7Hg/ccw/Wa1n+sJJ1OUTRiqOmqNcRznPzUQmZX
nS+mCuq0VLUdjmOATLIFfjx28yIOHQUGAVvwMmW92KnhxiwZqQJjM1IZ25SD/0DqVV+nb
V0NajOGzyZFpHBXpthzUOTi+EYAIYFRD1vvZpFE+iw5RWacRNbmDeVv/xG9bIOmZXa27h
m1Wnw1khTkE1E5TGw1Adyn+P9XlEAnL7JoMJv9Nc/39jB/PRmQdvUZwGCcTouQqzfhgMT
OeQFQQBkKrrQmQrqBigWNkLoOU2PvOmAAlE5gk7CbEPBJRt3iKqj/qzwzAZZ7dtrFYg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795158901;
h=DMARC-Filter:DKIM-Signature:Date:From:To:Cc:Subject:X-Priority:
X-Mailer:In-Reply-To:References:X-NTES-SC:Content-Transfer-Encoding:
Content-Type:MIME-Version:Message-ID:X-Coremail-Locale:X-CM-TRANSID:
X-CM-SenderInfo:X-Coremail-Antispam;
bh=yMb4y4ic9DcyyykxkiIHneI0onsh6rE3fLC/W+8P3us=;
b=1LBRSjy7jamQhbHK6jnU99x+OLOU8LVrHzUdA5dtH1aA0nS1sMtvylf4rOCcRWpQkytg
L+nGNr5tgMMwcx+Je4B+ptZj7yoMr+1WHdMSzNVo0qWvXL30jrJI/YMwzZAC/a2zzMYQl
gyk+ZwGbCWjnZZFO1iSJQrRxCOSM1IkKya0eScSixsaay7ZcOs46BeGoQGW1vPrDKcoWA
ZvTdTQKEKeTd7D0p2DVrrObWrDlmnW+OdS7VV94p5DoSBQMeEmY37IS0/KVb03Loe5aKP
jyTjuNJk+mPDzkwkx9Tm6FzJIze2FO8jN5TDWSO++CJc7vQ81FyHSgQQLZrHk0T5Ttg==
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=GUHZcepy;
arc=none smtp.remote-ip=117.135.210.5
X-Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.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 A474D606A320
for <netdev@vger.kernel.org>; Fri, 20 Nov 2026 07:15:00 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A474D606A320
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=Date:From:To:Subject:Content-Type:MIME-Version:
Message-ID; bh=yMb4y4ic9DcyyykxkiIHneI0onsh6rE3fLC/W+8P3us=; b=G
UHZcepytsf56JjHWfP3+8Pco4H6saqByTM5jVkEXGyP3oDdFbIWsJLtxlf4kTCjk
hxz+ee8vT2IgPpRjTYeCcsZ7Q5UN+LpvUXNmZ7f1SAYaPCfheAvltsvsq993Aw7+
PtxRYE4sezlfBprJH6HgArx/TCxpj62amXQwvraBzg=
X-Cc: "Jakub Kicinski" <kuba@kernel.org>,
"Eugenio Perez" <eperezma@redhat.com>,
"jasowangio@gmail.com" <jasowangio@gmail.com>,
"xuanzhuo@linux.alibaba.com" <xuanzhuo@linux.alibaba.com>,
"virtualization@lists.linux.dev" <virtualization@lists.linux.dev>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"Tang Longjun" <tanglongjun@kylinos.cn>
X-Priority: 3
X-Mailer: Coremail Webmail Server Version 2023.4-cmXT build
20260511(2e539873) Copyright (c) 2002-2026 www.mailtech.cn 163com
X-In-Reply-To: <20261112175123-mutt-send-email-mst@kernel.org>
X-NTES-SC: AL_Qu2SB/2et0At7iaQY+kfmUgRg+c/XsK4svUj24VVOJF8jCDp+SEJYHZTFGvuwfi3ASqsmSO8ahFRxdZ2Wohybrgll75L0dIR26Nc1Naf8dvUwg==
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-Coremail-Locale: zh_CN
X-CM-TRANSID: aigvCgC3_8ZU8_9qIX5yAA--.320W
X-CM-SenderInfo: 5odqwvxbwd0wi6rwjhhfrp/xtbC-RSs2mr-81R3CQAA3T
X-Coremail-Antispam: 1U5529EdanIXcx71UUUUU7vcSsGvfC2KfnxnUU==