Article View: linux.kernel.netdev
Article #24538[PATCH net 3/3] veth: order rx_notify_masked store in the veth_poll() re-arm path
From: hawk
Date: Mon, 30 Nov 2026 09:40
Date: Mon, 30 Nov 2026 09:40
100 lines
11661 bytes
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
Technical Details
Message-ID:
<20261130094000.2022376-4-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-374078-linux-kernel-netdev=dewy.ruReferences:
<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-374078-linux-kernel-netdev=dewy.ru From: hawk@kernel.org Newsgroups: linux.kernel.netdev Subject: [PATCH net 3/3] veth: order rx_notify_masked store in the veth_poll() re-arm path Date: Mon, 30 Nov 2026 10:40:00 +0100 Organization: Usenet Network Message-ID: <20261130094000.2022376-4-hawk@kernel.org> References: <20261130094000.2022376-1-hawk@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1395301"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:bpJWYeLmMuDHOZNKmWF7GLIF9eI= sha256:K9Hi9vsdDf414zuH7k/hg0oVuxb9fqtlVbtBXfrsEhU= sha1:yPAzeCUbiet+njuSNN+T9/bWHVY= sha256:dumlq33iD70cpXXNsQCh0ihYxukTmYZGdII/9G6UZ5c= 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 AF64A125FD2; 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 acWRDlVKhlkY; 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-374078-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 86FB4125FD5; Mon, 30 Nov 2026 12:40:27 +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 23DF823485; Mon, 30 Nov 2026 09:40:24 +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=1796031624; b=tr+zbeI/SHmBr/+cyVEmCgL+c0Nj346D6DDuHAUgQBTTx9rJ04PuMm4+aPfoo+HVVWgR fcuPHNMNnAV/g7FFGDMghelXBVCIX5mCKixzNTj83gUQgFUK/34Fe4+L4JPA4YTAsscMw ghEEvyYZ0rEm8aDGVH7EB+jyE5QJLZfJz0gpeAT5TbOKB9q/n76uD6xAmJmO2fXM1H1nv SEks72a1r12khucNbvOSOrEbafZVBY+BH5lIxhv6LPqThxwBrkqRvS9uM8d54gNRfAcm1 tuJtr/MwdN7fZpK+Eo/tL7+moV1j6l6EFbNrazlQBlb8ki1nUunaPO7rS+5Y3rVqZxg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796031624; 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=O5crPKc58BajUv/xf7URTgDl9j4EfyVk4NGq4Tk7/Xo=; b=qa5hckk27C9vpDSZPxS6dO90kgf4n/VN5Abg7/xKDetxjXXHDZMHmaKnH1z8HPxakJEn OvuYEscW7RKMLDQI6udM9A/taFoIyUW9jFsY5NX2mpmvueVMghLJRC4vMLzNawuumGukJ q5WAykvVnYzRPsalAG+J1GyaHdy3eLCqtwejUCeMCSxv1d8vIz37wHOf1DLglU76coWc0 PSsn3vvCMa4oUyjswN+bk2l1ILj/UVZWsuCCMpJT0u/iLrdUMSHvwGY474rJMvr9gz77B QHbRTW+eZt7Se7AQE3UVt+KlRWzfUBYMFGGKfp41qFubJxT546OQEeXYlet8XkjTNHQ== 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=DVIHj+Tf; 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 74FAF606A32D; Mon, 30 Nov 2026 09:40:24 +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=DVIHj+Tf 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=1796031618; b=vr+/ie8QblrNUZsj9EudtEEtWlyQaHlqX62EUsXZ4WLV/xsnonPjuD/NYAFklgUYSzPs TZqSbrR7GD3I8Qec30q50kbeyqnOypw+t9MqJD/7gwmz9oa2c8CJjMzctHLhDcJ4jDvOv ArRGkA7oBlJLG3lYY9PIxtzL1clnFXe69YYwuvd+6XPaw1garq2lqbHP182g0U6JlymzW 5NMs4qGkqvVHMsJMOLL7aD0vDSXjcTElf+tlYRIpSiVEBmRha9U7Zqy7v/lAcnKbKT9jY 0WuWrY/8UnWVbQO53vwOnc89sHjFTHeXYVWT6PqucBCVjkyIkKy7XvuknfTjXFmhCAw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796031618; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=O5crPKc58BajUv/xf7URTgDl9j4EfyVk4NGq4Tk7/Xo=; b=V6WC6vLV5j6dj+QwXcY120vKM1oUUR+0jM3YODC6aMhN4wL53KhGKL0obyjnJ0LKr4zz sVon6TBeYFLnGfcx1eXf4zvH24Hh1xjg93RkTNW3+rJqReLxXdW9ocWOnV1XQ+uMToCBZ h4LDFIUapsCgVyhG1hkaEFsUivNNDSA5EljeLs/KR3pfVmggmVl+LIckbdCUKKg1+9O+x ZyNeDjv+5HATZV4E3t3tQ+1bYTanfs9HTOW9iuk2BnKVHVHxowqd3ATKzOO6PDFB67JaL 0XUOkmuvTFaq8z7KYgO9SD5PrX+kMBHeYtuj9yaZ3QmzHun+sgog656+BZ6WagbWicg== 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=DVIHj+Tf; 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 91334606A325; Mon, 30 Nov 2026 09:40:18 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97E371F00897; Mon, 30 Nov 2026 09:40:14 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796031617; bh=O5crPKc58BajUv/xf7URTgDl9j4EfyVk4NGq4Tk7/Xo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DVIHj+TfGTDihlQxLAIfr9qSINEm2qd8z/GbVvj9gzeqVspqrP0i7MdsyYQoJDBfG +0pTXg8KPyYLIg6IdFUDQ4DuXCkjBxC3JDIM0v2uTq5S3vLSVSTzkcm++1rY65C7aa KoOTZ7ZcOwnxtT9smIwsXT+a7jyKJDW9pAQzDAqCQTurU23SUgUhPESVPWDhdUUxQr pNi/zQvwFVa652U4pkic6X/N8i+PYdRLdPn9amOJ/SGfUSePQ5RibW+hDUy9BVcZPL CYhhUtPMcB7LSnrX/QWwY9TCLWTeYI8cNyPE5QsSn1I0g2USA5XH0dJNE1TBnxs8HF 3pp5rSxB/vsbw== 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