From: Dekel Peled <dekelp@nvidia.com>
To: matan@nvidia.com, shahafs@nvidia.com, viacheslavo@nvidia.com
Cc: dev@dpdk.org, stable@dpdk.org
Subject: [dpdk-dev] [PATCH] net/mlx5: fix use of atomic cmpset for age state
Date: Thu, 15 Oct 2020 14:44:24 +0300 [thread overview]
Message-ID: <80931ca7b31b48beebb22d0d093e07a3d6539336.1602762247.git.dekelp@nvidia.com> (raw)
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
next reply other threads:[~2020-10-15 11:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-15 11:44 Dekel Peled [this message]
2020-10-19 10:48 ` Raslan Darawsheh
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=80931ca7b31b48beebb22d0d093e07a3d6539336.1602762247.git.dekelp@nvidia.com \
--to=dekelp@nvidia.com \
--cc=dev@dpdk.org \
--cc=matan@nvidia.com \
--cc=shahafs@nvidia.com \
--cc=stable@dpdk.org \
--cc=viacheslavo@nvidia.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;
as well as URLs for NNTP newsgroup(s).