net/mlx5e: Protect tc flow table with mutex
authorVlad Buslov <vladbu@mellanox.com>
Mon, 17 Sep 2018 11:01:58 +0000 (14:01 +0300)
committerSaeed Mahameed <saeedm@mellanox.com>
Mon, 29 Jul 2019 23:40:26 +0000 (16:40 -0700)
TC flow table is created when first flow is added, and destroyed when last
flow is removed. This assumes that all accesses to the table are externally
synchronized with rtnl lock. To remove dependency on rtnl lock, add new
mutex mlx5e_tc_table->t_lock and use it to protect the flow table.

Signed-off-by: Vlad Buslov <vladbu@mellanox.com>
Reviewed-by: Jianbo Liu <jianbol@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/en/fs.h
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

index eb70ada89b09a0706b6fe241e3d693991c481a02..4518ce19112ea15bb815b79b599ce130f1c0f427 100644 (file)
@@ -10,6 +10,8 @@ enum {
 };
 
 struct mlx5e_tc_table {
+       /* protects flow table */
+       struct mutex                    t_lock;
        struct mlx5_flow_table          *t;
 
        struct rhashtable               ht;
index 595a4c5667eaffcdc12604fa144f947250c7c170..f3ed028d50176b2af3bbc39f52aa169ff8153d92 100644 (file)
@@ -854,6 +854,7 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
                        return err;
        }
 
+       mutex_lock(&priv->fs.tc.t_lock);
        if (IS_ERR_OR_NULL(priv->fs.tc.t)) {
                int tc_grp_size, tc_tbl_size;
                u32 max_flow_counter;
@@ -873,6 +874,7 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
                                                            MLX5E_TC_TABLE_NUM_GROUPS,
                                                            MLX5E_TC_FT_LEVEL, 0);
                if (IS_ERR(priv->fs.tc.t)) {
+                       mutex_unlock(&priv->fs.tc.t_lock);
                        NL_SET_ERR_MSG_MOD(extack,
                                           "Failed to create tc offload table\n");
                        netdev_err(priv->netdev,
@@ -886,6 +888,7 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
 
        flow->rule[0] = mlx5_add_flow_rules(priv->fs.tc.t, &parse_attr->spec,
                                            &flow_act, dest, dest_ix);
+       mutex_unlock(&priv->fs.tc.t_lock);
 
        if (IS_ERR(flow->rule[0]))
                return PTR_ERR(flow->rule[0]);
@@ -904,10 +907,12 @@ static void mlx5e_tc_del_nic_flow(struct mlx5e_priv *priv,
                mlx5_del_flow_rules(flow->rule[0]);
        mlx5_fc_destroy(priv->mdev, counter);
 
+       mutex_lock(&priv->fs.tc.t_lock);
        if (!mlx5e_tc_num_filters(priv, MLX5_TC_FLAG(NIC_OFFLOAD)) && priv->fs.tc.t) {
                mlx5_destroy_flow_table(priv->fs.tc.t);
                priv->fs.tc.t = NULL;
        }
+       mutex_unlock(&priv->fs.tc.t_lock);
 
        if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)
                mlx5e_detach_mod_hdr(priv, flow);
@@ -3684,6 +3689,7 @@ int mlx5e_tc_nic_init(struct mlx5e_priv *priv)
        struct mlx5e_tc_table *tc = &priv->fs.tc;
        int err;
 
+       mutex_init(&tc->t_lock);
        hash_init(tc->mod_hdr_tbl);
        hash_init(tc->hairpin_tbl);
 
@@ -3722,6 +3728,7 @@ void mlx5e_tc_nic_cleanup(struct mlx5e_priv *priv)
                mlx5_destroy_flow_table(tc->t);
                tc->t = NULL;
        }
+       mutex_destroy(&tc->t_lock);
 }
 
 int mlx5e_tc_esw_init(struct rhashtable *tc_ht)