Skip to contentSkip to conversation

RDMA/hns: Fix memory leaks

PATCH In review Weihang Li 2 participants 5 messages Oct 26, 2019 – Oct 28, 2019

Subsystems (2)
lore
Share & tools
lore

Weihang Li

author
#0 lore raw

cover RDMA/hns: Fix memory leaks

Fix memory leaks about mr and eq in hip08.

Lijun Ou (2):
RDMA/hns: Fix memory leaks about mr
RDMA/hns: Prevent memory leaks about eq

 drivers/infiniband/hw/hns/hns_roce_hw_v1.c | 8 +++++---
 drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 6 +++---
 2 files changed, 8 insertions(+), 6 deletions(-)
Signature · 1 line
2.8.1
author
#1 lore raw

PATCH 1/2 RDMA/hns: Fix memory leaks about mr

From: Lijun Ou <[email protected]>

In hns_roce_v1_dereg_mr(), 'mr_work' is not freed in some cases, for example, try_wait_for_completion() runs fail, which will cause memory leaks.

Fixes bfcc681bd09d ("IB/hns: Fix the bug when free mr")
---
 drivers/infiniband/hw/hns/hns_roce_hw_v1.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/infiniband/hw/hns/hns_roce_hw_v1.c +5 -3
index 5f74bf5..88c1cd9 100644
@@ -1094,7 +1094,6 @@ static void hns_roce_v1_mr_free_work_fn(struct work_struct *work)
 free_work:
 	if (mr_work->comp_flag)
 		complete(mr_work->comp);
-	kfree(mr_work);
 }
 
 static int hns_roce_v1_dereg_mr(struct hns_roce_dev *hr_dev,
@@ -1137,18 +1136,21 @@ static int hns_roce_v1_dereg_mr(struct hns_roce_dev *hr_dev,
 
 	while (end > 0) {
 		if (try_wait_for_completion(&comp))
-			goto free_mr;
+			goto err;
 		msleep(HNS_ROCE_V1_FREE_MR_WAIT_VALUE);
 		end -= HNS_ROCE_V1_FREE_MR_WAIT_VALUE;
 	}
 
 	mr_work->comp_flag = 0;
 	if (try_wait_for_completion(&comp))
-		goto free_mr;
+		goto err;
 
 	dev_warn(dev, "Free mr work 0x%x over 50s and failed!\n", mr->key);
 	ret = -ETIMEDOUT;
 
+err:
+	kfree(mr_work);
+
 free_mr:
 	dev_dbg(dev, "Free mr 0x%x use 0x%x us.\n",
 		mr->key, jiffies_to_usecs(jiffies) - jiffies_to_usecs(start));
Signature · 1 line
2.8.1
author
#3 lore raw

PATCH 2/2 RDMA/hns: Prevent memory leaks about eq

In reply to Weihang Li

From: Lijun Ou <[email protected]>

eq->buf_list->buf and eq->buf_list should also be freed when eqe_hop_num is set to 0, or there will be memory leaks.

Fixes a5073d6054f7 ("RDMA/hns: Add eq support of hip08")
---
 drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/infiniband/hw/hns/hns_roce_hw_v2.c +3 -3
index 7a89d66..e82567f 100644
@@ -5389,9 +5389,9 @@ static void hns_roce_v2_free_eq(struct hns_roce_dev *hr_dev,
 		return;
 	}
 
-	if (eq->buf_list)
-		dma_free_coherent(hr_dev->dev, buf_chk_sz,
-				  eq->buf_list->buf, eq->buf_list->map);
+	dma_free_coherent(hr_dev->dev, buf_chk_sz, eq->buf_list->buf,
+			  eq->buf_list->map);
+	kfree(eq->buf_list);
 }
 
 static void hns_roce_config_eqc(struct hns_roce_dev *hr_dev,
Signature · 1 line
2.8.1
#2 lore raw

Re: [PATCH for-rc 1/2] RDMA/hns: Fix memory leaks about mr

In reply to Weihang Li
Quoted 33 lines · Weihang Li

From: Lijun Ou <[email protected]>

In hns_roce_v1_dereg_mr(), 'mr_work' is not freed in some cases, for example, try_wait_for_completion() runs fail, which will cause memory leaks.

Fixes bfcc681bd09d ("IB/hns: Fix the bug when free mr")
 drivers/infiniband/hw/hns/hns_roce_hw_v1.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/infiniband/hw/hns/hns_roce_hw_v1.c +2 -2
index 5f74bf5..88c1cd9 100644
+++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
@@ -1094,7 +1094,6 @@ static void hns_roce_v1_mr_free_work_fn(struct work_struct *work)
 free_work:
 	if (mr_work->comp_flag)
 		complete(mr_work->comp);
-	kfree(mr_work);
 }
 
 static int hns_roce_v1_dereg_mr(struct hns_roce_dev *hr_dev,
@@ -1137,18 +1136,21 @@ static int hns_roce_v1_dereg_mr(struct hns_roce_dev *hr_dev,
 
 	while (end > 0) {
 		if (try_wait_for_completion(&comp))
-			goto free_mr;
+			goto err;
 		msleep(HNS_ROCE_V1_FREE_MR_WAIT_VALUE);
 		end -= HNS_ROCE_V1_FREE_MR_WAIT_VALUE;
 	}
 

drivers/infiniband/hw/hns/hns_roce_hw_v1.c static int hns_roce_v1_dereg_mr(struct hns_roce_dev *hr_dev, · line 1152

Quoted 10 lines
drivers/infiniband/hw/hns/hns_roce_hw_v1.c +3 -1
 	mr_work->comp_flag = 0;
 	if (try_wait_for_completion(&comp))
-		goto free_mr;
+		goto err;
 
 	dev_warn(dev, "Free mr work 0x%x over 50s and failed!\n", mr->key);
 	ret = -ETIMEDOUT;
 
+err:
+	kfree(mr_work);

This whole thing makes absolutely no sense.

Why is work being pushed onto a WQ and then the same routine turns around and does wait_for_completion??

Further, trying to make this 'non blocking' by sleep spinning on 'try_wait_for_completion' is utterly insane.

Then going on to uncondionally free memory that we don't even know if the work is finished with or not is just wrong.

Doug, you took this spin loop stuff, you get to review the fixes for it! :)

Jason

#4 lore raw

Re: [PATCH for-rc 2/2] RDMA/hns: Prevent memory leaks about eq

In reply to Weihang Li
Quoted 11 lines · Weihang Li

From: Lijun Ou <[email protected]>

eq->buf_list->buf and eq->buf_list should also be freed when eqe_hop_num is set to 0, or there will be memory leaks.

Fixes a5073d6054f7 ("RDMA/hns: Add eq support of hip08")
---
 drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Applies to for-rc

Thanks,
Jason