Skip to content

Commit 525e84b

Browse files
w1ldptrSaeed Mahameed
authored andcommitted
net/mlx5e: Eswitch, change offloads num_flows type to atomic64
Eswitch implements its own locking by means of state_lock mutex and multiple fine-grained lock in containing data structures, and is supposed to not rely on rtnl lock. However, eswitch offloads num_flows type is a regular long long integer and cannot be modified concurrently. This is an implicit assumptions that mlx5 tc is serialized (by rtnl lock or any other means). In order to remove implicit dependency on rtnl lock, change num_flows type to atomic64 to allow concurrent modifications. Signed-off-by: Vlad Buslov <[email protected]> Reviewed-by: Jianbo Liu <[email protected]> Reviewed-by: Roi Dayan <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent ad86755 commit 525e84b

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

drivers/net/ethernet/mellanox/mlx5/core/eswitch.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,6 +1933,7 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev)
19331933

19341934
hash_init(esw->offloads.encap_tbl);
19351935
hash_init(esw->offloads.mod_hdr_tbl);
1936+
atomic64_set(&esw->offloads.num_flows, 0);
19361937
mutex_init(&esw->state_lock);
19371938

19381939
mlx5_esw_for_all_vports(esw, i, vport) {

drivers/net/ethernet/mellanox/mlx5/core/eswitch.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include <linux/if_ether.h>
3737
#include <linux/if_link.h>
38+
#include <linux/atomic.h>
3839
#include <net/devlink.h>
3940
#include <linux/mlx5/device.h>
4041
#include <linux/mlx5/eswitch.h>
@@ -179,7 +180,7 @@ struct mlx5_esw_offload {
179180
struct mutex termtbl_mutex; /* protects termtbl hash */
180181
const struct mlx5_eswitch_rep_ops *rep_ops[NUM_REP_TYPES];
181182
u8 inline_mode;
182-
u64 num_flows;
183+
atomic64_t num_flows;
183184
enum devlink_eswitch_encap_mode encap;
184185
};
185186

drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
233233
if (IS_ERR(rule))
234234
goto err_add_rule;
235235
else
236-
esw->offloads.num_flows++;
236+
atomic64_inc(&esw->offloads.num_flows);
237237

238238
return rule;
239239

@@ -298,7 +298,7 @@ mlx5_eswitch_add_fwd_rule(struct mlx5_eswitch *esw,
298298
if (IS_ERR(rule))
299299
goto add_err;
300300

301-
esw->offloads.num_flows++;
301+
atomic64_inc(&esw->offloads.num_flows);
302302

303303
return rule;
304304
add_err:
@@ -326,7 +326,7 @@ __mlx5_eswitch_del_rule(struct mlx5_eswitch *esw,
326326
mlx5_eswitch_termtbl_put(esw, attr->dests[i].termtbl);
327327
}
328328

329-
esw->offloads.num_flows--;
329+
atomic64_dec(&esw->offloads.num_flows);
330330

331331
if (fwd_rule) {
332332
esw_put_prio_table(esw, attr->chain, attr->prio, 1);
@@ -2349,7 +2349,7 @@ int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode,
23492349
break;
23502350
}
23512351

2352-
if (esw->offloads.num_flows > 0) {
2352+
if (atomic64_read(&esw->offloads.num_flows) > 0) {
23532353
NL_SET_ERR_MSG_MOD(extack,
23542354
"Can't set inline mode when flows are configured");
23552355
return -EOPNOTSUPP;
@@ -2459,7 +2459,7 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink,
24592459
if (esw->offloads.encap == encap)
24602460
return 0;
24612461

2462-
if (esw->offloads.num_flows > 0) {
2462+
if (atomic64_read(&esw->offloads.num_flows) > 0) {
24632463
NL_SET_ERR_MSG_MOD(extack,
24642464
"Can't set encapsulation when flows are configured");
24652465
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)