All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Congjie Zhou <zcjie0802@qq.com>
Cc: netdev <netdev@vger.kernel.org>,
	jasowangio <jasowangio@gmail.com>, eperezma <eperezma@redhat.com>,
	xuanzhuo <xuanzhuo@linux.alibaba.com>,
	andrew+netdev <andrew+netdev@lunn.ch>,
	davem <davem@davemloft.net>, edumazet <edumazet@kernel.org>,
	kuba <kuba@kernel.org>, pabeni <pabeni@redhat.com>,
	horms <horms@kernel.org>,
	virtualization <virtualization@lists.linux.dev>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [BUG] virtio_net: RX stall caused by masking callbacks after NAPI ownership release
Date: Mon, 16 Nov 2026 04:52:58 -0500	[thread overview]
Message-ID: <20261116044750-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <tencent_94953697D2BA27275BEF7A26404E69800605@qq.com>

On Mon, Nov 16, 2026 at 04:47:17PM +0800, Congjie Zhou wrote:
> Tried your patch with my earlier TCP test. No more complete NAPI
> stalls so far, thanks!
> 
> But LLM found another possible interleaving, though. I reproduced it
> in an instrumented KUnit test with injected delays, but haven't hit
> it in the TCP test.
> 
> With defer_hard_irqs=1, it goes like this:
> 
> CPU1 / old poll                  CPU2 / busy-poll
> -----------------------------    -----------------------------
> Complete: clear SCHED,
> arm timer, return false.
>                                  Take NAPI ownership.
>                                  Enter busy_poll_stop(), clear
>                                  IN_BUSY_POLL. The final poll
>                                  enables callbacks, then pauses
>                                  before completion.
> Watchdog expires, sees
> SCHED=1, exits without
> scheduling or setting MISSED.
> Disable callbacks.
> Timer=0, SCHED=1, so skip
> napi_schedule() and exit.
>                                  napi_complete_done(..., 0):
>                                  defer count=0, no MISSED.
>                                  Clear SCHED, return true.
>                                  Queue is empty, exit.
> 
> Then the device adds a used entry, but callbacks are still disabled,
> with no timer or poll pending.
> 
> So SCHED=1 at the check, but that poll has already enabled callbacks
> and won't enable them again after the old poll masks them.
> 


Oh good point.  Maybe let's just check the poll list.  And I guess it's
cleaner to add a helper in net core than poke at low level fields like
this.


diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index dd2c41ef6fbe7..0984f81848174 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -740,6 +740,8 @@ static bool virtqueue_napi_complete(struct napi_struct *napi,
 			return true;
 	} else {
 		virtqueue_disable_cb(vq);
+		if (!napi_has_pending_poll(napi))
+			napi_schedule(napi);
 	}
 
 	return false;
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index c0ae442c4344b..f728499872e8d 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -22,6 +22,7 @@
 #define _LINUX_NETDEVICE_H
 
 #include <linux/timer.h>
+#include <linux/hrtimer.h>
 #include <linux/bug.h>
 #include <linux/delay.h>
 #include <linux/atomic.h>
@@ -553,6 +554,21 @@ static inline bool napi_is_scheduled(struct napi_struct *n)
 	return test_bit(NAPI_STATE_SCHED, &n->state);
 }
 
+/**
+ * napi_has_pending_poll - test if NAPI will be polled again
+ * @n: NAPI context
+ *
+ * True if the deferral watchdog is armed or a poll is queued.  A
+ * false answer is "best-effort": a poll can be queued right after
+ * the check.
+ *
+ * Return: True if NAPI will be polled again, False otherwise.
+ */
+static inline bool napi_has_pending_poll(struct napi_struct *n)
+{
+	return hrtimer_active(&n->timer) || !list_empty(&n->poll_list);
+}
+
 bool napi_schedule_prep(struct napi_struct *n);
 
 /**


  reply	other threads:[~2026-11-16  9:53 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 13:36 [BUG] virtio_net: RX stall caused by masking callbacks after NAPI ownership release Congjie Zhou
2026-11-11 13:50 ` [PATCH net 1/2] net: napi: add completion with an ordered IRQ mask callback Congjie Zhou
2026-11-11 13:56   ` netdev-bot+sinfo
2026-11-11 15:08     ` zcj
2026-11-12 13:52   ` sashiko-bot
2026-11-11 13:50 ` [PATCH net 2/2] virtio_net: mask callbacks before releasing NAPI ownership Congjie Zhou
2026-11-12 13:52   ` sashiko-bot
2026-11-13 10:38     ` zcj
2026-11-15  7:12 ` [PATCH net v2 1/2] net: napi: add completion with an ordered IRQ mask callback Congjie Zhou
2026-11-15  7:21   ` sashiko-bot
2026-11-15 18:26   ` Jakub Kicinski
2026-11-15  7:12 ` [PATCH net v2 2/2] virtio_net: mask callbacks before releasing NAPI ownership Congjie Zhou
2026-11-15  7:21   ` sashiko-bot
2026-11-15 20:09 ` [BUG] virtio_net: RX stall caused by masking callbacks after NAPI ownership release Michael S. Tsirkin
2026-11-15 23:07 ` Michael S. Tsirkin
2026-11-16  8:47   ` Congjie Zhou
2026-11-16  9:52     ` Michael S. Tsirkin [this message]
2026-11-16 16:05       ` Congjie Zhou

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=20261116044750-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=horms@kernel.org \
    --cc=jasowangio@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    --cc=zcjie0802@qq.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.