[2/4] compress/mlx5: fix constant size in QP creation

Message ID 20210601071122.1612432-2-michaelba@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [1/4] regex/mlx5: fix size of setup constants |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Michael Baum June 1, 2021, 7:11 a.m. UTC
The mlx5_compress_qp_setup function makes shifting to the numeric
constant 1, then sends it as a parameter to rte_calloc function.

The rte_calloc function expects to get size_t (64 bits, unsigned) and
instead gets a 32-bit variable, because the numeric constant size is a
32-bit.
In case the shift is greater than 32 the variable will lose its value
even though the function can get 64-bit argument.

Change the size of the numeric constant 1 to 64-bit.

Fixes: 8619fcd5161b ("compress/mlx5: support queue pair operations")
Cc: stable@dpdk.org

Signed-off-by: Michael Baum <michaelba@nvidia.com>
---
 drivers/compress/mlx5/mlx5_compress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Matan Azrad June 7, 2021, 7:28 a.m. UTC | #1
From: Michael Baum:
> The mlx5_compress_qp_setup function makes shifting to the numeric
> constant 1, then sends it as a parameter to rte_calloc function.
> 
> The rte_calloc function expects to get size_t (64 bits, unsigned) and instead
> gets a 32-bit variable, because the numeric constant size is a 32-bit.
> In case the shift is greater than 32 the variable will lose its value even though
> the function can get 64-bit argument.
> 
> Change the size of the numeric constant 1 to 64-bit.
> 
> Fixes: 8619fcd5161b ("compress/mlx5: support queue pair operations")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Michael Baum <michaelba@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
  
Thomas Monjalon June 23, 2021, 6:47 a.m. UTC | #2
01/06/2021 09:11, Michael Baum:
> The mlx5_compress_qp_setup function makes shifting to the numeric
> constant 1, then sends it as a parameter to rte_calloc function.
> 
> The rte_calloc function expects to get size_t (64 bits, unsigned) and

No on 32-bit systems, size_t is 32 bits.

> instead gets a 32-bit variable, because the numeric constant size is a
> 32-bit.

Most of the patches of this series say "constant" where it is a variable.

> In case the shift is greater than 32 the variable will lose its value
> even though the function can get 64-bit argument.
> 
> Change the size of the numeric constant 1 to 64-bit.
[...]
> -	opaq_buf = rte_calloc(__func__, 1u << log_ops_n,
> +	opaq_buf = rte_calloc(__func__, RTE_BIT64(log_ops_n),
  
Michael Baum June 28, 2021, 2:21 p.m. UTC | #3
External email: Use caution opening links or attachments

> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Wednesday, June 23, 2021 9:48 AM
> To: Michael Baum <michaelba@nvidia.com>
> Cc: dev@dpdk.org; stable@dpdk.org; Matan Azrad <matan@nvidia.com>;
> Raslan Darawsheh <rasland@nvidia.com>; Slava Ovsiienko
> <viacheslavo@nvidia.com>
> Subject: Re: [dpdk-stable] [PATCH 2/4] compress/mlx5: fix constant size in
> QP creation
> 
> External email: Use caution opening links or attachments
> 
> 
> 01/06/2021 09:11, Michael Baum:
> > The mlx5_compress_qp_setup function makes shifting to the numeric
> > constant 1, then sends it as a parameter to rte_calloc function.
> >
> > The rte_calloc function expects to get size_t (64 bits, unsigned) and
> 
> No on 32-bit systems, size_t is 32 bits.

Thanks for the comment, I'll send v2.

> > instead gets a 32-bit variable, because the numeric constant size is a
> > 32-bit.
> 
> Most of the patches of this series say "constant" where it is a variable.
> 
> > In case the shift is greater than 32 the variable will lose its value
> > even though the function can get 64-bit argument.
> >
> > Change the size of the numeric constant 1 to 64-bit.
> [...]
> > -     opaq_buf = rte_calloc(__func__, 1u << log_ops_n,
> > +     opaq_buf = rte_calloc(__func__, RTE_BIT64(log_ops_n),
> 
>
  

Patch

diff --git a/drivers/compress/mlx5/mlx5_compress.c b/drivers/compress/mlx5/mlx5_compress.c
index 80c564f10b..90d009c56b 100644
--- a/drivers/compress/mlx5/mlx5_compress.c
+++ b/drivers/compress/mlx5/mlx5_compress.c
@@ -209,7 +209,7 @@  mlx5_compress_qp_setup(struct rte_compressdev *dev, uint16_t qp_id,
 		return -rte_errno;
 	}
 	dev->data->queue_pairs[qp_id] = qp;
-	opaq_buf = rte_calloc(__func__, 1u << log_ops_n,
+	opaq_buf = rte_calloc(__func__, RTE_BIT64(log_ops_n),
 			      sizeof(struct mlx5_gga_compress_opaque),
 			      sizeof(struct mlx5_gga_compress_opaque));
 	if (opaq_buf == NULL) {