mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-07 22:42:04 +00:00
ip6mr: Add refcounting to mfc
Since ipmr and ip6mr are using the same mr_mfc struct at their core, we can now refactor the ipmr_cache_{hold,put} logic and apply refcounting to both ipmr and ip6mr. Signed-off-by: Yuval Mintz <yuvalm@mellanox.com> Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
d3c07e5b99
commit
8c13af2a21
@ -360,7 +360,7 @@ mlxsw_sp_mr_route4_create(struct mlxsw_sp_mr_table *mr_table,
|
|||||||
|
|
||||||
/* Find min_mtu and link iVIF and eVIFs */
|
/* Find min_mtu and link iVIF and eVIFs */
|
||||||
mr_route->min_mtu = ETH_MAX_MTU;
|
mr_route->min_mtu = ETH_MAX_MTU;
|
||||||
ipmr_cache_hold(mfc);
|
mr_cache_hold(&mfc->_c);
|
||||||
mr_route->mfc4 = mfc;
|
mr_route->mfc4 = mfc;
|
||||||
mr_route->mr_table = mr_table;
|
mr_route->mr_table = mr_table;
|
||||||
for (i = 0; i < MAXVIFS; i++) {
|
for (i = 0; i < MAXVIFS; i++) {
|
||||||
@ -380,7 +380,7 @@ mlxsw_sp_mr_route4_create(struct mlxsw_sp_mr_table *mr_table,
|
|||||||
mr_route->route_action = mlxsw_sp_mr_route_action(mr_route);
|
mr_route->route_action = mlxsw_sp_mr_route_action(mr_route);
|
||||||
return mr_route;
|
return mr_route;
|
||||||
err:
|
err:
|
||||||
ipmr_cache_put(mfc);
|
mr_cache_put(&mfc->_c);
|
||||||
list_for_each_entry_safe(rve, tmp, &mr_route->evif_list, route_node)
|
list_for_each_entry_safe(rve, tmp, &mr_route->evif_list, route_node)
|
||||||
mlxsw_sp_mr_route_evif_unlink(rve);
|
mlxsw_sp_mr_route_evif_unlink(rve);
|
||||||
kfree(mr_route);
|
kfree(mr_route);
|
||||||
@ -393,7 +393,7 @@ static void mlxsw_sp_mr_route4_destroy(struct mlxsw_sp_mr_table *mr_table,
|
|||||||
struct mlxsw_sp_mr_route_vif_entry *rve, *tmp;
|
struct mlxsw_sp_mr_route_vif_entry *rve, *tmp;
|
||||||
|
|
||||||
mlxsw_sp_mr_route_ivif_unlink(mr_route);
|
mlxsw_sp_mr_route_ivif_unlink(mr_route);
|
||||||
ipmr_cache_put(mr_route->mfc4);
|
mr_cache_put((struct mr_mfc *)mr_route->mfc4);
|
||||||
list_for_each_entry_safe(rve, tmp, &mr_route->evif_list, route_node)
|
list_for_each_entry_safe(rve, tmp, &mr_route->evif_list, route_node)
|
||||||
mlxsw_sp_mr_route_evif_unlink(rve);
|
mlxsw_sp_mr_route_evif_unlink(rve);
|
||||||
kfree(mr_route);
|
kfree(mr_route);
|
||||||
|
@ -5685,11 +5685,11 @@ static void mlxsw_sp_router_fibmr_event_work(struct work_struct *work)
|
|||||||
replace);
|
replace);
|
||||||
if (err)
|
if (err)
|
||||||
mlxsw_sp_router_fib_abort(mlxsw_sp);
|
mlxsw_sp_router_fib_abort(mlxsw_sp);
|
||||||
ipmr_cache_put((struct mfc_cache *) fib_work->men_info.mfc);
|
mr_cache_put(fib_work->men_info.mfc);
|
||||||
break;
|
break;
|
||||||
case FIB_EVENT_ENTRY_DEL:
|
case FIB_EVENT_ENTRY_DEL:
|
||||||
mlxsw_sp_router_fibmr_del(mlxsw_sp, &fib_work->men_info);
|
mlxsw_sp_router_fibmr_del(mlxsw_sp, &fib_work->men_info);
|
||||||
ipmr_cache_put((struct mfc_cache *) fib_work->men_info.mfc);
|
mr_cache_put(fib_work->men_info.mfc);
|
||||||
break;
|
break;
|
||||||
case FIB_EVENT_VIF_ADD:
|
case FIB_EVENT_VIF_ADD:
|
||||||
err = mlxsw_sp_router_fibmr_vif_add(mlxsw_sp,
|
err = mlxsw_sp_router_fibmr_vif_add(mlxsw_sp,
|
||||||
@ -5769,7 +5769,7 @@ mlxsw_sp_router_fibmr_event(struct mlxsw_sp_fib_event_work *fib_work,
|
|||||||
case FIB_EVENT_ENTRY_ADD: /* fall through */
|
case FIB_EVENT_ENTRY_ADD: /* fall through */
|
||||||
case FIB_EVENT_ENTRY_DEL:
|
case FIB_EVENT_ENTRY_DEL:
|
||||||
memcpy(&fib_work->men_info, info, sizeof(fib_work->men_info));
|
memcpy(&fib_work->men_info, info, sizeof(fib_work->men_info));
|
||||||
ipmr_cache_hold((struct mfc_cache *) fib_work->men_info.mfc);
|
mr_cache_hold(fib_work->men_info.mfc);
|
||||||
break;
|
break;
|
||||||
case FIB_EVENT_VIF_ADD: /* fall through */
|
case FIB_EVENT_VIF_ADD: /* fall through */
|
||||||
case FIB_EVENT_VIF_DEL:
|
case FIB_EVENT_VIF_DEL:
|
||||||
|
@ -84,23 +84,4 @@ struct rtmsg;
|
|||||||
int ipmr_get_route(struct net *net, struct sk_buff *skb,
|
int ipmr_get_route(struct net *net, struct sk_buff *skb,
|
||||||
__be32 saddr, __be32 daddr,
|
__be32 saddr, __be32 daddr,
|
||||||
struct rtmsg *rtm, u32 portid);
|
struct rtmsg *rtm, u32 portid);
|
||||||
|
|
||||||
#ifdef CONFIG_IP_MROUTE
|
|
||||||
void ipmr_cache_free(struct mfc_cache *mfc_cache);
|
|
||||||
#else
|
|
||||||
static inline void ipmr_cache_free(struct mfc_cache *mfc_cache)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline void ipmr_cache_put(struct mfc_cache *c)
|
|
||||||
{
|
|
||||||
if (refcount_dec_and_test(&c->_c.mfc_un.res.refcount))
|
|
||||||
ipmr_cache_free(c);
|
|
||||||
}
|
|
||||||
static inline void ipmr_cache_hold(struct mfc_cache *c)
|
|
||||||
{
|
|
||||||
refcount_inc(&c->_c.mfc_un.res.refcount);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -125,6 +125,7 @@ enum {
|
|||||||
* @refcount: reference count for this entry
|
* @refcount: reference count for this entry
|
||||||
* @list: global entry list
|
* @list: global entry list
|
||||||
* @rcu: used for entry destruction
|
* @rcu: used for entry destruction
|
||||||
|
* @free: Operation used for freeing an entry under RCU
|
||||||
*/
|
*/
|
||||||
struct mr_mfc {
|
struct mr_mfc {
|
||||||
struct rhlist_head mnode;
|
struct rhlist_head mnode;
|
||||||
@ -150,8 +151,20 @@ struct mr_mfc {
|
|||||||
} mfc_un;
|
} mfc_un;
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
struct rcu_head rcu;
|
struct rcu_head rcu;
|
||||||
|
void (*free)(struct rcu_head *head);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline void mr_cache_put(struct mr_mfc *c)
|
||||||
|
{
|
||||||
|
if (refcount_dec_and_test(&c->mfc_un.res.refcount))
|
||||||
|
call_rcu(&c->rcu, c->free);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void mr_cache_hold(struct mr_mfc *c)
|
||||||
|
{
|
||||||
|
refcount_inc(&c->mfc_un.res.refcount);
|
||||||
|
}
|
||||||
|
|
||||||
struct mfc_entry_notifier_info {
|
struct mfc_entry_notifier_info {
|
||||||
struct fib_notifier_info info;
|
struct fib_notifier_info info;
|
||||||
struct mr_mfc *mfc;
|
struct mr_mfc *mfc;
|
||||||
|
@ -732,11 +732,10 @@ static void ipmr_cache_free_rcu(struct rcu_head *head)
|
|||||||
kmem_cache_free(mrt_cachep, (struct mfc_cache *)c);
|
kmem_cache_free(mrt_cachep, (struct mfc_cache *)c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ipmr_cache_free(struct mfc_cache *c)
|
static void ipmr_cache_free(struct mfc_cache *c)
|
||||||
{
|
{
|
||||||
call_rcu(&c->_c.rcu, ipmr_cache_free_rcu);
|
call_rcu(&c->_c.rcu, ipmr_cache_free_rcu);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(ipmr_cache_free);
|
|
||||||
|
|
||||||
/* Destroy an unresolved cache entry, killing queued skbs
|
/* Destroy an unresolved cache entry, killing queued skbs
|
||||||
* and reporting error to netlink readers.
|
* and reporting error to netlink readers.
|
||||||
@ -987,6 +986,7 @@ static struct mfc_cache *ipmr_cache_alloc(void)
|
|||||||
if (c) {
|
if (c) {
|
||||||
c->_c.mfc_un.res.last_assert = jiffies - MFC_ASSERT_THRESH - 1;
|
c->_c.mfc_un.res.last_assert = jiffies - MFC_ASSERT_THRESH - 1;
|
||||||
c->_c.mfc_un.res.minvif = MAXVIFS;
|
c->_c.mfc_un.res.minvif = MAXVIFS;
|
||||||
|
c->_c.free = ipmr_cache_free_rcu;
|
||||||
refcount_set(&c->_c.mfc_un.res.refcount, 1);
|
refcount_set(&c->_c.mfc_un.res.refcount, 1);
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
@ -1206,7 +1206,7 @@ static int ipmr_mfc_delete(struct mr_table *mrt, struct mfcctl *mfc, int parent)
|
|||||||
list_del_rcu(&c->_c.list);
|
list_del_rcu(&c->_c.list);
|
||||||
call_ipmr_mfc_entry_notifiers(net, FIB_EVENT_ENTRY_DEL, c, mrt->id);
|
call_ipmr_mfc_entry_notifiers(net, FIB_EVENT_ENTRY_DEL, c, mrt->id);
|
||||||
mroute_netlink_event(mrt, c, RTM_DELROUTE);
|
mroute_netlink_event(mrt, c, RTM_DELROUTE);
|
||||||
ipmr_cache_put(c);
|
mr_cache_put(&c->_c);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1318,7 +1318,7 @@ static void mroute_clean_tables(struct mr_table *mrt, bool all)
|
|||||||
call_ipmr_mfc_entry_notifiers(net, FIB_EVENT_ENTRY_DEL, cache,
|
call_ipmr_mfc_entry_notifiers(net, FIB_EVENT_ENTRY_DEL, cache,
|
||||||
mrt->id);
|
mrt->id);
|
||||||
mroute_netlink_event(mrt, cache, RTM_DELROUTE);
|
mroute_netlink_event(mrt, cache, RTM_DELROUTE);
|
||||||
ipmr_cache_put(cache);
|
mr_cache_put(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (atomic_read(&mrt->cache_resolve_queue_len) != 0) {
|
if (atomic_read(&mrt->cache_resolve_queue_len) != 0) {
|
||||||
|
@ -989,6 +989,8 @@ static struct mfc6_cache *ip6mr_cache_alloc(void)
|
|||||||
return NULL;
|
return NULL;
|
||||||
c->_c.mfc_un.res.last_assert = jiffies - MFC_ASSERT_THRESH - 1;
|
c->_c.mfc_un.res.last_assert = jiffies - MFC_ASSERT_THRESH - 1;
|
||||||
c->_c.mfc_un.res.minvif = MAXMIFS;
|
c->_c.mfc_un.res.minvif = MAXMIFS;
|
||||||
|
c->_c.free = ip6mr_cache_free_rcu;
|
||||||
|
refcount_set(&c->_c.mfc_un.res.refcount, 1);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1227,7 +1229,7 @@ static int ip6mr_mfc_delete(struct mr_table *mrt, struct mf6cctl *mfc,
|
|||||||
call_ip6mr_mfc_entry_notifiers(read_pnet(&mrt->net),
|
call_ip6mr_mfc_entry_notifiers(read_pnet(&mrt->net),
|
||||||
FIB_EVENT_ENTRY_DEL, c, mrt->id);
|
FIB_EVENT_ENTRY_DEL, c, mrt->id);
|
||||||
mr6_netlink_event(mrt, c, RTM_DELROUTE);
|
mr6_netlink_event(mrt, c, RTM_DELROUTE);
|
||||||
ip6mr_cache_free(c);
|
mr_cache_put(&c->_c);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1516,7 +1518,7 @@ static void mroute_clean_tables(struct mr_table *mrt, bool all)
|
|||||||
rhltable_remove(&mrt->mfc_hash, &c->mnode, ip6mr_rht_params);
|
rhltable_remove(&mrt->mfc_hash, &c->mnode, ip6mr_rht_params);
|
||||||
list_del_rcu(&c->list);
|
list_del_rcu(&c->list);
|
||||||
mr6_netlink_event(mrt, (struct mfc6_cache *)c, RTM_DELROUTE);
|
mr6_netlink_event(mrt, (struct mfc6_cache *)c, RTM_DELROUTE);
|
||||||
ip6mr_cache_free((struct mfc6_cache *)c);
|
mr_cache_put(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (atomic_read(&mrt->cache_resolve_queue_len) != 0) {
|
if (atomic_read(&mrt->cache_resolve_queue_len) != 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user