mlxsw: Couple of fixes
Subsystems (3)
cover mlxsw: Couple of fixes
From: Jiri Pirko <[email protected]>
Ido says:
The first patch prevents us from warning about valid situations that can happen due to the fact that some operations in switchdev are deferred.
Second patch fixes a long standing problem in which we didn't correctly free resources upon module removal, resulting in a memory leak.
Ido Schimmel (2):
mlxsw: spectrum_switchdev: Don't warn about valid situations
mlxsw: spectrum_switchdev: Release multicast groups during fini
.../ethernet/mellanox/mlxsw/spectrum_switchdev.c | 37 ++++++++++++++-------- 1 file changed, 24 insertions(+), 13 deletions(-)
Signature · 1 line
2.9.3
PATCH 1/2 mlxsw: spectrum_switchdev: Don't warn about valid situations
From: Ido Schimmel <[email protected]>
Some operations in the bridge driver such as MDB deletion are preformed in an atomic context and thus deferred to a process context by the switchdev infrastructure.
Therefore, by the time the operation is performed by the underlying device driver it's possible the bridge port context is already gone. This is especially true for removal flows, but theoretically can also be invoked during addition.
Remove the warnings in such situations and return normally.
--- .../ethernet/mellanox/mlxsw/spectrum_switchdev.c | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c +12 -12
@@ -626,8 +626,8 @@ static int mlxsw_sp_port_attr_br_flags_set(struct mlxsw_sp_port *mlxsw_sp_port, bridge_port =mlxsw_sp_bridge_port_find (mlxsw_sp_port->mlxsw_sp->bridge, orig_dev); -if (WARN_ON (!bridge_port)) -return -EINVAL ; +if (!bridge_port) +return 0 ; err = mlxsw_sp_bridge_port_flood_table_set(mlxsw_sp_port, bridge_port, MLXSW_SP_FLOOD_TYPE_UC,
@@ -711,8 +711,8 @@ static int mlxsw_sp_port_attr_mc_router_set(struct mlxsw_sp_port *mlxsw_sp_port, bridge_port =mlxsw_sp_bridge_port_find (mlxsw_sp_port->mlxsw_sp->bridge, orig_dev); -if (WARN_ON (!bridge_port)) -return -EINVAL ; +if (!bridge_port) +return 0 ;if (!bridge_port->bridge_device->multicast_enabled)return 0 ;
@@ -1283,15 +1283,15 @@ static int mlxsw_sp_port_mdb_add(struct mlxsw_sp_port *mlxsw_sp_port,return 0 ; bridge_port =mlxsw_sp_bridge_port_find (mlxsw_sp->bridge, orig_dev); -if (WARN_ON (!bridge_port)) -return -EINVAL ; +if (!bridge_port) +return 0 ; bridge_device = bridge_port->bridge_device; mlxsw_sp_port_vlan =mlxsw_sp_port_vlan_find_by_bridge (mlxsw_sp_port, bridge_device, mdb->vid); -if (WARN_ON (!mlxsw_sp_port_vlan)) -return -EINVAL ; +if (!mlxsw_sp_port_vlan) +return 0 ; fid_index =mlxsw_sp_fid_index (mlxsw_sp_port_vlan->fid);
@@ -1407,15 +1407,15 @@ static int mlxsw_sp_port_mdb_del(struct mlxsw_sp_port *mlxsw_sp_port,int err =0 ; bridge_port =mlxsw_sp_bridge_port_find (mlxsw_sp->bridge, orig_dev); -if (WARN_ON (!bridge_port)) -return -EINVAL ; +if (!bridge_port) +return 0 ; bridge_device = bridge_port->bridge_device; mlxsw_sp_port_vlan =mlxsw_sp_port_vlan_find_by_bridge (mlxsw_sp_port, bridge_device, mdb->vid); -if (WARN_ON (!mlxsw_sp_port_vlan)) -return -EINVAL ; +if (!mlxsw_sp_port_vlan) +return 0 ; fid_index =mlxsw_sp_fid_index (mlxsw_sp_port_vlan->fid);
Signature · 1 line
2.9.3
PATCH 2/2 mlxsw: spectrum_switchdev: Release multicast groups during fini
In reply to Jiri PirkoFrom: Ido Schimmel <[email protected]>
Each multicast group (MID) stores a bitmap of ports to which a packet should be forwarded to in case an MDB entry associated with the MID is hit.
Since the initial introduction of IGMP snooping in commit 3a49b4fde2a1 ("mlxsw: Adding layer 2 multicast support") the driver didn't correctly free these multicast groups upon ungraceful situations such as the removal of the upper bridge device or module removal.
The correct way to fix this is to associate each MID with the bridge ports member in it and then drop the reference in case the bridge port is destroyed, but this will result in a lot more code and will be fixed in net-next.
For now, upon module removal, traverse the MID list and release each one.
--- drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c +12 -1
@@ -1974,6 +1974,17 @@ static void mlxsw_sp_fdb_fini(struct mlxsw_sp *mlxsw_sp) } +static void mlxsw_sp_mids_fini (struct mlxsw_sp *mlxsw_sp) +{ +struct mlxsw_sp_mid *mid, *tmp; + +list_for_each_entry_safe (mid, tmp, &mlxsw_sp->bridge->mids_list, list) { +list_del (&mid->list); +clear_bit (mid->mid, mlxsw_sp->bridge->mids_bitmap); +kfree (mid); + } +} +int mlxsw_sp_switchdev_init (struct mlxsw_sp *mlxsw_sp) {struct mlxsw_sp_bridge *bridge;
@@ -1996,7 +2007,7 @@ int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp)void mlxsw_sp_switchdev_fini (struct mlxsw_sp *mlxsw_sp) {mlxsw_sp_fdb_fini (mlxsw_sp); -WARN_ON (!list_empty (&mlxsw_sp->bridge->mids_list)); +mlxsw_sp_mids_fini (mlxsw_sp);WARN_ON (!list_empty (&mlxsw_sp->bridge->bridges_list));kfree (mlxsw_sp->bridge); }
Signature · 1 line
2.9.3
David Miller
maintainerFrom: Jiri Pirko <[email protected]>
Date: Fri, 4 Aug 2017 14:12:28 +0200
Quoted 9 lines
From: Jiri Pirko <[email protected]>
Ido says:
The first patch prevents us from warning about valid situations that can happen due to the fact that some operations in switchdev are deferred.
Second patch fixes a long standing problem in which we didn't correctly free resources upon module removal, resulting in a memory leak.
Series applied, thanks!