common/mlx5: fix memory leak in Windows dereg MR function
PATCH 1/1 common/mlx5: fix memory leak in Windows dereg MR function
From: Michael Baum <[email protected]>
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.
--- drivers/common/mlx5/windows/mlx5_common_os.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/common/mlx5/windows/mlx5_common_os.c +5 -3
@@ -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)); }
Signature · 1 line
2.25.1
Hi,
Quoted 30 lines
-----Original Message-----
From: Michael Baum <[email protected]>
Sent: Wednesday, November 17, 2021 1:03 PM
To: [email protected]
Cc: Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; Slava Ovsiienko <[email protected]>; Michael Baum <[email protected]>; [email protected]
Subject: [PATCH] common/mlx5: fix memory leak in Windows dereg MR functionFrom: Michael Baum <[email protected]>
The "
mlx5_devx_cmd_mkey_create" DevX cmd allocates DevX object usingmlx5_mallocand 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 usingmlx5_free.On Windows OS, the
reg_mrfunction creates Mkey using "mlx5_devx_cmd_mkey_create" cmd, butdereg_mrfunction using directly glue function without freeing the object.
This behavior causes memory leak at each MR release.In addition, the
dereg_mrfunction 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_mrfunction to use "mlx5_devx_cmd_destroy" instead of glue function, and extends the validity test to the whole function.
Quoted 5 lines
Fixes ba420719823c ("common/mlx5: add reg/dereg MR on Windows")Signed-off-by Michael Baum <[email protected]>Acked-by Matan Azrad <[email protected]>
Patch applied to next-net-mlx,
Kindest regards,
Raslan Darawsheh