aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdgpu
diff options
context:
space:
mode:
authorChristian König <christian.koenig@amd.com>2017-09-03 09:22:06 -0400
committerAlex Deucher <alexander.deucher@amd.com>2017-09-12 14:24:00 -0400
commitb72cf4fca2bb786e20864b5e8755105aa9626fb4 (patch)
tree0f3f739d3fdbe0b8c2a7510689f8fdf482da295d /drivers/gpu/drm/amd/amdgpu
parent862095237c392887819e98018d6dc187d8c78726 (diff)
drm/amdgpu: move taking mmap_sem into get_user_pages v2
This didn't helped as intended, just simplify the code. v2: unlock mmap_sem in the error path as well Signed-off-by: Christian König <christian.koenig@amd.com> Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c12
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c4
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c8
3 files changed, 8 insertions, 16 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 3fe816f6beca..283a216ee758 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -500,18 +500,14 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
500 struct amdgpu_fpriv *fpriv = p->filp->driver_priv; 500 struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
501 struct amdgpu_bo_list_entry *e; 501 struct amdgpu_bo_list_entry *e;
502 struct list_head duplicates; 502 struct list_head duplicates;
503 bool need_mmap_lock = false;
504 unsigned i, tries = 10; 503 unsigned i, tries = 10;
505 int r; 504 int r;
506 505
507 INIT_LIST_HEAD(&p->validated); 506 INIT_LIST_HEAD(&p->validated);
508 507
509 p->bo_list = amdgpu_bo_list_get(fpriv, cs->in.bo_list_handle); 508 p->bo_list = amdgpu_bo_list_get(fpriv, cs->in.bo_list_handle);
510 if (p->bo_list) { 509 if (p->bo_list)
511 need_mmap_lock = p->bo_list->first_userptr !=
512 p->bo_list->num_entries;
513 amdgpu_bo_list_get_list(p->bo_list, &p->validated); 510 amdgpu_bo_list_get_list(p->bo_list, &p->validated);
514 }
515 511
516 INIT_LIST_HEAD(&duplicates); 512 INIT_LIST_HEAD(&duplicates);
517 amdgpu_vm_get_pd_bo(&fpriv->vm, &p->validated, &p->vm_pd); 513 amdgpu_vm_get_pd_bo(&fpriv->vm, &p->validated, &p->vm_pd);
@@ -519,9 +515,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
519 if (p->uf_entry.robj) 515 if (p->uf_entry.robj)
520 list_add(&p->uf_entry.tv.head, &p->validated); 516 list_add(&p->uf_entry.tv.head, &p->validated);
521 517
522 if (need_mmap_lock)
523 down_read(&current->mm->mmap_sem);
524
525 while (1) { 518 while (1) {
526 struct list_head need_pages; 519 struct list_head need_pages;
527 unsigned i; 520 unsigned i;
@@ -674,9 +667,6 @@ error_validate:
674 667
675error_free_pages: 668error_free_pages:
676 669
677 if (need_mmap_lock)
678 up_read(&current->mm->mmap_sem);
679
680 if (p->bo_list) { 670 if (p->bo_list) {
681 for (i = p->bo_list->first_userptr; 671 for (i = p->bo_list->first_userptr;
682 i < p->bo_list->num_entries; ++i) { 672 i < p->bo_list->num_entries; ++i) {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index f1e61b3df640..b0d45c8e6bb3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -318,8 +318,6 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
318 } 318 }
319 319
320 if (args->flags & AMDGPU_GEM_USERPTR_VALIDATE) { 320 if (args->flags & AMDGPU_GEM_USERPTR_VALIDATE) {
321 down_read(&current->mm->mmap_sem);
322
323 r = amdgpu_ttm_tt_get_user_pages(bo->tbo.ttm, 321 r = amdgpu_ttm_tt_get_user_pages(bo->tbo.ttm,
324 bo->tbo.ttm->pages); 322 bo->tbo.ttm->pages);
325 if (r) 323 if (r)
@@ -334,8 +332,6 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
334 amdgpu_bo_unreserve(bo); 332 amdgpu_bo_unreserve(bo);
335 if (r) 333 if (r)
336 goto free_pages; 334 goto free_pages;
337
338 up_read(&current->mm->mmap_sem);
339 } 335 }
340 336
341 r = drm_gem_handle_create(filp, gobj, &handle); 337 r = drm_gem_handle_create(filp, gobj, &handle);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 28e121984332..ea0378c8b049 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -622,6 +622,8 @@ int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages)
622 if (!(gtt->userflags & AMDGPU_GEM_USERPTR_READONLY)) 622 if (!(gtt->userflags & AMDGPU_GEM_USERPTR_READONLY))
623 flags |= FOLL_WRITE; 623 flags |= FOLL_WRITE;
624 624
625 down_read(&current->mm->mmap_sem);
626
625 if (gtt->userflags & AMDGPU_GEM_USERPTR_ANONONLY) { 627 if (gtt->userflags & AMDGPU_GEM_USERPTR_ANONONLY) {
626 /* check that we only use anonymous memory 628 /* check that we only use anonymous memory
627 to prevent problems with writeback */ 629 to prevent problems with writeback */
@@ -629,8 +631,10 @@ int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages)
629 struct vm_area_struct *vma; 631 struct vm_area_struct *vma;
630 632
631 vma = find_vma(gtt->usermm, gtt->userptr); 633 vma = find_vma(gtt->usermm, gtt->userptr);
632 if (!vma || vma->vm_file || vma->vm_end < end) 634 if (!vma || vma->vm_file || vma->vm_end < end) {
635 up_read(&current->mm->mmap_sem);
633 return -EPERM; 636 return -EPERM;
637 }
634 } 638 }
635 639
636 do { 640 do {
@@ -657,10 +661,12 @@ int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages)
657 661
658 } while (pinned < ttm->num_pages); 662 } while (pinned < ttm->num_pages);
659 663
664 up_read(&current->mm->mmap_sem);
660 return 0; 665 return 0;
661 666
662release_pages: 667release_pages:
663 release_pages(pages, pinned, 0); 668 release_pages(pages, pinned, 0);
669 up_read(&current->mm->mmap_sem);
664 return r; 670 return r;
665} 671}
666 672