linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/mlx5: Fix a memory leak bug
@ 2019-08-13  8:21 Wenwen Wang
  2019-08-19 13:00 ` Moshe Shemesh
  2019-08-20 21:00 ` Saeed Mahameed
  0 siblings, 2 replies; 3+ messages in thread
From: Wenwen Wang @ 2019-08-13  8:21 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Saeed Mahameed, Leon Romanovsky, David S. Miller,
	open list:MELLANOX MLX5 core VPI driver,
	open list:MELLANOX MLX5 core VPI driver, open list

In mlx5_cmd_invoke(), 'ent' is allocated through kzalloc() in alloc_cmd().
After the work is queued, wait_func() is invoked to wait the completion of
the work. If wait_func() returns -ETIMEDOUT, the following execution will
be terminated. However, the allocated 'ent' is not deallocated on this
program path, leading to a memory leak bug.

To fix the above issue, free 'ent' before returning the error.

Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
---
 drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
index 8cdd7e6..90cdb9a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
@@ -1036,7 +1036,7 @@ static int mlx5_cmd_invoke(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *in,
 
 	err = wait_func(dev, ent);
 	if (err == -ETIMEDOUT)
-		goto out;
+		goto out_free;
 
 	ds = ent->ts2 - ent->ts1;
 	op = MLX5_GET(mbox_in, in->first.data, opcode);
-- 
2.7.4


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

* Re: [PATCH] net/mlx5: Fix a memory leak bug
  2019-08-13  8:21 [PATCH] net/mlx5: Fix a memory leak bug Wenwen Wang
@ 2019-08-19 13:00 ` Moshe Shemesh
  2019-08-20 21:00 ` Saeed Mahameed
  1 sibling, 0 replies; 3+ messages in thread
From: Moshe Shemesh @ 2019-08-19 13:00 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Saeed Mahameed, Leon Romanovsky, David S. Miller,
	open list:MELLANOX MLX5 core VPI driver,
	open list:MELLANOX MLX5 core VPI driver, open list

Please don't change that.
On command timeout we don't release ent, since the FW event on
completion can occur after timeout, so it is released on the
completion handler mlx5_cmd_comp_handler().
See commit 73dd3a4839c1d ("net/mlx5: Avoid using pending command
interface slots").

On Tue, Aug 13, 2019 at 11:22 AM Wenwen Wang <wenwen@cs.uga.edu> wrote:
>
> In mlx5_cmd_invoke(), 'ent' is allocated through kzalloc() in alloc_cmd().
> After the work is queued, wait_func() is invoked to wait the completion of
> the work. If wait_func() returns -ETIMEDOUT, the following execution will
> be terminated. However, the allocated 'ent' is not deallocated on this
> program path, leading to a memory leak bug.
>
> To fix the above issue, free 'ent' before returning the error.
>
> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
> ---
>  drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> index 8cdd7e6..90cdb9a 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> @@ -1036,7 +1036,7 @@ static int mlx5_cmd_invoke(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *in,
>
>         err = wait_func(dev, ent);
>         if (err == -ETIMEDOUT)
> -               goto out;
> +               goto out_free;
>
>         ds = ent->ts2 - ent->ts1;
>         op = MLX5_GET(mbox_in, in->first.data, opcode);
> --
> 2.7.4
>

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

* Re: [PATCH] net/mlx5: Fix a memory leak bug
  2019-08-13  8:21 [PATCH] net/mlx5: Fix a memory leak bug Wenwen Wang
  2019-08-19 13:00 ` Moshe Shemesh
@ 2019-08-20 21:00 ` Saeed Mahameed
  1 sibling, 0 replies; 3+ messages in thread
From: Saeed Mahameed @ 2019-08-20 21:00 UTC (permalink / raw)
  To: wenwen; +Cc: linux-rdma, davem, netdev, leon, linux-kernel

On Tue, 2019-08-13 at 03:21 -0500, Wenwen Wang wrote:
> In mlx5_cmd_invoke(), 'ent' is allocated through kzalloc() in
> alloc_cmd().
> After the work is queued, wait_func() is invoked to wait the
> completion of
> the work. If wait_func() returns -ETIMEDOUT, the following execution
> will
> be terminated. However, the allocated 'ent' is not deallocated on
> this
> program path, leading to a memory leak bug.
> 
> To fix the above issue, free 'ent' before returning the error.

Hi Wenewn, sorry i have to nack this.

As Moshe already pointed out, we intentionally don't free ent, since
even if the driver decided to timeout, FW might still send a
completion, until the FW sends the completion, this entry shouldn't be
freed and is not reusable by driver.

So this is not a memory leak, it just means that only FW completion is
allowed to free this entry or driver shutdown.. otherwise this command
entry is just dead until next fw completion.

Thanks,
Saeed.


> 
> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
> ---
>  drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> index 8cdd7e6..90cdb9a 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> @@ -1036,7 +1036,7 @@ static int mlx5_cmd_invoke(struct mlx5_core_dev
> *dev, struct mlx5_cmd_msg *in,
>  
>  	err = wait_func(dev, ent);
>  	if (err == -ETIMEDOUT)
> -		goto out;
> +		goto out_free;
>  
>  	ds = ent->ts2 - ent->ts1;
>  	op = MLX5_GET(mbox_in, in->first.data, opcode);

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

end of thread, other threads:[~2019-08-20 21:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-13  8:21 [PATCH] net/mlx5: Fix a memory leak bug Wenwen Wang
2019-08-19 13:00 ` Moshe Shemesh
2019-08-20 21:00 ` Saeed Mahameed

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).