From: Felix Kuehling <felix.kuehling@amd.com>
To: Ramesh Errabolu <Ramesh.Errabolu@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amd/amdkfd: Fix a resource leak in svm_range_validate_and_map()
Date: Wed, 1 May 2024 14:34:10 -0400 [thread overview]
Message-ID: <5ec8572d-1eb3-4475-b953-2f70f5df9493@amd.com> (raw)
In-Reply-To: <20240430232901.2878169-1-Ramesh.Errabolu@amd.com>
On 2024-04-30 19:29, Ramesh Errabolu wrote:
> Analysis of code by Coverity, a static code analyser, has identified
> a resource leak in the symbol hmm_range. This leak occurs when one of
> the prior steps before it is released encounters an error.
>
> Signed-off-by: Ramesh Errabolu <Ramesh.Errabolu@amd.com>
> ---
> drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> index 386875e6eb96..dcb1d5d3f860 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> @@ -1658,7 +1658,7 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
> start = map_start << PAGE_SHIFT;
> end = (map_last + 1) << PAGE_SHIFT;
> for (addr = start; !r && addr < end; ) {
> - struct hmm_range *hmm_range;
> + struct hmm_range *hmm_range = NULL;
> unsigned long map_start_vma;
> unsigned long map_last_vma;
> struct vm_area_struct *vma;
> @@ -1696,7 +1696,9 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
> }
>
> svm_range_lock(prange);
> - if (!r && amdgpu_hmm_range_get_pages_done(hmm_range)) {
> +
> + // Free backing memory of hmm_range if it was initialized
> + if (hmm_range && amdgpu_hmm_range_get_pages_done(hmm_range)) {
> pr_debug("hmm update the range, need validate again\n");
> r = -EAGAIN;
Nack! This can now override other error codes that aren't meant to be
overridden with -EAGAIN.
I think a better solution would be to just revserse this condition to
ensure that amdgpu_hmm_range_get_pages_done is always called:
if (amdgpu_hmm_range_get_pages_done(hmm_range) && !r) {
...
r = -EAGAIN;
}
Regards,
Felix
> }
next prev parent reply other threads:[~2024-05-01 18:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-30 23:29 [PATCH] drm/amd/amdkfd: Fix a resource leak in svm_range_validate_and_map() Ramesh Errabolu
2024-05-01 18:22 ` Philip Yang
2024-05-01 18:34 ` Felix Kuehling [this message]
2024-05-01 18:59 ` Felix Kuehling
2024-05-01 20:38 ` Errabolu, Ramesh
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=5ec8572d-1eb3-4475-b953-2f70f5df9493@amd.com \
--to=felix.kuehling@amd.com \
--cc=Ramesh.Errabolu@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.