From: Marek Kroemeke __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 Signed-off-by: Marek Kroemeke Signed-off-by: Jesper Dangaard Brouer --- 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