linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Weihang Li <liweihang@hisilicon.com>, dledford@redhat.com
Cc: linux-rdma@vger.kernel.org, linuxarm@huawei.com
Subject: Re: [PATCH for-rc 1/2] RDMA/hns: Fix memory leaks about mr
Date: Mon, 28 Oct 2019 15:24:29 -0300	[thread overview]
Message-ID: <20191028182429.GA14440@ziepe.ca> (raw)
In-Reply-To: <1572072995-11277-2-git-send-email-liweihang@hisilicon.com>

On Sat, Oct 26, 2019 at 02:56:34PM +0800, Weihang Li wrote:
> From: Lijun Ou <oulijun@huawei.com>
> 
> 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")
> Signed-off-by: Lijun Ou <oulijun@huawei.com>
> Signed-off-by: Weihang Li <liweihang@hisilicon.com>
>  drivers/infiniband/hw/hns/hns_roce_hw_v1.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> 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;
>  	}
>  
>  	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

  reply	other threads:[~2019-10-28 18:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-26  6:56 [PATCH for-rc 0/2] RDMA/hns: Fix memory leaks Weihang Li
2019-10-26  6:56 ` [PATCH for-rc 1/2] RDMA/hns: Fix memory leaks about mr Weihang Li
2019-10-28 18:24   ` Jason Gunthorpe [this message]
2019-10-26  6:56 ` [PATCH for-rc 2/2] RDMA/hns: Prevent memory leaks about eq Weihang Li
2019-10-28 18:25   ` Jason Gunthorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191028182429.GA14440@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=dledford@redhat.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=liweihang@hisilicon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).