drm/ttm: split BO structure initialization into a separate function
Subsystems (4)
PATCH 1/3 drm/ttm: split BO structure initialization into a separate function
From: Nicolai Hähnle <[email protected]>
Allow callers to opt out of calling ttm_bo_validate immediately. This allows more flexibility in how locking of the reservation object is done, which is needed to fix a locking bug (destroy locked mutex) in amdgpu.
--- drivers/gpu/drm/ttm/ttm_bo.c | 62 +++++++++++++++++++++++++++++--------------- include/drm/ttm/ttm_bo_api.h | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 21 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +41 -21
@@ -1120,41 +1120,30 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_validate); -int ttm_bo_init (struct ttm_bo_device *bdev, -struct ttm_buffer_object *bo, -unsigned long size, -enum ttm_bo_type type, -struct ttm_placement *placement, -uint32_t page_alignment, -bool interruptible, -struct file *persistent_swap_storage, -size_t acc_size, -struct sg_table *sg, -struct reservation_object *resv, -void (*destroy) (struct ttm_buffer_object *)) +int ttm_bo_init_top (struct ttm_bo_device *bdev, +struct ttm_buffer_object *bo, +unsigned long size, +enum ttm_bo_type type, +uint32_t page_alignment, +struct file *persistent_swap_storage, +size_t acc_size, +struct sg_table *sg, +struct reservation_object *resv, +void (*destroy) (struct ttm_buffer_object *)) {int ret =0 ;unsigned long num_pages;struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; -bool locked; ret =ttm_mem_global_alloc (mem_glob, acc_size, false, false);if (ret) {pr_err ("Out of kernel memory\n" ); -if (destroy) - (*destroy)(bo); -else -kfree (bo);return -ENOMEM ; } num_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ;if (num_pages ==0 ) {pr_err ("Illegal buffer object size\n" ); -if (destroy) - (*destroy)(bo); -else -kfree (bo);ttm_mem_global_free (mem_glob, acc_size);return -EINVAL ; }
@@ -1204,6 +1193,37 @@ int ttm_bo_init(struct ttm_bo_device *bdev, ret =drm_vma_offset_add (&bdev->vma_manager, &bo->vma_node, bo->mem.num_pages); +return ret; +} +EXPORT_SYMBOL (ttm_bo_init_top); + +int ttm_bo_init (struct ttm_bo_device *bdev, +struct ttm_buffer_object *bo, +unsigned long size, +enum ttm_bo_type type, +struct ttm_placement *placement, +uint32_t page_alignment, +bool interruptible, +struct file *persistent_swap_storage, +size_t acc_size, +struct sg_table *sg, +struct reservation_object *resv, +void (*destroy) (struct ttm_buffer_object *)) +{ +bool locked; +int ret; + + ret =ttm_bo_init_top (bdev, bo, size, type, page_alignment, + persistent_swap_storage, acc_size, sg, resv, + destroy); +if (ret) { +if (destroy) + (*destroy)(bo); +else +kfree (bo); +return ret; + } +/* passed reservation objects should already be locked, * since otherwise lockdep will be angered in radeon. */
include/drm/ttm/ttm_bo_api.h +45 -0
51 lines not on this page · raw message
Signature · 6 lines
2.9.3 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 20170214103744.4133-1-nhaehnle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
PATCH 2/3 drm/ttm: fix the documentation of ttm_bo_init
From: Nicolai Hähnle <[email protected]>
As the comment says: callers of ttm_bo_init cannot rely on having the only reference to the BO when the function returns successfully.
--- include/drm/ttm/ttm_bo_api.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
include/drm/ttm/ttm_bo_api.h +5 -1
@@ -521,7 +521,11 @@ extern int ttm_bo_init_top(struct ttm_bo_device *bdev,* As this object may be part of a larger structure, this function, * together with the @destroy function, * enables driver-specific objects derived from a ttm_buffer_object. -* On successful return, the object kref and list_kref are set to 1. +* +* On successful return, the caller owns an object kref to @bo. The kref and +* list_kref are usually set to 1, but note that in some situations, other +* tasks may already be holding references to @bo as well. +* * If a failure occurs, the function will call the @destroy function, or * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is * illegal and will likely cause memory corruption.
Signature · 6 lines
2.9.3 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/3 drm/amdgpu: fix lock cleanup during buffer creation
In reply to a message not in the archiveFrom: Nicolai Hähnle <[email protected]>
Open-code the initial ttm_bo_validate call, so that we can properly unlock the reservation lock when it fails. Also, properly destruct the reservation object when the first part of TTM BO initialization fails.
Actual deadlocks caused by the missing unlock should have been fixed by "drm/ttm: never add BO that failed to validate to the LRU list", superseding the flawed fix in commit 38fc4856ad98 ("drm/amdgpu: fix a potential deadlock in amdgpu_bo_create_restricted()").
This change fixes remaining recursive locking errors that can be seen with lock debugging enabled, and avoids the error of freeing a locked mutex.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 32 +++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +27 -5
@@ -399,12 +399,34 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, locked =ww_mutex_trylock (&bo->tbo.ttm_resv.lock);WARN_ON (!locked); } - r =ttm_bo_init (&adev->mman.bdev, &bo->tbo, size, type, - &bo->placement, page_align, !kernel,NULL , - acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, - &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) + r =ttm_bo_init_top (&adev->mman.bdev, &bo->tbo, size, type, + page_align,NULL , + acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, + &amdgpu_ttm_bo_destroy); +if (unlikely (r !=0 )) { +if (!resv) { +ww_mutex_unlock (&bo->tbo.ttm_resv.lock); +reservation_object_fini (&bo->tbo.ttm_resv); + } +amdgpu_ttm_bo_destroy (&bo->tbo); +return r; + } + + r =ttm_bo_validate (&bo->tbo, &bo->placement, !kernel, false); +if (unlikely (r !=0 )) { +struct ttm_buffer_object *tbo = &bo->tbo; + +if (!resv) +ww_mutex_unlock (&bo->tbo.ttm_resv.lock); +ttm_bo_unref (&tbo);return r; + } + +if (!(bo->tbo.mem.placement &TTM_PL_FLAG_NO_EVICT )) { +spin_lock (&bo->tbo.glob->lru_lock); +ttm_bo_add_to_lru (&bo->tbo); +spin_unlock (&bo->tbo.glob->lru_lock); + } bo->tbo.priority =ilog2 (bo->tbo.num_pages);if (kernel)
Signature · 6 lines
2.9.3 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 70 lines · Nicolai Hähnle
From: Nicolai Hähnle <[email protected]>
Allow callers to opt out of calling
ttm_bo_validateimmediately. This allows more flexibility in how locking of the reservation object is done, which is needed to fix a locking bug (destroy locked mutex) in amdgpu.Signed-off-by Nicolai Hähnle <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 62 +++++++++++++++++++++++++++++--------------- include/drm/ttm/ttm_bo_api.h | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +10
-21@@ -1120,41 +1120,30 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_validate); -int ttm_bo_init (struct ttm_bo_device *bdev, -struct ttm_buffer_object *bo, -unsigned long size, -enum ttm_bo_type type, -struct ttm_placement *placement, -uint32_t page_alignment, -bool interruptible, -struct file *persistent_swap_storage, -size_t acc_size, -struct sg_table *sg, -struct reservation_object *resv, -void (*destroy) (struct ttm_buffer_object *)) +int ttm_bo_init_top (struct ttm_bo_device *bdev, +struct ttm_buffer_object *bo, +unsigned long size, +enum ttm_bo_type type, +uint32_t page_alignment, +struct file *persistent_swap_storage, +size_t acc_size, +struct sg_table *sg, +struct reservation_object *resv, +void (*destroy) (struct ttm_buffer_object *)) {int ret =0 ;unsigned long num_pages;struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; -bool locked; ret =ttm_mem_global_alloc (mem_glob, acc_size, false, false);if (ret) {pr_err ("Out of kernel memory\n" ); -if (destroy) - (*destroy)(bo); -else -kfree (bo);return -ENOMEM ; } num_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ;if (num_pages ==0 ) {pr_err ("Illegal buffer object size\n" ); -if (destroy) - (*destroy)(bo); -else -kfree (bo);ttm_mem_global_free (mem_glob, acc_size);return -EINVAL ; }
drivers/gpu/drm/ttm/ttm_bo.c int ttm_bo_init(struct ttm_bo_device *bdev, · line 1194
Quoted 2 lines
drivers/gpu/drm/ttm/ttm_bo.c +0
-0@@ -1204,6 +1193,37 @@ int ttm_bo_init(struct ttm_bo_device *bdev, ret =drm_vma_offset_add (&bdev->vma_manager, &bo->vma_node, bo->mem.num_pages);
if (ret && !resv), we should call reservation_object_fini(&bo->ttm_resv), right?
Quoted 11 lines
drivers/gpu/drm/ttm/ttm_bo.c +10
-0+return ret; +} +EXPORT_SYMBOL (ttm_bo_init_top); + +int ttm_bo_init(struct ttm_bo_device *bdev, + struct ttm_buffer_object *bo, + unsigned long size, + enum ttm_bo_type type, + struct ttm_placement *placement, + uint32_t page_alignment,
drivers/gpu/drm/ttm/ttm_bo.c int ttm_bo_init(struct ttm_bo_device *bdev, · line 1215
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +10
-0+bool interruptible, + struct file *persistent_swap_storage, + size_t acc_size, + struct sg_table *sg, + struct reservation_object *resv, + void (*destroy) (struct ttm_buffer_object *)) +{ + bool locked; +int ret; +
Can we lock resv anyway before ttm_bo_init_top like what you did in patch #3? if yes, seems we don't need patch#3 any more, right?
if (!resv) {
bool locked;
reservation_object_init(&bo->tbo.ttm_resv);
locked = ww_mutex_trylock(&bo->tbo.ttm_resv.lock);
WARN_ON(!locked);
}
r = ttm_bo_init_top(&adev->mman.bdev, &bo->tbo, size, type,
page_align, NULL,
acc_size, sg, resv ? resv : &bo->tbo.ttm_resv,
&amdgpu_ttm_bo_destroy);Regards,
David Zhou
Quoted 60 lines
drivers/gpu/drm/ttm/ttm_bo.c +11
-0+ ret =ttm_bo_init_top (bdev, bo, size, type, page_alignment, + persistent_swap_storage, acc_size, sg, resv, + destroy); +if (ret) { +if (destroy) + (*destroy)(bo); +else +kfree (bo); +return ret; + } +/* passed reservation objects should already be locked, * since otherwise lockdep will be angered in radeon. */ include/drm/ttm/ttm_bo_api.h +38
-0@@ -453,6 +453,51 @@ size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev, unsigned struct_size);/** +* ttm_bo_init_top +* +* @bdev: Pointer to a ttm_bo_device struct. +* @bo: Pointer to a ttm_buffer_object to be initialized. +* @size: Requested size of buffer object. +* @type: Requested type of buffer object. +* @flags: Initial placement flags. +* @page_alignment: Data alignment in pages. +* @persistent_swap_storage: Usually the swap storage is deleted for buffers +* pinned in physical memory. If this behaviour is not desired, this member +* holds a pointer to a persistent shmem object. Typically, this would +* point to the shmem object backing a GEM object if TTM is used to back a +* GEM user interface. +* @acc_size: Accounted size for this object. +* @resv: Pointer to a reservation_object, or NULL to let ttm allocate one. +* @destroy: Destroy function. Use NULL for kfree(). +* +* This function initializes a pre-allocated struct ttm_buffer_object. +* As this object may be part of a larger structure, this function, +* together with the @destroy function, +* enables driver-specific objects derived from a ttm_buffer_object. +* +* Unlike ttm_bo_init, @bo is not validated, and when an error is returned, +* the caller is responsible for freeing @bo (but the setup performed by +* ttm_bo_init_top itself is cleaned up). +* +* On successful return, the object kref and list_kref are set to 1. +* +* Returns +* -ENOMEM: Out of memory. +* -EINVAL: Invalid buffer size. +*/ + +extern int ttm_bo_init_top(struct ttm_bo_device *bdev, + struct ttm_buffer_object *bo, + unsigned long size, + enum ttm_bo_type type, + uint32_t page_alignment,
include/drm/ttm/ttm_bo_api.h size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev, · line 503
Quoted 10 lines
include/drm/ttm/ttm_bo_api.h +7
-0+struct file *persistent_swap_storage, + size_t acc_size, + struct sg_table *sg, + struct reservation_object *resv, + void (*destroy) (struct ttm_buffer_object *)); + +/** * ttm_bo_init * * @bdev: Pointer to a ttm_bo_device struct.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 65 lines · On 15.02.2017 04:16, zhoucm1 wrote:
Quoted 64 lines · Nicolai Hähnle
From: Nicolai Hähnle <[email protected]>
Allow callers to opt out of calling
ttm_bo_validateimmediately. This allows more flexibility in how locking of the reservation object is done, which is needed to fix a locking bug (destroy locked mutex) in amdgpu.Signed-off-by Nicolai Hähnle <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 62 +++++++++++++++++++++++++++++--------------- include/drm/ttm/ttm_bo_api.h | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +10
-20@@ -1120,41 +1120,30 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_validate); -int ttm_bo_init(struct ttm_bo_device *bdev, - struct ttm_buffer_object *bo, - unsigned long size, - enum ttm_bo_type type, - struct ttm_placement *placement, - uint32_t page_alignment, - bool interruptible, - struct file *persistent_swap_storage, - size_t acc_size, - struct sg_table *sg, - struct reservation_object *resv, - void (*destroy) (struct ttm_buffer_object *)) +int ttm_bo_init_top(struct ttm_bo_device *bdev, +struct ttm_buffer_object *bo, +unsigned long size, +enum ttm_bo_type type, +uint32_t page_alignment, +struct file *persistent_swap_storage, +size_t acc_size, +struct sg_table *sg, +struct reservation_object *resv, +void (*destroy) (struct ttm_buffer_object *)) { int ret = 0;unsigned long num_pages;struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; -bool locked; ret =ttm_mem_global_alloc (mem_glob, acc_size, false, false);if (ret) {pr_err ("Out of kernel memory\n" ); -if (destroy) - (*destroy)(bo); -else -kfree (bo);return -ENOMEM ; } num_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ;if (num_pages ==0 ) {pr_err ("Illegal buffer object size\n" ); -if (destroy) - (*destroy)(bo); -else -kfree (bo);
Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c int ttm_bo_init(struct ttm_bo_device *bdev, · line 1194
Quoted 6 lines
drivers/gpu/drm/ttm/ttm_bo.c +0
-0ttm_mem_global_free (mem_glob, acc_size);return -EINVAL ; }@@ -1204,6 +1193,37 @@ int ttm_bo_init(struct ttm_bo_device *bdev, ret =drm_vma_offset_add (&bdev->vma_manager, &bo->vma_node, bo->mem.num_pages);if (ret && !resv), we should call
reservation_object_fini(&bo->ttm_resv), right?
Good point, though actually, ret can never be != 0 here, so this can be simplified a bit.
Quoted 24 lines
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +9
-0+ return ret; +} +EXPORT_SYMBOL (ttm_bo_init_top); + +int ttm_bo_init(struct ttm_bo_device *bdev, + struct ttm_buffer_object *bo, + unsigned long size, + enum ttm_bo_type type, + struct ttm_placement *placement, + uint32_t page_alignment,drivers/gpu/drm/ttm/ttm_bo.c int ttm_bo_init(struct ttm_bo_device *bdev, · line 1215
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +10
-0+bool interruptible, + struct file *persistent_swap_storage, + size_t acc_size, + struct sg_table *sg, + struct reservation_object *resv, + void (*destroy) (struct ttm_buffer_object *)) +{ + bool locked; +int ret; +Can we lock resv anyway before
ttm_bo_init_toplike what you did in patch #3? if yes, seems we don't need patch#3 any more, right?
Quoted 11 lines
if (!resv) {
bool locked;
reservation_object_init(&bo->tbo.ttm_resv);
locked = ww_mutex_trylock(&bo->tbo.ttm_resv.lock);
WARN_ON(!locked);
}
r = ttm_bo_init_top(&adev->mman.bdev, &bo->tbo, size, type,
page_align, NULL,
acc_size, sg, resv ? resv : &bo->tbo.ttm_resv,
&amdgpu_ttm_bo_destroy);No, because there's still different behavior when it comes to unlocking. There are three different behaviors that are needed:
1. resv == NULL, and leaving ttm_bo_init with the BO unreserved.
2. resv != NULL, and not changing the reserved status during initialization.
3. resv != NULL, and leaving initialization with the BO reserved, but unlocking when the BO is destroyed.
1+2 can be expressed well with the ttm_bo_init interface, but 3 cannot.
I think a possible alternative would be to change ttm_bo_init so that it always returns on success with the BO reserved, but that would require changing all the drivers, and I don't really see the advantage over just being more explicit in each driver.
Cheers,
Nicolai
Quoted 70 lines
Regards,
David ZhouQuoted 67 lines
drivers/gpu/drm/ttm/ttm_bo.c +11
-0+ ret =ttm_bo_init_top (bdev, bo, size, type, page_alignment, + persistent_swap_storage, acc_size, sg, resv, + destroy); +if (ret) { +if (destroy) + (*destroy)(bo); +else +kfree (bo); +return ret; + } +/* passed reservation objects should already be locked, * since otherwise lockdep will be angered in radeon. */ include/drm/ttm/ttm_bo_api.h +9
-0@@ -453,6 +453,51 @@ size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev, unsigned struct_size);/** +* ttm_bo_init_top +* +* @bdev: Pointer to a ttm_bo_device struct. +* @bo: Pointer to a ttm_buffer_object to be initialized. +* @size: Requested size of buffer object. +* @type: Requested type of buffer object. +* @flags: Initial placement flags. +* @page_alignment: Data alignment in pages. +* @persistent_swap_storage: Usually the swap storage is deleted for buffers
+ * pinned in physical memory. If this behaviour is not desired, this member
+ * holds a pointer to a persistent shmem object. Typically, this would
+ * point to the shmem object backing a GEM object if TTM is used to back a
+ * GEM user interface.
+ * @acc_size: Accounted size for this object.
+ * @resv: Pointer to areservation_object, or NULL to let ttm allocate one.
+ * @destroy: Destroy function. Use NULL forkfree().
+ *
+ * This function initializes a pre-allocated structttm_buffer_object.
+ * As this object may be part of a larger structure, this function,
+ * together with the @destroy function,
+ * enables driver-specific objects derived from attm_buffer_object.
+ *
+ * Unlikettm_bo_init, @bo is not validated, and when an error is returned,
+ * the caller is responsible for freeing @bo (but the setup performed by
+ *ttm_bo_init_topitself is cleaned up).
+ *
+ * On successful return, the object kref andlist_krefare set to 1.
+ *
+ * Returns
+ *-ENOMEM: Out of memory.
+ *-EINVAL: Invalid buffer size.
+ */include/drm/ttm/ttm_bo_api.h +8
-0+ +extern int ttm_bo_init_top(struct ttm_bo_device *bdev, + struct ttm_buffer_object *bo, + unsigned long size, + enum ttm_bo_type type, + uint32_t page_alignment, + struct file *persistent_swap_storage, + size_t acc_size,
Quoted 9 lines
include/drm/ttm/ttm_bo_api.h size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev, · line 503
Quoted 8 lines
include/drm/ttm/ttm_bo_api.h +5
-0+struct sg_table *sg, + struct reservation_object *resv, + void (*destroy) (struct ttm_buffer_object *)); + +/** * ttm_bo_init * * @bdev: Pointer to a ttm_bo_device struct.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 403a8be3-7f55-085c-b9ad-19551be33332-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 120 lines · Nicolai Hähnle
Quoted 66 lines · On 15.02.2017 04:16, zhoucm1 wrote:
Quoted 65 lines · Nicolai Hähnle
From: Nicolai Hähnle <[email protected]>
Allow callers to opt out of calling
ttm_bo_validateimmediately. This allows more flexibility in how locking of the reservation object is done, which is needed to fix a locking bug (destroy locked mutex) in amdgpu.Signed-off-by Nicolai Hähnle <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 62 +++++++++++++++++++++++++++++--------------- include/drm/ttm/ttm_bo_api.h | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +10
-20@@ -1120,41 +1120,30 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_validate); -int ttm_bo_init(struct ttm_bo_device *bdev, - struct ttm_buffer_object *bo, - unsigned long size, - enum ttm_bo_type type, - struct ttm_placement *placement, - uint32_t page_alignment, - bool interruptible, - struct file *persistent_swap_storage, - size_t acc_size, - struct sg_table *sg, - struct reservation_object *resv, - void (*destroy) (struct ttm_buffer_object *)) +int ttm_bo_init_top(struct ttm_bo_device *bdev, +struct ttm_buffer_object *bo, +unsigned long size, +enum ttm_bo_type type, +uint32_t page_alignment, +struct file *persistent_swap_storage, +size_t acc_size, +struct sg_table *sg, +struct reservation_object *resv, +void (*destroy) (struct ttm_buffer_object *)) { int ret = 0;unsigned long num_pages;struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; -bool locked; ret =ttm_mem_global_alloc (mem_glob, acc_size, false, false);if (ret) {pr_err ("Out of kernel memory\n" ); -if (destroy) - (*destroy)(bo); -else -kfree (bo);return -ENOMEM ; } num_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ;if (num_pages ==0 ) {pr_err ("Illegal buffer object size\n" ); -if (destroy) - (*destroy)(bo); -else -kfree (bo);Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c int ttm_bo_init(struct ttm_bo_device *bdev, · line 1194
Quoted 6 lines
drivers/gpu/drm/ttm/ttm_bo.c +0
-0ttm_mem_global_free (mem_glob, acc_size);return -EINVAL ; }@@ -1204,6 +1193,37 @@ int ttm_bo_init(struct ttm_bo_device *bdev, ret =drm_vma_offset_add (&bdev->vma_manager, &bo->vma_node, bo->mem.num_pages);if (ret && !resv), we should call
reservation_object_fini(&bo->ttm_resv), right?Good point, though actually, ret can never be != 0 here, so this can be simplified a bit.
Quoted 27 lines
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +9
-0+ return ret; +} +EXPORT_SYMBOL (ttm_bo_init_top); + +int ttm_bo_init(struct ttm_bo_device *bdev, + struct ttm_buffer_object *bo, + unsigned long size, + enum ttm_bo_type type, + struct ttm_placement *placement, + uint32_t page_alignment,drivers/gpu/drm/ttm/ttm_bo.c int ttm_bo_init(struct ttm_bo_device *bdev, · line 1215
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +10
-0+bool interruptible, + struct file *persistent_swap_storage, + size_t acc_size, + struct sg_table *sg, + struct reservation_object *resv, + void (*destroy) (struct ttm_buffer_object *)) +{ + bool locked; +int ret; +Can we lock resv anyway before
ttm_bo_init_toplike what you did in patch #3? if yes, seems we don't need patch#3 any more, right?if (!resv) { bool locked;Quoted 9 lines
reservation_object_init(&bo->tbo.ttm_resv); locked = ww_mutex_trylock(&bo->tbo.ttm_resv.lock); WARN_ON(!locked); } r = ttm_bo_init_top(&adev->mman.bdev, &bo->tbo, size, type, page_align, NULL, acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy);No, because there's still different behavior when it comes to unlocking. There are three different behaviors that are needed:
1. resv == NULL, and leaving
ttm_bo_initwith the BO unreserved.
Quoted 7 lines
2. resv != NULL, and not changing the reserved status during initialization.
3. resv != NULL, and leaving initialization with the BO reserved, but unlocking when the BO is destroyed.
1+2 can be expressed well with the
ttm_bo_initinterface, but 3 cannot.I think a possible alternative would be to change
ttm_bo_initso that it always returns on success with the BO reserved, but that would require changing all the drivers, and I don't really see the advantage over just being more explicit in each driver.
OK, make sense, then wait Alex to submit to staging branch and verify it.
Thanks,
David Zhou
Quoted 85 lines
Cheers,
NicolaiQuoted 80 lines
Regards,
David ZhouQuoted 76 lines
drivers/gpu/drm/ttm/ttm_bo.c +11
-0+ ret =ttm_bo_init_top (bdev, bo, size, type, page_alignment, + persistent_swap_storage, acc_size, sg, resv, + destroy); +if (ret) { +if (destroy) + (*destroy)(bo); +else +kfree (bo); +return ret; + } +/* passed reservation objects should already be locked, * since otherwise lockdep will be angered in radeon. */ include/drm/ttm/ttm_bo_api.h +9
-0@@ -453,6 +453,51 @@ size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev, unsigned struct_size);/** +* ttm_bo_init_top +* +* @bdev: Pointer to a ttm_bo_device struct. +* @bo: Pointer to a ttm_buffer_object to be initialized. +* @size: Requested size of buffer object. +* @type: Requested type of buffer object. +* @flags: Initial placement flags. +* @page_alignment: Data alignment in pages. +* @persistent_swap_storage: Usually the swap storage is deleted for buffers
+ * pinned in physical memory. If this behaviour is not desired, this member
+ * holds a pointer to a persistent shmem object. Typically, this would
+ * point to the shmem object backing a GEM object if TTM is used to back a
+ * GEM user interface.
+ * @acc_size: Accounted size for this object.
+ * @resv: Pointer to areservation_object, or NULL to let ttm allocate one.
+ * @destroy: Destroy function. Use NULL forkfree().
+ *
+ * This function initializes a pre-allocated structttm_buffer_object.
+ * As this object may be part of a larger structure, this function,
+ * together with the @destroy function,
+ * enables driver-specific objects derived from attm_buffer_object.
+ *
+ * Unlikettm_bo_init, @bo is not validated, and when an error is returned,
+ * the caller is responsible for freeing @bo (but the setup performed by
+ *ttm_bo_init_topitself is cleaned up).
+ *
+ * On successful return, the object kref andlist_krefare set to 1.
+ *
+ * Returns
+ *-ENOMEM: Out of memory.
+ *-EINVAL: Invalid buffer size.
+ */include/drm/ttm/ttm_bo_api.h +13
-0+ +extern int ttm_bo_init_top (struct ttm_bo_device *bdev, +struct ttm_buffer_object *bo, +unsigned long size, +enum ttm_bo_type type, +uint32_t page_alignment, +struct file *persistent_swap_storage, +size_t acc_size, +struct sg_table *sg, +struct reservation_object *resv, +void (*destroy) (struct ttm_buffer_object *)); + +/** * ttm_bo_init * * @bdev: Pointer to a ttm_bo_device struct.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 67 lines · On 15.02.2017 04:16, zhoucm1 wrote:
Quoted 64 lines · Nicolai Hähnle
From: Nicolai Hähnle <[email protected]>
Allow callers to opt out of calling
ttm_bo_validateimmediately. This allows more flexibility in how locking of the reservation object is done, which is needed to fix a locking bug (destroy locked mutex) in amdgpu.Signed-off-by Nicolai Hähnle <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 62 +++++++++++++++++++++++++++++--------------- include/drm/ttm/ttm_bo_api.h | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +10
-20@@ -1120,41 +1120,30 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_validate); -int ttm_bo_init(struct ttm_bo_device *bdev, - struct ttm_buffer_object *bo, - unsigned long size, - enum ttm_bo_type type, - struct ttm_placement *placement, - uint32_t page_alignment, - bool interruptible, - struct file *persistent_swap_storage, - size_t acc_size, - struct sg_table *sg, - struct reservation_object *resv, - void (*destroy) (struct ttm_buffer_object *)) +int ttm_bo_init_top(struct ttm_bo_device *bdev, +struct ttm_buffer_object *bo, +unsigned long size, +enum ttm_bo_type type, +uint32_t page_alignment, +struct file *persistent_swap_storage, +size_t acc_size, +struct sg_table *sg, +struct reservation_object *resv, +void (*destroy) (struct ttm_buffer_object *)) { int ret = 0;unsigned long num_pages;struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; -bool locked; ret =ttm_mem_global_alloc (mem_glob, acc_size, false, false);if (ret) {pr_err ("Out of kernel memory\n" ); -if (destroy) - (*destroy)(bo); -else -kfree (bo);return -ENOMEM ; } num_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ;if (num_pages ==0 ) {pr_err ("Illegal buffer object size\n" ); -if (destroy) - (*destroy)(bo); -else -kfree (bo);
Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c int ttm_bo_init(struct ttm_bo_device *bdev, · line 1194
Quoted 6 lines
drivers/gpu/drm/ttm/ttm_bo.c +0
-0ttm_mem_global_free (mem_glob, acc_size);return -EINVAL ; }@@ -1204,6 +1193,37 @@ int ttm_bo_init(struct ttm_bo_device *bdev, ret =drm_vma_offset_add (&bdev->vma_manager, &bo->vma_node, bo->mem.num_pages);if (ret && !resv), we should call
reservation_object_fini(&bo->ttm_resv), right?
FWIW, you were right about this (and also mutex_destroy needs to be called for wu_mutex, etc.). But I'm following Christian's suggestion of having the caller use ttm_bo_unref for error cleanup, so all this error cleanup needn't be duplicated.
Cheers,
Nicola
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 14.02.2017 um 11:37 schrieb Nicolai Hähnle:
Quoted 8 lines
From: Nicolai Hähnle <[email protected]>
Allow callers to opt out of calling
ttm_bo_validateimmediately. This allows more flexibility in how locking of the reservation object is done, which is needed to fix a locking bug (destroy locked mutex) in amdgpu.Signed-off-by Nicolai Hähnle <[email protected]>
Please squash that into your other patch. It fixes another bug, but I don't think fixing one bug just to run into another is really a good idea.
Additional to that one comment below.
Quoted 51 lines
--- drivers/gpu/drm/ttm/ttm_bo.c | 62 +++++++++++++++++++++++++++++--------------- include/drm/ttm/ttm_bo_api.h | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +10
-17@@ -1120,41 +1120,30 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_validate); -int ttm_bo_init (struct ttm_bo_device *bdev, -struct ttm_buffer_object *bo, -unsigned long size, -enum ttm_bo_type type, -struct ttm_placement *placement, -uint32_t page_alignment, -bool interruptible, -struct file *persistent_swap_storage, -size_t acc_size, -struct sg_table *sg, -struct reservation_object *resv, -void (*destroy) (struct ttm_buffer_object *)) +int ttm_bo_init_top (struct ttm_bo_device *bdev, +struct ttm_buffer_object *bo, +unsigned long size, +enum ttm_bo_type type, +uint32_t page_alignment, +struct file *persistent_swap_storage, +size_t acc_size, +struct sg_table *sg, +struct reservation_object *resv, +void (*destroy) (struct ttm_buffer_object *)) {int ret =0 ;unsigned long num_pages;struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; -bool locked; ret =ttm_mem_global_alloc (mem_glob, acc_size, false, false);if (ret) {pr_err ("Out of kernel memory\n" ); -if (destroy) - (*destroy)(bo); -else -kfree (bo);return -ENOMEM ; }
drivers/gpu/drm/ttm/ttm_bo.c int ttm_bo_validate(struct ttm_buffer_object *bo, · line 1149
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +0
-4num_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ;if (num_pages ==0 ) {pr_err ("Illegal buffer object size\n" ); -if (destroy) - (*destroy)(bo); -else -kfree (bo);ttm_mem_global_free (mem_glob, acc_size);return -EINVAL ; }
I would move those checks after all the field initializations. This way the structure has at least a valid content and we can safely use ttm_bo_unref on it.
Regards,
Christian.
Quoted 84 lines
drivers/gpu/drm/ttm/ttm_bo.c +31
-0@@ -1204,6 +1193,37 @@ int ttm_bo_init(struct ttm_bo_device *bdev, ret =drm_vma_offset_add (&bdev->vma_manager, &bo->vma_node, bo->mem.num_pages); +return ret; +} +EXPORT_SYMBOL (ttm_bo_init_top); + +int ttm_bo_init (struct ttm_bo_device *bdev, +struct ttm_buffer_object *bo, +unsigned long size, +enum ttm_bo_type type, +struct ttm_placement *placement, +uint32_t page_alignment, +bool interruptible, +struct file *persistent_swap_storage, +size_t acc_size, +struct sg_table *sg, +struct reservation_object *resv, +void (*destroy) (struct ttm_buffer_object *)) +{ +bool locked; +int ret; + + ret =ttm_bo_init_top (bdev, bo, size, type, page_alignment, + persistent_swap_storage, acc_size, sg, resv, + destroy); +if (ret) { +if (destroy) + (*destroy)(bo); +else +kfree (bo); +return ret; + } +/* passed reservation objects should already be locked, * since otherwise lockdep will be angered in radeon. */ include/drm/ttm/ttm_bo_api.h +38
-0@@ -453,6 +453,51 @@ size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev, unsigned struct_size);/** +* ttm_bo_init_top +* +* @bdev: Pointer to a ttm_bo_device struct. +* @bo: Pointer to a ttm_buffer_object to be initialized. +* @size: Requested size of buffer object. +* @type: Requested type of buffer object. +* @flags: Initial placement flags. +* @page_alignment: Data alignment in pages. +* @persistent_swap_storage: Usually the swap storage is deleted for buffers +* pinned in physical memory. If this behaviour is not desired, this member +* holds a pointer to a persistent shmem object. Typically, this would +* point to the shmem object backing a GEM object if TTM is used to back a +* GEM user interface. +* @acc_size: Accounted size for this object. +* @resv: Pointer to a reservation_object, or NULL to let ttm allocate one. +* @destroy: Destroy function. Use NULL for kfree(). +* +* This function initializes a pre-allocated struct ttm_buffer_object. +* As this object may be part of a larger structure, this function, +* together with the @destroy function, +* enables driver-specific objects derived from a ttm_buffer_object. +* +* Unlike ttm_bo_init, @bo is not validated, and when an error is returned, +* the caller is responsible for freeing @bo (but the setup performed by +* ttm_bo_init_top itself is cleaned up). +* +* On successful return, the object kref and list_kref are set to 1. +* +* Returns +* -ENOMEM: Out of memory. +* -EINVAL: Invalid buffer size. +*/ + +extern int ttm_bo_init_top(struct ttm_bo_device *bdev, + struct ttm_buffer_object *bo, + unsigned long size, + enum ttm_bo_type type, + uint32_t page_alignment,
include/drm/ttm/ttm_bo_api.h size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev, · line 503
Quoted 10 lines
include/drm/ttm/ttm_bo_api.h +7
-0+struct file *persistent_swap_storage, + size_t acc_size, + struct sg_table *sg, + struct reservation_object *resv, + void (*destroy) (struct ttm_buffer_object *)); + +/** * ttm_bo_init * * @bdev: Pointer to a ttm_bo_device struct.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
A message that is not in the archive (sent off-list or not yet received): b9c665fe-4e9a-7163-aa8a-0c9ce73a78a0-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Quoted 8 lines · Christian König
Am 14.02.2017 um 11:37 schrieb Nicolai Hähnle:
Quoted 7 lines
From: Nicolai Hähnle <[email protected]>
Allow callers to opt out of calling
ttm_bo_validateimmediately. This allows more flexibility in how locking of the reservation object is done, which is needed to fix a locking bug (destroy locked mutex) in amdgpu.
Quoted 4 lines
Quoted 1 line
Signed-off-by Nicolai Hähnle <[email protected]>Please squash that into your other patch. It fixes another bug, but I don't think fixing one bug just to run into another is really a good idea.
I don't understand. I'm not aware that this patch fixes anything, it just enables the subsequent fix in amdgpu in patch #2. I don't think squashing those together is a good idea (one is in ttm, the other in amdgpu).
Quoted 57 lines
Additional to that one comment below.
Quoted 55 lines
--- drivers/gpu/drm/ttm/ttm_bo.c | 62 +++++++++++++++++++++++++++++--------------- include/drm/ttm/ttm_bo_api.h | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +10
-19@@ -1120,41 +1120,30 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_validate); -int ttm_bo_init(struct ttm_bo_device *bdev, - struct ttm_buffer_object *bo, - unsigned long size, - enum ttm_bo_type type, - struct ttm_placement *placement, - uint32_t page_alignment, - bool interruptible, - struct file *persistent_swap_storage, - size_t acc_size, - struct sg_table *sg, - struct reservation_object *resv, - void (*destroy) (struct ttm_buffer_object *)) +int ttm_bo_init_top(struct ttm_bo_device *bdev, +struct ttm_buffer_object *bo, +unsigned long size, +enum ttm_bo_type type, +uint32_t page_alignment, +struct file *persistent_swap_storage, +size_t acc_size, +struct sg_table *sg, +struct reservation_object *resv, +void (*destroy) (struct ttm_buffer_object *)) { int ret = 0;unsigned long num_pages;struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; -bool locked; ret =ttm_mem_global_alloc (mem_glob, acc_size, false, false);if (ret) {pr_err ("Out of kernel memory\n" ); -if (destroy) - (*destroy)(bo); -else -kfree (bo);return -ENOMEM ; } num_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ;if (num_pages ==0 ) {pr_err ("Illegal buffer object size\n" ); -if (destroy) - (*destroy)(bo); -else
Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c int ttm_bo_validate(struct ttm_buffer_object *bo, · line 1149
Quoted 4 lines
drivers/gpu/drm/ttm/ttm_bo.c +0
-1-kfree (bo);ttm_mem_global_free (mem_glob, acc_size);return -EINVAL ; }I would move those checks after all the field initializations. This way the structure has at least a valid content and we can safely use
ttm_bo_unrefon it.
That feels odd to me, since the return value indicates that the buffer wasn't properly initialized, but I don't feel strongly about it.
Cheers,
Nicolai
Quoted 94 lines
Regards,
Christian.Quoted 90 lines
drivers/gpu/drm/ttm/ttm_bo.c +30
-0@@ -1204,6 +1193,37 @@ int ttm_bo_init(struct ttm_bo_device *bdev, ret =drm_vma_offset_add (&bdev->vma_manager, &bo->vma_node, bo->mem.num_pages); + return ret; +} +EXPORT_SYMBOL (ttm_bo_init_top); + +int ttm_bo_init (struct ttm_bo_device *bdev, +struct ttm_buffer_object *bo, +unsigned long size, +enum ttm_bo_type type, +struct ttm_placement *placement, +uint32_t page_alignment, +bool interruptible, +struct file *persistent_swap_storage, +size_t acc_size, +struct sg_table *sg, +struct reservation_object *resv, +void (*destroy) (struct ttm_buffer_object *)) +{ +bool locked; +int ret; + + ret =ttm_bo_init_top (bdev, bo, size, type, page_alignment, + persistent_swap_storage, acc_size, sg, resv, + destroy); +if (ret) { +if (destroy) + (*destroy)(bo); +else +kfree (bo); +return ret; + } +/* passed reservation objects should already be locked, * since otherwise lockdep will be angered in radeon. */ include/drm/ttm/ttm_bo_api.h +9
-0@@ -453,6 +453,51 @@ size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev, unsigned struct_size);/** +* ttm_bo_init_top +* +* @bdev: Pointer to a ttm_bo_device struct. +* @bo: Pointer to a ttm_buffer_object to be initialized. +* @size: Requested size of buffer object. +* @type: Requested type of buffer object. +* @flags: Initial placement flags. +* @page_alignment: Data alignment in pages. +* @persistent_swap_storage: Usually the swap storage is deleted for buffers
+ * pinned in physical memory. If this behaviour is not desired, this member
+ * holds a pointer to a persistent shmem object. Typically, this would
+ * point to the shmem object backing a GEM object if TTM is used to back a
+ * GEM user interface.
+ * @acc_size: Accounted size for this object.
+ * @resv: Pointer to areservation_object, or NULL to let ttm allocate one.
+ * @destroy: Destroy function. Use NULL forkfree().
+ *
+ * This function initializes a pre-allocated structttm_buffer_object.
+ * As this object may be part of a larger structure, this function,
+ * together with the @destroy function,
+ * enables driver-specific objects derived from attm_buffer_object.
+ *
+ * Unlikettm_bo_init, @bo is not validated, and when an error is returned,
+ * the caller is responsible for freeing @bo (but the setup performed by
+ *ttm_bo_init_topitself is cleaned up).
+ *
+ * On successful return, the object kref andlist_krefare set to 1.
+ *
+ * Returns
+ *-ENOMEM: Out of memory.
+ *-EINVAL: Invalid buffer size.
+ */include/drm/ttm/ttm_bo_api.h +8
-0+ +extern int ttm_bo_init_top(struct ttm_bo_device *bdev, + struct ttm_buffer_object *bo, + unsigned long size, + enum ttm_bo_type type, + uint32_t page_alignment, + struct file *persistent_swap_storage, + size_t acc_size,
Quoted 10 lines
include/drm/ttm/ttm_bo_api.h size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev, · line 503
Quoted 8 lines
include/drm/ttm/ttm_bo_api.h +5
-0+struct sg_table *sg, + struct reservation_object *resv, + void (*destroy) (struct ttm_buffer_object *)); + +/** * ttm_bo_init * * @bdev: Pointer to a ttm_bo_device struct.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 9229e0d9-4e9d-0233-4ba2-c54c7192acfa-5C7GfCeVMHo@public.gmane.org
Am 14.02.2017 um 13:00 schrieb Nicolai Hähnle:
Quoted 9 lines · Christian König
Quoted 8 lines
Am 14.02.2017 um 11:37 schrieb Nicolai Hähnle:
Quoted 7 lines
From: Nicolai Hähnle <[email protected]>
Allow callers to opt out of calling
ttm_bo_validateimmediately. This allows more flexibility in how locking of the reservation object is done, which is needed to fix a locking bug (destroy locked mutex) in amdgpu.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Nicolai Hähnle <[email protected]>Please squash that into your other patch. It fixes another bug, but I don't think fixing one bug just to run into another is really a good idea.
I don't understand. I'm not aware that this patch fixes anything, it just enables the subsequent fix in amdgpu in patch #2. I don't think squashing those together is a good idea (one is in ttm, the other in amdgpu).
Ok, forget it I've messed up the different reference count.
With at least initializing bo->kref and bo->destroy before returning the first error the patch is Reviewed-by: Christian König <[email protected]>.
Regards,
Christian.
Quoted 69 lines
Quoted 60 lines
Additional to that one comment below.
Quoted 56 lines
--- drivers/gpu/drm/ttm/ttm_bo.c | 62 +++++++++++++++++++++++++++++--------------- include/drm/ttm/ttm_bo_api.h | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +10
-19@@ -1120,41 +1120,30 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_validate); -int ttm_bo_init(struct ttm_bo_device *bdev, - struct ttm_buffer_object *bo, - unsigned long size, - enum ttm_bo_type type, - struct ttm_placement *placement, - uint32_t page_alignment, - bool interruptible, - struct file *persistent_swap_storage, - size_t acc_size, - struct sg_table *sg, - struct reservation_object *resv, - void (*destroy) (struct ttm_buffer_object *)) +int ttm_bo_init_top(struct ttm_bo_device *bdev, +struct ttm_buffer_object *bo, +unsigned long size, +enum ttm_bo_type type, +uint32_t page_alignment, +struct file *persistent_swap_storage, +size_t acc_size, +struct sg_table *sg, +struct reservation_object *resv, +void (*destroy) (struct ttm_buffer_object *)) { int ret = 0;unsigned long num_pages;struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; -bool locked; ret =ttm_mem_global_alloc (mem_glob, acc_size, false, false);if (ret) {pr_err ("Out of kernel memory\n" ); -if (destroy) - (*destroy)(bo); -else -kfree (bo);return -ENOMEM ; } num_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ;if (num_pages ==0 ) {pr_err ("Illegal buffer object size\n" ); -if (destroy) - (*destroy)(bo); -else Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c int ttm_bo_validate(struct ttm_buffer_object *bo, · line 1149
Quoted 4 lines
drivers/gpu/drm/ttm/ttm_bo.c +0
-1-kfree (bo);ttm_mem_global_free (mem_glob, acc_size);return -EINVAL ; }I would move those checks after all the field initializations. This way the structure has at least a valid content and we can safely use
ttm_bo_unrefon it.
Quoted 112 lines
That feels odd to me, since the return value indicates that the buffer wasn't properly initialized, but I don't feel strongly about it.
Cheers,
NicolaiQuoted 105 lines
Regards,
Christian.Quoted 99 lines
drivers/gpu/drm/ttm/ttm_bo.c +30
-0@@ -1204,6 +1193,37 @@ int ttm_bo_init(struct ttm_bo_device *bdev, ret =drm_vma_offset_add (&bdev->vma_manager, &bo->vma_node, bo->mem.num_pages); + return ret; +} +EXPORT_SYMBOL (ttm_bo_init_top); + +int ttm_bo_init (struct ttm_bo_device *bdev, +struct ttm_buffer_object *bo, +unsigned long size, +enum ttm_bo_type type, +struct ttm_placement *placement, +uint32_t page_alignment, +bool interruptible, +struct file *persistent_swap_storage, +size_t acc_size, +struct sg_table *sg, +struct reservation_object *resv, +void (*destroy) (struct ttm_buffer_object *)) +{ +bool locked; +int ret; + + ret =ttm_bo_init_top (bdev, bo, size, type, page_alignment, + persistent_swap_storage, acc_size, sg, resv, + destroy); +if (ret) { +if (destroy) + (*destroy)(bo); +else +kfree (bo); +return ret; + } +/* passed reservation objects should already be locked, * since otherwise lockdep will be angered in radeon. */ include/drm/ttm/ttm_bo_api.h +9
-0@@ -453,6 +453,51 @@ size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev, unsigned struct_size);/** +* ttm_bo_init_top +* +* @bdev: Pointer to a ttm_bo_device struct. +* @bo: Pointer to a ttm_buffer_object to be initialized. +* @size: Requested size of buffer object. +* @type: Requested type of buffer object. +* @flags: Initial placement flags. +* @page_alignment: Data alignment in pages. +* @persistent_swap_storage: Usually the swap storage is deleted for buffers
+ * pinned in physical memory. If this behaviour is not desired, this member
+ * holds a pointer to a persistent shmem object. Typically, this would
+ * point to the shmem object backing a GEM object if TTM is used to back a
+ * GEM user interface.
+ * @acc_size: Accounted size for this object.
+ * @resv: Pointer to areservation_object, or NULL to let ttm allocate one.
+ * @destroy: Destroy function. Use NULL forkfree().
+ *
+ * This function initializes a pre-allocated structttm_buffer_object.
+ * As this object may be part of a larger structure, this function,
+ * together with the @destroy function,
+ * enables driver-specific objects derived from attm_buffer_object.
+ *
+ * Unlikettm_bo_init, @bo is not validated, and when an error is returned,
+ * the caller is responsible for freeing @bo (but the setup performed by
+ *ttm_bo_init_topitself is cleaned up).
+ *
+ * On successful return, the object kref andlist_krefare set to 1.
+ *
+ * Returns
+ *-ENOMEM: Out of memory.
+ *-EINVAL: Invalid buffer size.
+ */include/drm/ttm/ttm_bo_api.h +13
-0+ +extern int ttm_bo_init_top (struct ttm_bo_device *bdev, +struct ttm_buffer_object *bo, +unsigned long size, +enum ttm_bo_type type, +uint32_t page_alignment, +struct file *persistent_swap_storage, +size_t acc_size, +struct sg_table *sg, +struct reservation_object *resv, +void (*destroy) (struct ttm_buffer_object *)); + +/** * ttm_bo_init * * @bdev: Pointer to a ttm_bo_device struct.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): f43631b3-2527-54c1-d0bc-98460772b77b-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Quoted 21 lines · Christian König
Am 14.02.2017 um 13:00 schrieb Nicolai Hähnle:
Quoted 11 lines · Christian König
Quoted 10 lines
Am 14.02.2017 um 11:37 schrieb Nicolai Hähnle:
Quoted 8 lines
From: Nicolai Hähnle <[email protected]>
Allow callers to opt out of calling
ttm_bo_validateimmediately. This allows more flexibility in how locking of the reservation object is done, which is needed to fix a locking bug (destroy locked mutex) in amdgpu.Signed-off-by Nicolai Hähnle <[email protected]>Quoted 8 lines
Quoted 3 lines
Please squash that into your other patch. It fixes another bug, but I don't think fixing one bug just to run into another is really a good idea.
I don't understand. I'm not aware that this patch fixes anything, it just enables the subsequent fix in amdgpu in patch #2. I don't think squashing those together is a good idea (one is in ttm, the other in amdgpu).
Quoted 5 lines
Ok, forget it I've messed up the different reference count.
With at least initializing
bo->krefandbo->destroybefore returning the first error the patch is Reviewed-by: Christian König <[email protected]>.
Thanks. Does this apply to patches #2 and #3 as well?
Cheers,
Nicolai
Quoted 189 lines
Regards,
Christian.Quoted 184 lines
Quoted 61 lines
Additional to that one comment below.
Quoted 57 lines
--- drivers/gpu/drm/ttm/ttm_bo.c | 62 +++++++++++++++++++++++++++++--------------- include/drm/ttm/ttm_bo_api.h | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +10
-19@@ -1120,41 +1120,30 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_validate); -int ttm_bo_init(struct ttm_bo_device *bdev, - struct ttm_buffer_object *bo, - unsigned long size, - enum ttm_bo_type type, - struct ttm_placement *placement, - uint32_t page_alignment, - bool interruptible, - struct file *persistent_swap_storage, - size_t acc_size, - struct sg_table *sg, - struct reservation_object *resv, - void (*destroy) (struct ttm_buffer_object *)) +int ttm_bo_init_top(struct ttm_bo_device *bdev, +struct ttm_buffer_object *bo, +unsigned long size, +enum ttm_bo_type type, +uint32_t page_alignment, +struct file *persistent_swap_storage, +size_t acc_size, +struct sg_table *sg, +struct reservation_object *resv, +void (*destroy) (struct ttm_buffer_object *)) { int ret = 0;unsigned long num_pages;struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; -bool locked; ret =ttm_mem_global_alloc (mem_glob, acc_size, false, false);if (ret) {pr_err ("Out of kernel memory\n" ); -if (destroy) - (*destroy)(bo); -else -kfree (bo);return -ENOMEM ; } num_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ;if (num_pages ==0 ) {pr_err ("Illegal buffer object size\n" ); -if (destroy) - (*destroy)(bo); -else Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c int ttm_bo_validate(struct ttm_buffer_object · line 1148
Quoted 4 lines
drivers/gpu/drm/ttm/ttm_bo.c +0
-1-kfree (bo);ttm_mem_global_free (mem_glob, acc_size);return -EINVAL ; }I would move those checks after all the field initializations. This way the structure has at least a valid content and we can safely use
ttm_bo_unrefon it.That feels odd to me, since the return value indicates that the buffer wasn't properly initialized, but I don't feel strongly about it.
Cheers,
NicolaiQuoted 106 lines
Regards,
Christian.Quoted 100 lines
drivers/gpu/drm/ttm/ttm_bo.c +30
-0@@ -1204,6 +1193,37 @@ int ttm_bo_init(struct ttm_bo_device *bdev, ret =drm_vma_offset_add (&bdev->vma_manager, &bo->vma_node, bo->mem.num_pages); + return ret; +} +EXPORT_SYMBOL (ttm_bo_init_top); + +int ttm_bo_init (struct ttm_bo_device *bdev, +struct ttm_buffer_object *bo, +unsigned long size, +enum ttm_bo_type type, +struct ttm_placement *placement, +uint32_t page_alignment, +bool interruptible, +struct file *persistent_swap_storage, +size_t acc_size, +struct sg_table *sg, +struct reservation_object *resv, +void (*destroy) (struct ttm_buffer_object *)) +{ +bool locked; +int ret; + + ret =ttm_bo_init_top (bdev, bo, size, type, page_alignment, + persistent_swap_storage, acc_size, sg, resv, + destroy); +if (ret) { +if (destroy) + (*destroy)(bo); +else +kfree (bo); +return ret; + } +/* passed reservation objects should already be locked, * since otherwise lockdep will be angered in radeon. */ include/drm/ttm/ttm_bo_api.h +9
-0@@ -453,6 +453,51 @@ size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev, unsigned struct_size);/** +* ttm_bo_init_top +* +* @bdev: Pointer to a ttm_bo_device struct. +* @bo: Pointer to a ttm_buffer_object to be initialized. +* @size: Requested size of buffer object. +* @type: Requested type of buffer object. +* @flags: Initial placement flags. +* @page_alignment: Data alignment in pages. +* @persistent_swap_storage: Usually the swap storage is deleted for buffers
+ * pinned in physical memory. If this behaviour is not desired, this member
+ * holds a pointer to a persistent shmem object. Typically, this would
+ * point to the shmem object backing a GEM object if TTM is used to back a
+ * GEM user interface.
+ * @acc_size: Accounted size for this object.
+ * @resv: Pointer to areservation_object, or NULL to let ttm allocate one.
+ * @destroy: Destroy function. Use NULL forkfree().
+ *
+ * This function initializes a pre-allocated structttm_buffer_object.
+ * As this object may be part of a larger structure, this function,
+ * together with the @destroy function,
+ * enables driver-specific objects derived from attm_buffer_object.
+ *
+ * Unlikettm_bo_init, @bo is not validated, and when an error is returned,
+ * the caller is responsible for freeing @bo (but the setup performed by
+ *ttm_bo_init_topitself is cleaned up).
+ *
+ * On successful return, the object kref andlist_krefare set to 1.
+ *
+ * Returns
+ *-ENOMEM: Out of memory.
+ *-EINVAL: Invalid buffer size.
+ */include/drm/ttm/ttm_bo_api.h +13
-0+ +extern int ttm_bo_init_top (struct ttm_bo_device *bdev, +struct ttm_buffer_object *bo, +unsigned long size, +enum ttm_bo_type type, +uint32_t page_alignment, +struct file *persistent_swap_storage, +size_t acc_size, +struct sg_table *sg, +struct reservation_object *resv, +void (*destroy) (struct ttm_buffer_object *)); + +/** * ttm_bo_init * * @bdev: Pointer to a ttm_bo_device struct.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 06a90674-9f46-e646-9893-8b2748ddd9e4-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 22 lines · Nicolai Hähnle
Quoted 21 lines · Christian König
Am 14.02.2017 um 13:00 schrieb Nicolai Hähnle:
Quoted 19 lines · Christian König
Quoted 8 lines
Am 14.02.2017 um 11:37 schrieb Nicolai Hähnle:
Quoted 7 lines
From: Nicolai Hähnle <[email protected]>
Allow callers to opt out of calling
ttm_bo_validateimmediately. This allows more flexibility in how locking of the reservation object is done, which is needed to fix a locking bug (destroy locked mutex) in amdgpu.Quoted 5 lines
Quoted 1 line
Signed-off-by Nicolai Hähnle <[email protected]>Please squash that into your other patch. It fixes another bug, but I don't think fixing one bug just to run into another is really a good idea.
I don't understand. I'm not aware that this patch fixes anything, it just enables the subsequent fix in amdgpu in patch #2. I don't think squashing those together is a good idea (one is in ttm, the other in amdgpu).
Quoted 7 lines
Quoted 5 lines
Ok, forget it I've messed up the different reference count.
With at least initializing
bo->krefandbo->destroybefore returning the first error the patch is Reviewed-by: Christian König <[email protected]>.Thanks. Does this apply to patches #2 and #3 as well?
Well, there's some minor necessary rebase fixes, so I'll probably just send out a new version once I got to test it.
Nicolai
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx