team: fix team_adjust_ops with regard to enabled ports
team_adjust_ops should check for enabled ports, not all ports. This may lead to division by zero. This patch fixes this. Signed-off-by: Jiri Pirko <jpirko@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
72fd5a8b75
commit
122bb046bc
@@ -508,26 +508,31 @@ static void team_set_no_mode(struct team *team)
|
|||||||
team->mode = &__team_no_mode;
|
team->mode = &__team_no_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void team_adjust_ops(struct team *team)
|
static void __team_adjust_ops(struct team *team, int en_port_count)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* To avoid checks in rx/tx skb paths, ensure here that non-null and
|
* To avoid checks in rx/tx skb paths, ensure here that non-null and
|
||||||
* correct ops are always set.
|
* correct ops are always set.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (list_empty(&team->port_list) ||
|
if (!en_port_count || !team_is_mode_set(team) ||
|
||||||
!team_is_mode_set(team) || !team->mode->ops->transmit)
|
!team->mode->ops->transmit)
|
||||||
team->ops.transmit = team_dummy_transmit;
|
team->ops.transmit = team_dummy_transmit;
|
||||||
else
|
else
|
||||||
team->ops.transmit = team->mode->ops->transmit;
|
team->ops.transmit = team->mode->ops->transmit;
|
||||||
|
|
||||||
if (list_empty(&team->port_list) ||
|
if (!en_port_count || !team_is_mode_set(team) ||
|
||||||
!team_is_mode_set(team) || !team->mode->ops->receive)
|
!team->mode->ops->receive)
|
||||||
team->ops.receive = team_dummy_receive;
|
team->ops.receive = team_dummy_receive;
|
||||||
else
|
else
|
||||||
team->ops.receive = team->mode->ops->receive;
|
team->ops.receive = team->mode->ops->receive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void team_adjust_ops(struct team *team)
|
||||||
|
{
|
||||||
|
__team_adjust_ops(team, team->en_port_count);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We can benefit from the fact that it's ensured no port is present
|
* We can benefit from the fact that it's ensured no port is present
|
||||||
* at the time of mode change. Therefore no packets are in fly so there's no
|
* at the time of mode change. Therefore no packets are in fly so there's no
|
||||||
@@ -687,6 +692,7 @@ static void team_port_enable(struct team *team,
|
|||||||
port->index = team->en_port_count++;
|
port->index = team->en_port_count++;
|
||||||
hlist_add_head_rcu(&port->hlist,
|
hlist_add_head_rcu(&port->hlist,
|
||||||
team_port_index_hash(team, port->index));
|
team_port_index_hash(team, port->index));
|
||||||
|
team_adjust_ops(team);
|
||||||
if (team->ops.port_enabled)
|
if (team->ops.port_enabled)
|
||||||
team->ops.port_enabled(team, port);
|
team->ops.port_enabled(team, port);
|
||||||
}
|
}
|
||||||
@@ -708,16 +714,20 @@ static void __reconstruct_port_hlist(struct team *team, int rm_index)
|
|||||||
static void team_port_disable(struct team *team,
|
static void team_port_disable(struct team *team,
|
||||||
struct team_port *port)
|
struct team_port *port)
|
||||||
{
|
{
|
||||||
int rm_index = port->index;
|
|
||||||
|
|
||||||
if (!team_port_enabled(port))
|
if (!team_port_enabled(port))
|
||||||
return;
|
return;
|
||||||
if (team->ops.port_disabled)
|
if (team->ops.port_disabled)
|
||||||
team->ops.port_disabled(team, port);
|
team->ops.port_disabled(team, port);
|
||||||
hlist_del_rcu(&port->hlist);
|
hlist_del_rcu(&port->hlist);
|
||||||
__reconstruct_port_hlist(team, rm_index);
|
__reconstruct_port_hlist(team, port->index);
|
||||||
team->en_port_count--;
|
|
||||||
port->index = -1;
|
port->index = -1;
|
||||||
|
__team_adjust_ops(team, team->en_port_count - 1);
|
||||||
|
/*
|
||||||
|
* Wait until readers see adjusted ops. This ensures that
|
||||||
|
* readers never see team->en_port_count == 0
|
||||||
|
*/
|
||||||
|
synchronize_rcu();
|
||||||
|
team->en_port_count--;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TEAM_VLAN_FEATURES (NETIF_F_ALL_CSUM | NETIF_F_SG | \
|
#define TEAM_VLAN_FEATURES (NETIF_F_ALL_CSUM | NETIF_F_SG | \
|
||||||
@@ -874,7 +884,6 @@ static int team_port_add(struct team *team, struct net_device *port_dev)
|
|||||||
port->index = -1;
|
port->index = -1;
|
||||||
team_port_enable(team, port);
|
team_port_enable(team, port);
|
||||||
list_add_tail_rcu(&port->list, &team->port_list);
|
list_add_tail_rcu(&port->list, &team->port_list);
|
||||||
team_adjust_ops(team);
|
|
||||||
__team_compute_features(team);
|
__team_compute_features(team);
|
||||||
__team_port_change_check(port, !!netif_carrier_ok(port_dev));
|
__team_port_change_check(port, !!netif_carrier_ok(port_dev));
|
||||||
__team_options_change_check(team);
|
__team_options_change_check(team);
|
||||||
@@ -928,7 +937,6 @@ static int team_port_del(struct team *team, struct net_device *port_dev)
|
|||||||
__team_port_change_check(port, false);
|
__team_port_change_check(port, false);
|
||||||
team_port_disable(team, port);
|
team_port_disable(team, port);
|
||||||
list_del_rcu(&port->list);
|
list_del_rcu(&port->list);
|
||||||
team_adjust_ops(team);
|
|
||||||
netdev_rx_handler_unregister(port_dev);
|
netdev_rx_handler_unregister(port_dev);
|
||||||
netdev_set_master(port_dev, NULL);
|
netdev_set_master(port_dev, NULL);
|
||||||
vlan_vids_del_by_dev(port_dev, dev);
|
vlan_vids_del_by_dev(port_dev, dev);
|
||||||
|
Reference in New Issue
Block a user