From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 93EF4A04DC for ; Thu, 15 Oct 2020 13:45:28 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6D1DA1E4E9; Thu, 15 Oct 2020 13:45:27 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 1DFDA1DE82 for ; Thu, 15 Oct 2020 13:45:24 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from dekelp@nvidia.com) with SMTP; 15 Oct 2020 14:45:18 +0300 Received: from mtl-vdi-280.wap.labs.mlnx. (mtl-vdi-280.wap.labs.mlnx [10.228.134.250]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 09FBjIGB004446; Thu, 15 Oct 2020 14:45:18 +0300 From: Dekel Peled To: matan@nvidia.com, shahafs@nvidia.com, viacheslavo@nvidia.com Cc: dev@dpdk.org, stable@dpdk.org Date: Thu, 15 Oct 2020 14:44:24 +0300 Message-Id: <80931ca7b31b48beebb22d0d093e07a3d6539336.1602762247.git.dekelp@nvidia.com> X-Mailer: git-send-email 1.7.1 Subject: [dpdk-stable] [PATCH] net/mlx5: fix use of atomic cmpset for age state X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "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 Acked-by: Matan Azrad --- 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