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 2/3] veth: order rx_notify_masked store before __napi_schedule()
Date: Mon, 30 Nov 2026 10:39:59 +0100 [thread overview]
Message-ID: <20261130094000.2022376-3-hawk@kernel.org> (raw)
In-Reply-To: <20261130094000.2022376-1-hawk@kernel.org>
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
next prev parent 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 ` [PATCH net 1/3] veth: enable dev_watchdog and recover stalled peer NAPI hawk
2026-11-30 9:39 ` hawk [this message]
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-3-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