net: team: don't recurse on the port's netdev ops lock

__team_port_change_send() calls __ethtool_get_link_ksettings() on
the port, which will soon take the port's ops lock. The notifier
caller already holds it while the slave-add/del callers do not,
so the function would either deadlock or run unprotected depending
on the path.

Make __team_port_change_send() expect the port's ops lock held and
switch to netif_get_link_ksettings(). team_device_event()'s NETDEV_UP /
NETDEV_CHANGE already arrive with the port's ops lock held.
team_port_add() now take it explicitly.

Note that NETDEV_DOWN and team_port_del() will pass false as @linkup
so they will not execute netif_get_link_ksettings(). This is fortunate
as NETDEV_DOWN has somewhat mixed locking right now.

Link: https://patch.msgid.link/20260603012840.2254293-7-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski
2026-06-02 18:28:35 -07:00
parent 107b097790
commit a6882c1583

View File

@@ -1375,7 +1375,9 @@ static int team_port_add(struct team *team, struct net_device *port_dev,
list_add_tail_rcu(&port->list, &team->port_list);
team_port_enable(team, port);
netdev_compute_master_upper_features(dev, true);
netdev_lock_ops(port_dev);
__team_port_change_port_added(port, !!netif_oper_up(port_dev));
netdev_unlock_ops(port_dev);
__team_options_change_check(team);
netdev_info(dev, "Port device %s added\n", portname);
@@ -3090,7 +3092,7 @@ static void __team_port_change_send(struct team_port *port, bool linkup)
if (linkup) {
struct ethtool_link_ksettings ecmd;
err = __ethtool_get_link_ksettings(port->dev, &ecmd);
err = netif_get_link_ksettings(port->dev, &ecmd);
if (!err) {
port->state.speed = ecmd.base.speed;
port->state.duplex = ecmd.base.duplex;