]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: ethtool: cmis_cdb: hold instance lock for ops locked devices
authorJakub Kicinski <kuba@kernel.org>
Wed, 3 Jun 2026 01:28:31 +0000 (18:28 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 4 Jun 2026 21:04:55 +0000 (14:04 -0700)
FW module flashing was written so that the flashing happens
without holding rtnl_lock. This allows flashing multiple modules
at once. Current drivers can handle that well, but we should
let drivers depend on the netdev instance lock. Instance lock
is per netdev, and so is the module so we won't break parallel
updates.

Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20260603012840.2254293-3-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/netdev_lock.h
net/ethtool/cmis_cdb.c
net/ethtool/cmis_fw_update.c
net/ethtool/module.c

index 8e84d29b0bfb001bf12b08be9bb7216c1c8baf0c..d3daec4e93f33d3cb8a43a48b0d3c50ae6c2a414 100644 (file)
@@ -80,6 +80,12 @@ netdev_assert_locked_ops_compat_or_invisible(const struct net_device *dev)
                netdev_assert_locked_ops_compat(dev);
 }
 
+static inline void netdev_assert_locked_ops(const struct net_device *dev)
+{
+       if (netdev_need_ops_lock(dev))
+               netdev_assert_locked(dev);
+}
+
 static inline void netdev_lock_ops_compat(struct net_device *dev)
 {
        if (netdev_need_ops_lock(dev))
index f3a53a984460996aadb4dd9d7d1c7b51814c87fd..a4e8f4b3fb7577e186978283dcbf86df02d9b21e 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <linux/ethtool.h>
 #include <linux/jiffies.h>
+#include <net/netdev_lock.h>
 
 #include "common.h"
 #include "module_fw.h"
@@ -179,6 +180,7 @@ cmis_cdb_validate_password(struct ethtool_cmis_cdb *cdb,
 
        pe_pl = *((struct cmis_password_entry_pl *)page_data.data);
        pe_pl.password = params->password;
+       netdev_assert_locked_ops(dev);
        err = ops->set_module_eeprom_by_page(dev, &page_data, &extack);
        if (err < 0) {
                if (extack._msg)
@@ -546,6 +548,7 @@ __ethtool_cmis_cdb_execute_cmd(struct net_device *dev,
        if (!page_data->data)
                return -ENOMEM;
 
+       netdev_assert_locked_ops(dev);
        err = ops->set_module_eeprom_by_page(dev, page_data, &extack);
        if (err < 0) {
                if (extack._msg)
index 291d04d2776a5cfd66e684a6cf47ffe2917ede6e..dff83807e975c520dd4045818d626c9ee6c4618f 100644 (file)
@@ -435,13 +435,9 @@ cmis_fw_update_commit_image(struct ethtool_cmis_cdb *cdb,
 static int cmis_fw_update_reset(struct net_device *dev)
 {
        __u32 reset_data = ETH_RESET_PHY;
-       int ret;
 
-       netdev_lock_ops(dev);
-       ret = dev->ethtool_ops->reset(dev, &reset_data);
-       netdev_unlock_ops(dev);
-
-       return ret;
+       netdev_assert_locked_ops(dev);
+       return dev->ethtool_ops->reset(dev, &reset_data);
 }
 
 void
index ea4fb2a7665005bddec877140d0289e8dd4b6571..c3388e6d7ec88b18b6a3d4004190a7aa97827fd8 100644 (file)
@@ -226,7 +226,9 @@ static void module_flash_fw_work(struct work_struct *work)
        module_fw = container_of(work, struct ethtool_module_fw_flash, work);
        dev = module_fw->fw_update.dev;
 
+       netdev_lock_ops(dev);
        ethtool_cmis_fw_update(&module_fw->fw_update);
+       netdev_unlock_ops(dev);
 
        module_flash_fw_work_list_del(&module_fw->list);