🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
5 messages
5 total messages Started by hawk Mon, 30 Nov 2026 09:39
[PATCH net 0/3] veth: fix lost NAPI wakeup with threaded NAPI
#24536
Author: hawk
Date: Mon, 30 Nov 2026 09:39
59 lines
10469 bytes
From: Jesper Dangaard Brouer <hawk@kernel.org>

On ARM64 servers (Ampere Altra Max) with threaded NAPI, veth TX queues
can stall permanently. The peer rq has rx_notify_masked set while its
NAPI is idle. Producers then skip scheduling NAPI, and nothing drains
the ptr_ring. With a qdisc, the TXQ stays stopped, because of commit
dc82a33297fc ("veth: apply qdisc backpressure on full ptr_ring to
reduce TX drops"). Without a qdisc, veth silently drops all packets for
that queue.

The cause is a missing write barrier. __veth_xdp_flush() stores
rx_notify_masked = true, then __napi_schedule() sets
NAPI_STATE_SCHED_THREADED with a relaxed set_bit(). On ARM64 the second
store can become visible first. An awake NAPI kthread on another CPU
then runs a full poll and stores rx_notify_masked = false, and the late
true store lands after it. Commit 68468d8c4cd4 ("veth: fix races around
rq->rx_notify_masked") opened this window, when it moved
napi_schedule_prep() before the store.

Patch 1 is a failsafe. It enables dev_watchdog for veth and recovers
the peer NAPI on TX timeout. A TXQ wake alone does not help, because
veth_xmit() hits the full ring and stops the TXQ again. We found the
bug fixed by commit 5442a9da6978 ("veth: more robust handing of race to
avoid txq getting stuck") with a similar watchdog patch in production.

Patch 2 is the fix: smp_wmb() in __veth_xdp_flush().

Patch 3 adds the same barrier to the re-arm path in veth_poll(). That
path can only race when a socket busy-polls a threaded NAPI. The patch
moves the schedule sequence into one helper, so both paths share it.

herd7 litmus tests back both patches, for LKMM and for herd7's arm64
model. Without a barrier, the bad state is reachable. With patch 2
only, it is still reachable through the busy poll re-arm. With both
patches, no test reaches it. Tests and results:

  https://github.com/netoptimizer/veth-backpressure-performance-testing/pull/15

Testing: in virtme-ng we starved the peer NAPI kthread for 12 seconds
under a UDP flood, on 6.18 and on the net tree. The watchdog fired, the
queue recovered, and the kernel log had no warnings. The test cannot
reproduce the ARM64 race, but it shows that the watchdog recovery
works. selftests/net/veth.sh passes. The test is here:

  https://github.com/netoptimizer/veth-backpressure-performance-testing/pull/14

Jesper Dangaard Brouer (2):
  veth: enable dev_watchdog and recover stalled peer NAPI
  veth: order rx_notify_masked store in the veth_poll() re-arm path

Marek Kroemeke (1):
  veth: order rx_notify_masked store before __napi_schedule()

 drivers/net/veth.c | 63 ++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 52 insertions(+), 11 deletions(-)

-- 
2.43.0
[PATCH net 2/3] veth: order rx_notify_masked store before __napi_schedule()
#24537
Author: hawk
Date: Mon, 30 Nov 2026 09:39
87 lines
11641 bytes
From: Marek Kroemeke <mkroemeke@cloudflare.com>

__veth_xdp_flush() stores rx_notify_masked = true and then calls
__napi_schedule(). With threaded NAPI, ____napi_schedule() sets
NAPI_STATE_SCHED_THREADED with a relaxed set_bit() before
wake_up_process(). An awake NAPI kthread in napi_thread_wait() sees the
bit with test_bit(), without the barriers in wake_up_process().

On weakly ordered CPUs such as ARM64, the rx_notify_masked store can
become visible after the set_bit(). The kthread can then complete a
full poll in between (masked is rq->rx_notify_masked):

  producer CPU                    NAPI kthread
  ------------                    ------------
  WRITE_ONCE(masked, true)
  set_bit(SCHED_THREADED)
                                  test_bit(SCHED_THREADED)
                                  veth_poll()
                                    napi_complete_done()
                                    smp_store_mb(masked, false)
  store masked = true lands, overwrites false

  any producer CPU, later
  __veth_xdp_flush()
    masked is true: skip NAPI

Now rx_notify_masked is true while NAPI is idle. __veth_xdp_flush()
never schedules NAPI again, and the ring stays full. We saw this on
ARM64 (Ampere Altra Max) with threaded NAPI and a qdisc on the veth:
the TXQ stayed stopped. With the previous patch, the watchdog recovers
it after 5 seconds.

Without a qdisc, veth_xmit() drops the packet instead of stopping the
TXQ. The stuck queue then silently drops all its packets, until the
receiving veth goes down or the last of XDP and GRO is turned off on
it. Kernels before commit dc82a33297fc ("veth: apply qdisc backpressure
on full ptr_ring to reduce TX drops") drop in the same way, with or
without a qdisc.

Commit 68468d8c4cd4 ("veth: fix races around rq->rx_notify_masked")
opened this window in v5.17, when it moved napi_schedule_prep(), a
fully ordered atomic, before the store.

Add smp_wmb() between the store and __napi_schedule(). On the kthread
side, the test_bit() control dependency and the napi_complete_done()
cmpxchg order the later smp_store_mb(). On x86_64 smp_wmb() is only a
compiler barrier.

The ordering gap is in the threaded NAPI handoff: ____napi_schedule()
sets NAPI_STATE_SCHED_THREADED with a relaxed set_bit(). A barrier there
would also cover other drivers with the same pattern. This patch fixes
veth only, to keep the stable backport small. A core change can follow
separately.

Verified with herd7 7.58, with the LKMM of v6.18.65 and with herd7's
arm64 model. Without smp_wmb(), every test reaches the bad state:
rx_notify_masked is true while NAPI is idle. With smp_wmb() in
__veth_xdp_flush(), the producer handoff tests report Never, also with
two producers, with two polls by the kthread, and for arm64 with
dmb ishst. The tests and results are here:

  https://github.com/netoptimizer/veth-backpressure-performance-testing/pull/15

Fixes: 68468d8c4cd4 ("veth: fix races around rq->rx_notify_masked")
Suggested-by: Matt Fleming <matt@readmodwrite.com>
Signed-off-by: Marek Kroemeke <mkroemeke@cloudflare.com>
Signed-off-by: Jesper Dangaard Brouer <hawk@kernel.org>
---
 drivers/net/veth.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 819ae6141b41..0988c7aadb5e 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -306,6 +306,8 @@ static void __veth_xdp_flush(struct veth_rq *rq)
 	if (!READ_ONCE(rq->rx_notify_masked) &&
 	    napi_schedule_prep(&rq->xdp_napi)) {
 		WRITE_ONCE(rq->rx_notify_masked, true);
+		/* Order rx_notify_masked before NAPI_STATE_SCHED_THREADED */
+		smp_wmb();
 		__napi_schedule(&rq->xdp_napi);
 	}
 }
-- 
2.43.0
[PATCH net 3/3] veth: order rx_notify_masked store in the veth_poll() re-arm path
#24538
Author: hawk
Date: Mon, 30 Nov 2026 09:40
100 lines
11661 bytes
From: Jesper Dangaard Brouer <hawk@kernel.org>

The re-arm path at the end of veth_poll() has the same store sequence
as __veth_xdp_flush(), without the barrier added in the previous patch.

Normally this is safe. The next poll runs in the same NAPI kthread, or
in softirq on the same CPU, so program order keeps the two stores in
order. Busy polling breaks this. veth GRO sets the NAPI ID on the skb,
so a socket can busy-poll the veth NAPI from another CPU. When the busy
poll loop ends, busy_poll_stop() calls veth_poll() on the busy-polling
CPU, and the re-arm hands NAPI to the kthread on another CPU:

  busy-poll CPU                   NAPI kthread
  -------------                   ------------
  busy_poll_stop()
    veth_poll()
      napi_schedule_prep()
      WRITE_ONCE(masked, true)
      set_bit(SCHED_THREADED)
                                  test_bit(SCHED_THREADED)
                                  veth_poll()
                                    napi_complete_done()
                                    smp_store_mb(masked, false)
  store masked = true lands, overwrites false

The race needs all three: threaded NAPI, busy polling on the same
queue, and an awake kthread. A kthread that sleeps is woken by
wake_up_process(), which orders the stores. The result is the same
latch as in the previous patch. We found this by code review, not in
production. herd7 confirms it: with the barrier only in
__veth_xdp_flush(), the veth-busypoll-rearm litmus tests still reach
the latch. With the helper, they do not. The tests are here:

  https://github.com/netoptimizer/veth-backpressure-performance-testing/pull/15

Move the schedule sequence into a helper, veth_napi_schedule(), and use
it in both places. Both callers schedule NAPI the same way, so the
ordering rule now lives in one place.

No functional change for __veth_xdp_flush().

Fixes: 68468d8c4cd4 ("veth: fix races around rq->rx_notify_masked")
Signed-off-by: Jesper Dangaard Brouer <hawk@kernel.org>
---
 drivers/net/veth.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 0988c7aadb5e..b0fd49dc839a 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -299,17 +299,23 @@ static void veth_ptr_free(void *ptr)
 		kfree_skb(ptr);
 }
 
+static void veth_napi_schedule(struct veth_rq *rq)
+{
+	if (!napi_schedule_prep(&rq->xdp_napi))
+		return;
+
+	WRITE_ONCE(rq->rx_notify_masked, true);
+	/* Order rx_notify_masked before NAPI_STATE_SCHED_THREADED */
+	smp_wmb();
+	__napi_schedule(&rq->xdp_napi);
+}
+
 static void __veth_xdp_flush(struct veth_rq *rq)
 {
 	/* Write ptr_ring before reading rx_notify_masked */
 	smp_mb();
-	if (!READ_ONCE(rq->rx_notify_masked) &&
-	    napi_schedule_prep(&rq->xdp_napi)) {
-		WRITE_ONCE(rq->rx_notify_masked, true);
-		/* Order rx_notify_masked before NAPI_STATE_SCHED_THREADED */
-		smp_wmb();
-		__napi_schedule(&rq->xdp_napi);
-	}
+	if (!READ_ONCE(rq->rx_notify_masked))
+		veth_napi_schedule(rq);
 }
 
 static int veth_xdp_rx(struct veth_rq *rq, struct sk_buff *skb)
@@ -1001,12 +1007,8 @@ static int veth_poll(struct napi_struct *napi, int budget)
 	if (done < budget && napi_complete_done(napi, done)) {
 		/* Write rx_notify_masked before reading ptr_ring */
 		smp_store_mb(rq->rx_notify_masked, false);
-		if (unlikely(!__ptr_ring_empty(&rq->xdp_ring))) {
-			if (napi_schedule_prep(&rq->xdp_napi)) {
-				WRITE_ONCE(rq->rx_notify_masked, true);
-				__napi_schedule(&rq->xdp_napi);
-			}
-		}
+		if (unlikely(!__ptr_ring_empty(&rq->xdp_ring)))
+			veth_napi_schedule(rq);
 	}
 
 	/* Release backpressure per NAPI poll */
-- 
2.43.0
Re: [PATCH net 0/3] veth: fix lost NAPI wakeup with threaded NAPI
#24579
Author: Jesper Dangaard Brouer
Date: Mon, 30 Nov 2026 11:35
27 lines
9052 bytes

On 11/30/26 10:39, hawk@kernel.org wrote:
> herd7 litmus tests back both patches, for LKMM and for herd7's arm64
> model. Without a barrier, the bad state is reachable. With patch 2
> only, it is still reachable through the busy poll re-arm. With both
> patches, no test reaches it. Tests and results:
> 
>    https://github.com/netoptimizer/veth-backpressure-performance-testing/ 
> pull/15

Merged and avail as: [1] [2]
- 
https://github.com/netoptimizer/veth-backpressure-performance-testing/tree/main/memory-model

Full disclosure, it was the the LLM (Claude Fable 5.2) that went above
and beyond analyzing the memory barrier against the Linux Kernel memory
model (tools/memory-model/). I don't claim to understand the herd7
litmus tests myself.

--Jesper

[1] 
https://github.com/netoptimizer/veth-backpressure-performance-testing/tree/main/memory-model#readme
[2] 
https://github.com/netoptimizer/veth-backpressure-performance-testing/blob/main/memory-model/RESULTS.md
Re: [PATCH net 0/3] veth: fix lost NAPI wakeup with threaded NAPI
#25033
Author: Simon Schippers
Date: Tue, 01 Dec 2026 07:19
30 lines
9869 bytes
On 11/30/26 10:39, hawk@kernel.org wrote:
> From: Jesper Dangaard Brouer <hawk@kernel.org>
> 
> On ARM64 servers (Ampere Altra Max) with threaded NAPI, veth TX queues
> can stall permanently. The peer rq has rx_notify_masked set while its
> NAPI is idle. Producers then skip scheduling NAPI, and nothing drains
> the ptr_ring. With a qdisc, the TXQ stays stopped, because of commit
> dc82a33297fc ("veth: apply qdisc backpressure on full ptr_ring to
> reduce TX drops"). Without a qdisc, veth silently drops all packets for
> that queue.
> 
> The cause is a missing write barrier. __veth_xdp_flush() stores
> rx_notify_masked = true, then __napi_schedule() sets
> NAPI_STATE_SCHED_THREADED with a relaxed set_bit(). On ARM64 the second
> store can become visible first. An awake NAPI kthread on another CPU
> then runs a full poll and stores rx_notify_masked = false, and the late
> true store lands after it. Commit 68468d8c4cd4 ("veth: fix races around
> rq->rx_notify_masked") opened this window, when it moved
> napi_schedule_prep() before the store.
> 

Nit: Please state in the comments what exactly the smp_wmb() pairs with
in napi_complete_done().

FYI: netdev/contest couldn't apply the series, see patchwork.

For the series:

Reviewed-by: Simon Schippers <simon.schippers@tu-dortmund.de>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads