From edb726666b26bcec63ef9cba7f8417a9c6fedd28 Mon Sep 17 00:00:00 2001 From: Izabela Bakollari Date: Tue, 7 Nov 2023 16:38:48 +0100 Subject: [PATCH] net: transfer rtnl_lock() requirement from ethtool_set_ethtool_phy_ops() to caller JIRA: https://issues.redhat.com/browse/RHEL-946 commit 70ef7d87f62a86674c21a99341dabc175c19681a Author: Vladimir Oltean Date: Tue Aug 1 17:28:22 2023 +0300 net: transfer rtnl_lock() requirement from ethtool_set_ethtool_phy_ops() to caller phy_init() and phy_exit() will have to do more stuff under rtnl_lock() in a future change. Since rtnl_unlock() -> netdev_run_todo() does a lot of stuff under the hood, it's a pity to lock and unlock the rtnetlink mutex twice in a row. Change the calling convention such that the only caller of ethtool_set_ethtool_phy_ops(), phy_device.c, provides a context where the rtnl_mutex is already acquired. Signed-off-by: Vladimir Oltean Link: https://lore.kernel.org/r/20230801142824.1772134-11-vladimir.oltean@nxp.com Signed-off-by: Jakub Kicinski Signed-off-by: Izabela Bakollari --- drivers/net/phy/phy_device.c | 7 +++++++ net/ethtool/common.c | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index c7cf61fe41cf..19794ff25530 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -3442,7 +3443,9 @@ static int __init phy_init(void) { int rc; + rtnl_lock(); ethtool_set_ethtool_phy_ops(&phy_ethtool_phy_ops); + rtnl_unlock(); rc = mdio_bus_init(); if (rc) @@ -3465,7 +3468,9 @@ err_c45: err_mdio_bus: mdio_bus_exit(); err_ethtool_phy_ops: + rtnl_lock(); ethtool_set_ethtool_phy_ops(NULL); + rtnl_unlock(); return rc; } @@ -3475,7 +3480,9 @@ static void __exit phy_exit(void) phy_driver_unregister(&genphy_c45_driver); phy_driver_unregister(&genphy_driver); mdio_bus_exit(); + rtnl_lock(); ethtool_set_ethtool_phy_ops(NULL); + rtnl_unlock(); } subsys_initcall(phy_init); diff --git a/net/ethtool/common.c b/net/ethtool/common.c index c586db0c5e68..47fe5e3cc231 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -664,9 +664,8 @@ const struct ethtool_phy_ops *ethtool_phy_ops; void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops) { - rtnl_lock(); + ASSERT_RTNL(); ethtool_phy_ops = ops; - rtnl_unlock(); } EXPORT_SYMBOL_GPL(ethtool_set_ethtool_phy_ops);