]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: ethtool: don't take rtnl_lock for global string dump
authorJakub Kicinski <kuba@kernel.org>
Wed, 27 May 2026 16:25:22 +0000 (09:25 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 28 May 2026 21:46:10 +0000 (14:46 -0700)
ETHTOOL_MSG_STRSET_GET is the only op which sets allow_nodev_do.
When no device is provided it dumps static tables, there's no
need to hold rtnl_lock for this.

Not taking rtnl_lock is a minor win in itself so I think this
patch stands on its own merits. Later on it will be useful
to do locking only in paths which have access to a netdev,
so that we can decide which locks to take per-netdev.

Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Link: https://patch.msgid.link/20260527162522.3344231-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ethtool/netlink.c
net/ethtool/netlink.h

index 7d45f9a884e5071b33664d2bf226e4f59e665f23..6cbd13b61bd184a5dab40e20895a71ff95367724 100644 (file)
@@ -526,13 +526,15 @@ static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info)
                goto err_free;
        ethnl_init_reply_data(reply_data, ops, req_info->dev);
 
-       rtnl_lock();
-       if (req_info->dev)
+       if (req_info->dev) {
+               rtnl_lock();
                netdev_lock_ops(req_info->dev);
+       }
        ret = ops->prepare_data(req_info, reply_data, info);
-       if (req_info->dev)
+       if (req_info->dev) {
                netdev_unlock_ops(req_info->dev);
-       rtnl_unlock();
+               rtnl_unlock();
+       }
        if (ret < 0)
                goto err_dev;
        ret = ops->reply_size(req_info, reply_data);
index fd2198e45d2bba46940e205786f4838f8b26fc1d..674c9c19529b73071ec488e48dde130799504e69 100644 (file)
@@ -333,7 +333,9 @@ int ethnl_sock_priv_set(struct sk_buff *skb, struct net *net, u32 portid,
  * @hdr_attr:         attribute type for request header
  * @req_info_size:    size of request info
  * @reply_data_size:  size of reply data
- * @allow_nodev_do:   allow non-dump request with no device identification
+ * @allow_nodev_do:
+ *     Allow non-dump request with no device identification.
+ *     Note that locks (rtnl_lock etc.) are only taken if device is set.
  * @set_ntf_cmd:      notification to generate on changes (SET)
  * @parse_request:
  *     Parse request except common header (struct ethnl_req_info). Common