Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796031614; b=XLtW/puBaBbl5nn1lkOSD1vIy4Uqp14bPf+loqhQE9Ce4RnNy7X00OWVt4NOP0Lj3UH7 sfGwNYIRpyl/5s2HJVIBLU1vAK10Y5W3ECaEVmjsUyTBWk44aE+WmJJKJt/eAO9kRaC0h tQDyoFPC0HZXMzjvu+cBtyM1XQ36Vn69LdnVGeRZkSsGypzlzju88zFO7GQ6MYL28pleP rqoyTEZHrArH6ZS0Nu3YbnecvKaqHyPgdqPK4PsFaxFjliTcCnK7vqY9egCCFzA2dElDg WCAAJDiapcFusSce1k1XIBRQZiNiPa9AfL2aOqbm31vNLkMsqJ9rCNKCPOGVWVbzPHg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796031614; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=CGu53c5/XkXhrIcNXVwyQTXK9ix0NZPKTLryfO4P7v4=; b=IDkHlel1SZuEb1/VoVcovzeblVaI69JcPNTllEYThyr0eM1LtqBjo8EIkwLf/3CXH3MJ LWFnV6xEzUruG6XLpremefzPh8ye5CnNLCK+Eqd7RNtAV0gbIEOInGYiwpmZFcIx7nsG7 Aj8z7tF7TSure3jqgGLSGW7HCRpxfHFMOEBtWMj8Tm24Xvx4V3XCvXS5yHzW01U+D1lA/ 98lSbrsTE0mZNXvXaiJfHiG08hBeH+1Gu30RGfxw7SywfMPQqwNYIagoG02Arj+yYdZNw KreHsk8f2mrFL3GPqFTuQD9reixjkGoyzGvC47vN1rcU2hMEIKMNzRC8tM6e1e9s0yw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J0j2dX7e; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 603DE606A31C; Mon, 30 Nov 2026 09:40:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J0j2dX7e Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CC411F008A0; Mon, 30 Nov 2026 09:40:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796031613; bh=CGu53c5/XkXhrIcNXVwyQTXK9ix0NZPKTLryfO4P7v4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=J0j2dX7ePSfqtU2WAXWjOGPAR5B5iN8Vm2c48n4Kjm9vZnXgEADKxsQchOgba6BwT gT1cYf20NDN0cCBChlEz9GRQa/goW03Ja0USY2V1UPxrYrDTLRW0FY6fNhFcXZ4I7g jDgLUfvQS+v4IiO+bfYURzA7XLf9u4sMxfrFebf881jUYyZwIbz3abWKa78EZ5x7Kf S5pcObj/AiM8MyL2QUe/sUIC1CpcLHXrd+IiYNcP7wEYlpJC+DEsmx6Lckemgh3fNc +SBNE9Y2ygv+f2FNreq0dQKoRu0Br0ep34F3xU7GtLYVfWgAEnq+JTdly/oJRMyzZx pkCCqdQgKvpIA== 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 , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Stanislav Fomichev , Toshiaki Makita Subject: [PATCH net 2/3] veth: order rx_notify_masked store before __napi_schedule() Date: Mon, 30 Nov 2026 10:39:59 +0100 Message-ID: <20261130094000.2022376-3-hawk@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130094000.2022376-1-hawk@kernel.org> References: <20261130094000.2022376-1-hawk@kernel.org> X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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