BPF List
 help / color / mirror / Atom feed
From: hawk@kernel.org
To: netdev@vger.kernel.org
Cc: bpf@vger.kernel.org, mkroemeke@cloudflare.com,
	matt@readmodwrite.com, kernel-team@cloudflare.com,
	hawk@kernel.org, simon.schippers@tu-dortmund.de,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	Stanislav Fomichev <sdf@fomichev.me>,
	Toshiaki Makita <toshiaki.makita1@gmail.com>
Subject: [PATCH net 1/3] veth: enable dev_watchdog and recover stalled peer NAPI
Date: Mon, 30 Nov 2026 10:39:58 +0100	[thread overview]
Message-ID: <20261130094000.2022376-2-hawk@kernel.org> (raw)
In-Reply-To: <20261130094000.2022376-1-hawk@kernel.org>

From: Jesper Dangaard Brouer <hawk@kernel.org>

Since commit dc82a33297fc ("veth: apply qdisc backpressure on full
ptr_ring to reduce TX drops"), veth stops the TXQ when the peer ptr_ring
is full, and only the peer veth_poll() wakes it again. If a race loses
the NAPI wakeup, the TXQ stays stopped and the qdisc cannot send.

We now hit such a race on ARM64: the peer rq has rx_notify_masked set
while NAPI is idle, so __veth_xdp_flush() never schedules NAPI and
nothing drains the ring. The patches "veth: order rx_notify_masked
store before __napi_schedule()" and "veth: order rx_notify_masked store
in the veth_poll() re-arm path" fix that race.

Enable dev_watchdog as a failsafe, with a 5 second timeout. On timeout,
if the peer NAPI is not scheduled, clear rx_notify_masked on the peer
rq and call __veth_xdp_flush() to schedule NAPI. Then wake the TXQ. A
TXQ wake alone does not help, because veth_xmit() hits the full ring and
stops the TXQ again. If the peer NAPI is already scheduled,
rx_notify_masked is correct, and the handler only wakes the TXQ. The
timer runs on every veth with carrier, like on any driver with
ndo_tx_timeout. Each run scans dev->num_tx_queues, which for veth is
num_possible_cpus().

This watchdog is a fix in its own right, and it belongs in stable.
Lost wakeups in this path keep showing up.
Commit 5442a9da6978 ("veth: more robust handing of race to avoid txq
getting stuck") and commit 60db47f02bfa ("veth: fix queue index used
to wake the peer txq in veth_poll") each fixed one. Each of them caused
a permanent TXQ stall, because veth has no ndo_tx_timeout. We found the
first one with a watchdog like this one, which never went upstream. The
watchdog covers the whole class on veths with a qdisc. If a race we do
not know about yet loses a wakeup, the TXQ stalls for about 5 seconds
instead of permanently, and the log shows the state needed to debug it.
Without a qdisc the TXQ never stops, so the watchdog cannot help there.
dev_watchdog() handles one timed-out queue per run, so with several
stalled queues, each one waits for its own run.

The log line prints the peer rq state from before the recovery, to show
which lost wakeup happened. The state is the raw napi_struct state
word, for diagnostics only (hinic and hns3 print it the same way):

 veth0: NETDEV WATCHDOG: CPU: 34: transmit queue 0 timed out 5393 ms
 veth0: veth backpressure stalled(n:1) TXQ(0) re-enable peer napi:1 masked:1 state:0x110

Fixes: dc82a33297fc ("veth: apply qdisc backpressure on full ptr_ring to reduce TX drops")
Signed-off-by: Jesper Dangaard Brouer <hawk@kernel.org>
---
 drivers/net/veth.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index faa837acea7b..819ae6141b41 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -1403,6 +1403,41 @@ static int veth_set_channels(struct net_device *dev,
 	goto out;
 }
 
+static void veth_tx_timeout(struct net_device *dev, unsigned int txqueue)
+{
+	struct netdev_queue *txq = netdev_get_tx_queue(dev, txqueue);
+	struct veth_priv *priv = netdev_priv(dev);
+	bool masked = false, napi = false;
+	unsigned long napi_state = 0;
+	struct net_device *rcv;
+
+	rcu_read_lock();
+	rcv = rcu_dereference(priv->peer);
+	if (rcv && txqueue < rcv->real_num_rx_queues) {
+		struct veth_priv *rcv_priv = netdev_priv(rcv);
+		struct veth_rq *rq = &rcv_priv->rq[txqueue];
+
+		if (rcu_access_pointer(rq->napi)) {
+			napi = true;
+			masked = READ_ONCE(rq->rx_notify_masked);
+			napi_state = READ_ONCE(rq->xdp_napi.state);
+			/* Recover lost NAPI wakeup if rx_notify_masked stuck */
+			if (!(napi_state & NAPIF_STATE_SCHED)) {
+				WRITE_ONCE(rq->rx_notify_masked, false);
+				__veth_xdp_flush(rq);
+			}
+		}
+	}
+	rcu_read_unlock();
+
+	netdev_err(dev,
+		   "veth backpressure stalled(n:%ld) TXQ(%u) re-enable peer napi:%d masked:%d state:%#lx\n",
+		   atomic_long_read(&txq->trans_timeout), txqueue,
+		   napi, masked, napi_state);
+
+	netif_tx_wake_queue(txq);
+}
+
 static int veth_open(struct net_device *dev)
 {
 	struct veth_priv *priv = netdev_priv(dev);
@@ -1741,6 +1776,7 @@ static const struct net_device_ops veth_netdev_ops = {
 	.ndo_bpf		= veth_xdp,
 	.ndo_xdp_xmit		= veth_ndo_xdp_xmit,
 	.ndo_get_peer_dev	= veth_peer_dev,
+	.ndo_tx_timeout		= veth_tx_timeout,
 };
 
 static const struct xdp_metadata_ops veth_xdp_metadata_ops = {
@@ -1779,6 +1815,7 @@ static void veth_setup(struct net_device *dev)
 	dev->priv_destructor = veth_dev_free;
 	dev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
 	dev->max_mtu = ETH_MAX_MTU;
+	dev->watchdog_timeo = msecs_to_jiffies(5000);
 
 	dev->hw_features = VETH_FEATURES;
 	dev->hw_enc_features = VETH_FEATURES;
-- 
2.43.0


  reply	other threads:[~2026-11-30  9:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  9:39 [PATCH net 0/3] veth: fix lost NAPI wakeup with threaded NAPI hawk
2026-11-30  9:39 ` hawk [this message]
2026-11-30  9:39 ` [PATCH net 2/3] veth: order rx_notify_masked store before __napi_schedule() hawk
2026-11-30  9:40 ` [PATCH net 3/3] veth: order rx_notify_masked store in the veth_poll() re-arm path hawk
2026-11-30 11:35 ` [PATCH net 0/3] veth: fix lost NAPI wakeup with threaded NAPI Jesper Dangaard Brouer

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=20261130094000.2022376-2-hawk@kernel.org \
    --to=hawk@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kernel-team@cloudflare.com \
    --cc=kuba@kernel.org \
    --cc=matt@readmodwrite.com \
    --cc=mkroemeke@cloudflare.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=simon.schippers@tu-dortmund.de \
    --cc=toshiaki.makita1@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox