net: ethtool: don't take rtnl_lock for global string dump
Subsystems (3)
Jakub Kicinski
maintainerPATCH 1/1 net: ethtool: don't take rtnl_lock for global string dump
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.
---
CC: [email protected]
CC: [email protected]
--- net/ethtool/netlink.h | 4 +++- net/ethtool/netlink.c | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-)
net/ethtool/netlink.h +3 -1
@@ -333,7 +333,9 @@ int ethnl_sock_priv_set(struct sk_buff *skb, struct net_device *dev, 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
net/ethtool/netlink.c +6 -4
@@ -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);
Signature · 1 line
2.54.0
Quoted 47 lines · Jakub Kicinski
ETHTOOL_MSG_STRSET_GETis the only op which setsallow_nodev_do. When no device is provided it dumps static tables, there's no need to holdrtnl_lockfor this.Not taking
rtnl_lockis 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.Signed-off-by Jakub Kicinski <[email protected]>---
CC: [email protected]
CC: [email protected]--- net/ethtool/netlink.h | 4 +++- net/ethtool/netlink.c | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-)net/ethtool/netlink.h +3
-1@@ -333,7 +333,9 @@ int ethnl_sock_priv_set(struct sk_buff *skb, struct net_device *dev, 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 net/ethtool/netlink.c +3
-2@@ -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); + }
net/ethtool/netlink.c static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info) · line 540
Quoted 10 lines
net/ethtool/netlink.c +3
-2ret = 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);
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Wed, 27 May 2026 09:25:22 -0700 you wrote:
ETHTOOL_MSG_STRSET_GETis the only op which setsallow_nodev_do. When no device is provided it dumps static tables, there's no need to holdrtnl_lockfor this.Not taking
rtnl_lockis 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.[...]
Here is the summary with links:
- [net-next] net: ethtool: don't take rtnl_lock for global string dump
https://git.kernel.org/netdev/net-next/c/f635b0c91275
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html