Commit 93531c67 authored by David Ahern's avatar David Ahern Committed by David S. Miller

net/ipv6: separate handling of FIB entries from dst based routes

Last step before flipping the data type for FIB entries:
- use fib6_info_alloc to create FIB entries in ip6_route_info_create
  and addrconf_dst_alloc
- use fib6_info_release in place of dst_release, ip6_rt_put and
  rt6_release
- remove the dst_hold before calling __ip6_ins_rt or ip6_del_rt
- when purging routes, drop per-cpu routes
- replace inc and dec of rt6i_ref with fib6_info_hold and fib6_info_release
- use rt->from since it points to the FIB entry
- drop references to exception bucket, fib6_metrics and per-cpu from
  dst entries (those are relevant for fib entries only)
Signed-off-by: default avatarDavid Ahern <dsahern@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a64efe14
...@@ -314,9 +314,7 @@ static inline u32 rt6_get_cookie(const struct rt6_info *rt) ...@@ -314,9 +314,7 @@ static inline u32 rt6_get_cookie(const struct rt6_info *rt)
if (rt->rt6i_flags & RTF_PCPU || if (rt->rt6i_flags & RTF_PCPU ||
(unlikely(!list_empty(&rt->rt6i_uncached)) && rt->from)) (unlikely(!list_empty(&rt->rt6i_uncached)) && rt->from))
rt = rt->from; rt6_get_cookie_safe(rt->from, &cookie);
rt6_get_cookie_safe(rt, &cookie);
return cookie; return cookie;
} }
......
...@@ -114,8 +114,7 @@ static inline int ip6_route_get_saddr(struct net *net, struct rt6_info *rt, ...@@ -114,8 +114,7 @@ static inline int ip6_route_get_saddr(struct net *net, struct rt6_info *rt,
unsigned int prefs, unsigned int prefs,
struct in6_addr *saddr) struct in6_addr *saddr)
{ {
struct inet6_dev *idev = struct inet6_dev *idev = rt ? rt->rt6i_idev : NULL;
rt ? ip6_dst_idev((struct dst_entry *)rt) : NULL;
int err = 0; int err = 0;
if (rt && rt->rt6i_prefsrc.plen) if (rt && rt->rt6i_prefsrc.plen)
......
...@@ -916,7 +916,6 @@ void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp) ...@@ -916,7 +916,6 @@ void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp)
pr_warn("Freeing alive inet6 address %p\n", ifp); pr_warn("Freeing alive inet6 address %p\n", ifp);
return; return;
} }
ip6_rt_put(ifp->rt);
kfree_rcu(ifp, rcu); kfree_rcu(ifp, rcu);
} }
...@@ -1102,8 +1101,8 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, ...@@ -1102,8 +1101,8 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr,
inet6addr_notifier_call_chain(NETDEV_UP, ifa); inet6addr_notifier_call_chain(NETDEV_UP, ifa);
out: out:
if (unlikely(err < 0)) { if (unlikely(err < 0)) {
if (rt) fib6_info_release(rt);
ip6_rt_put(rt);
if (ifa) { if (ifa) {
if (ifa->idev) if (ifa->idev)
in6_dev_put(ifa->idev); in6_dev_put(ifa->idev);
...@@ -1191,7 +1190,7 @@ cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, bool del_r ...@@ -1191,7 +1190,7 @@ cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, bool del_r
else { else {
if (!(rt->rt6i_flags & RTF_EXPIRES)) if (!(rt->rt6i_flags & RTF_EXPIRES))
fib6_set_expires(rt, expires); fib6_set_expires(rt, expires);
ip6_rt_put(rt); fib6_info_release(rt);
} }
} }
} }
...@@ -2375,8 +2374,7 @@ static struct rt6_info *addrconf_get_prefix_route(const struct in6_addr *pfx, ...@@ -2375,8 +2374,7 @@ static struct rt6_info *addrconf_get_prefix_route(const struct in6_addr *pfx,
continue; continue;
if ((rt->rt6i_flags & noflags) != 0) if ((rt->rt6i_flags & noflags) != 0)
continue; continue;
if (!dst_hold_safe(&rt->dst)) fib6_info_hold(rt);
rt = NULL;
break; break;
} }
out: out:
...@@ -2687,7 +2685,7 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao) ...@@ -2687,7 +2685,7 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)
addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len, addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len,
dev, expires, flags, GFP_ATOMIC); dev, expires, flags, GFP_ATOMIC);
} }
ip6_rt_put(rt); fib6_info_release(rt);
} }
/* Try to figure out our local address for this prefix */ /* Try to figure out our local address for this prefix */
...@@ -3361,7 +3359,7 @@ static int fixup_permanent_addr(struct net *net, ...@@ -3361,7 +3359,7 @@ static int fixup_permanent_addr(struct net *net,
ifp->rt = rt; ifp->rt = rt;
spin_unlock(&ifp->lock); spin_unlock(&ifp->lock);
ip6_rt_put(prev); fib6_info_release(prev);
} }
if (!(ifp->flags & IFA_F_NOPREFIXROUTE)) { if (!(ifp->flags & IFA_F_NOPREFIXROUTE)) {
...@@ -5636,8 +5634,8 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) ...@@ -5636,8 +5634,8 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
ip6_del_rt(net, rt); ip6_del_rt(net, rt);
} }
if (ifp->rt) { if (ifp->rt) {
if (dst_hold_safe(&ifp->rt->dst)) ip6_del_rt(net, ifp->rt);
ip6_del_rt(net, ifp->rt); ifp->rt = NULL;
} }
rt_genid_bump_ipv6(net); rt_genid_bump_ipv6(net);
break; break;
......
...@@ -213,7 +213,7 @@ static void aca_put(struct ifacaddr6 *ac) ...@@ -213,7 +213,7 @@ static void aca_put(struct ifacaddr6 *ac)
{ {
if (refcount_dec_and_test(&ac->aca_refcnt)) { if (refcount_dec_and_test(&ac->aca_refcnt)) {
in6_dev_put(ac->aca_idev); in6_dev_put(ac->aca_idev);
dst_release(&ac->aca_rt->dst); fib6_info_release(ac->aca_rt);
kfree(ac); kfree(ac);
} }
} }
...@@ -231,6 +231,7 @@ static struct ifacaddr6 *aca_alloc(struct rt6_info *rt, ...@@ -231,6 +231,7 @@ static struct ifacaddr6 *aca_alloc(struct rt6_info *rt,
aca->aca_addr = *addr; aca->aca_addr = *addr;
in6_dev_hold(idev); in6_dev_hold(idev);
aca->aca_idev = idev; aca->aca_idev = idev;
fib6_info_hold(rt);
aca->aca_rt = rt; aca->aca_rt = rt;
aca->aca_users = 1; aca->aca_users = 1;
/* aca_tstamp should be updated upon changes */ /* aca_tstamp should be updated upon changes */
...@@ -274,7 +275,7 @@ int __ipv6_dev_ac_inc(struct inet6_dev *idev, const struct in6_addr *addr) ...@@ -274,7 +275,7 @@ int __ipv6_dev_ac_inc(struct inet6_dev *idev, const struct in6_addr *addr)
} }
aca = aca_alloc(rt, addr); aca = aca_alloc(rt, addr);
if (!aca) { if (!aca) {
ip6_rt_put(rt); fib6_info_release(rt);
err = -ENOMEM; err = -ENOMEM;
goto out; goto out;
} }
...@@ -330,7 +331,6 @@ int __ipv6_dev_ac_dec(struct inet6_dev *idev, const struct in6_addr *addr) ...@@ -330,7 +331,6 @@ int __ipv6_dev_ac_dec(struct inet6_dev *idev, const struct in6_addr *addr)
write_unlock_bh(&idev->lock); write_unlock_bh(&idev->lock);
addrconf_leave_solict(idev, &aca->aca_addr); addrconf_leave_solict(idev, &aca->aca_addr);
dst_hold(&aca->aca_rt->dst);
ip6_del_rt(dev_net(idev->dev), aca->aca_rt); ip6_del_rt(dev_net(idev->dev), aca->aca_rt);
aca_put(aca); aca_put(aca);
...@@ -358,7 +358,6 @@ void ipv6_ac_destroy_dev(struct inet6_dev *idev) ...@@ -358,7 +358,6 @@ void ipv6_ac_destroy_dev(struct inet6_dev *idev)
addrconf_leave_solict(idev, &aca->aca_addr); addrconf_leave_solict(idev, &aca->aca_addr);
dst_hold(&aca->aca_rt->dst);
ip6_del_rt(dev_net(idev->dev), aca->aca_rt); ip6_del_rt(dev_net(idev->dev), aca->aca_rt);
aca_put(aca); aca_put(aca);
......
...@@ -170,6 +170,7 @@ struct rt6_info *fib6_info_alloc(gfp_t gfp_flags) ...@@ -170,6 +170,7 @@ struct rt6_info *fib6_info_alloc(gfp_t gfp_flags)
void fib6_info_destroy(struct rt6_info *f6i) void fib6_info_destroy(struct rt6_info *f6i)
{ {
struct rt6_exception_bucket *bucket; struct rt6_exception_bucket *bucket;
struct dst_metrics *m;
WARN_ON(f6i->rt6i_node); WARN_ON(f6i->rt6i_node);
...@@ -201,6 +202,10 @@ void fib6_info_destroy(struct rt6_info *f6i) ...@@ -201,6 +202,10 @@ void fib6_info_destroy(struct rt6_info *f6i)
if (f6i->fib6_nh.nh_dev) if (f6i->fib6_nh.nh_dev)
dev_put(f6i->fib6_nh.nh_dev); dev_put(f6i->fib6_nh.nh_dev);
m = f6i->fib6_metrics;
if (m != &dst_default_metrics && refcount_dec_and_test(&m->refcnt))
kfree(m);
kfree(f6i); kfree(f6i);
} }
EXPORT_SYMBOL_GPL(fib6_info_destroy); EXPORT_SYMBOL_GPL(fib6_info_destroy);
...@@ -714,7 +719,7 @@ static struct fib6_node *fib6_add_1(struct net *net, ...@@ -714,7 +719,7 @@ static struct fib6_node *fib6_add_1(struct net *net,
/* clean up an intermediate node */ /* clean up an intermediate node */
if (!(fn->fn_flags & RTN_RTINFO)) { if (!(fn->fn_flags & RTN_RTINFO)) {
RCU_INIT_POINTER(fn->leaf, NULL); RCU_INIT_POINTER(fn->leaf, NULL);
rt6_release(leaf); fib6_info_release(leaf);
/* remove null_entry in the root node */ /* remove null_entry in the root node */
} else if (fn->fn_flags & RTN_TL_ROOT && } else if (fn->fn_flags & RTN_TL_ROOT &&
rcu_access_pointer(fn->leaf) == rcu_access_pointer(fn->leaf) ==
...@@ -898,12 +903,32 @@ static void fib6_purge_rt(struct rt6_info *rt, struct fib6_node *fn, ...@@ -898,12 +903,32 @@ static void fib6_purge_rt(struct rt6_info *rt, struct fib6_node *fn,
if (!(fn->fn_flags & RTN_RTINFO) && leaf == rt) { if (!(fn->fn_flags & RTN_RTINFO) && leaf == rt) {
new_leaf = fib6_find_prefix(net, table, fn); new_leaf = fib6_find_prefix(net, table, fn);
atomic_inc(&new_leaf->rt6i_ref); atomic_inc(&new_leaf->rt6i_ref);
rcu_assign_pointer(fn->leaf, new_leaf); rcu_assign_pointer(fn->leaf, new_leaf);
rt6_release(rt); fib6_info_release(rt);
} }
fn = rcu_dereference_protected(fn->parent, fn = rcu_dereference_protected(fn->parent,
lockdep_is_held(&table->tb6_lock)); lockdep_is_held(&table->tb6_lock));
} }
if (rt->rt6i_pcpu) {
int cpu;
/* release the reference to this fib entry from
* all of its cached pcpu routes
*/
for_each_possible_cpu(cpu) {
struct rt6_info **ppcpu_rt;
struct rt6_info *pcpu_rt;
ppcpu_rt = per_cpu_ptr(rt->rt6i_pcpu, cpu);
pcpu_rt = *ppcpu_rt;
if (pcpu_rt) {
fib6_info_release(pcpu_rt->from);
pcpu_rt->from = NULL;
}
}
}
} }
} }
...@@ -1099,7 +1124,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt, ...@@ -1099,7 +1124,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
fib6_purge_rt(iter, fn, info->nl_net); fib6_purge_rt(iter, fn, info->nl_net);
if (rcu_access_pointer(fn->rr_ptr) == iter) if (rcu_access_pointer(fn->rr_ptr) == iter)
fn->rr_ptr = NULL; fn->rr_ptr = NULL;
rt6_release(iter); fib6_info_release(iter);
if (nsiblings) { if (nsiblings) {
/* Replacing an ECMP route, remove all siblings */ /* Replacing an ECMP route, remove all siblings */
...@@ -1115,7 +1140,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt, ...@@ -1115,7 +1140,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
fib6_purge_rt(iter, fn, info->nl_net); fib6_purge_rt(iter, fn, info->nl_net);
if (rcu_access_pointer(fn->rr_ptr) == iter) if (rcu_access_pointer(fn->rr_ptr) == iter)
fn->rr_ptr = NULL; fn->rr_ptr = NULL;
rt6_release(iter); fib6_info_release(iter);
nsiblings--; nsiblings--;
info->nl_net->ipv6.rt6_stats->fib_rt_entries--; info->nl_net->ipv6.rt6_stats->fib_rt_entries--;
} else { } else {
...@@ -1183,9 +1208,6 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, ...@@ -1183,9 +1208,6 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
int replace_required = 0; int replace_required = 0;
int sernum = fib6_new_sernum(info->nl_net); int sernum = fib6_new_sernum(info->nl_net);
if (WARN_ON_ONCE(!atomic_read(&rt->dst.__refcnt)))
return -EINVAL;
if (info->nlh) { if (info->nlh) {
if (!(info->nlh->nlmsg_flags & NLM_F_CREATE)) if (!(info->nlh->nlmsg_flags & NLM_F_CREATE))
allow_create = 0; allow_create = 0;
...@@ -1300,7 +1322,7 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, ...@@ -1300,7 +1322,7 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
if (pn_leaf == rt) { if (pn_leaf == rt) {
pn_leaf = NULL; pn_leaf = NULL;
RCU_INIT_POINTER(pn->leaf, NULL); RCU_INIT_POINTER(pn->leaf, NULL);
atomic_dec(&rt->rt6i_ref); fib6_info_release(rt);
} }
if (!pn_leaf && !(pn->fn_flags & RTN_RTINFO)) { if (!pn_leaf && !(pn->fn_flags & RTN_RTINFO)) {
pn_leaf = fib6_find_prefix(info->nl_net, table, pn_leaf = fib6_find_prefix(info->nl_net, table,
...@@ -1312,7 +1334,7 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, ...@@ -1312,7 +1334,7 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
info->nl_net->ipv6.fib6_null_entry; info->nl_net->ipv6.fib6_null_entry;
} }
#endif #endif
atomic_inc(&pn_leaf->rt6i_ref); fib6_info_hold(pn_leaf);
rcu_assign_pointer(pn->leaf, pn_leaf); rcu_assign_pointer(pn->leaf, pn_leaf);
} }
} }
...@@ -1334,10 +1356,6 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, ...@@ -1334,10 +1356,6 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
(fn->fn_flags & RTN_TL_ROOT && (fn->fn_flags & RTN_TL_ROOT &&
!rcu_access_pointer(fn->leaf)))) !rcu_access_pointer(fn->leaf))))
fib6_repair_tree(info->nl_net, table, fn); fib6_repair_tree(info->nl_net, table, fn);
/* Always release dst as dst->__refcnt is guaranteed
* to be taken before entering this function
*/
dst_release_immediate(&rt->dst);
return err; return err;
} }
...@@ -1637,7 +1655,7 @@ static struct fib6_node *fib6_repair_tree(struct net *net, ...@@ -1637,7 +1655,7 @@ static struct fib6_node *fib6_repair_tree(struct net *net,
new_fn_leaf = net->ipv6.fib6_null_entry; new_fn_leaf = net->ipv6.fib6_null_entry;
} }
#endif #endif
atomic_inc(&new_fn_leaf->rt6i_ref); fib6_info_hold(new_fn_leaf);
rcu_assign_pointer(fn->leaf, new_fn_leaf); rcu_assign_pointer(fn->leaf, new_fn_leaf);
return pn; return pn;
} }
...@@ -1693,7 +1711,7 @@ static struct fib6_node *fib6_repair_tree(struct net *net, ...@@ -1693,7 +1711,7 @@ static struct fib6_node *fib6_repair_tree(struct net *net,
return pn; return pn;
RCU_INIT_POINTER(pn->leaf, NULL); RCU_INIT_POINTER(pn->leaf, NULL);
rt6_release(pn_leaf); fib6_info_release(pn_leaf);
fn = pn; fn = pn;
} }
} }
...@@ -1763,7 +1781,7 @@ static void fib6_del_route(struct fib6_table *table, struct fib6_node *fn, ...@@ -1763,7 +1781,7 @@ static void fib6_del_route(struct fib6_table *table, struct fib6_node *fn,
call_fib6_entry_notifiers(net, FIB_EVENT_ENTRY_DEL, rt, NULL); call_fib6_entry_notifiers(net, FIB_EVENT_ENTRY_DEL, rt, NULL);
if (!info->skip_notify) if (!info->skip_notify)
inet6_rt_notify(RTM_DELROUTE, rt, info, 0); inet6_rt_notify(RTM_DELROUTE, rt, info, 0);
rt6_release(rt); fib6_info_release(rt);
} }
/* Need to own table->tb6_lock */ /* Need to own table->tb6_lock */
...@@ -2261,9 +2279,8 @@ static int ipv6_route_seq_show(struct seq_file *seq, void *v) ...@@ -2261,9 +2279,8 @@ static int ipv6_route_seq_show(struct seq_file *seq, void *v)
dev = rt->fib6_nh.nh_dev; dev = rt->fib6_nh.nh_dev;
seq_printf(seq, " %08x %08x %08x %08x %8s\n", seq_printf(seq, " %08x %08x %08x %08x %8s\n",
rt->rt6i_metric, atomic_read(&rt->dst.__refcnt), rt->rt6i_metric, atomic_read(&rt->rt6i_ref), 0,
rt->dst.__use, rt->rt6i_flags, rt->rt6i_flags, dev ? dev->name : "");
dev ? dev->name : "");
iter->w.leaf = NULL; iter->w.leaf = NULL;
return 0; return 0;
} }
......
...@@ -968,7 +968,8 @@ static int ip6_dst_lookup_tail(struct net *net, const struct sock *sk, ...@@ -968,7 +968,8 @@ static int ip6_dst_lookup_tail(struct net *net, const struct sock *sk,
if (!had_dst) if (!had_dst)
*dst = ip6_route_output(net, sk, fl6); *dst = ip6_route_output(net, sk, fl6);
rt = (*dst)->error ? NULL : (struct rt6_info *)*dst; rt = (*dst)->error ? NULL : (struct rt6_info *)*dst;
err = ip6_route_get_saddr(net, rt, &fl6->daddr, err = ip6_route_get_saddr(net, rt ? rt->from : NULL,
&fl6->daddr,
sk ? inet6_sk(sk)->srcprefs : 0, sk ? inet6_sk(sk)->srcprefs : 0,
&fl6->saddr); &fl6->saddr);
if (err) if (err)
......
...@@ -1283,7 +1283,7 @@ static void ndisc_router_discovery(struct sk_buff *skb) ...@@ -1283,7 +1283,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
ND_PRINTK(0, err, ND_PRINTK(0, err,
"RA: %s got default router without neighbour\n", "RA: %s got default router without neighbour\n",
__func__); __func__);
ip6_rt_put(rt); fib6_info_release(rt);
return; return;
} }
} }
...@@ -1313,7 +1313,7 @@ static void ndisc_router_discovery(struct sk_buff *skb) ...@@ -1313,7 +1313,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
ND_PRINTK(0, err, ND_PRINTK(0, err,
"RA: %s got default router without neighbour\n", "RA: %s got default router without neighbour\n",
__func__); __func__);
ip6_rt_put(rt); fib6_info_release(rt);
return; return;
} }
neigh->flags |= NTF_ROUTER; neigh->flags |= NTF_ROUTER;
...@@ -1499,7 +1499,7 @@ static void ndisc_router_discovery(struct sk_buff *skb) ...@@ -1499,7 +1499,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
ND_PRINTK(2, warn, "RA: invalid RA options\n"); ND_PRINTK(2, warn, "RA: invalid RA options\n");
} }
out: out:
ip6_rt_put(rt); fib6_info_release(rt);
if (neigh) if (neigh)
neigh_release(neigh); neigh_release(neigh);
} }
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment