From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
andrew+netdev@lunn.ch, horms@kernel.org, jakub@cloudflare.com,
maxime.chevallier@bootlin.com, nb@tipi-net.de, lee@kernel.org,
linux-leds@vger.kernel.org, pavel@kernel.org, jv@jvosburgh.net,
michael.chan@broadcom.com, jhs@mojatatu.com,
vinicius.gomes@intel.com, idosch@nvidia.com, razor@blackwall.org,
hare@suse.de, jhasan@marvell.com, danieller@nvidia.com,
Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next v2 04/11] net: ethtool: add netif_get_link_ksettings() for correct ops-locked use
Date: Tue, 2 Jun 2026 18:28:33 -0700 [thread overview]
Message-ID: <20260603012840.2254293-5-kuba@kernel.org> (raw)
In-Reply-To: <20260603012840.2254293-1-kuba@kernel.org>
__ethtool_get_link_ksettings() is exported and called from sysfs
and many drivers. It invokes ethtool_ops->get_link_ksettings
so by our own docs it should be holding netdev lock for ops locked
devices. Looks like commit 2bcf4772e45a ("net: ethtool:
try to protect all callback with netdev instance lock")
missed adding the ops lock here.
There's a number of callers we need to fix up so let's add the
netif_get_link_ksettings() helper first, without any actual
locking changes (this commit is a nop).
Not treating this as a fix because I don't think any driver cares
at this point, but if we want to remove the rtnl_lock protection
this will become critical.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v2:
- split into multiple patches
---
include/linux/ethtool.h | 2 ++
net/ethtool/ioctl.c | 17 ++++++++++++++---
net/ethtool/linkinfo.c | 4 ++--
net/ethtool/linkmodes.c | 4 ++--
4 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
index 1cb0740ba331..f51346a6a686 100644
--- a/include/linux/ethtool.h
+++ b/include/linux/ethtool.h
@@ -325,6 +325,8 @@ struct ethtool_link_ksettings {
extern int
__ethtool_get_link_ksettings(struct net_device *dev,
struct ethtool_link_ksettings *link_ksettings);
+int netif_get_link_ksettings(struct net_device *dev,
+ struct ethtool_link_ksettings *link_ksettings);
struct ethtool_keee {
__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index bd97f9b9bf18..49da873b673d 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -436,10 +436,10 @@ struct ethtool_link_usettings {
};
/* Internal kernel helper to query a device ethtool_link_settings. */
-int __ethtool_get_link_ksettings(struct net_device *dev,
- struct ethtool_link_ksettings *link_ksettings)
+int netif_get_link_ksettings(struct net_device *dev,
+ struct ethtool_link_ksettings *link_ksettings)
{
- ASSERT_RTNL();
+ /* once callers fixed - assert ops locked */
if (!dev->ethtool_ops->get_link_ksettings)
return -EOPNOTSUPP;
@@ -450,6 +450,17 @@ int __ethtool_get_link_ksettings(struct net_device *dev,
memset(link_ksettings, 0, sizeof(*link_ksettings));
return dev->ethtool_ops->get_link_ksettings(dev, link_ksettings);
}
+EXPORT_SYMBOL(netif_get_link_ksettings);
+
+/* Convenience helper for callers that hold only rtnl_lock(). */
+int __ethtool_get_link_ksettings(struct net_device *dev,
+ struct ethtool_link_ksettings *link_ksettings)
+{
+ ASSERT_RTNL();
+
+ /* once callers fixed - take the ops lock around this call */
+ return netif_get_link_ksettings(dev, link_ksettings);
+}
EXPORT_SYMBOL(__ethtool_get_link_ksettings);
/* convert ethtool_link_usettings in user space to a kernel internal
diff --git a/net/ethtool/linkinfo.c b/net/ethtool/linkinfo.c
index 244ff92e2ff9..d5b3dbc53c5f 100644
--- a/net/ethtool/linkinfo.c
+++ b/net/ethtool/linkinfo.c
@@ -34,7 +34,7 @@ static int linkinfo_prepare_data(const struct ethnl_req_info *req_base,
ret = ethnl_ops_begin(dev);
if (ret < 0)
return ret;
- ret = __ethtool_get_link_ksettings(dev, &data->ksettings);
+ ret = netif_get_link_ksettings(dev, &data->ksettings);
if (ret < 0)
GENL_SET_ERR_MSG(info, "failed to retrieve link settings");
ethnl_ops_complete(dev);
@@ -104,7 +104,7 @@ ethnl_set_linkinfo(struct ethnl_req_info *req_info, struct genl_info *info)
bool mod = false;
int ret;
- ret = __ethtool_get_link_ksettings(dev, &ksettings);
+ ret = netif_get_link_ksettings(dev, &ksettings);
if (ret < 0) {
GENL_SET_ERR_MSG(info, "failed to retrieve link settings");
return ret;
diff --git a/net/ethtool/linkmodes.c b/net/ethtool/linkmodes.c
index 30d703531652..a6d32f0d9fcc 100644
--- a/net/ethtool/linkmodes.c
+++ b/net/ethtool/linkmodes.c
@@ -39,7 +39,7 @@ static int linkmodes_prepare_data(const struct ethnl_req_info *req_base,
if (ret < 0)
return ret;
- ret = __ethtool_get_link_ksettings(dev, &data->ksettings);
+ ret = netif_get_link_ksettings(dev, &data->ksettings);
if (ret < 0) {
GENL_SET_ERR_MSG(info, "failed to retrieve link settings");
goto out;
@@ -324,7 +324,7 @@ ethnl_set_linkmodes(struct ethnl_req_info *req_info, struct genl_info *info)
bool mod = false;
int ret;
- ret = __ethtool_get_link_ksettings(dev, &ksettings);
+ ret = netif_get_link_ksettings(dev, &ksettings);
if (ret < 0) {
GENL_SET_ERR_MSG(info, "failed to retrieve link settings");
return ret;
--
2.54.0
next prev parent reply other threads:[~2026-06-03 1:28 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 1:28 [PATCH net-next v2 00/11] net: ethtool: make sure __ethtool_get_link_ksettings() is ops-locked Jakub Kicinski
2026-06-03 1:28 ` [PATCH net-next v2 01/11] net: rename netdev_ops_assert_locked() Jakub Kicinski
2026-06-03 7:29 ` Nicolai Buchwitz
2026-06-03 11:15 ` Jakub Sitnicki
2026-06-03 17:05 ` Stanislav Fomichev
2026-06-03 1:28 ` [PATCH net-next v2 02/11] net: ethtool: cmis_cdb: hold instance lock for ops locked devices Jakub Kicinski
2026-06-03 17:06 ` Stanislav Fomichev
2026-06-03 1:28 ` [PATCH net-next v2 03/11] net: document NETDEV_CHANGENAME as ops locked Jakub Kicinski
2026-06-03 12:47 ` Jakub Sitnicki
2026-06-03 17:06 ` Stanislav Fomichev
2026-06-03 1:28 ` Jakub Kicinski [this message]
2026-06-03 6:40 ` [PATCH net-next v2 04/11] net: ethtool: add netif_get_link_ksettings() for correct ops-locked use Maxime Chevallier
2026-06-03 17:06 ` Stanislav Fomichev
2026-06-03 1:28 ` [PATCH net-next v2 05/11] net: bonding: don't recurse on the slave's netdev ops lock Jakub Kicinski
2026-06-03 7:20 ` Nicolai Buchwitz
2026-06-03 1:28 ` [PATCH net-next v2 06/11] net: team: don't recurse on the port's " Jakub Kicinski
2026-06-03 1:28 ` [PATCH net-next v2 07/11] net: bridge: " Jakub Kicinski
2026-06-03 7:16 ` Nicolai Buchwitz
2026-06-03 7:54 ` Nikolay Aleksandrov
2026-06-03 13:28 ` Ido Schimmel
2026-06-03 1:28 ` [PATCH net-next v2 08/11] net: sched: don't recurse on the netdev ops lock in qdiscs Jakub Kicinski
2026-06-04 23:38 ` Vinicius Costa Gomes
2026-06-03 1:28 ` [PATCH net-next v2 09/11] leds: trigger: netdev: don't recurse on the netdev ops lock Jakub Kicinski
2026-06-03 1:28 ` [PATCH net-next v2 10/11] scsi: fcoe: don't recurse on the netdev's " Jakub Kicinski
2026-06-03 1:28 ` [PATCH net-next v2 11/11] net: ethtool: make sure __ethtool_get_link_ksettings() is ops-locked Jakub Kicinski
2026-06-03 7:18 ` Nicolai Buchwitz
2026-06-03 17:06 ` Stanislav Fomichev
2026-06-04 21:30 ` [PATCH net-next v2 00/11] " patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260603012840.2254293-5-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=danieller@nvidia.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hare@suse.de \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=jakub@cloudflare.com \
--cc=jhasan@marvell.com \
--cc=jhs@mojatatu.com \
--cc=jv@jvosburgh.net \
--cc=lee@kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=maxime.chevallier@bootlin.com \
--cc=michael.chan@broadcom.com \
--cc=nb@tipi-net.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pavel@kernel.org \
--cc=razor@blackwall.org \
--cc=vinicius.gomes@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.