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=1796031618; b=vr+/ie8QblrNUZsj9EudtEEtWlyQaHlqX62EUsXZ4WLV/xsnonPjuD/NYAFklgUYSzPs TZqSbrR7GD3I8Qec30q50kbeyqnOypw+t9MqJD/7gwmz9oa2c8CJjMzctHLhDcJ4jDvOv ArRGkA7oBlJLG3lYY9PIxtzL1clnFXe69YYwuvd+6XPaw1garq2lqbHP182g0U6JlymzW 5NMs4qGkqvVHMsJMOLL7aD0vDSXjcTElf+tlYRIpSiVEBmRha9U7Zqy7v/lAcnKbKT9jY 0WuWrY/8UnWVbQO53vwOnc89sHjFTHeXYVWT6PqucBCVjkyIkKy7XvuknfTjXFmhCAw== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97E371F00897; Mon, 30 Nov 2026 09:40:14 +0000 (UTC) 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== 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 3/3] veth: order rx_notify_masked store in the veth_poll() re-arm path Date: Mon, 30 Nov 2026 10:40:00 +0100 Message-ID: <20261130094000.2022376-4-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: Jesper Dangaard Brouer 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 --- 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