Skip to content

Commit d90cfe2

Browse files
idoschkuba-moo
authored andcommitted
mlxsw: spectrum_acl_tcam: Fix race during rehash delayed work
The purpose of the rehash delayed work is to reduce the number of masks (eRPs) used by an ACL region as the eRP bank is a global and limited resource. This is done in three steps: 1. Creating a new set of masks and a new ACL region which will use the new masks and to which the existing filters will be migrated to. The new region is assigned to 'vregion->region' and the region from which the filters are migrated from is assigned to 'vregion->region2'. 2. Migrating all the filters from the old region to the new region. 3. Destroying the old region and setting 'vregion->region2' to NULL. Only the second steps is performed under the 'vregion->lock' mutex although its comments says that among other things it "Protects consistency of region, region2 pointers". This is problematic as the first step can race with filter insertion from user space that uses 'vregion->region', but under the mutex. Fix by holding the mutex across the entirety of the delayed work and not only during the second step. Fixes: 2bffc53 ("mlxsw: spectrum_acl: Don't take mutex in mlxsw_sp_acl_tcam_vregion_rehash_work()") Signed-off-by: Ido Schimmel <idosch@nvidia.com> Tested-by: Alexander Zubkov <green@qrator.net> Reviewed-by: Petr Machata <petrm@nvidia.com> Signed-off-by: Petr Machata <petrm@nvidia.com> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://lore.kernel.org/r/1ec1d54edf2bad0a369e6b4fa030aba64e1f124b.1713797103.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 627f9c1 commit d90cfe2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,9 @@ static void mlxsw_sp_acl_tcam_vregion_rehash_work(struct work_struct *work)
718718
rehash.dw.work);
719719
int credits = MLXSW_SP_ACL_TCAM_VREGION_REHASH_CREDITS;
720720

721+
mutex_lock(&vregion->lock);
721722
mlxsw_sp_acl_tcam_vregion_rehash(vregion->mlxsw_sp, vregion, &credits);
723+
mutex_unlock(&vregion->lock);
722724
if (credits < 0)
723725
/* Rehash gone out of credits so it was interrupted.
724726
* Schedule the work as soon as possible to continue.
@@ -1323,7 +1325,6 @@ mlxsw_sp_acl_tcam_vregion_migrate(struct mlxsw_sp *mlxsw_sp,
13231325
int err, err2;
13241326

13251327
trace_mlxsw_sp_acl_tcam_vregion_migrate(mlxsw_sp, vregion);
1326-
mutex_lock(&vregion->lock);
13271328
err = mlxsw_sp_acl_tcam_vchunk_migrate_all(mlxsw_sp, vregion,
13281329
ctx, credits);
13291330
if (err) {
@@ -1343,7 +1344,6 @@ mlxsw_sp_acl_tcam_vregion_migrate(struct mlxsw_sp *mlxsw_sp,
13431344
/* Let the rollback to be continued later on. */
13441345
}
13451346
}
1346-
mutex_unlock(&vregion->lock);
13471347
trace_mlxsw_sp_acl_tcam_vregion_migrate_end(mlxsw_sp, vregion);
13481348
return err;
13491349
}

0 commit comments

Comments
 (0)