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 via email to