🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24537

[PATCH net 2/3] veth: order rx_notify_masked store before __napi_schedule()

#24537
From: 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
Technical Details
Message-ID: <20261130094000.2022376-3-hawk@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374077-linux-kernel-netdev=dewy.ru
References: <20261130094000.2022376-1-hawk@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374077-linux-kernel-netdev=dewy.ru
From: hawk@kernel.org
Newsgroups: linux.kernel.netdev
Subject: [PATCH net 2/3] veth: order rx_notify_masked store before __napi_schedule()
Date: Mon, 30 Nov 2026 10:39:59 +0100
Organization: Usenet Network
Message-ID: <20261130094000.2022376-3-hawk@kernel.org>
References: <20261130094000.2022376-1-hawk@kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1395253"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:/JK2Fp3sQsy9qZvBOjPp0/NgFgM= sha256:wsSt393paaL5niK76f0uHrTKnE0fEIesQqBRXjvmq6k=
	sha1:fzvt07fgi32Pla1xyMnUS4iuuS8= sha256:vCU0zkq6KLJ0Mjb5w99pdWo7IJi4MkgTtXsh+e1BK5M=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 274D1125FD4; Mon, 30 Nov 2026 12:40:39 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id rxdcoYM1qVIt;
	Mon, 30 Nov 2026 12:40:36 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-374077-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 86F7E125FD2; Mon, 30 Nov 2026 12:40:26 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 1AD6A232BF; Mon, 30 Nov 2026 09:40:23 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796031620;
	b=WH08n7jc/JwZyM1aP1QG+tBhSLu9tLquM+u816ElitLD2LCJtdJyEkQCXgIsg02uVCyD
	 N9HcfwtYHGJ0coENYFiWyKwLGERmyc9a1RfOG54mdIwD7PDmiyUfrXdrqbCyeqgch/XQz
	 nP68rQMHo1vYrrS3pDynYZREWNcIo5jB6XY4jiCkxTs6kvh4+TT58zkwjppr4ab8qlz4u
	 ZzxbvPwzmjzyPSN3SMUiOJOq1NIino5d1Dnk9BBsaulFAoWqnrqNKG06sb4d/kJNOdTgt
	 m6Z9Qru4R5O8aSB+2jwqTIGzxw8VfKU2EXym6fAXISewb0haR3Gnv0OuVfMDcuM/gPA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796031620;
	h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding;
	bh=CGu53c5/XkXhrIcNXVwyQTXK9ix0NZPKTLryfO4P7v4=;
	b=QAqXexEsDRjsVHYU1X80G6x2Ybck44WxG/Ga29IfX7hNjS8zY8XZMkZzHDvTOLITBNCz
	 iUqg+8dRj8E1vu5tZe+9jELepHFP+mCNg5n+fA1bzSO/TIBuNzxcUy8O5VFraWkZXmDGk
	 xMi6gtvl+F6ZzV98MYBJxJeHQXgGpoAq1bvBDt1JEEtDohi/bG1RVpjD+nuRUH7q2vZyi
	 KGyO+093RNZgl8/wPluemHwGt+UZKBydTtxE09TrBM3fNbX3QLnnh/mUYFq2NSPeMlnvS
	 9GcNlAU/Fz+ca3wEYjwN7s6gVGmEJNhVhzLpqH+HFcOKsZssXXVyw9zRuSSCIlBAnhw==
X-ARC-Authentication-Results: i=2; 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=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 44CFC606A334;
	Mon, 30 Nov 2026 09:40:20 +0000 (UTC)
X-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
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-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==
X-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==
X-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
X-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)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CC411F008A0;
	Mon, 30 Nov 2026 09:40:10 +0000 (UTC)
X-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==
X-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>
X-Mailer: git-send-email 2.43.0
X-In-Reply-To: <20261130094000.2022376-1-hawk@kernel.org>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list