Skip to content

Commit ad86755

Browse files
w1ldptrSaeed Mahameed
authored andcommitted
net/mlx5e: Protect unready flows with dedicated lock
In order to remove dependency on rtnl lock for protecting unready_flows list when reoffloading unready flows on workqueue, extend representor uplink private structure with dedicated 'unready_flows_lock' mutex. Take the lock in all users of unready_flows list before accessing it. Implement helper functions to add and delete unready flow. 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 c5d326b commit ad86755

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,7 @@ static int mlx5e_init_rep_tx(struct mlx5e_priv *priv)
15601560
if (rpriv->rep->vport == MLX5_VPORT_UPLINK) {
15611561
uplink_priv = &rpriv->uplink_priv;
15621562

1563+
mutex_init(&uplink_priv->unready_flows_lock);
15631564
INIT_LIST_HEAD(&uplink_priv->unready_flows);
15641565

15651566
/* init shared tc flow table */
@@ -1604,6 +1605,7 @@ static void mlx5e_cleanup_rep_tx(struct mlx5e_priv *priv)
16041605

16051606
/* delete shared tc flow table */
16061607
mlx5e_tc_esw_cleanup(&rpriv->uplink_priv.tc_ht);
1608+
mutex_destroy(&rpriv->uplink_priv.unready_flows_lock);
16071609
}
16081610
}
16091611

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ struct mlx5_rep_uplink_priv {
7575

7676
struct mlx5_tun_entropy tun_entropy;
7777

78+
/* protects unready_flows */
79+
struct mutex unready_flows_lock;
7880
struct list_head unready_flows;
7981
struct work_struct reoffload_flows_work;
8082
};

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

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,25 @@ mlx5e_tc_unoffload_from_slow_path(struct mlx5_eswitch *esw,
996996
flow_flag_clear(flow, SLOW);
997997
}
998998

999+
/* Caller must obtain uplink_priv->unready_flows_lock mutex before calling this
1000+
* function.
1001+
*/
1002+
static void unready_flow_add(struct mlx5e_tc_flow *flow,
1003+
struct list_head *unready_flows)
1004+
{
1005+
flow_flag_set(flow, NOT_READY);
1006+
list_add_tail(&flow->unready, unready_flows);
1007+
}
1008+
1009+
/* Caller must obtain uplink_priv->unready_flows_lock mutex before calling this
1010+
* function.
1011+
*/
1012+
static void unready_flow_del(struct mlx5e_tc_flow *flow)
1013+
{
1014+
list_del(&flow->unready);
1015+
flow_flag_clear(flow, NOT_READY);
1016+
}
1017+
9991018
static void add_unready_flow(struct mlx5e_tc_flow *flow)
10001019
{
10011020
struct mlx5_rep_uplink_priv *uplink_priv;
@@ -1006,14 +1025,24 @@ static void add_unready_flow(struct mlx5e_tc_flow *flow)
10061025
rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
10071026
uplink_priv = &rpriv->uplink_priv;
10081027

1009-
flow_flag_set(flow, NOT_READY);
1010-
list_add_tail(&flow->unready, &uplink_priv->unready_flows);
1028+
mutex_lock(&uplink_priv->unready_flows_lock);
1029+
unready_flow_add(flow, &uplink_priv->unready_flows);
1030+
mutex_unlock(&uplink_priv->unready_flows_lock);
10111031
}
10121032

10131033
static void remove_unready_flow(struct mlx5e_tc_flow *flow)
10141034
{
1015-
list_del(&flow->unready);
1016-
flow_flag_clear(flow, NOT_READY);
1035+
struct mlx5_rep_uplink_priv *uplink_priv;
1036+
struct mlx5e_rep_priv *rpriv;
1037+
struct mlx5_eswitch *esw;
1038+
1039+
esw = flow->priv->mdev->priv.eswitch;
1040+
rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
1041+
uplink_priv = &rpriv->uplink_priv;
1042+
1043+
mutex_lock(&uplink_priv->unready_flows_lock);
1044+
unready_flow_del(flow);
1045+
mutex_unlock(&uplink_priv->unready_flows_lock);
10171046
}
10181047

10191048
static int
@@ -3723,10 +3752,10 @@ void mlx5e_tc_reoffload_flows_work(struct work_struct *work)
37233752
reoffload_flows_work);
37243753
struct mlx5e_tc_flow *flow, *tmp;
37253754

3726-
rtnl_lock();
3755+
mutex_lock(&rpriv->unready_flows_lock);
37273756
list_for_each_entry_safe(flow, tmp, &rpriv->unready_flows, unready) {
37283757
if (!mlx5e_tc_add_fdb_flow(flow->priv, flow, NULL))
3729-
remove_unready_flow(flow);
3758+
unready_flow_del(flow);
37303759
}
3731-
rtnl_unlock();
3760+
mutex_unlock(&rpriv->unready_flows_lock);
37323761
}

0 commit comments

Comments
 (0)