Article View: linux.kernel.netdev
Article #20283[PATCH net-next v5 3/4] nexthop: release cached routes when a nexthop leaves a group
From: Qiliang Yuan
Date: Sat, 21 Nov 2026 23:21
Date: Sat, 21 Nov 2026 23:21
69 lines
11164 bytes
11164 bytes
When a nexthop is removed while other members keep its group alive, only
the group array changes: the routes through the group stay in the FIB,
and the dsts they cached through the removed nexthop are released when
that nexthop is freed, from an RCU callback.
Until then those dsts stay valid. IPv6 route exceptions, such as the
ones created on Packet Too Big, are checked against the cookie of their
FIB node, which does not change, so a socket keeps sending through the
removed nexthop. When the nexthop goes away with its device, removing
the device's IPv6 addresses usually flushes the routing tree first, but
not when the device carries no IPv6 address.
Once all readers see the new group arrays, release the per-cpu routes and
exceptions of a removed IPv6 nexthop, as replacing a group already does
for its old members, and flush the IPv4 route cache once if any of the
groups carries IPv4 routes. The routes using the nexthop directly are
already gone at that point.
A connected UDP socket in netns A sends to a route through group {nh 1,
nh 2}, on an IPv6 exception of nh 1 created by Packet Too Big, while nh 1
is deleted. Datagrams still sent through nh 1 after the new group is
published and before nh 1 is freed, 10 trials, median and range, the
ones left after the change being sent before the dsts are released:
before (datagrams) after (datagrams) change
per trial 2832 (390-3805) 1 (1-6) -99.96%
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
net/ipv4/nexthop.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index 42e55b5a755ee..3fccd4f2f916b 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -2116,6 +2116,7 @@ remove_nexthop_from_groups(struct net *net, struct nexthop *nh,
struct nh_grp_entry *nhge, *tmp;
LIST_HEAD(deferred_free);
bool need_flush = false;
+ struct nh_info *nhi;
/* If there is nothing to do, let's avoid the costly call to
* synchronize_net()
@@ -2130,6 +2131,20 @@ remove_nexthop_from_groups(struct net *net, struct nexthop *nh,
/* make sure all see the newly published array before releasing rtnl */
synchronize_net();
+ /* Routes through the groups can still hold dsts cached through @nh,
+ * which are only released when @nh is freed. Release them now that
+ * no reader can pick @nh from the old groups any more.
+ */
+ nhi = rtnl_dereference(nh->nh_info);
+ if (nhi->family == AF_INET6)
+ fib6_nh_release_dsts(&nhi->fib6_nh);
+ list_for_each_entry(nhge, &deferred_free, nh_list) {
+ if (!list_empty(&nhge->nh_parent->fi_list)) {
+ rt_cache_flush(net);
+ break;
+ }
+ }
+
/* Now safe to free percpu stats — all RCU readers have finished */
list_for_each_entry_safe(nhge, tmp, &deferred_free, nh_list) {
list_del(&nhge->nh_list);
--
2.43.0
Technical Details
Message-ID:
<20261121-bug-net-netns-move-rcu-barrier-v5-3-100a3b5d9090@linux.dev>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-368517-linux-kernel-netdev=dewy.ruReferences:
<20261121-bug-net-netns-move-rcu-barrier-v5-0-100a3b5d9090@linux.dev>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-368517-linux-kernel-netdev=dewy.ru From: qiliang.yuan@linux.dev (Qiliang Yuan) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next v5 3/4] nexthop: release cached routes when a nexthop leaves a group Date: Sat, 21 Nov 2026 18:21:21 -0500 Organization: Usenet Network Message-ID: <20261121-bug-net-netns-move-rcu-barrier-v5-3-100a3b5d9090@linux.dev> References: <20261121-bug-net-netns-move-rcu-barrier-v5-0-100a3b5d9090@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3520481"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:ExZqz4DLmyUBWTVshbIWbM0gpAc= sha256:dGRampbEgZBrlI5v2cp27eYlhOEnKOgyDHddXxPOoxY= sha1:19KNXb+NOvd6W6QRFI9cxb6/MVg= sha256:Yx9WeR+TY2xbt9Owdr1mOyhF8u4/LC1ysE8G6Gxx8gs= 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 CAEFC116025; Sun, 22 Nov 2026 02:22:06 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.051 X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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 (1024-bit key) header.d=linux.dev 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 I8xviYPoit5g; Sun, 22 Nov 2026 02:22:04 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-368517-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 6EB1D115C30; Sun, 22 Nov 2026 02:21:54 +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 95DC529037; Sat, 21 Nov 2026 23:21:52 +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=1795303310; b=3i8gewh20t1BLi8oVgnst7zAtnGEjRGtlpSOj5JhGvEARg9evMAJ4iEaVBlSLpp0v9Dt Qv9R2IUFWP5FlVBmw/3iBGn59ys7djnyy4ff7AofHtTmryScUZmgPvoU86+6N2BXLtKeD 7JO22htGV69LMVRvjyzt2GNxxxDM6pH9Wtlz2wP6kvPGbn/FN3tIkI8eTm5Xj34yeMNT0 Rop1QQVIzuHwGfYfHOTiFzwG6xR52kFcxRZ3c5MRHkPk90nf4GpozCx1gYonR5y2sYuCx 9Ap+1ncwVPrne3g+NVG5+STzt0NhFjCTPdAnw8BfplKpMCJyyecRjey5hPbiwmn2/1Q== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795303310; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:From:Date: Subject:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer; bh=CeRmkXb4PaO+jzA+zVIO/f6aAfAmNuevRYNzWo5MlYc=; b=LYyRfgJ4jBi2PJDcBqFdF5a4soJWhzVos5ZjCYeD1hh2cdADUSuyEjJXn2AahGQI3zPq Kvr3xyYC9GKRAWEcRG/CPYyBRKBgE3D1XyK3fzxyOBS2DoeoZRnsijNjki/p8+eAs8IZn ABt//D2HXjHxPeqIHIGyq8l0SetDlYg5dOByDWFj+hsRpxRKuoMOOvigOIJ5GYWoG1Unx c+vSvmrhjCJypIE7PF97ztDpIw/OTYYxnn6/sWWuNBcyZCOFqyvmC3uYJLXj+ObS0E86q 1WHBbD5k8sH+QHJFQNRs55ojZYP1CTctqE0J3RBy16phXjgQy0SmCrT002Zj97cKRpw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=NMw2xf2q; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; 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 06E1D606A333; Sat, 21 Nov 2026 23:21:50 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=NMw2xf2q X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.33 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795303309; b=zCx5PEkFM2hsHIJwwHDSEj8aoX/swlBe69Vk+7Vr/aaKnJr6hGRv4HJbkKlL2CJ5gwKj b4APUpLyZ6EkOn1DUxD33dU8LodMu9KWwt6Nt9NGQCOL3d3NJvGwWnuTZmqMY5oBzXP2e iIIWoTeQXj2eojLBkdJei3Tlbrb3vmgMlvg62CkwYrw5Cg1jHWltW/dUvjWLeLVpOzhcq OQ4v+M+kZaP3VLZCWVH4dt3o5Dv2k9gNaPlO49SSM1zwWjiM8Ej3ks0WvP3y6yKPtHD7L q2jA+Zs6ncCyNuQPW0/n+Rcbf6BYyVQxppm6z87d1243L1W9z66IMbs40RPVv08ilhw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795303309; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer; bh=CeRmkXb4PaO+jzA+zVIO/f6aAfAmNuevRYNzWo5MlYc=; b=kDzsoy7CnLMwzl6oVxNSDR0dZ16XkEd+CeOe5fL5YOoCMRZNOxEhTInBV6vmpQ9El3/h 6KzHizBqgKJN4oRaqwmltQl82apiY9TvUjJaXOG1Lb6b5CR8qam+CCuc4rhR0RqNIIZA2 xaAPaxslaVQh3UzIZKITPAz7ElfzV3fhnjL9Qv7WcjX0lilJ9hACPGdjoZL6v5bJGAyyY QDjmUZgqkpvsVue9EpIp8XrmTR3BZ5pTOLqd39vibFr67nt+z4ZTUX/XeeQh5jTtGkham q3EwQ8xec8ad9cP16ViVj66Vg5MUMbyf/6ht/2aT3c7u997J1OScPfIimh7PJAqqJHg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=NMw2xf2q; arc=none smtp.remote-ip=91.218.175.33 X-Received: from mta0.migadu.com (out-33.mta0.migadu.com [91.218.175.33]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85E97606A330 for <netdev@vger.kernel.org>; Sat, 21 Nov 2026 23:21:48 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 85E97606A330 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=hm61AzN/MAJszg1nQNhYCz6kJuFkbVQtftEGzmQdmDk=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795303306; v=1; x=1795908106; b=NMw2xf2qjvWfL8XJKyJwUglsH9z+WHrBF+WPQ7ioM8bXKF9ohNkRGLXbUZMGAPZjZ+k1s6PJ l+x2JTkZcobUGfKZRdSlp3BX6xb861/HXqRmQs1GNfJ1Wl4V4PYuyXFlbsmGl+j0oaRX5lKymjl ZkR67yLY6WvkcPztZ3wmPmiQ= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id 21ba8d938a5604e2; Sat, 21 Nov 2026 23:21:46 +0000 X-Mizu-Trace-ID: 21ba8d938a5604e2 X-Migadu-Flow: FLOW_OUT 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 X-In-Reply-To: <20261121-bug-net-netns-move-rcu-barrier-v5-0-100a3b5d9090@linux.dev> X-Cc: Kuniyuki Iwashima <kuniyu@google.com>, Ralf Lici <ralf@mandelbit.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Qiliang Yuan <qiliang.yuan@linux.dev> X-Mailer: b4 0.13.0