DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] common/mlx5: fix memory leak in Windows dereg MR function
@ 2021-11-17 11:02 michaelba
  2021-11-17 14:44 ` Raslan Darawsheh
  0 siblings, 1 reply; 2+ messages in thread
From: michaelba @ 2021-11-17 11:02 UTC (permalink / raw)
  To: dev
  Cc: Matan Azrad, Raslan Darawsheh, Viacheslav Ovsiienko,
	Michael Baum, stable

From: Michael Baum <michaelba@nvidia.com>

The "mlx5_devx_cmd_mkey_create" DevX cmd allocates DevX object using
mlx5_malloc and then creates MKey using glue function.
Compatibly, "mlx5_devx_cmd_destroy" cmd releases first the MKey using
glue function, and then free the DevX object using mlx5_free.

On Windows OS, the reg_mr function creates Mkey using
"mlx5_devx_cmd_mkey_create" cmd, but dereg_mr function using directly
glue function without freeing the object.
This behavior causes memory leak at each MR release.

In addition, the dereg_mr function makes sure that the MR pointer is
valid before destroying its fields, but always calls the memset function
that makes a difference to it.

This patch moves the dereg_mr function to use "mlx5_devx_cmd_destroy"
instead of glue function, and extends the validity test to the whole
function.

Fixes: ba420719823c ("common/mlx5: add reg/dereg MR on Windows")
Cc: stable@dpdk.org

Signed-off-by: Michael Baum <michaelba@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/common/mlx5/windows/mlx5_common_os.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/common/mlx5/windows/mlx5_common_os.c b/drivers/common/mlx5/windows/mlx5_common_os.c
index 5fb45d12ea..162c7476cc 100644
--- a/drivers/common/mlx5/windows/mlx5_common_os.c
+++ b/drivers/common/mlx5/windows/mlx5_common_os.c
@@ -368,9 +368,11 @@ mlx5_os_reg_mr(void *pd,
 static void
 mlx5_os_dereg_mr(struct mlx5_pmd_mr *pmd_mr)
 {
-	if (pmd_mr && pmd_mr->mkey)
-		claim_zero(mlx5_glue->devx_obj_destroy(pmd_mr->mkey->obj));
-	if (pmd_mr && pmd_mr->obj)
+	if (!pmd_mr)
+		return;
+	if (pmd_mr->mkey)
+		claim_zero(mlx5_devx_cmd_destroy(pmd_mr->mkey));
+	if (pmd_mr->obj)
 		claim_zero(mlx5_os_umem_dereg(pmd_mr->obj));
 	memset(pmd_mr, 0, sizeof(*pmd_mr));
 }
-- 
2.25.1


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

* RE: [PATCH] common/mlx5: fix memory leak in Windows dereg MR function
  2021-11-17 11:02 [PATCH] common/mlx5: fix memory leak in Windows dereg MR function michaelba
@ 2021-11-17 14:44 ` Raslan Darawsheh
  0 siblings, 0 replies; 2+ messages in thread
From: Raslan Darawsheh @ 2021-11-17 14:44 UTC (permalink / raw)
  To: Michael Baum, dev; +Cc: Matan Azrad, Slava Ovsiienko, stable

Hi,

> -----Original Message-----
> From: Michael Baum <michaelba@nvidia.com>
> Sent: Wednesday, November 17, 2021 1:03 PM
> To: dev@dpdk.org
> Cc: Matan Azrad <matan@nvidia.com>; Raslan Darawsheh
> <rasland@nvidia.com>; Slava Ovsiienko <viacheslavo@nvidia.com>; Michael
> Baum <michaelba@nvidia.com>; stable@dpdk.org
> Subject: [PATCH] common/mlx5: fix memory leak in Windows dereg MR
> function
> 
> From: Michael Baum <michaelba@nvidia.com>
> 
> The "mlx5_devx_cmd_mkey_create" DevX cmd allocates DevX object using
> mlx5_malloc and then creates MKey using glue function.
> Compatibly, "mlx5_devx_cmd_destroy" cmd releases first the MKey using
> glue function, and then free the DevX object using mlx5_free.
> 
> On Windows OS, the reg_mr function creates Mkey using
> "mlx5_devx_cmd_mkey_create" cmd, but dereg_mr function using directly
> glue function without freeing the object.
> This behavior causes memory leak at each MR release.
> 
> In addition, the dereg_mr function makes sure that the MR pointer is
> valid before destroying its fields, but always calls the memset function
> that makes a difference to it.
> 
> This patch moves the dereg_mr function to use "mlx5_devx_cmd_destroy"
> instead of glue function, and extends the validity test to the whole
> function.
> 
> Fixes: ba420719823c ("common/mlx5: add reg/dereg MR on Windows")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Michael Baum <michaelba@nvidia.com>
> Acked-by: Matan Azrad <matan@nvidia.com>

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh

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

end of thread, other threads:[~2021-11-17 14:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-17 11:02 [PATCH] common/mlx5: fix memory leak in Windows dereg MR function michaelba
2021-11-17 14:44 ` Raslan Darawsheh

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