ipv6: take dst->__refcnt for insertion into fib6 tree
In IPv6 routing code, struct rt6_info is created for each static route and RTF_CACHE route and inserted into fib6 tree. In both cases, dst ref count is not taken. As explained in the previous patch, this leads to the need of the dst garbage collector. This patch holds ref count of dst before inserting the route into fib6 tree and properly releases the dst when deleting it from the fib6 tree as a preparation in order to fully get rid of dst gc later. Also, correct fib6_age() logic to check dst->__refcnt to be 1 to indicate no user is referencing the dst. And remove dst_hold() in vrf_rt6_create() as ip6_dst_alloc() already puts dst->__refcnt to 1. Signed-off-by: Wei Wang <weiwan@google.com> Acked-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
b838d5e1c5
commit
1cfb71eeb1
@@ -172,6 +172,7 @@ static void rt6_free_pcpu(struct rt6_info *non_pcpu_rt)
|
||||
ppcpu_rt = per_cpu_ptr(non_pcpu_rt->rt6i_pcpu, cpu);
|
||||
pcpu_rt = *ppcpu_rt;
|
||||
if (pcpu_rt) {
|
||||
dst_release(&pcpu_rt->dst);
|
||||
rt6_rcu_free(pcpu_rt);
|
||||
*ppcpu_rt = NULL;
|
||||
}
|
||||
@@ -185,6 +186,7 @@ static void rt6_release(struct rt6_info *rt)
|
||||
{
|
||||
if (atomic_dec_and_test(&rt->rt6i_ref)) {
|
||||
rt6_free_pcpu(rt);
|
||||
dst_release(&rt->dst);
|
||||
rt6_rcu_free(rt);
|
||||
}
|
||||
}
|
||||
@@ -1101,6 +1103,10 @@ out:
|
||||
atomic_inc(&pn->leaf->rt6i_ref);
|
||||
}
|
||||
#endif
|
||||
/* Always release dst as dst->__refcnt is guaranteed
|
||||
* to be taken before entering this function
|
||||
*/
|
||||
dst_release(&rt->dst);
|
||||
if (!(rt->dst.flags & DST_NOCACHE))
|
||||
dst_free(&rt->dst);
|
||||
}
|
||||
@@ -1113,6 +1119,10 @@ out:
|
||||
st_failure:
|
||||
if (fn && !(fn->fn_flags & (RTN_RTINFO|RTN_ROOT)))
|
||||
fib6_repair_tree(info->nl_net, fn);
|
||||
/* Always release dst as dst->__refcnt is guaranteed
|
||||
* to be taken before entering this function
|
||||
*/
|
||||
dst_release(&rt->dst);
|
||||
if (!(rt->dst.flags & DST_NOCACHE))
|
||||
dst_free(&rt->dst);
|
||||
return err;
|
||||
@@ -1783,7 +1793,7 @@ static int fib6_age(struct rt6_info *rt, void *arg)
|
||||
}
|
||||
gc_args->more++;
|
||||
} else if (rt->rt6i_flags & RTF_CACHE) {
|
||||
if (atomic_read(&rt->dst.__refcnt) == 0 &&
|
||||
if (atomic_read(&rt->dst.__refcnt) == 1 &&
|
||||
time_after_eq(now, rt->dst.lastuse + gc_args->timeout)) {
|
||||
RT6_TRACE("aging clone %p\n", rt);
|
||||
return -1;
|
||||
|
Reference in New Issue
Block a user