Various TTM cleanups (v2)
Subsystems (3)
Various TTM cleanups (mostly no functional changes).
Notably patch #1 fixes a bug in the access_kmap() function.
The rest are either coding style fixes or simplifications.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 1/12 drm/ttm: Fix 'buf' pointer update in ttm_bo_vm_access_kmap() (v2)
The buf pointer was not being incremented inside the loop meaning the same block of data would be read or written repeatedly.
(v2) Change 'buf' pointer to uint8_t* type
--- drivers/gpu/drm/ttm/ttm_bo_vm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo_vm.c +2 -1
@@ -316,7 +316,7 @@ static void ttm_bo_vm_close(struct vm_area_struct *vma)static int ttm_bo_vm_access_kmap (struct ttm_buffer_object *bo,unsigned long offset, -void *buf,int len,int write) +uint8_t *buf,int len,int write) {unsigned long page = offset >>PAGE_SHIFT ;unsigned long bytes_left = len;
@@ -345,6 +345,7 @@ static int ttm_bo_vm_access_kmap(struct ttm_buffer_object *bo,ttm_bo_kunmap (&map); page++; + buf += bytes; bytes_left -= bytes; offset =0 ; }while (bytes_left);
Signature · 6 lines
2.14.3 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/12 drm/ttm: Fix coding style in ttm_bo.c
In reply to a message not in the archiveCorrect indentation and {} brace style.
--- drivers/gpu/drm/ttm/ttm_bo.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +2 -5
@@ -149,9 +149,8 @@ static void ttm_bo_release_list(struct kref *list_kref)mutex_destroy (&bo->wu_mutex);if (bo->destroy) bo->destroy (bo); -else { +else kfree (bo); - }ttm_mem_global_free (bdev->glob->mem_glob, acc_size); }
@@ -163,7 +162,6 @@ void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)reservation_object_assert_held (bo->resv);if (!(bo->mem.placement &TTM_PL_FLAG_NO_EVICT )) { -BUG_ON (!list_empty (&bo->lru)); man = &bdev->man[bo->mem.mem_type];
@@ -614,10 +612,9 @@ static void ttm_bo_delayed_workqueue(struct work_struct *work)struct ttm_bo_device *bdev = container_of(work, struct ttm_bo_device, wq.work); -if (!ttm_bo_delayed_delete (bdev, false)) { +if (!ttm_bo_delayed_delete (bdev, false))schedule_delayed_work (&bdev->wq, ((HZ /100 ) <1 ) ?1 :HZ /100 ); - } }static void ttm_bo_release (struct kref *kref)
Signature · 6 lines
2.14.3 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/12 drm/ttm: Add a default BO destructor to simplify code (v2)
In reply to a message not in the archive(v2): Remove stray ; noticed by Felix
--- drivers/gpu/drm/ttm/ttm_bo.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +8 -5
@@ -49,6 +49,12 @@ static struct attribute ttm_bo_count = { .mode = S_IRUGO }; +/* default destructor */ +static void ttm_bo_default_destroy (struct ttm_buffer_object *bo) +{ +kfree (bo); +} +static inline int ttm_mem_type_from_place (const struct ttm_place *place,uint32_t *mem_type) {
@@ -147,10 +153,7 @@ static void ttm_bo_release_list(struct kref *list_kref)dma_fence_put (bo->moving);reservation_object_fini (&bo->ttm_resv);mutex_destroy (&bo->wu_mutex); -if (bo->destroy) - bo->destroy (bo); -else -kfree (bo); + bo->destroy (bo);ttm_mem_global_free (bdev->glob->mem_glob, acc_size); }
@@ -1176,7 +1179,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,ttm_mem_global_free (mem_glob, acc_size);return -EINVAL ; } - bo->destroy = destroy; + bo->destroy = destroy ? destroy : ttm_bo_default_destroy;kref_init (&bo->kref);kref_init (&bo->list_kref);
Signature · 6 lines
2.14.3 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/12 drm/ttm: Change ttm_tt page allocations to return errors
In reply to a message not in the archiveExplicitly return errors in ttm_tt_alloc_page_directory() and ttm_dma_tt_alloc_page_directory() instead of relying on further logic to detect errors.
--- drivers/gpu/drm/ttm/ttm_tt.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +10 -6
@@ -50,19 +50,25 @@/** * Allocates storage for pointers to the pages that back the ttm. */ -static void ttm_tt_alloc_page_directory (struct ttm_tt *ttm) +static int ttm_tt_alloc_page_directory (struct ttm_tt *ttm) { ttm->pages =kvmalloc_array (ttm->num_pages,sizeof (void *),GFP_KERNEL | __GFP_ZERO); +if (!ttm->pages) +return -ENOMEM ; +return 0 ; } -static void ttm_dma_tt_alloc_page_directory (struct ttm_dma_tt *ttm) +static int ttm_dma_tt_alloc_page_directory (struct ttm_dma_tt *ttm) { ttm->ttm.pages =kvmalloc_array (ttm->ttm.num_pages,sizeof (*ttm->ttm.pages) +sizeof (*ttm->dma_address),GFP_KERNEL | __GFP_ZERO); +if (!ttm->ttm.pages) +return -ENOMEM ; ttm->dma_address = (void *) (ttm->ttm.pages + ttm->ttm.num_pages); +return 0 ; }#ifdef CONFIG_X86
@@ -197,8 +203,7 @@ int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev, ttm->state = tt_unpopulated; ttm->swap_storage =NULL ; -ttm_tt_alloc_page_directory (ttm); -if (!ttm->pages) { +if (ttm_tt_alloc_page_directory (ttm)) {ttm_tt_destroy (ttm);pr_err ("Failed allocating page table\n" );return -ENOMEM ;
@@ -230,8 +235,7 @@ int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_bo_device *bdev, ttm->swap_storage =NULL ;INIT_LIST_HEAD (&ttm_dma->pages_list); -ttm_dma_tt_alloc_page_directory (ttm_dma); -if (!ttm->pages) { +if (ttm_dma_tt_alloc_page_directory (ttm_dma)) {ttm_tt_destroy (ttm);pr_err ("Failed allocating page table\n" );return -ENOMEM ;
Signature · 6 lines
2.14.3 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 5/12 drm/ttm: Fix coding style in ttm_pool_store()
In reply to a message not in the archiveCorrect missing {} style.
--- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +4 -3
@@ -210,6 +210,7 @@ static ssize_t ttm_pool_store(struct kobject *kobj, struct attribute *attr, container_of(kobj, struct ttm_pool_manager, kobj);int chars;unsigned val; + chars =sscanf (buffer,"%u" , &val);if (chars ==0 )return size;
@@ -217,11 +218,11 @@ static ssize_t ttm_pool_store(struct kobject *kobj, struct attribute *attr,/* Convert kb to number of pages */ val = val / (PAGE_SIZE >>10 ); -if (attr == &ttm_page_pool_max) +if (attr == &ttm_page_pool_max) { m->options.max_size = val; -else if (attr == &ttm_page_pool_small) + }else if (attr == &ttm_page_pool_small) { m->options.small = val; -else if (attr == &ttm_page_pool_alloc_size) { + }else if (attr == &ttm_page_pool_alloc_size) {if (val >NUM_PAGES_TO_ALLOC *8 ) { pr_err("Setting allocation size to %lu is not allowed. Recommended size is %lu\n", NUM_PAGES_TO_ALLOC*(PAGE_SIZE >> 7),
Signature · 6 lines
2.14.3 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 6/12 drm/ttm: Simplify ttm_dma_find_pool() (v2)
In reply to a message not in the archiveFlip the logic of the comparison and remove
the redudant variable for the pool address.
(v2): Remove {} bracing.
--- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +6 -9
@@ -682,10 +682,10 @@ static struct dma_pool *ttm_dma_pool_init(struct device *dev, gfp_t flags,static struct dma_pool *ttm_dma_find_pool (struct device *dev,enum pool_type type) { -struct dma_pool *pool, *tmp, *found =NULL ; +struct dma_pool *pool, *tmp;if (type ==IS_UNDEFINED ) -return found; +return NULL ;/* NB: We iterate on the 'struct dev' which has no spinlock, but * it does have a kref which we have taken. The kref is taken during
@@ -698,13 +698,10 @@ static struct dma_pool *ttm_dma_find_pool(struct device *dev,* thing is at that point of time there are no pages associated with the * driver so this function will not be called. */ -list_for_each_entry_safe (pool, tmp, &dev->dma_pools, pools) { -if (pool->type != type) -continue ; - found = pool; -break ; - } -return found; +list_for_each_entry_safe (pool, tmp, &dev->dma_pools, pools) +if (pool->type == type) +return pool; +return NULL ; }/*
Signature · 6 lines
2.14.3 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 7/12 drm/ttm: Fix coding style in ttm_bo_move_memcpy()
In reply to a message not in the archiveAdd missing {} braces.
--- drivers/gpu/drm/ttm/ttm_bo_util.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo_util.c +2 -1
@@ -402,8 +402,9 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo, PAGE_KERNEL); ret =ttm_copy_io_ttm_page (ttm, old_iomap, page, prot); - }else + }else { ret =ttm_copy_io_page (new_iomap, old_iomap, page); + }if (ret) goto out1; }
Signature · 6 lines
2.14.3 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 8/12 drm/ttm: Remove unncessary retval from ttm_bo_vm_fault()
In reply to Tom St DenisThe dual ret/retval was more complex than need be. Now we drop the retval variable and assign the appropriate VM codes to ret instead.
--- drivers/gpu/drm/ttm/ttm_bo_vm.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-)
drivers/gpu/drm/ttm/ttm_bo_vm.c +13 -15
@@ -118,7 +118,6 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)int ret;int i;unsigned long address = vmf->address; -int retval =VM_FAULT_NOPAGE ;struct ttm_mem_type_manager *man = &bdev->man[bo->mem.mem_type];struct vm_area_struct cvma;
@@ -158,7 +157,7 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)* (if at all) by redirecting mmap to the exporter. */ if (bo->ttm && (bo->ttm->page_flags &TTM_PAGE_FLAG_SG )) { - retval =VM_FAULT_SIGBUS ; + ret =VM_FAULT_SIGBUS ; goto out_unlock; }
@@ -169,10 +168,10 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)break ;case -EBUSY :case -ERESTARTSYS : - retval =VM_FAULT_NOPAGE ; + ret =VM_FAULT_NOPAGE ; goto out_unlock;default : - retval =VM_FAULT_SIGBUS ; + ret =VM_FAULT_SIGBUS ; goto out_unlock; } }
@@ -183,12 +182,10 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)*/ ret =ttm_bo_vm_fault_idle (bo, vmf);if (unlikely (ret !=0 )) { - retval = ret; - -if (retval ==VM_FAULT_RETRY && +if (ret ==VM_FAULT_RETRY && !(vmf->flags &FAULT_FLAG_RETRY_NOWAIT )) {/* The BO has already been unreserved. */ -return retval; +return ret; } goto out_unlock;
@@ -196,12 +193,12 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf) ret =ttm_mem_io_lock (man, true);if (unlikely (ret !=0 )) { - retval =VM_FAULT_NOPAGE ; + ret =VM_FAULT_NOPAGE ; goto out_unlock; } ret =ttm_mem_io_reserve_vm (bo);if (unlikely (ret !=0 )) { - retval =VM_FAULT_SIGBUS ; + ret =VM_FAULT_SIGBUS ; goto out_io_unlock; }
@@ -211,7 +208,7 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)drm_vma_node_start (&bo->vma_node);if (unlikely (page_offset >= bo->num_pages)) { - retval =VM_FAULT_SIGBUS ; + ret =VM_FAULT_SIGBUS ; goto out_io_unlock; }
@@ -238,7 +235,7 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)/* Allocate all page at once, most common usage */ if (ttm->bdev->driver->ttm_tt_populate (ttm, &ctx)) { - retval =VM_FAULT_OOM ; + ret =VM_FAULT_OOM ; goto out_io_unlock; } }
@@ -255,7 +252,7 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf) }else { page = ttm->pages[page_offset];if (unlikely (!page && i ==0 )) { - retval =VM_FAULT_OOM ; + ret =VM_FAULT_OOM ; goto out_io_unlock; }else if (unlikely (!page)) {break ;
@@ -280,7 +277,7 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)if (unlikely ((ret == -EBUSY ) || (ret !=0 && i >0 )))break ;else if (unlikely (ret !=0 )) { - retval = + ret = (ret == -ENOMEM ) ?VM_FAULT_OOM :VM_FAULT_SIGBUS ; goto out_io_unlock; }
@@ -289,11 +286,12 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)if (unlikely (++page_offset >= page_last))break ; } + ret =VM_FAULT_NOPAGE ; out_io_unlock:ttm_mem_io_unlock (man); out_unlock:ttm_bo_unreserve (bo); -return retval; +return ret; }static void ttm_bo_vm_open (struct vm_area_struct *vma)
Signature · 6 lines
2.14.3 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 9/12 drm/ttm: Simplify ttm_eu_reserve_buffers()
In reply to a message not in the archiveHoist the comparison of the ret to -EDEADLK above
the two code paths to simplify the function.
--- drivers/gpu/drm/ttm/ttm_execbuf_util.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/gpu/drm/ttm/ttm_execbuf_util.c +8 -6
@@ -139,12 +139,14 @@ int ttm_eu_reserve_buffers(struct ww_acquire_ctx *ticket,*/ ttm_eu_backoff_reservation_reverse (list, entry); -if (ret == -EDEADLK && intr) { - ret =ww_mutex_lock_slow_interruptible (&bo->resv->lock, - ticket); - }else if (ret == -EDEADLK ) { -ww_mutex_lock_slow (&bo->resv->lock, ticket); - ret =0 ; +if (ret == -EDEADLK ) { +if (intr) { + ret =ww_mutex_lock_slow_interruptible (&bo->resv->lock, + ticket); + }else { +ww_mutex_lock_slow (&bo->resv->lock, ticket); + ret =0 ; + } }if (!ret && entry->shared)
Signature · 6 lines
2.14.3 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 10/12 drm/ttm: Fix coding style in ttm_tt_swapout()
In reply to a message not in the archiveAdd missing {} braces.
--- drivers/gpu/drm/ttm/ttm_tt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_tt.c +2 -1
@@ -352,8 +352,9 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)pr_err ("Failed allocating swap storage\n" );return PTR_ERR (swap_storage); } - }else + }else { swap_storage = persistent_swap_storage; + } swap_space = swap_storage->f_mapping;
Signature · 6 lines
2.14.3 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 11/12 drm/ttm: Fix coding style in ttm_dma_pool_alloc_new_pages()
In reply to Tom St DenisAdd missing {} braces.
--- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1 -2
@@ -763,10 +763,9 @@ static int ttm_dma_pool_alloc_new_pages(struct dma_pool *pool,return -ENOMEM ; } -if (count >1 ) { +if (count >1 )pr_debug ("%s: (%s:%d) Getting %d pages\n" , pool->dev_name, pool->name, current->pid, count); - }for (i =0 , cpages =0 ; i < count; ++i) { dma_p =__ttm_dma_alloc_page (pool);
Signature · 6 lines
2.14.3 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 12/12 drm/ttm: Simplify ttm_dma_page_put()
In reply to a message not in the archiveRemove redundant store of return code.
--- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1 -3
@@ -390,14 +390,12 @@ static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page) {struct page *page = d_page->p;unsigned i, num_pages; -int ret;/* Don't set WB on WB page pool. */ if (!(pool->type &IS_CACHED )) { num_pages = pool->size /PAGE_SIZE ;for (i =0 ; i < num_pages; ++i, ++page) { - ret =set_pages_array_wb (&page,1 ); -if (ret) { +if (set_pages_array_wb (&page,1 )) {pr_err ("%s: Failed to set %d pages to wb!\n" , pool->dev_name,1 ); }
Signature · 6 lines
2.14.3 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 01/12] drm/ttm: Fix 'buf' pointer update in ttm_bo_vm_access_kmap() (v2)
In reply to a message not in the archiveQuoted 6 lines · Tom St Denis
The buf pointer was not being incremented inside the loop meaning the same block of data would be read or written repeatedly.
Signed-off-by Tom St Denis <[email protected]>Reviewed-by Christian König <[email protected]>
Please add:
so that it'll get backported to the relevant stable branches.
Signature · 6 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 01/12] drm/ttm: Fix 'buf' pointer update in ttm_bo_vm_access_kmap() (v2)
Am 29.01.2018 um 15:31 schrieb Michel Dänzer:
Quoted 11 lines · Tom St Denis
Quoted 6 lines
The buf pointer was not being incremented inside the loop meaning the same block of data would be read or written repeatedly.
Signed-off-by Tom St Denis <[email protected]>Reviewed-by Christian König <[email protected]>Please add:
Fixes 09ac4fcb3f25 ("drm/ttm: Implement vm_operations_struct.access v2")
What Michel meant here is that you should add the "Cc: " and "Fixes: " tags to the commit message and NOT send it manually to [email protected].
The "Cc:" tag results in automatically backporting of the patch to stable kernels. Manually sending a patch to [email protected] is only necessary when the automated backport doesn't work.
Christian.
Quoted 4 lines
so that it'll get backported to the relevant stable branches.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
The series is Reviewed-by: Felix Kuehling <[email protected]>
Regards,
Felix
Quoted 11 lines · Tom St Denis
Various TTM cleanups (mostly no functional changes).
Notably patch #1 fixes a bug in the
access_kmap()function.The rest are either coding style fixes or simplifications.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel