]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: bridge: don't recurse on the port's netdev ops lock
authorJakub Kicinski <kuba@kernel.org>
Wed, 3 Jun 2026 01:28:36 +0000 (18:28 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 4 Jun 2026 21:04:56 +0000 (14:04 -0700)
port_cost() calls __ethtool_get_link_ksettings() on the port device,
which will soon take the port's ops lock. br_port_carrier_check()
is reached via the NETDEV_CHANGE notifier from linkwatch, which
already holds the port's ops lock, so the call would deadlock.

Make port_cost() expect the port's ops lock held and switch to
netif_get_link_ksettings(). The only other caller is new_nbp(),
make sure it takes the lock explicitly.

Reviewed-by: Nicolai Buchwitz <nb@tipi-net.de>
Acked-by: Nikolay Aleksandrov <razor@blackwall.org>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Link: https://patch.msgid.link/20260603012840.2254293-8-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/bridge/br_if.c

index d39571e13744431f5e4c67f34ee7de34eb8bb6b0..049d1d25bc2602bfd6e25ee5199151172834f7b3 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/if_ether.h>
 #include <linux/slab.h>
 #include <net/dsa.h>
+#include <net/netdev_lock.h>
 #include <net/sock.h>
 #include <linux/if_vlan.h>
 #include <net/switchdev.h>
  * Determine initial path cost based on speed.
  * using recommendations from 802.1d standard
  *
- * Since driver might sleep need to not be holding any locks.
+ * Since driver might sleep, we need to not be holding any bridge spinlocks.
  */
 static int port_cost(struct net_device *dev)
 {
        struct ethtool_link_ksettings ecmd;
 
-       if (!__ethtool_get_link_ksettings(dev, &ecmd)) {
+       if (!netif_get_link_ksettings(dev, &ecmd)) {
                switch (ecmd.base.speed) {
                case SPEED_10000:
                        return 2;
@@ -436,7 +437,9 @@ static struct net_bridge_port *new_nbp(struct net_bridge *br,
        p->br = br;
        netdev_hold(dev, &p->dev_tracker, GFP_KERNEL);
        p->dev = dev;
+       netdev_lock_ops(dev);
        p->path_cost = port_cost(dev);
+       netdev_unlock_ops(dev);
        p->priority = 0x8000 >> BR_PORT_BITS;
        p->port_no = index;
        p->flags = BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD | BR_BCAST_FLOOD;