Commit 5380d64f authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

rtnetlink: move rtnl_lock handling out of af_netlink

Now that we have an intermediate layer of code for handling
rtnl-level netlink dump quirks, we can move the rtnl_lock
taking there.

For dump handlers with RTNL_FLAG_DUMP_SPLIT_NLM_DONE we can
avoid taking rtnl_lock just to generate NLM_DONE, once again.
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Reviewed-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c917b26e
...@@ -6486,6 +6486,7 @@ static int rtnl_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -6486,6 +6486,7 @@ static int rtnl_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
static int rtnl_dumpit(struct sk_buff *skb, struct netlink_callback *cb) static int rtnl_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
{ {
const bool needs_lock = !(cb->flags & RTNL_FLAG_DUMP_UNLOCKED);
rtnl_dumpit_func dumpit = cb->data; rtnl_dumpit_func dumpit = cb->data;
int err; int err;
...@@ -6495,7 +6496,11 @@ static int rtnl_dumpit(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -6495,7 +6496,11 @@ static int rtnl_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
if (!dumpit) if (!dumpit)
return 0; return 0;
if (needs_lock)
rtnl_lock();
err = dumpit(skb, cb); err = dumpit(skb, cb);
if (needs_lock)
rtnl_unlock();
/* Old dump handlers used to send NLM_DONE as in a separate recvmsg(). /* Old dump handlers used to send NLM_DONE as in a separate recvmsg().
* Some applications which parse netlink manually depend on this. * Some applications which parse netlink manually depend on this.
...@@ -6515,7 +6520,8 @@ static int rtnetlink_dump_start(struct sock *ssk, struct sk_buff *skb, ...@@ -6515,7 +6520,8 @@ static int rtnetlink_dump_start(struct sock *ssk, struct sk_buff *skb,
const struct nlmsghdr *nlh, const struct nlmsghdr *nlh,
struct netlink_dump_control *control) struct netlink_dump_control *control)
{ {
if (control->flags & RTNL_FLAG_DUMP_SPLIT_NLM_DONE) { if (control->flags & RTNL_FLAG_DUMP_SPLIT_NLM_DONE ||
!(control->flags & RTNL_FLAG_DUMP_UNLOCKED)) {
WARN_ON(control->data); WARN_ON(control->data);
control->data = control->dump; control->data = control->dump;
control->dump = rtnl_dumpit; control->dump = rtnl_dumpit;
...@@ -6703,7 +6709,6 @@ static int __net_init rtnetlink_net_init(struct net *net) ...@@ -6703,7 +6709,6 @@ static int __net_init rtnetlink_net_init(struct net *net)
struct netlink_kernel_cfg cfg = { struct netlink_kernel_cfg cfg = {
.groups = RTNLGRP_MAX, .groups = RTNLGRP_MAX,
.input = rtnetlink_rcv, .input = rtnetlink_rcv,
.cb_mutex = &rtnl_mutex,
.flags = NL_CFG_F_NONROOT_RECV, .flags = NL_CFG_F_NONROOT_RECV,
.bind = rtnetlink_bind, .bind = rtnetlink_bind,
}; };
......
...@@ -2330,8 +2330,6 @@ static int netlink_dump(struct sock *sk, bool lock_taken) ...@@ -2330,8 +2330,6 @@ static int netlink_dump(struct sock *sk, bool lock_taken)
cb->extack = &extack; cb->extack = &extack;
if (cb->flags & RTNL_FLAG_DUMP_UNLOCKED)
extra_mutex = NULL;
if (extra_mutex) if (extra_mutex)
mutex_lock(extra_mutex); mutex_lock(extra_mutex);
nlk->dump_done_errno = cb->dump(skb, cb); nlk->dump_done_errno = cb->dump(skb, cb);
......
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