patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH] net/mlx5: fix use of atomic cmpset for age state
@ 2020-10-15 11:44 Dekel Peled
  2020-10-19 10:48 ` [dpdk-stable] [dpdk-dev] " Raslan Darawsheh
  0 siblings, 1 reply; 2+ messages in thread
From: Dekel Peled @ 2020-10-15 11:44 UTC (permalink / raw)
  To: matan, shahafs, viacheslavo; +Cc: dev, stable

According to documentation [1], function rte_atomic16_cmpset()
return value is non-zero on success; 0 on failure.
In existing code this function is called, and the return value
is compared to AGE_CANDIDATE, which is defined as 1.
Such comparison is incorrect and can lead to unwanted behavior.

This patch updates the calls to rte_atomic16_cmpset(), to check
that the return value is 0 or non-zero.

[1] https://doc.dpdk.org/api/rte__atomic_8h.html

Fixes: fa2d01c87d2b ("net/mlx5: support flow aging")
Cc: stable@dpdk.org

Signed-off-by: Dekel Peled <dekelp@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/net/mlx5/mlx5_flow.c    | 8 ++------
 drivers/net/mlx5/mlx5_flow_dv.c | 9 ++++-----
 2 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index 3d38e11..2729629 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -6747,12 +6747,8 @@ struct mlx5_meter_domains_infos *
 		priv = rte_eth_devices[age_param->port_id].data->dev_private;
 		age_info = GET_PORT_AGE_INFO(priv);
 		rte_spinlock_lock(&age_info->aged_sl);
-		/* If the cpmset fails, release happens. */
-		if (rte_atomic16_cmpset((volatile uint16_t *)
-					&age_param->state,
-					AGE_CANDIDATE,
-					AGE_TMOUT) ==
-					AGE_CANDIDATE) {
+		if (rte_atomic16_cmpset((volatile uint16_t *)&age_param->state,
+					AGE_CANDIDATE, AGE_TMOUT)) {
 			TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
 			MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
 		}
diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index 361c32d..174189a 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -5103,10 +5103,8 @@ struct field_modify_info modify_tcp[] = {
 
 	age_info = GET_PORT_AGE_INFO(priv);
 	age_param = flow_dv_counter_idx_get_age(dev, counter);
-	if (rte_atomic16_cmpset((volatile uint16_t *)
-			&age_param->state,
-			AGE_CANDIDATE, AGE_FREE)
-			!= AGE_CANDIDATE) {
+	if (!rte_atomic16_cmpset((volatile uint16_t *)&age_param->state,
+				 AGE_CANDIDATE, AGE_FREE)) {
 		/**
 		 * We need the lock even it is age timeout,
 		 * since counter may still in process.
@@ -5114,9 +5112,10 @@ struct field_modify_info modify_tcp[] = {
 		rte_spinlock_lock(&age_info->aged_sl);
 		TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
 		rte_spinlock_unlock(&age_info->aged_sl);
+		rte_atomic16_set(&age_param->state, AGE_FREE);
 	}
-	rte_atomic16_set(&age_param->state, AGE_FREE);
 }
+
 /**
  * Release a flow counter.
  *
-- 
1.8.3.1


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

end of thread, other threads:[~2020-10-19 10:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-15 11:44 [dpdk-stable] [PATCH] net/mlx5: fix use of atomic cmpset for age state Dekel Peled
2020-10-19 10:48 ` [dpdk-stable] [dpdk-dev] " 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).