Skip to content

Commit

Permalink
rtnetlink: move rtnl_lock handling out of af_netlink
Browse files Browse the repository at this point in the history
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: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jakub Kicinski authored and David S. Miller committed Jun 10, 2024
1 parent c917b26 commit 5380d64
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 7 additions & 2 deletions net/core/rtnetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
const bool needs_lock = !(cb->flags & RTNL_FLAG_DUMP_UNLOCKED);
rtnl_dumpit_func dumpit = cb->data;
int err;

Expand All @@ -6495,7 +6496,11 @@ static int rtnl_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
if (!dumpit)
return 0;

if (needs_lock)
rtnl_lock();
err = dumpit(skb, cb);
if (needs_lock)
rtnl_unlock();

/* Old dump handlers used to send NLM_DONE as in a separate recvmsg().
* Some applications which parse netlink manually depend on this.
Expand All @@ -6515,7 +6520,8 @@ static int rtnetlink_dump_start(struct sock *ssk, struct sk_buff *skb,
const struct nlmsghdr *nlh,
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);
control->data = control->dump;
control->dump = rtnl_dumpit;
Expand Down Expand Up @@ -6703,7 +6709,6 @@ static int __net_init rtnetlink_net_init(struct net *net)
struct netlink_kernel_cfg cfg = {
.groups = RTNLGRP_MAX,
.input = rtnetlink_rcv,
.cb_mutex = &rtnl_mutex,
.flags = NL_CFG_F_NONROOT_RECV,
.bind = rtnetlink_bind,
};
Expand Down
2 changes: 0 additions & 2 deletions net/netlink/af_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -2330,8 +2330,6 @@ static int netlink_dump(struct sock *sk, bool lock_taken)

cb->extack = &extack;

if (cb->flags & RTNL_FLAG_DUMP_UNLOCKED)
extra_mutex = NULL;
if (extra_mutex)
mutex_lock(extra_mutex);
nlk->dump_done_errno = cb->dump(skb, cb);
Expand Down

0 comments on commit 5380d64

Please sign in to comment.