Article View: linux.kernel.netdev
Article #18261[PATCH net-next v4 3/4] nexthop: release cached routes when a nexthop leaves a group
From: Qiliang Yuan
Date: Wed, 18 Nov 2026 02:28
Date: Wed, 18 Nov 2026 02:28
69 lines
11199 bytes
11199 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 1140 (367-3788) 1 (1-3) -99.9%
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:
<20261117-bug-net-netns-move-rcu-barrier-v4-3-43e1ca0aac7f@linux.dev>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365817-linux-kernel-netdev=dewy.ruReferences:
<20261117-bug-net-netns-move-rcu-barrier-v4-0-43e1ca0aac7f@linux.dev>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365817-linux-kernel-netdev=dewy.ru From: qiliang.yuan@linux.dev (Qiliang Yuan) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next v4 3/4] nexthop: release cached routes when a nexthop leaves a group Date: Tue, 17 Nov 2026 21:28:32 -0500 Organization: Usenet Network Message-ID: <20261117-bug-net-netns-move-rcu-barrier-v4-3-43e1ca0aac7f@linux.dev> References: <20261117-bug-net-netns-move-rcu-barrier-v4-0-43e1ca0aac7f@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2483785"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:RvrbON/LiFu+uV/iv9LQj3IVL2M= sha256:QNYLV7f1C8IXiHIK9YlW8nLlAFkD0I5xjRZ4yo77dio= sha1:L/kl4Ox3OJFC4l0fwO8s0PjoZXw= sha256:IR87T79h8JYwSR3B5gex7jUZ96Zf9qiawemcU3nnXQs= 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 4F2E911515B; Wed, 18 Nov 2026 05:29:39 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.05 X-Spam-Status: No, score=-3.05 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, URIBL_BLOCKED=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 kJx5F2OMpNuw; Wed, 18 Nov 2026 05:29:35 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-365817-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 57F8E115154; Wed, 18 Nov 2026 05:29:25 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id EB4904439E; Wed, 18 Nov 2026 02:29:12 +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=1794968952; b=Ih+KOSSYF/SXrqXnxaoa5YNwjQbu4V3rraTPgPzLNIWLDCBGfhsRKeoHcZ5Rtnb9pQ6v J67X2YV4oU179QYBSdXroxDOinmc6d0PDZLe9T2gatAfcl4RfMTs6S2/3R8g6BrgUTyE+ /+KRghstyMWewIt41UTZnbdxLIrh8CTzwOsw6BQAJiKyE/LmqjqqXceAAKxp6vsAr+NBp /SamrD1uLZYyT+AnS8IjwHJ6InIFjj1JjSdwKER5GfdqPi+jMmV0rk1XnHBLo+lQBjbsI lT9zDFvJBPrZtVeaE5h17M5lVwUatiNxbqb6H/8/b7Zdu0k0wdVNUJlsaB55D4r4BCw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794968952; 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=cPxS1SkmvsscQRV5MYIa8akRylBV+jAccSMpvpxeFnk=; b=WYn7xtFsod/cMwrsto/OWBpqOwZ/QB9kJN+VxeZUSqaLlH7cX/Ck8VTFZxG30WIETid0 vvdAi238Ae2b6ERogcrp1yCc1jHwsHHkAdGFYYd783omAE5bx3hDHcEGwGm2X77MOeWTz tTZVPaj5LJ6/zd0LHmaDOeuX4h8OyOczIpI7cLp1BMYO90yk8HDjzl53hqisO8IvYedIP z9L8yPObVrPzcICTFulcFFVvETaDD8mP/hJ7y3qP+m0lUDSfg7KZso1d3iI5/ZdTdsZhZ /97wwpO1ffgpg5CMs81irYLcVzEs5rB7ap5Xzikm0OajiieLpUkQ6XzstyOmMGc5ARQ== 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=no5g0K7t; 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 A06E6606A339; Wed, 18 Nov 2026 02:29:12 +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=no5g0K7t X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.137 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794968951; b=BgPzfCGbDCnFRglui+EBclQ1KioZSVmaAuIwLrNVUViuuN2FoGvay7ZqJ08aP2GOsZok E+q9x+Zlne1U4e0FOfMahq4vp1kEFj6p7j6KpV4i4dwpVW/sKBelJGeAD9c/Pk8/rksre R1LD1hnhrvd1YKvlMjX5ylYTiwysYsovMr7M8b3UU9tqVDE0e4GKVw37SNiVdIxw/hovz y+nWuVnjEcc4YYzUvbJ2eaHPGJtjg6loIDtXa24CB+Ly/2Jen0rK0w6UQ0pVRti/TwF0w 84x+AEs+tBoXJBp5cb/s0otNtdQmvuKj4XCnkG2OWsqYtSsfjW52FHsLqSXRSSHPZTw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794968951; 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=cPxS1SkmvsscQRV5MYIa8akRylBV+jAccSMpvpxeFnk=; b=a9PiZGHFDf+Wg3RhurSONjJJ72fYsrDOrEyOWJGj99yzy9oeXr3xd0nKjD1bLWGJr8E/ 5gbt7o+5D9uabYfthqnrmuLGu2KdvKV5FNReKH9C6msHpRXYpGNGN7nZqqtG/q4cIr+0n ecas6V7g3sc57CNYRLwoG2SuCkhJmFLH6mTskXRNzL9VXS6UCe/LRGNDYeRklX4tsKcVa lMW7Gwc7MCUJpxQyrysW6s6cuKRejU/QTfDhTQKoGiZnnU5LSOkzGyfZLOGYJQZ6+FX8v 1DtgIShHpCNqSqO2WW9/bdjqJ6EgEgI58OkgRJNTLnK1HcLbFGErt0mLgn/3/2Vgmlw== 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=no5g0K7t; arc=none smtp.remote-ip=95.215.58.137 X-Received: from mta1.migadu.com (out-137.mta1.migadu.com [95.215.58.137]) (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 DBC8F606A325 for <netdev@vger.kernel.org>; Wed, 18 Nov 2026 02:29:10 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DBC8F606A325 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=j8FO9OwvBDhGPbMXs2woLTjOBZA6uj/qJHh1sSWVpWM=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1794968949; v=1; x=1795573749; b=no5g0K7tHxBWwUm3C9JV9oF1vpaT4TWbGOOTottJnqjyQP7uXYxQZ6UZ4jlcDVP8IAeQLvi4 Qw0EpSfNPdE+HYMVct2GrjFItHi6LPHNYBz/+CM79xv2dIrK6TMxPjAzPU9h0Wd3jKvzDliz75k GEBYDKxeJ7mYlJtdZraJGVmc= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id 5391049313abef4a; Wed, 18 Nov 2026 02:29:09 +0000 X-Mizu-Trace-ID: 5391049313abef4a 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: <20261117-bug-net-netns-move-rcu-barrier-v4-0-43e1ca0aac7f@linux.dev> X-Cc: Kuniyuki Iwashima <kuniyu@google.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Qiliang Yuan <qiliang.yuan@linux.dev> X-Mailer: b4 0.13.0