Skip to content

Commit 5ec2ee2

Browse files
jpirkodavem330
authored andcommitted
mlxsw: spectrum_acl: Introduce a mutex to guard region list updates
In order to remove RTNL lock dependency, it is needed to protect the regions list in a group. Introduce a mutex to do the job. Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 2802aad commit 5ec2ee2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/list.h>
99
#include <linux/rhashtable.h>
1010
#include <linux/netdevice.h>
11+
#include <linux/mutex.h>
1112
#include <trace/events/mlxsw.h>
1213

1314
#include "reg.h"
@@ -161,6 +162,7 @@ struct mlxsw_sp_acl_tcam_pattern {
161162
struct mlxsw_sp_acl_tcam_group {
162163
struct mlxsw_sp_acl_tcam *tcam;
163164
u16 id;
165+
struct mutex lock; /* guards region list updates */
164166
struct list_head region_list;
165167
unsigned int region_count;
166168
};
@@ -259,6 +261,7 @@ mlxsw_sp_acl_tcam_group_add(struct mlxsw_sp_acl_tcam *tcam,
259261
int err;
260262

261263
group->tcam = tcam;
264+
mutex_init(&group->lock);
262265
INIT_LIST_HEAD(&group->region_list);
263266

264267
err = mlxsw_sp_acl_tcam_group_id_get(tcam, &group->id);
@@ -272,6 +275,7 @@ static void mlxsw_sp_acl_tcam_group_del(struct mlxsw_sp_acl_tcam_group *group)
272275
{
273276
struct mlxsw_sp_acl_tcam *tcam = group->tcam;
274277

278+
mutex_destroy(&group->lock);
275279
mlxsw_sp_acl_tcam_group_id_put(tcam, group->id);
276280
WARN_ON(!list_empty(&group->region_list));
277281
}
@@ -390,8 +394,11 @@ mlxsw_sp_acl_tcam_group_region_attach(struct mlxsw_sp *mlxsw_sp,
390394
struct list_head *pos;
391395
int err;
392396

393-
if (group->region_count == group->tcam->max_group_size)
394-
return -ENOBUFS;
397+
mutex_lock(&group->lock);
398+
if (group->region_count == group->tcam->max_group_size) {
399+
err = -ENOBUFS;
400+
goto err_region_count_check;
401+
}
395402

396403
if (next_region) {
397404
/* If the next region is defined, place the new one
@@ -415,10 +422,13 @@ mlxsw_sp_acl_tcam_group_region_attach(struct mlxsw_sp *mlxsw_sp,
415422
goto err_group_update;
416423

417424
group->region_count++;
425+
mutex_unlock(&group->lock);
418426
return 0;
419427

420428
err_group_update:
421429
list_del(&region->list);
430+
err_region_count_check:
431+
mutex_unlock(&group->lock);
422432
return err;
423433
}
424434

@@ -428,9 +438,11 @@ mlxsw_sp_acl_tcam_group_region_detach(struct mlxsw_sp *mlxsw_sp,
428438
{
429439
struct mlxsw_sp_acl_tcam_group *group = region->group;
430440

441+
mutex_lock(&group->lock);
431442
list_del(&region->list);
432443
group->region_count--;
433444
mlxsw_sp_acl_tcam_group_update(mlxsw_sp, group);
445+
mutex_unlock(&group->lock);
434446
}
435447

436448
static int

0 commit comments

Comments
 (0)