ipv6: Fix two GC issues with permanent routes
Subsystems (3)
v2 cover ipv6: Fix two GC issues with permanent routes
Patch 1 fixes the unbounded growth of tb6_gc_hlist due to permanent routes whose exception routes have all expired.
Patch 2 fixes an issue where exception routes tied to permanent routes are not properly aged.
Changes:
v2:
Patch 2: Fix build failure when CONFIG_IPV6=n (no net->ipv6 definition)
v1: https://lore.kernel.org/netdev/[email protected]/
Kuniyuki Iwashima (2):
ipv6: Remove permanent routes from tb6_gc_hlist when all exceptions
expire.
ipv6: Don't remove permanent routes with exceptions from tb6_gc_hlist.
include/net/ip6_fib.h | 19 ++++++++++++++++++- net/ipv6/addrconf.c | 4 ++-- net/ipv6/ip6_fib.c | 15 +++++++++++++-- net/ipv6/route.c | 2 +- 4 files changed, 34 insertions(+), 6 deletions(-)
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
PATCH v2 1/2 ipv6: Remove permanent routes from tb6_gc_hlist when all exceptions expire.
Commit 5eb902b8e719 ("net/ipv6: Remove expired routes with a separated list of routes.") introduced a per-table GC list and changed GC to iterate over that list instead of traversing the entire route table.
However, it forgot to add permanent routes to tb6_gc_hlist when exception routes are added.
Commit cfe82469a00f ("ipv6: add exception routes to GC list in rt6_insert_exception") fixed that issue but introduced another one.
Even after all exception routes expire, the permanent routes remain in tb6_gc_hlist, potentially negating the performance benefits intended by the initial change.
Let's count gc_args->more before and after rt6_age_exceptions() and remove the permanent route when the delta is 0.
Note that the next patch will reuse fib6_age_exceptions().
--- net/ipv6/ip6_fib.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
net/ipv6/ip6_fib.c +12 -1
@@ -2348,6 +2348,17 @@ static void fib6_flush_trees(struct net *net)/* * Garbage collection */ +static void fib6_age_exceptions (struct fib6_info *rt,struct fib6_gc_args *gc_args, +unsigned long now) +{ +bool may_expire = rt->fib6_flags &RTF_EXPIRES && rt->expires; +int old_more = gc_args->more; + +rt6_age_exceptions (rt, gc_args, now); + +if (!may_expire && old_more == gc_args->more) +fib6_remove_gc_list (rt); +}static int fib6_age (struct fib6_info *rt,struct fib6_gc_args *gc_args) {
@@ -2370,7 +2381,7 @@ static int fib6_age(struct fib6_info *rt, struct fib6_gc_args *gc_args)* Note, that clones are aged out * only if they are not in use now. */ -rt6_age_exceptions (rt, gc_args, now); +fib6_age_exceptions (rt, gc_args, now);return 0 ; }
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
PATCH v2 2/2 ipv6: Don't remove permanent routes with exceptions from tb6_gc_hlist.
In reply to Kuniyuki IwashimaThe cited commit mechanically put fib6_remove_gc_list() just after every fib6_clean_expires() call.
When a temporary route is promoted to a permanent route, there may already be exception routes tied to it.
If fib6_remove_gc_list() removes the route from tb6_gc_hlist, such exception routes will no longer be aged.
Let's replace fib6_remove_gc_list() with a new helper fib6_may_remove_gc_list() and use fib6_age_exceptions() there.
---
v2: Fix build failure when CONFIG_IPV6=n (no net->ipv6 definition)
--- include/net/ip6_fib.h | 19 ++++++++++++++++++- net/ipv6/addrconf.c | 4 ++-- net/ipv6/ip6_fib.c | 6 +++--- net/ipv6/route.c | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-)
include/net/ip6_fib.h +18 -1
@@ -507,12 +507,14 @@ void fib6_rt_update(struct net *net, struct fib6_info *rt,void inet6_rt_notify (int event,struct fib6_info *rt,struct nl_info *info,unsigned int flags); +void fib6_age_exceptions (struct fib6_info *rt,struct fib6_gc_args *gc_args, +unsigned long now);void fib6_run_gc (unsigned long expires,struct net *net,bool force); -void fib6_gc_cleanup (void );int fib6_init (void ); +#ifdef CONFIG_IPV6 /* Add the route to the gc list if it is not already there * * The callers should hold f6i->fib6_table->tb6_lock.
@@ -545,6 +547,21 @@ static inline void fib6_remove_gc_list(struct fib6_info *f6i)hlist_del_init (&f6i->gc_link); } +static inline void fib6_may_remove_gc_list (struct net *net, +struct fib6_info *f6i) +{ +struct fib6_gc_args gc_args; + +if (hlist_unhashed (&f6i->gc_link)) +return ; + + gc_args.timeout =READ_ONCE (net->ipv6.sysctl.ip6_rt_gc_interval), + gc_args.more =0 , + +fib6_age_exceptions (f6i, &gc_args, jiffies); +} +#endif +struct ipv6_route_iter {struct seq_net_private p;struct fib6_walker w;
net/ipv6/addrconf.c +2 -2
@@ -2862,7 +2862,7 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)fib6_add_gc_list (rt); }else {fib6_clean_expires (rt); -fib6_remove_gc_list (rt); +fib6_may_remove_gc_list (net, rt); }spin_unlock_bh (&table->tb6_lock);
@@ -4840,7 +4840,7 @@ static int modify_prefix_route(struct net *net, struct inet6_ifaddr *ifp,if (!(flags &RTF_EXPIRES )) {fib6_clean_expires (f6i); -fib6_remove_gc_list (f6i); +fib6_may_remove_gc_list (net, f6i); }else {fib6_set_expires (f6i, expires);fib6_add_gc_list (f6i);
net/ipv6/ip6_fib.c +3 -3
@@ -1133,7 +1133,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt,return -EEXIST ;if (!(rt->fib6_flags &RTF_EXPIRES )) {fib6_clean_expires (iter); -fib6_remove_gc_list (iter); +fib6_may_remove_gc_list (info->nl_net, iter); }else {fib6_set_expires (iter, rt->expires);fib6_add_gc_list (iter);
@@ -2348,8 +2348,8 @@ static void fib6_flush_trees(struct net *net)/* * Garbage collection */ -static void fib6_age_exceptions (struct fib6_info *rt,struct fib6_gc_args *gc_args, -unsigned long now) +void fib6_age_exceptions (struct fib6_info *rt,struct fib6_gc_args *gc_args, +unsigned long now) {bool may_expire = rt->fib6_flags &RTF_EXPIRES && rt->expires;int old_more = gc_args->more;
net/ipv6/route.c +1 -1
@@ -1033,7 +1033,7 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,if (!addrconf_finite_timeout (lifetime)) {fib6_clean_expires (rt); -fib6_remove_gc_list (rt); +fib6_may_remove_gc_list (net, rt); }else {fib6_set_expires (rt, jiffies +HZ * lifetime);fib6_add_gc_list (rt);
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
kernel test robot
build botRe: [PATCH v2 net 2/2] ipv6: Don't remove permanent routes with exceptions from tb6_gc_hlist.
kernel test robot noticed the following build errors:
Hi Kuniyuki,
kernel test robot noticed the following build errors:
[auto build test ERROR on net/main]
url: https://github.com/intel-lab-lkp/linux/commits/Kuniyuki-Iwashima/ipv6-Remove-permanent-routes-from-tb6_gc_hlist-when-all-exceptions-expire/20260308-113030 base: net/main patch link: https://lore.kernel.org/r/20260308032304.1841198-3-kuniyu%40google.com patch subject: [PATCH v2 net 2/2] ipv6: Don't remove permanent routes with exceptions from tb6_gc_hlist. config: nios2-allmodconfig (https://download.01.org/0day-ci/archive/20260308/[email protected]/config) compiler: nios2-linux-gcc (GCC) 11.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260308/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
net/ipv6/addrconf.c: In function 'cleanup_prefix_route':
>> net/ipv6/addrconf.c:1282:33: error: implicit declaration of function 'fib6_add_gc_list' [-Werror=implicit-function-declaration]
1282 | fib6_add_gc_list(f6i);
| ^~~~~~~~~~~~~~~~
net/ipv6/addrconf.c: In function 'addrconf_prefix_rcv':
>> net/ipv6/addrconf.c:2865:41: error: implicit declaration of function 'fib6_may_remove_gc_list' [-Werror=implicit-function-declaration]
2865 | fib6_may_remove_gc_list(net, rt);
| ^~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
--
net/ipv6/route.c: In function 'rt6_route_rcv':
>> net/ipv6/route.c:1036:25: error: implicit declaration of function 'fib6_may_remove_gc_list' [-Werror=implicit-function-declaration]
1036 | fib6_may_remove_gc_list(net, rt);
| ^~~~~~~~~~~~~~~~~~~~~~~
>> net/ipv6/route.c:1039:25: error: implicit declaration of function 'fib6_add_gc_list' [-Werror=implicit-function-declaration]
1039 | fib6_add_gc_list(rt);
| ^~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
--
net/ipv6/ip6_fib.c: In function 'fib6_purge_rt':
>> net/ipv6/ip6_fib.c:1073:9: error: implicit declaration of function 'fib6_remove_gc_list' [-Werror=implicit-function-declaration]
1073 | fib6_remove_gc_list(rt);
| ^~~~~~~~~~~~~~~~~~~
net/ipv6/ip6_fib.c: In function 'fib6_add_rt2node':
>> net/ipv6/ip6_fib.c:1136:41: error: implicit declaration of function 'fib6_may_remove_gc_list' [-Werror=implicit-function-declaration]
1136 | fib6_may_remove_gc_list(info->nl_net, iter);
| ^~~~~~~~~~~~~~~~~~~~~~~
>> net/ipv6/ip6_fib.c:1139:41: error: implicit declaration of function 'fib6_add_gc_list' [-Werror=implicit-function-declaration]
1139 | fib6_add_gc_list(iter);
| ^~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
--
net/ipv6/ndisc.c: In function 'ndisc_router_discovery':
>> net/ipv6/ndisc.c:1405:17: error: implicit declaration of function 'fib6_add_gc_list' [-Werror=implicit-function-declaration]
1405 | fib6_add_gc_list(rt);
| ^~~~~~~~~~~~~~~~cc1: some warnings being treated as errors
vim +/fib6_add_gc_list +1282 net/ipv6/addrconf.c
5b84efecb7d939 Thomas Haller 2014-01-15 1262
5b84efecb7d939 Thomas Haller 2014-01-15 1263 static void
d0098e4c6b83e5 Hangbin Liu 2020-03-03 1264 cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires,
d0098e4c6b83e5 Hangbin Liu 2020-03-03 1265 bool del_rt, bool del_peer)
5b84efecb7d939 Thomas Haller 2014-01-15 1266 {
5eb902b8e7193c Kui-Feng Lee 2024-02-08 1267 struct fib6_table *table;
93c2fb253d177a David Ahern 2018-04-18 1268 struct fib6_info *f6i;
5b84efecb7d939 Thomas Haller 2014-01-15 1269
d0098e4c6b83e5 Hangbin Liu 2020-03-03 1270 f6i = addrconf_get_prefix_route(del_peer ? &ifp->peer_addr : &ifp->addr,
d0098e4c6b83e5 Hangbin Liu 2020-03-03 1271 ifp->prefix_len,
2b2450ca4a2d9d David Ahern 2019-03-27 1272 ifp->idev->dev, 0, RTF_DEFAULT, true);
93c2fb253d177a David Ahern 2018-04-18 1273 if (f6i) {
5b84efecb7d939 Thomas Haller 2014-01-15 1274 if (del_rt)
11dd74b338bf83 Roopa Prabhu 2020-04-27 1275 ip6_del_rt(dev_net(ifp->idev->dev), f6i, false);
5b84efecb7d939 Thomas Haller 2014-01-15 1276 else {
5eb902b8e7193c Kui-Feng Lee 2024-02-08 1277 if (!(f6i->fib6_flags & RTF_EXPIRES)) {
5eb902b8e7193c Kui-Feng Lee 2024-02-08 1278 table = f6i->fib6_table;
5eb902b8e7193c Kui-Feng Lee 2024-02-08 1279 spin_lock_bh(&table->tb6_lock);
5eb902b8e7193c Kui-Feng Lee 2024-02-08 1280
93c2fb253d177a David Ahern 2018-04-18 1281 fib6_set_expires(f6i, expires);
5eb902b8e7193c Kui-Feng Lee 2024-02-08 @1282 fib6_add_gc_list(f6i);
5eb902b8e7193c Kui-Feng Lee 2024-02-08 1283
5eb902b8e7193c Kui-Feng Lee 2024-02-08 1284 spin_unlock_bh(&table->tb6_lock);
5eb902b8e7193c Kui-Feng Lee 2024-02-08 1285 }
93c2fb253d177a David Ahern 2018-04-18 1286 fib6_info_release(f6i);
5b84efecb7d939 Thomas Haller 2014-01-15 1287 }
5b84efecb7d939 Thomas Haller 2014-01-15 1288 }
5b84efecb7d939 Thomas Haller 2014-01-15 1289 }
5b84efecb7d939 Thomas Haller 2014-01-15 1290 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v2 net 2/2] ipv6: Don't remove permanent routes with exceptions from tb6_gc_hlist.
In reply to Kuniyuki Iwashimakernel test robot noticed the following build errors:
Hi Kuniyuki,
kernel test robot noticed the following build errors:
[auto build test ERROR on net/main]
url: https://github.com/intel-lab-lkp/linux/commits/Kuniyuki-Iwashima/ipv6-Remove-permanent-routes-from-tb6_gc_hlist-when-all-exceptions-expire/20260308-113030 base: net/main patch link: https://lore.kernel.org/r/20260308032304.1841198-3-kuniyu%40google.com patch subject: [PATCH v2 net 2/2] ipv6: Don't remove permanent routes with exceptions from tb6_gc_hlist. config: sparc64-allmodconfig (https://download.01.org/0day-ci/archive/20260308/[email protected]/config) compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project c32caeec8158d634bb71ab8911a6031248b9fc47) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260308/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> net/ipv6/addrconf.c:1282:5: error: call to undeclared function 'fib6_add_gc_list'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
1282 | fib6_add_gc_list(f6i);
| ^
net/ipv6/addrconf.c:2862:6: error: call to undeclared function 'fib6_add_gc_list'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2862 | fib6_add_gc_list(rt);
| ^
>> net/ipv6/addrconf.c:2865:6: error: call to undeclared function 'fib6_may_remove_gc_list'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2865 | fib6_may_remove_gc_list(net, rt);
| ^
net/ipv6/addrconf.c:4843:4: error: call to undeclared function 'fib6_may_remove_gc_list'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
4843 | fib6_may_remove_gc_list(net, f6i);
| ^
net/ipv6/addrconf.c:4846:4: error: call to undeclared function 'fib6_add_gc_list'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
4846 | fib6_add_gc_list(f6i);
| ^
5 errors generated.
--
>> net/ipv6/route.c:1036:4: error: call to undeclared function 'fib6_may_remove_gc_list'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
1036 | fib6_may_remove_gc_list(net, rt);
| ^
>> net/ipv6/route.c:1039:4: error: call to undeclared function 'fib6_add_gc_list'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
1039 | fib6_add_gc_list(rt);
| ^
net/ipv6/route.c:1786:3: error: call to undeclared function 'fib6_add_gc_list'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
1786 | fib6_add_gc_list(f6i);
| ^
3 errors generated.
--
>> net/ipv6/ip6_fib.c:1073:2: error: call to undeclared function 'fib6_remove_gc_list'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
1073 | fib6_remove_gc_list(rt);
| ^
>> net/ipv6/ip6_fib.c:1136:6: error: call to undeclared function 'fib6_may_remove_gc_list'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
1136 | fib6_may_remove_gc_list(info->nl_net, iter);
| ^
>> net/ipv6/ip6_fib.c:1139:6: error: call to undeclared function 'fib6_add_gc_list'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
1139 | fib6_add_gc_list(iter);
| ^
net/ipv6/ip6_fib.c:1546:4: error: call to undeclared function 'fib6_add_gc_list'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
1546 | fib6_add_gc_list(rt);
| ^
net/ipv6/ip6_fib.c:2360:3: error: call to undeclared function 'fib6_remove_gc_list'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2360 | fib6_remove_gc_list(rt);
| ^
5 errors generated.
--
>> net/ipv6/ndisc.c:1405:3: error: call to undeclared function 'fib6_add_gc_list'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
1405 | fib6_add_gc_list(rt);
| ^1 error generated.
vim +/fib6_add_gc_list +1282 net/ipv6/addrconf.c
5b84efecb7d939d Thomas Haller 2014-01-15 1262
5b84efecb7d939d Thomas Haller 2014-01-15 1263 static void
d0098e4c6b83e50 Hangbin Liu 2020-03-03 1264 cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires,
d0098e4c6b83e50 Hangbin Liu 2020-03-03 1265 bool del_rt, bool del_peer)
5b84efecb7d939d Thomas Haller 2014-01-15 1266 {
5eb902b8e7193cd Kui-Feng Lee 2024-02-08 1267 struct fib6_table *table;
93c2fb253d177a0 David Ahern 2018-04-18 1268 struct fib6_info *f6i;
5b84efecb7d939d Thomas Haller 2014-01-15 1269
d0098e4c6b83e50 Hangbin Liu 2020-03-03 1270 f6i = addrconf_get_prefix_route(del_peer ? &ifp->peer_addr : &ifp->addr,
d0098e4c6b83e50 Hangbin Liu 2020-03-03 1271 ifp->prefix_len,
2b2450ca4a2d9d7 David Ahern 2019-03-27 1272 ifp->idev->dev, 0, RTF_DEFAULT, true);
93c2fb253d177a0 David Ahern 2018-04-18 1273 if (f6i) {
5b84efecb7d939d Thomas Haller 2014-01-15 1274 if (del_rt)
11dd74b338bf83f Roopa Prabhu 2020-04-27 1275 ip6_del_rt(dev_net(ifp->idev->dev), f6i, false);
5b84efecb7d939d Thomas Haller 2014-01-15 1276 else {
5eb902b8e7193cd Kui-Feng Lee 2024-02-08 1277 if (!(f6i->fib6_flags & RTF_EXPIRES)) {
5eb902b8e7193cd Kui-Feng Lee 2024-02-08 1278 table = f6i->fib6_table;
5eb902b8e7193cd Kui-Feng Lee 2024-02-08 1279 spin_lock_bh(&table->tb6_lock);
5eb902b8e7193cd Kui-Feng Lee 2024-02-08 1280
93c2fb253d177a0 David Ahern 2018-04-18 1281 fib6_set_expires(f6i, expires);
5eb902b8e7193cd Kui-Feng Lee 2024-02-08 @1282 fib6_add_gc_list(f6i);
5eb902b8e7193cd Kui-Feng Lee 2024-02-08 1283
5eb902b8e7193cd Kui-Feng Lee 2024-02-08 1284 spin_unlock_bh(&table->tb6_lock);
5eb902b8e7193cd Kui-Feng Lee 2024-02-08 1285 }
93c2fb253d177a0 David Ahern 2018-04-18 1286 fib6_info_release(f6i);
5b84efecb7d939d Thomas Haller 2014-01-15 1287 }
5b84efecb7d939d Thomas Haller 2014-01-15 1288 }
5b84efecb7d939d Thomas Haller 2014-01-15 1289 }
5b84efecb7d939d Thomas Haller 2014-01-15 1290 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2 net 2/2] ipv6: Don't remove permanent routes with exceptions from tb6_gc_hlist.
Quoted 20 lines · kernel test robot
Hi Kuniyuki,
kernel test robot noticed the following build errors:
[auto build test ERROR on net/main]
url: https://github.com/intel-lab-lkp/linux/commits/Kuniyuki-Iwashima/ipv6-Remove-permanent-routes-from-tb6_gc_hlist-when-all-exceptions-expire/20260308-113030 base: net/main patch link: https://lore.kernel.org/r/20260308032304.1841198-3-kuniyu%40google.com patch subject: [PATCH v2 net 2/2] ipv6: Don't remove permanent routes with exceptions from tb6_gc_hlist. config: sparc64-allmodconfig (https://download.01.org/0day-ci/archive/20260308/[email protected]/config) compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project c32caeec8158d634bb71ab8911a6031248b9fc47) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260308/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Quoted 4 lines
All errors (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
net/ipv6/addrconf.c:1282:5: error: call to undeclared function 'fib6_add_gc_list'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]1282 | fib6_add_gc_list(f6i);
Ugh, apparently I should've used IS_ENABLE()...
Will fix it.
Sorry for noise !