Skip to content

Commit

Permalink
rtnetlink: small rtnl lock pushdown
Browse files Browse the repository at this point in the history
instead of rtnl lock/unload at the top level, push it down
to the called function.

This is just an intermediate step, next commit switches protection
of the rtnl_link ops table to rcu, in which case (for dumps) the
rtnl lock is acquired only by the netlink dumper infrastructure
(current lock/unlock/dump/lock/unlock rtnl sequence becomes
 rcu lock/rcu unlock/dump).

Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Florian Westphal authored and David S. Miller committed Aug 9, 2017
1 parent 019a316 commit 0cc0902
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions net/core/rtnetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -4178,9 +4178,11 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
rtnl_dumpit_func dumpit;
u16 min_dump_alloc = 0;

rtnl_lock();

dumpit = rtnl_get_dumpit(family, type);
if (dumpit == NULL)
return -EOPNOTSUPP;
goto err_unlock;

refcount_inc(&rtnl_msg_handlers_ref[family]);

Expand All @@ -4196,23 +4198,28 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
};
err = netlink_dump_start(rtnl, skb, nlh, &c);
}
rtnl_lock();
refcount_dec(&rtnl_msg_handlers_ref[family]);
return err;
}

rtnl_lock();
doit = rtnl_get_doit(family, type);
if (doit == NULL)
return -EOPNOTSUPP;
goto err_unlock;

return doit(skb, nlh, extack);
err = doit(skb, nlh, extack);
rtnl_unlock();

return err;

err_unlock:
rtnl_unlock();
return -EOPNOTSUPP;
}

static void rtnetlink_rcv(struct sk_buff *skb)
{
rtnl_lock();
netlink_rcv_skb(skb, &rtnetlink_rcv_msg);
rtnl_unlock();
}

static int rtnetlink_bind(struct net *net, int group)
Expand Down

0 comments on commit 0cc0902

Please sign in to comment.