Skip to content

Commit 0e18134

Browse files
w1ldptrSaeed Mahameed
authored andcommitted
net/mlx5e: Eswitch, use state_lock to synchronize vlan change
esw->state_lock is already used to protect vlan vport configuration change. However, all preparation and correctness checks, and code that sets vport data are not protected by this lock and assume external synchronization by rtnl lock. In order to remove dependency on rtnl lock, extend esw->state_lock protection to whole eswitch vlan add/del functions. 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 525e84b commit 0e18134

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,35 +2086,36 @@ int __mlx5_eswitch_set_vport_vlan(struct mlx5_eswitch *esw,
20862086
if (vlan > 4095 || qos > 7)
20872087
return -EINVAL;
20882088

2089-
mutex_lock(&esw->state_lock);
2090-
20912089
err = modify_esw_vport_cvlan(esw->dev, vport, vlan, qos, set_flags);
20922090
if (err)
2093-
goto unlock;
2091+
return err;
20942092

20952093
evport->info.vlan = vlan;
20962094
evport->info.qos = qos;
20972095
if (evport->enabled && esw->mode == MLX5_ESWITCH_LEGACY) {
20982096
err = esw_vport_ingress_config(esw, evport);
20992097
if (err)
2100-
goto unlock;
2098+
return err;
21012099
err = esw_vport_egress_config(esw, evport);
21022100
}
21032101

2104-
unlock:
2105-
mutex_unlock(&esw->state_lock);
21062102
return err;
21072103
}
21082104

21092105
int mlx5_eswitch_set_vport_vlan(struct mlx5_eswitch *esw,
21102106
u16 vport, u16 vlan, u8 qos)
21112107
{
21122108
u8 set_flags = 0;
2109+
int err;
21132110

21142111
if (vlan || qos)
21152112
set_flags = SET_VLAN_STRIP | SET_VLAN_INSERT;
21162113

2117-
return __mlx5_eswitch_set_vport_vlan(esw, vport, vlan, qos, set_flags);
2114+
mutex_lock(&esw->state_lock);
2115+
err = __mlx5_eswitch_set_vport_vlan(esw, vport, vlan, qos, set_flags);
2116+
mutex_unlock(&esw->state_lock);
2117+
2118+
return err;
21182119
}
21192120

21202121
int mlx5_eswitch_set_vport_spoofchk(struct mlx5_eswitch *esw,

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,11 @@ int mlx5_eswitch_add_vlan_action(struct mlx5_eswitch *esw,
442442
fwd = !!((attr->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) &&
443443
!attr->dest_chain);
444444

445+
mutex_lock(&esw->state_lock);
446+
445447
err = esw_add_vlan_action_check(attr, push, pop, fwd);
446448
if (err)
447-
return err;
449+
goto unlock;
448450

449451
attr->vlan_handled = false;
450452

@@ -457,11 +459,11 @@ int mlx5_eswitch_add_vlan_action(struct mlx5_eswitch *esw,
457459
attr->vlan_handled = true;
458460
}
459461

460-
return 0;
462+
goto unlock;
461463
}
462464

463465
if (!push && !pop)
464-
return 0;
466+
goto unlock;
465467

466468
if (!(offloads->vlan_push_pop_refcount)) {
467469
/* it's the 1st vlan rule, apply global vlan pop policy */
@@ -486,6 +488,8 @@ int mlx5_eswitch_add_vlan_action(struct mlx5_eswitch *esw,
486488
out:
487489
if (!err)
488490
attr->vlan_handled = true;
491+
unlock:
492+
mutex_unlock(&esw->state_lock);
489493
return err;
490494
}
491495

@@ -508,14 +512,16 @@ int mlx5_eswitch_del_vlan_action(struct mlx5_eswitch *esw,
508512
pop = !!(attr->action & MLX5_FLOW_CONTEXT_ACTION_VLAN_POP);
509513
fwd = !!(attr->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST);
510514

515+
mutex_lock(&esw->state_lock);
516+
511517
vport = esw_vlan_action_get_vport(attr, push, pop);
512518

513519
if (!push && !pop && fwd) {
514520
/* tracks VF --> wire rules without vlan push action */
515521
if (attr->dests[0].rep->vport == MLX5_VPORT_UPLINK)
516522
vport->vlan_refcount--;
517523

518-
return 0;
524+
goto out;
519525
}
520526

521527
if (push) {
@@ -533,12 +539,13 @@ int mlx5_eswitch_del_vlan_action(struct mlx5_eswitch *esw,
533539
skip_unset_push:
534540
offloads->vlan_push_pop_refcount--;
535541
if (offloads->vlan_push_pop_refcount)
536-
return 0;
542+
goto out;
537543

538544
/* no more vlan rules, stop global vlan pop policy */
539545
err = esw_set_global_vlan_pop(esw, 0);
540546

541547
out:
548+
mutex_unlock(&esw->state_lock);
542549
return err;
543550
}
544551

0 commit comments

Comments
 (0)