Netdev List
 help / color / mirror / Atom feed
From: Saeed Mahameed <saeedm@mellanox.com>
To: "David S. Miller" <davem@davemloft.net>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Vlad Buslov <vladbu@mellanox.com>,
	Jianbo Liu <jianbol@mellanox.com>, Roi Dayan <roid@mellanox.com>,
	Saeed Mahameed <saeedm@mellanox.com>
Subject: [net-next 13/13] net/mlx5e: Protect tc flow table with mutex
Date: Mon, 29 Jul 2019 23:50:36 +0000	[thread overview]
Message-ID: <20190729234934.23595-14-saeedm@mellanox.com> (raw)
In-Reply-To: <20190729234934.23595-1-saeedm@mellanox.com>

From: Vlad Buslov <vladbu@mellanox.com>

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 | 2 ++
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 7 +++++++
 2 files changed, 9 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h b/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h
index eb70ada89b09..4518ce19112e 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h
@@ -10,6 +10,8 @@ enum {
 };
 
 struct mlx5e_tc_table {
+	/* protects flow table */
+	struct mutex			t_lock;
 	struct mlx5_flow_table		*t;
 
 	struct rhashtable               ht;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index 595a4c5667ea..f3ed028d5017 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -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)
-- 
2.21.0


  parent reply	other threads:[~2019-07-29 23:52 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-29 23:50 [pull request][net-next 00/13] Mellanox, mlx5 tc flow handling for concurrent execution (Part 1) Saeed Mahameed
2019-07-29 23:50 ` [net-next 01/13] net/mlx5e: Print a warning when LRO feature is dropped or not allowed Saeed Mahameed
2019-07-30 15:52   ` Willem de Bruijn
2019-07-30 20:07     ` Saeed Mahameed
2019-07-30 21:34       ` Willem de Bruijn
2019-07-29 23:50 ` [net-next 02/13] net/mlx5e: Avoid warning print when not required Saeed Mahameed
2019-07-29 23:50 ` [net-next 03/13] net/mlx5e: Improve ethtool rxnfc callback structure Saeed Mahameed
2019-07-29 23:50 ` [net-next 04/13] net/mlx5e: Fix unnecessary flow_block_cb_is_busy call Saeed Mahameed
2019-07-29 23:50 ` [net-next 05/13] net/mlx5e: Simplify get_route_and_out_devs helper function Saeed Mahameed
2019-07-29 23:50 ` [net-next 06/13] net/mlx5e: Extend tc flow struct with reference counter Saeed Mahameed
2019-07-29 23:50 ` [net-next 07/13] net/mlx5e: Change flow flags type to unsigned long Saeed Mahameed
2019-07-29 23:50 ` [net-next 08/13] net/mlx5e: Protect tc flows hashtable with rcu Saeed Mahameed
2019-07-30 16:15   ` Willem de Bruijn
2019-07-30 16:37     ` Willem de Bruijn
2019-07-30 20:09       ` Saeed Mahameed
2019-07-29 23:50 ` [net-next 09/13] net/mlx5e: Protect unready flows with dedicated lock Saeed Mahameed
2019-07-29 23:50 ` [net-next 10/13] net/mlx5e: Eswitch, change offloads num_flows type to atomic64 Saeed Mahameed
2019-07-29 23:50 ` [net-next 11/13] net/mlx5e: Eswitch, use state_lock to synchronize vlan change Saeed Mahameed
2019-07-29 23:50 ` [net-next 12/13] net/mlx5e: Rely on rcu instead of rtnl lock when getting upper dev Saeed Mahameed
2019-07-29 23:50 ` Saeed Mahameed [this message]
2019-07-31 22:48 ` [pull request][net-next 00/13] Mellanox, mlx5 tc flow handling for concurrent execution (Part 1) David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190729234934.23595-14-saeedm@mellanox.com \
    --to=saeedm@mellanox.com \
    --cc=davem@davemloft.net \
    --cc=jianbol@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=roid@mellanox.com \
    --cc=vladbu@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox