Skip to contentSkip to conversation

net: net_failover: Fix the deadlock in slave register

PATCH Superseded [email protected] 3 participants 4 messages May 7 – May 13

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 net: net_failover: Fix the deadlock in slave register

From: Faicker Mo <[email protected]>

There is netdev_lock_ops() before the NETDEV_REGISTER notifier in register_netdevice(), so use the non-locking functions in net_failover_slave_register().

Call Trace:
 <TASK>
 __schedule+0x30d/0x7a0
 schedule+0x27/0x90
 schedule_preempt_disabled+0x15/0x30
 __mutex_lock.constprop.0+0x538/0x9e0
 __mutex_lock_slowpath+0x13/0x20
 mutex_lock+0x3b/0x50
 dev_set_mtu+0x40/0xe0
 net_failover_slave_register+0x24/0x280
 failover_slave_register+0x103/0x1b0
 failover_event+0x15e/0x210
 ? dropmon_net_event+0xac/0xe0
 notifier_call_chain+0x5e/0xe0
 raw_notifier_call_chain+0x16/0x30
 call_netdevice_notifiers_info+0x52/0xa0
 register_netdevice+0x5f4/0x7c0
 register_netdev+0x1e/0x40
 _mlx5e_probe+0xe2/0x370 [mlx5_core]
 mlx5e_probe+0x59/0x70 [mlx5_core]
 ? __pfx_mlx5e_probe+0x10/0x10 [mlx5_core]
Fixes 4c975fd70002 ("net: hold instance lock during NETDEV_REGISTER/UP")

---
Changes since v1:
- Fix the space chars (Simon)
- Change the dev_close to netif_close (Simon)
- Change the label err_dev_open to err_netif_open
Changes since v2:
- Add lock ops in failover_existing_slave_register (Jakub Kicinski)

---
 drivers/net/net_failover.c | 12 ++++++------
 net/core/failover.c        |  5 ++++-
 2 files changed, 10 insertions(+), 7 deletions(-)
drivers/net/net_failover.c +6 -6
index d0361aaf25ef..3f7d31033bae 100644
@@ -502,7 +502,7 @@ static int net_failover_slave_register(struct net_device *slave_dev,
 
 	/* Align MTU of slave with failover dev */
 	orig_mtu = slave_dev->mtu;
-	err = dev_set_mtu(slave_dev, failover_dev->mtu);
+	err = netif_set_mtu(slave_dev, failover_dev->mtu);
 	if (err) {
 		netdev_err(failover_dev, "unable to change mtu of %s to %u register failed\n",
 			   slave_dev->name, failover_dev->mtu);
@@ -512,11 +512,11 @@ static int net_failover_slave_register(struct net_device *slave_dev,
 	dev_hold(slave_dev);
 
 	if (netif_running(failover_dev)) {
-		err = dev_open(slave_dev, NULL);
+		err = netif_open(slave_dev, NULL);
 		if (err && (err != -EBUSY)) {
 			netdev_err(failover_dev, "Opening slave %s failed err:%d\n",
 				   slave_dev->name, err);
-			goto err_dev_open;
+			goto err_netif_open;
 		}
 	}
 
@@ -562,10 +562,10 @@ static int net_failover_slave_register(struct net_device *slave_dev,
 err_vlan_add:
 	dev_uc_unsync(slave_dev, failover_dev);
 	dev_mc_unsync(slave_dev, failover_dev);
-	dev_close(slave_dev);
-err_dev_open:
+	netif_close(slave_dev);
+err_netif_open:
 	dev_put(slave_dev);
-	dev_set_mtu(slave_dev, orig_mtu);
+	netif_set_mtu(slave_dev, orig_mtu);
 done:
 	return err;
 }
net/core/failover.c +4 -1
index 11bb183c7a1b..122fbcbf915a 100644
@@ -221,8 +221,11 @@ failover_existing_slave_register(struct net_device *failover_dev)
 	for_each_netdev(net, dev) {
 		if (netif_is_failover(dev))
 			continue;
-		if (ether_addr_equal(failover_dev->perm_addr, dev->perm_addr))
+		if (ether_addr_equal(failover_dev->perm_addr, dev->perm_addr)) {
+			netdev_lock_ops(dev);
 			failover_slave_register(dev);
+			netdev_unlock_ops(dev);
+		}
 	}
 	rtnl_unlock();
 }
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 3 lines · On Thu, 7 May 2026 15:43:32 +0800 [email protected] wrote:

There is netdev_lock_ops() before the NETDEV_REGISTER notifier in register_netdevice(), so use the non-locking functions in net_failover_slave_register().

net/core/failover.c:227:25: error: implicit declaration of function ‘netdev_unlock_ops’; did you mean ‘netdev_unlock’? [-Wimplicit-function-declaration]

  227 |                         netdev_unlock_ops(dev);
      |                         ^~~~~~~~~~~~~~~~~
Signature · 1 line
pw-bot: cr
#2 lore raw
In reply to [email protected]
kernel test robot noticed the following build errors:

Hi,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]
[also build test ERROR on net/main linus/master v7.1-rc3 next-20260508] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/faicker-mo-gmail-com/net-net_failover-Fix-the-deadlock-in-slave-register/20260513-045805
base:   net-next/main
patch link:    https://lore.kernel.org/r/20260507074332.2543229-1-faicker.mo%40gmail.com
patch subject: [PATCH v3] net: net_failover: Fix the deadlock in slave register
config: riscv-defconfig (https://download.01.org/0day-ci/archive/20260513/[email protected]/config)
compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project 5bac06718f502014fade905512f1d26d578a18f3)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260513/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> net/core/failover.c:225:4: error: call to undeclared function 'netdev_lock_ops'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     225 |                         netdev_lock_ops(dev);
         |                         ^
   net/core/failover.c:225:4: note: did you mean 'netdev_lock'?
   include/linux/netdevice.h:2822:20: note: 'netdev_lock' declared here
    2822 | static inline void netdev_lock(struct net_device *dev)
         |                    ^
>> net/core/failover.c:227:4: error: call to undeclared function 'netdev_unlock_ops'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     227 |                         netdev_unlock_ops(dev);
         |                         ^

2 errors generated.

vim +/netdev_lock_ops +225 net/core/failover.c

213
214 static void
215 failover_existing_slave_register(struct net_device *failover_dev)
216 {
217 struct net *net = dev_net(failover_dev);
218 struct net_device *dev;
219
220 rtnl_lock();
221 for_each_netdev(net, dev) {
222 if (netif_is_failover(dev))
223 continue;
224 if (ether_addr_equal(failover_dev->perm_addr, dev->perm_addr)) {

 > 225				netdev_lock_ops(dev);
   226				failover_slave_register(dev);
 > 227				netdev_unlock_ops(dev);

228 }
229 }
230 rtnl_unlock();
231 }
232

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

#3 lore raw
In reply to [email protected]
kernel test robot noticed the following build errors:

Hi,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]
[also build test ERROR on net/main linus/master v7.1-rc3 next-20260508] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/faicker-mo-gmail-com/net-net_failover-Fix-the-deadlock-in-slave-register/20260513-045805
base:   net-next/main
patch link:    https://lore.kernel.org/r/20260507074332.2543229-1-faicker.mo%40gmail.com
patch subject: [PATCH v3] net: net_failover: Fix the deadlock in slave register
config: i386-randconfig-141-20260513 (https://download.01.org/0day-ci/archive/20260513/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
smatch: v0.5.0-9185-gbcc58b9c
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260513/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

net/core/failover.c: In function 'failover_existing_slave_register':

>> net/core/failover.c:225:25: error: implicit declaration of function 'netdev_lock_ops'; did you mean 'netdev_lock'? [-Wimplicit-function-declaration]
     225 |                         netdev_lock_ops(dev);
         |                         ^~~~~~~~~~~~~~~
         |                         netdev_lock
>> net/core/failover.c:227:25: error: implicit declaration of function 'netdev_unlock_ops'; did you mean 'netdev_unlock'? [-Wimplicit-function-declaration]
     227 |                         netdev_unlock_ops(dev);
         |                         ^~~~~~~~~~~~~~~~~
         |                         netdev_unlock

vim +225 net/core/failover.c

213
214 static void
215 failover_existing_slave_register(struct net_device *failover_dev)
216 {
217 struct net *net = dev_net(failover_dev);
218 struct net_device *dev;
219
220 rtnl_lock();
221 for_each_netdev(net, dev) {
222 if (netif_is_failover(dev))
223 continue;
224 if (ether_addr_equal(failover_dev->perm_addr, dev->perm_addr)) {

 > 225				netdev_lock_ops(dev);
   226				failover_slave_register(dev);
 > 227				netdev_unlock_ops(dev);

228 }
229 }
230 rtnl_unlock();
231 }
232

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki