rtnetlink: move rtnl_lock handling out of af_netlink

JIRA: https://issues.redhat.com/browse/RHEL-57756

Upstream commit(s):
commit 5380d64f8d766576ac5c0f627418b2d0e1d2641f
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Thu Jun 6 12:29:05 2024 -0700

    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: 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>

Signed-off-by: Petr Oros <poros@redhat.com>
This commit is contained in:
Petr Oros 2024-11-25 10:55:08 +01:00
parent 3797450a08
commit c976657153
2 changed files with 7 additions and 4 deletions

View File

@ -6503,6 +6503,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;
@ -6512,7 +6513,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.
@ -6532,7 +6537,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;
@ -6720,7 +6726,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,
};

View File

@ -2320,8 +2320,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);