[dpdk-dev] [PATCH v5] net/mlx5: fix mutex unlock in txpp cleanup

Ferruh Yigit ferruh.yigit at intel.com
Wed Nov 10 17:57:27 CET 2021


On 10/12/2021 11:02 AM, Chengfeng Ye wrote:
> The lock sh->txpp.mutex was not correctly released on one path
> of cleanup function return, potentially causing the deadlock.
> 
> Fixes: d133f4cdb7 ("net/mlx5: create clock queue for packet pacing")
> Cc: stable at dpdk.org
> 
> Signed-off-by: Chengfeng Ye <cyeaa at connect.ust.hk>
> ---
>   drivers/net/mlx5/mlx5_txpp.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/mlx5/mlx5_txpp.c b/drivers/net/mlx5/mlx5_txpp.c
> index 4f6da9f2d1..0ece788a84 100644
> --- a/drivers/net/mlx5/mlx5_txpp.c
> +++ b/drivers/net/mlx5/mlx5_txpp.c
> @@ -961,8 +961,12 @@ mlx5_txpp_stop(struct rte_eth_dev *dev)
>   	MLX5_ASSERT(!ret);
>   	RTE_SET_USED(ret);
>   	MLX5_ASSERT(sh->txpp.refcnt);
> -	if (!sh->txpp.refcnt || --sh->txpp.refcnt)
> +	if (!sh->txpp.refcnt || --sh->txpp.refcnt) {
> +		ret = pthread_mutex_unlock(&sh->txpp.mutex);
> +		MLX5_ASSERT(!ret);
> +		RTE_SET_USED(ret);

Is this 'RTE_SET_USED()' need to be used multiple times for same variable?

This usage looks ugly, I can see why it is used but I wonder if this can
be solved differently, what about something like following:

  #ifdef RTE_LIBRTE_MLX5_DEBUG
   #define MLX5_ASSERT(exp) RTE_VERIFY(exp)
  #else
   #ifdef RTE_ENABLE_ASSERT
    #define MLX5_ASSERT(exp) RTE_ASSERT(exp)
   #else
    #define MLX5_ASSERT(exp) RTE_SET_USED(exp)
   #endif
  #endif

>   		return;
> +	}
>   	/* No references any more, do actual destroy. */
>   	mlx5_txpp_destroy(sh);
>   	ret = pthread_mutex_unlock(&sh->txpp.mutex);
> 



More information about the stable mailing list