DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 1/2] net/mlx5: fix age action pool protection
@ 2021-11-01  6:30 Jiawei Wang
  2021-11-01  6:30 ` [dpdk-dev] [PATCH 2/2] net/mlx5: fix meter " Jiawei Wang
  2021-11-02  8:09 ` [dpdk-dev] [PATCH 1/2] net/mlx5: fix age " Raslan Darawsheh
  0 siblings, 2 replies; 3+ messages in thread
From: Jiawei Wang @ 2021-11-01  6:30 UTC (permalink / raw)
  To: matan, orika, viacheslavo, thomas, Suanming Mou; +Cc: dev, rasland, stable

The age action with flows creation could be supported on the multiple
threads. The age pools were created to manage the age resources, if
there is no room in the current pool then resize the age pool to the new
pool size and free the old one.

There's a race condition while one thread resizes the age pool and the
old pool resource be freed, and another thread query the age action
value of the old pool so the queried value is invalid.

This patch uses the read-write lock to protect the pool resource while
resizing and query.

Fixes: a5835d530f00 ("net/mlx5: optimize Rx queue match")
Cc: stable@dpdk.org

Signed-off-by: Jiawei Wang <jiaweiw@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/net/mlx5/mlx5.c          | 2 +-
 drivers/net/mlx5/mlx5.h          | 2 +-
 drivers/net/mlx5/mlx5_flow.c     | 5 ++++-
 drivers/net/mlx5/mlx5_flow_aso.c | 8 ++++----
 drivers/net/mlx5/mlx5_flow_dv.c  | 6 +++---
 5 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index 4fe7e34578..b90752c56d 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -450,7 +450,7 @@ mlx5_flow_aso_age_mng_init(struct mlx5_dev_ctx_shared *sh)
 		mlx5_free(sh->aso_age_mng);
 		return -1;
 	}
-	rte_spinlock_init(&sh->aso_age_mng->resize_sl);
+	rte_rwlock_init(&sh->aso_age_mng->resize_rwl);
 	rte_spinlock_init(&sh->aso_age_mng->free_sl);
 	LIST_INIT(&sh->aso_age_mng->free);
 	return 0;
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index a3b2a3d8e5..5e88dfcfea 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -549,7 +549,7 @@ struct mlx5_aso_age_mng {
 	struct mlx5_aso_age_pool **pools;
 	uint16_t n; /* Total number of pools. */
 	uint16_t next; /* Number of pools in use, index of next free pool. */
-	rte_spinlock_t resize_sl; /* Lock for resize objects. */
+	rte_rwlock_t resize_rwl; /* Lock for resize objects. */
 	rte_spinlock_t free_sl; /* Lock for free list access. */
 	struct aso_age_list free; /* Free age actions list - ready to use. */
 	struct mlx5_aso_sq aso_sq; /* ASO queue objects. */
diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index d222914cf5..d5ed673891 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -3675,8 +3675,11 @@ flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
 	uint16_t offset = (age_idx >> 16) & UINT16_MAX;
 	struct mlx5_priv *priv = dev->data->dev_private;
 	struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
-	struct mlx5_aso_age_pool *pool = mng->pools[pool_idx];
+	struct mlx5_aso_age_pool *pool;
 
+	rte_rwlock_read_lock(&mng->resize_rwl);
+	pool = mng->pools[pool_idx];
+	rte_rwlock_read_unlock(&mng->resize_rwl);
 	return &pool->actions[offset - 1];
 }
 
diff --git a/drivers/net/mlx5/mlx5_flow_aso.c b/drivers/net/mlx5/mlx5_flow_aso.c
index 1fc1000b01..bcdad31330 100644
--- a/drivers/net/mlx5/mlx5_flow_aso.c
+++ b/drivers/net/mlx5/mlx5_flow_aso.c
@@ -417,9 +417,9 @@ mlx5_aso_sq_enqueue_burst(struct mlx5_aso_age_mng *mng, uint16_t n)
 		wqe = &sq->sq_obj.aso_wqes[sq->head & mask];
 		rte_prefetch0(&sq->sq_obj.aso_wqes[(sq->head + 1) & mask]);
 		/* Fill next WQE. */
-		rte_spinlock_lock(&mng->resize_sl);
+		rte_rwlock_read_lock(&mng->resize_rwl);
 		pool = mng->pools[sq->next];
-		rte_spinlock_unlock(&mng->resize_sl);
+		rte_rwlock_read_unlock(&mng->resize_rwl);
 		sq->elts[sq->head & mask].pool = pool;
 		wqe->general_cseg.misc =
 				rte_cpu_to_be_32(((struct mlx5_devx_obj *)
@@ -635,9 +635,9 @@ mlx5_flow_aso_alarm(void *arg)
 	uint32_t us = 100u;
 	uint16_t n;
 
-	rte_spinlock_lock(&sh->aso_age_mng->resize_sl);
+	rte_rwlock_read_lock(&sh->aso_age_mng->resize_rwl);
 	n = sh->aso_age_mng->next;
-	rte_spinlock_unlock(&sh->aso_age_mng->resize_sl);
+	rte_rwlock_read_unlock(&sh->aso_age_mng->resize_rwl);
 	mlx5_aso_completion_handle(sh);
 	if (sq->next == n) {
 		/* End of loop: wait 1 second. */
diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index 8529930897..22081dddd3 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -11857,18 +11857,18 @@ flow_dv_age_pool_create(struct rte_eth_dev *dev,
 	}
 	pool->flow_hit_aso_obj = obj;
 	pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
-	rte_spinlock_lock(&mng->resize_sl);
+	rte_rwlock_write_lock(&mng->resize_rwl);
 	pool->index = mng->next;
 	/* Resize pools array if there is no room for the new pool in it. */
 	if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
 		claim_zero(mlx5_devx_cmd_destroy(obj));
 		mlx5_free(pool);
-		rte_spinlock_unlock(&mng->resize_sl);
+		rte_rwlock_write_unlock(&mng->resize_rwl);
 		return NULL;
 	}
 	mng->pools[pool->index] = pool;
 	mng->next++;
-	rte_spinlock_unlock(&mng->resize_sl);
+	rte_rwlock_write_unlock(&mng->resize_rwl);
 	/* Assign the first action in the new pool, the rest go to free list. */
 	*age_free = &pool->actions[0];
 	for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
-- 
2.18.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [dpdk-dev] [PATCH 2/2] net/mlx5: fix meter action pool protection
  2021-11-01  6:30 [dpdk-dev] [PATCH 1/2] net/mlx5: fix age action pool protection Jiawei Wang
@ 2021-11-01  6:30 ` Jiawei Wang
  2021-11-02  8:09 ` [dpdk-dev] [PATCH 1/2] net/mlx5: fix age " Raslan Darawsheh
  1 sibling, 0 replies; 3+ messages in thread
From: Jiawei Wang @ 2021-11-01  6:30 UTC (permalink / raw)
  To: matan, orika, viacheslavo, thomas, Suanming Mou; +Cc: dev, rasland, stable

The ASO meter action with flows creation could be supported on
multiple threads. The meter pools were created to manage the meter
object resources, if there is no room in the current meter pool then
resize the meter pool to the new pool size and free the old one.

There's a race condition while one thread resizes the meter pool and
the old pool resource be freed, and another thread query the meter
object by index on the old pool, the return value is invalid.

This patch adds a read-write lock to protect the pool resource while
resizing and query.

Fixes: a5835d530f00 ("net/mlx5: optimize Rx queue match")
Cc: stable@dpdk.org

Signed-off-by: Jiawei Wang <jiaweiw@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/net/mlx5/mlx5.c            |  1 +
 drivers/net/mlx5/mlx5.h            |  1 +
 drivers/net/mlx5/mlx5_flow.h       |  2 ++
 drivers/net/mlx5/mlx5_flow_dv.c    |  3 +++
 drivers/net/mlx5/mlx5_flow_meter.c | 17 +++++++----------
 5 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index b90752c56d..4ba850af26 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -632,6 +632,7 @@ mlx5_aso_flow_mtrs_mng_init(struct mlx5_dev_ctx_shared *sh)
 		}
 		if (sh->meter_aso_en) {
 			rte_spinlock_init(&sh->mtrmng->pools_mng.mtrsl);
+			rte_rwlock_init(&sh->mtrmng->pools_mng.resize_mtrwl);
 			LIST_INIT(&sh->mtrmng->pools_mng.meters);
 		}
 		sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 5e88dfcfea..39c001aa1b 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -895,6 +895,7 @@ struct mlx5_aso_mtr_pools_mng {
 	volatile uint16_t n_valid; /* Number of valid pools. */
 	uint16_t n; /* Number of pools. */
 	rte_spinlock_t mtrsl; /* The ASO flow meter free list lock. */
+	rte_rwlock_t resize_mtrwl; /* Lock for resize objects. */
 	struct aso_meter_list meters; /* Free ASO flow meter list. */
 	struct mlx5_aso_sq sq; /*SQ using by ASO flow meter. */
 	struct mlx5_aso_mtr_pool **pools; /* ASO flow meter pool array. */
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 01ecfab9f4..5509c28f01 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -1337,7 +1337,9 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx)
 	/* Decrease to original index. */
 	idx--;
 	MLX5_ASSERT(idx / MLX5_ASO_MTRS_PER_POOL < pools_mng->n);
+	rte_rwlock_read_lock(&pools_mng->resize_mtrwl);
 	pool = pools_mng->pools[idx / MLX5_ASO_MTRS_PER_POOL];
+	rte_rwlock_read_unlock(&pools_mng->resize_mtrwl);
 	return &pool->mtrs[idx % MLX5_ASO_MTRS_PER_POOL];
 }
 
diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index 22081dddd3..8962d26c75 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -6398,14 +6398,17 @@ flow_dv_mtr_pool_create(struct rte_eth_dev *dev, struct mlx5_aso_mtr **mtr_free)
 		return NULL;
 	}
 	pool->devx_obj = dcs;
+	rte_rwlock_write_lock(&pools_mng->resize_mtrwl);
 	pool->index = pools_mng->n_valid;
 	if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
 		mlx5_free(pool);
 		claim_zero(mlx5_devx_cmd_destroy(dcs));
+		rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
 		return NULL;
 	}
 	pools_mng->pools[pool->index] = pool;
 	pools_mng->n_valid++;
+	rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
 	for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
 		pool->mtrs[i].offset = i;
 		LIST_INSERT_HEAD(&pools_mng->meters, &pool->mtrs[i], next);
diff --git a/drivers/net/mlx5/mlx5_flow_meter.c b/drivers/net/mlx5/mlx5_flow_meter.c
index ba4e9fca17..f4a7b697e6 100644
--- a/drivers/net/mlx5/mlx5_flow_meter.c
+++ b/drivers/net/mlx5/mlx5_flow_meter.c
@@ -1789,24 +1789,21 @@ mlx5_flow_meter_find(struct mlx5_priv *priv, uint32_t meter_id,
 	struct mlx5_aso_mtr_pools_mng *pools_mng =
 				&priv->sh->mtrmng->pools_mng;
 	union mlx5_l3t_data data;
+	uint16_t n_valid;
 
 	if (priv->sh->meter_aso_en) {
-		rte_spinlock_lock(&pools_mng->mtrsl);
-		if (!pools_mng->n_valid || !priv->mtr_idx_tbl) {
-			rte_spinlock_unlock(&pools_mng->mtrsl);
+		rte_rwlock_read_lock(&pools_mng->resize_mtrwl);
+		n_valid = pools_mng->n_valid;
+		rte_rwlock_read_unlock(&pools_mng->resize_mtrwl);
+		if (!n_valid || !priv->mtr_idx_tbl ||
+		    (mlx5_l3t_get_entry(priv->mtr_idx_tbl, meter_id, &data) ||
+		    !data.dword))
 			return NULL;
-		}
-		if (mlx5_l3t_get_entry(priv->mtr_idx_tbl, meter_id, &data) ||
-			!data.dword) {
-			rte_spinlock_unlock(&pools_mng->mtrsl);
-			return NULL;
-		}
 		if (mtr_idx)
 			*mtr_idx = data.dword;
 		aso_mtr = mlx5_aso_meter_by_idx(priv, data.dword);
 		/* Remove reference taken by the mlx5_l3t_get_entry. */
 		mlx5_l3t_clear_entry(priv->mtr_idx_tbl, meter_id);
-		rte_spinlock_unlock(&pools_mng->mtrsl);
 		if (!aso_mtr || aso_mtr->state == ASO_METER_FREE)
 			return NULL;
 		return &aso_mtr->fm;
-- 
2.18.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH 1/2] net/mlx5: fix age action pool protection
  2021-11-01  6:30 [dpdk-dev] [PATCH 1/2] net/mlx5: fix age action pool protection Jiawei Wang
  2021-11-01  6:30 ` [dpdk-dev] [PATCH 2/2] net/mlx5: fix meter " Jiawei Wang
@ 2021-11-02  8:09 ` Raslan Darawsheh
  1 sibling, 0 replies; 3+ messages in thread
From: Raslan Darawsheh @ 2021-11-02  8:09 UTC (permalink / raw)
  To: Jiawei(Jonny) Wang, Matan Azrad, Ori Kam, Slava Ovsiienko,
	NBU-Contact-Thomas Monjalon, Suanming Mou
  Cc: dev, stable

Hi,

> -----Original Message-----
> From: Jiawei(Jonny) Wang <jiaweiw@nvidia.com>
> Sent: Monday, November 1, 2021 8:31 AM
> To: Matan Azrad <matan@nvidia.com>; Ori Kam <orika@nvidia.com>; Slava
> Ovsiienko <viacheslavo@nvidia.com>; NBU-Contact-Thomas Monjalon
> <thomas@monjalon.net>; Suanming Mou <suanmingm@nvidia.com>
> Cc: dev@dpdk.org; Raslan Darawsheh <rasland@nvidia.com>;
> stable@dpdk.org
> Subject: [PATCH 1/2] net/mlx5: fix age action pool protection
> 
> The age action with flows creation could be supported on the multiple
> threads. The age pools were created to manage the age resources, if
> there is no room in the current pool then resize the age pool to the new
> pool size and free the old one.
> 
> There's a race condition while one thread resizes the age pool and the
> old pool resource be freed, and another thread query the age action
> value of the old pool so the queried value is invalid.
> 
> This patch uses the read-write lock to protect the pool resource while
> resizing and query.
> 
> Fixes: a5835d530f00 ("net/mlx5: optimize Rx queue match")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Jiawei Wang <jiaweiw@nvidia.com>
> Acked-by: Matan Azrad <matan@nvidia.com>

Series applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-02  8:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-01  6:30 [dpdk-dev] [PATCH 1/2] net/mlx5: fix age action pool protection Jiawei Wang
2021-11-01  6:30 ` [dpdk-dev] [PATCH 2/2] net/mlx5: fix meter " Jiawei Wang
2021-11-02  8:09 ` [dpdk-dev] [PATCH 1/2] net/mlx5: fix age " Raslan Darawsheh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).