net/ipv6: do not copy DST_NOCOUNT flag on rt init
Subsystems (3)
PATCH 1/1 net/ipv6: do not copy DST_NOCOUNT flag on rt init
DST_NOCOUNT in dst_entry::flags tracks whether the entry counts toward route cache size (net->ipv6.sysctl.ip6_rt_max_size).
If the flag is NOT set, dst_ops::pcpuc_entries counter is incremented in dist_init() and decremented in dst_destroy().
This flag is tied to allocation/deallocation of dst_entry and should not be copied from another dst/route. Otherwise it can happen that dst_ops::pcpuc_entries counter grows until no new routes can be allocated because the counter reached ip6_rt_max_size due to DST_NOCOUNT not set and thus no counter decrements on gc-ed routes.
--- net/ipv6/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/route.c +1 -1
@@ -946,7 +946,7 @@ static void ip6_rt_init_dst_reject(struct rt6_info *rt, struct fib6_info *ort)static void ip6_rt_init_dst (struct rt6_info *rt,struct fib6_info *ort) { - rt->dst.flags |=fib6_info_dst_flags (ort); + rt->dst.flags |=fib6_info_dst_flags (ort) & ~DST_NOCOUNT ;if (ort->fib6_flags &RTF_REJECT ) {ip6_rt_init_dst_reject (rt, ort);
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
net/ipv6/route.c static void ip6_rt_init_dst_reject(struct rt6_info *rt, struct fib6_info *ort) · line 949
Quoted 10 lines · Peter Oskolkov
net/ipv6/route.c +1
-1@@ -946,7 +946,7 @@ static void ip6_rt_init_dst_reject(struct rt6_info *rt, struct fib6_info *ort)static void ip6_rt_init_dst (struct rt6_info *rt,struct fib6_info *ort) { - rt->dst.flags |=fib6_info_dst_flags (ort); + rt->dst.flags |=fib6_info_dst_flags (ort) & ~DST_NOCOUNT ;
I think my mistake is setting dst.flags in ip6_rt_init_dst. Flags argument is passed to ip6_dst_alloc which is always invoked before ip6_rt_copy_init is called which is the only caller of ip6_rt_init_dst.
Quoted 4 lines
net/ipv6/route.c +0
-0if (ort->fib6_flags &RTF_REJECT ) {ip6_rt_init_dst_reject (rt, ort);
Quoted 9 lines · David Ahern
Quoted 6 lines · Peter Oskolkov
net/ipv6/route.c +0
-0@@ -946,7 +946,7 @@ static void ip6_rt_init_dst_reject(struct rt6_info *rt, struct fib6_info *ort)
Quoted 8 lines
net/ipv6/route.c static void ip6_rt_init_dst_reject(struct rt6_info *rt, struct fib6_info *ort) · line 949
Quoted 4 lines
net/ipv6/route.c +1
-1static void ip6_rt_init_dst (struct rt6_info *rt,struct fib6_info *ort) { - rt->dst.flags |=fib6_info_dst_flags (ort); + rt->dst.flags |=fib6_info_dst_flags (ort) & ~DST_NOCOUNT ;I think my mistake is setting dst.flags in
ip6_rt_init_dst. Flags argument is passed toip6_dst_allocwhich is always invoked beforeip6_rt_copy_initis called which is the only caller ofip6_rt_init_dst.
ip6_rt_cache_alloc calls ip6_dst_alloc with zero as flags; and only one flag is copied later (DST_HOST) outside of ip6_rt_init_dst(). If the flag assignment is completely removed from ip6_rt_init_dst(), then DST_NOPOLICY flag will be lost.
Which may be OK, but is more than what this patch tries to solve (do not copy DST_NOCOUNT flag).
Quoted 6 lines
Quoted 5 lines
net/ipv6/route.c +0
-0if (ort->fib6_flags &RTF_REJECT ) {ip6_rt_init_dst_reject (rt, ort);
Quoted 19 lines · Peter Oskolkov
Quoted 9 lines · David Ahern
Quoted 6 lines · Peter Oskolkov
net/ipv6/route.c +0
-0@@ -946,7 +946,7 @@ static void ip6_rt_init_dst_reject(struct rt6_info *rt, struct fib6_info *ort)Quoted 8 lines
net/ipv6/route.c static void ip6_rt_init_dst_reject(struct rt6_info *rt, struct fib6_info *ort) · line 949
Quoted 4 lines
net/ipv6/route.c +1
-1static void ip6_rt_init_dst (struct rt6_info *rt,struct fib6_info *ort) { - rt->dst.flags |=fib6_info_dst_flags (ort); + rt->dst.flags |=fib6_info_dst_flags (ort) & ~DST_NOCOUNT ;I think my mistake is setting dst.flags in
ip6_rt_init_dst. Flags argument is passed toip6_dst_allocwhich is always invoked beforeip6_rt_copy_initis called which is the only caller ofip6_rt_init_dst.
Quoted 7 lines
ip6_rt_cache_alloccallsip6_dst_allocwith zero as flags; and only one flag is copied later (DST_HOST) outside ofip6_rt_init_dst(). If the flag assignment is completely removed fromip6_rt_init_dst(), thenDST_NOPOLICYflag will be lost.Which may be OK, but is more than what this patch tries to solve (do not copy
DST_NOCOUNTflag).
After 5+ days mostly offline I just started looking at this problem. Give me some time to chase down a thought I had from my last response.
Quoted 19 lines · Peter Oskolkov
Quoted 9 lines · David Ahern
Quoted 6 lines · Peter Oskolkov
net/ipv6/route.c +0
-0@@ -946,7 +946,7 @@ static void ip6_rt_init_dst_reject(struct rt6_info *rt, struct fib6_info *ort)Quoted 8 lines
net/ipv6/route.c static void ip6_rt_init_dst_reject(struct rt6_info *rt, struct fib6_info *ort) · line 949
Quoted 4 lines
net/ipv6/route.c +1
-1static void ip6_rt_init_dst (struct rt6_info *rt,struct fib6_info *ort) { - rt->dst.flags |=fib6_info_dst_flags (ort); + rt->dst.flags |=fib6_info_dst_flags (ort) & ~DST_NOCOUNT ;I think my mistake is setting dst.flags in
ip6_rt_init_dst. Flags argument is passed toip6_dst_allocwhich is always invoked beforeip6_rt_copy_initis called which is the only caller ofip6_rt_init_dst.
Quoted 7 lines
ip6_rt_cache_alloccallsip6_dst_allocwith zero as flags; and only one flag is copied later (DST_HOST) outside ofip6_rt_init_dst(). If the flag assignment is completely removed fromip6_rt_init_dst(), thenDST_NOPOLICYflag will be lost.Which may be OK, but is more than what this patch tries to solve (do not copy
DST_NOCOUNTflag).
In the 4.17 kernel (prior to the fib6_info change), ip6_rt_cache_alloc calls __ip6_dst_alloc with 0 for flags so this is correct. The mistake is ip6_rt_copy_init -> ip6_rt_init_dst -> fib6_info_dst_flags.
I believe the right fix is to drop the 'rt->dst.flags |= fib6_info_dst_flags(ort);' from ip6_rt_init_dst.
Quoted 29 lines · David Ahern
Quoted 19 lines · Peter Oskolkov
Quoted 9 lines · David Ahern
Quoted 6 lines · Peter Oskolkov
net/ipv6/route.c +0
-0@@ -946,7 +946,7 @@ static void ip6_rt_init_dst_reject(struct rt6_info *rt, struct fib6_info *ort)Quoted 8 lines
net/ipv6/route.c static void ip6_rt_init_dst_reject(struct rt6_info *rt, struct fib6_info *ort) · line 949
Quoted 4 lines
net/ipv6/route.c +1
-1static void ip6_rt_init_dst (struct rt6_info *rt,struct fib6_info *ort) { - rt->dst.flags |=fib6_info_dst_flags (ort); + rt->dst.flags |=fib6_info_dst_flags (ort) & ~DST_NOCOUNT ;I think my mistake is setting dst.flags in
ip6_rt_init_dst. Flags argument is passed toip6_dst_allocwhich is always invoked beforeip6_rt_copy_initis called which is the only caller ofip6_rt_init_dst.Quoted 7 lines
ip6_rt_cache_alloccallsip6_dst_allocwith zero as flags; and only one flag is copied later (DST_HOST) outside ofip6_rt_init_dst(). If the flag assignment is completely removed fromip6_rt_init_dst(), thenDST_NOPOLICYflag will be lost.Which may be OK, but is more than what this patch tries to solve (do not copy
DST_NOCOUNTflag).
Quoted 6 lines
In the 4.17 kernel (prior to the
fib6_infochange),ip6_rt_cache_alloccalls__ip6_dst_allocwith 0 for flags so this is correct. The mistake isip6_rt_copy_init->ip6_rt_init_dst->fib6_info_dst_flags.I believe the right fix is to drop the '
rt->dst.flags|=fib6_info_dst_flags(ort);' fromip6_rt_init_dst.
OK, I sent a v2 with the assignment removed. Thanks for the review!