From: "Yang, Philip" <Philip.Yang-5C7GfCeVMHo@public.gmane.org>
To: "Kuehling, Felix" <Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>,
"amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org"
<amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>
Subject: Re: [PATCH 1/1] drm/amdgpu: Improve error handling for HMM
Date: Thu, 9 May 2019 13:33:35 +0000 [thread overview]
Message-ID: <502904df-f52e-7ef5-ece2-60e0afcd7305@amd.com> (raw)
In-Reply-To: <20190507215202.14616-1-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
On 2019-05-07 5:52 p.m., Kuehling, Felix wrote:
> Use unsigned long for number of pages.
>
> Check that pfns are valid after hmm_vma_fault. If they are not,
> return an error instead of continuing with invalid page pointers and
> PTEs.
>
> Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: Philip Yang <Philip.Yang@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 22 ++++++++++++++++++----
> 1 file changed, 18 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index c14198737dcd..38ce11e338e0 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -734,10 +734,11 @@ int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages)
> struct mm_struct *mm = gtt->usertask->mm;
> unsigned long start = gtt->userptr;
> unsigned long end = start + ttm->num_pages * PAGE_SIZE;
> - struct hmm_range *ranges;
> struct vm_area_struct *vma = NULL, *vmas[MAX_NR_VMAS];
> + struct hmm_range *ranges;
> + unsigned long nr_pages, i;
> uint64_t *pfns, f;
> - int r = 0, i, nr_pages;
> + int r = 0;
>
> if (!mm) /* Happens during process shutdown */
> return -ESRCH;
> @@ -813,8 +814,14 @@ int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages)
>
> up_read(&mm->mmap_sem);
>
> - for (i = 0; i < ttm->num_pages; i++)
> + for (i = 0; i < ttm->num_pages; i++) {
> pages[i] = hmm_pfn_to_page(&ranges[0], pfns[i]);
> + if (!pages[i]) {
> + pr_err("Page fault failed for pfn[%lu] = 0x%llx\n",
> + i, pfns[i]);
> + goto out_invalid_pfn;
> + }
> + }
> gtt->ranges = ranges;
>
> return 0;
> @@ -827,6 +834,13 @@ int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages)
> up_read(&mm->mmap_sem);
>
> return r;
> +
> +out_invalid_pfn:
> + for (i = 0; i < gtt->nr_ranges; i++)
> + hmm_vma_range_done(&ranges[i]);
> + kvfree(pfns);
> + kvfree(ranges);
> + return -ENOMEM;
> }
>
> /**
> @@ -871,7 +885,7 @@ bool amdgpu_ttm_tt_get_user_pages_done(struct ttm_tt *ttm)
> */
> void amdgpu_ttm_tt_set_user_pages(struct ttm_tt *ttm, struct page **pages)
> {
> - unsigned i;
> + unsigned long i;
>
> for (i = 0; i < ttm->num_pages; ++i)
> ttm->pages[i] = pages ? pages[i] : NULL;
>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
prev parent reply other threads:[~2019-05-09 13:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-07 21:52 [PATCH 1/1] drm/amdgpu: Improve error handling for HMM Kuehling, Felix
[not found] ` <20190507215202.14616-1-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2019-05-09 13:33 ` Yang, Philip [this message]
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=502904df-f52e-7ef5-ece2-60e0afcd7305@amd.com \
--to=philip.yang-5c7gfcevmho@public.gmane.org \
--cc=Felix.Kuehling-5C7GfCeVMHo@public.gmane.org \
--cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox