Skip to contentSkip to conversation

Provide ttm_bo_{get,put} for TMM BO ref-counting

PATCH In review Thomas Zimmermann 3 participants 8 messages Jun 21, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Provide ttm_bo_{get,put} for TMM BO ref-counting

TTM buffer objects provide ttm_bo_reference() and ttm_bo_unref() for managing reference counters. This patch set introduces ttm_bo_get() and ttm_ot_put(), which follow Linux kernel conventions.

A call to ttm_bo_unref() clears the supplied pointer to NULL. This is unnecessary in most cases and occationally callers have to work around this behaviour. ttm_bo_put() only releases the reference, but keeps the pointer's value.

This patch set introduces ttm_bo_get() and ttm_bo_put(), and converts TTM to the new functions. The old functions remain in place until all callers have been converted.

Thomas Zimmermann (3):
drm/ttm: Introduce ttm_bo_get() and ttm_bo_put() for ref counting drm/ttm: Replace ttm_bo_reference() with ttm_bo_get() drm/ttm: Replace ttm_bo_unref() with ttm_bo_put()

 drivers/gpu/drm/ttm/ttm_bo.c      | 10 ++++++++--
 drivers/gpu/drm/ttm/ttm_bo_util.c | 11 ++++++-----
 drivers/gpu/drm/ttm/ttm_bo_vm.c   | 18 ++++++++++--------
 include/drm/ttm/ttm_bo_api.h      | 25 ++++++++++++++++++++++++-
 4 files changed, 48 insertions(+), 16 deletions(-)

--
2.14.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#1 lore raw

PATCH 1/3 drm/ttm: Introduce ttm_bo_get() and ttm_bo_put() for ref counting

The TTM buffer-object interface provides ttm_bo_reference() and ttm_bo_unref() for managing reference counts. Replacing them with ttm_bo_get() and ttm_bo_put() aligns the API with conventions used throughout the Linux kernel.

The implementation of ttm_bo_unref() clears the supplied pointer to NULL. This leads to workarounds where the caller saves the pointer's value before de-referencing the BO. ttm_bo_put() does not clear the supplied pointer.

---
 drivers/gpu/drm/ttm/ttm_bo.c |  8 +++++++-
 include/drm/ttm/ttm_bo_api.h | 25 ++++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +7 -1
index 5d8688e522d1..43d9aea82c39 100644
@@ -590,12 +590,18 @@ static void ttm_bo_release(struct kref *kref)
 	kref_put(&bo->list_kref, ttm_bo_release_list);
 }
 
+void ttm_bo_put(struct ttm_buffer_object *bo)
+{
+	kref_put(&bo->kref, ttm_bo_release);
+}
+EXPORT_SYMBOL(ttm_bo_put);
+
 void ttm_bo_unref(struct ttm_buffer_object **p_bo)
 {
 	struct ttm_buffer_object *bo = *p_bo;
 
 	*p_bo = NULL;
-	kref_put(&bo->kref, ttm_bo_release);
+	ttm_bo_put(bo);
 }
 EXPORT_SYMBOL(ttm_bo_unref);
 
include/drm/ttm/ttm_bo_api.h +24 -1
index c67977aa1a0e..a01ba2032f0e 100644
@@ -283,18 +283,30 @@ struct ttm_operation_ctx {
 /* when serving page fault or suspend, allow alloc anyway */
 #define TTM_OPT_FLAG_FORCE_ALLOC		0x2
 
+/**
+ * ttm_bo_get - reference a struct ttm_buffer_object
+ *
+ * @bo: The buffer object.
+ */
+static inline void ttm_bo_get(struct ttm_buffer_object *bo)
+{
+	kref_get(&bo->kref);
+}
+
 /**
  * ttm_bo_reference - reference a struct ttm_buffer_object
  *
  * @bo: The buffer object.
  *
  * Returns a refcounted pointer to a buffer object.
+ *
+ * This function is deprecated. Use @ttm_bo_get instead.
  */
 
 static inline struct ttm_buffer_object *
 ttm_bo_reference(struct ttm_buffer_object *bo)
 {
-	kref_get(&bo->kref);
+	ttm_bo_get(bo);
 	return bo;
 }
 
@@ -345,12 +357,23 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
 		    struct ttm_placement *placement,
 		    struct ttm_operation_ctx *ctx);
 
+/**
+ * ttm_bo_put
+ *
+ * @bo: The buffer object.
+ *
+ * Unreference a buffer object.
+ */
+void ttm_bo_put(struct ttm_buffer_object *bo);
+
 /**
  * ttm_bo_unref
  *
  * @bo: The buffer object.
  *
  * Unreference and clear a pointer to a buffer object.
+ *
+ * This function is deprecated. Use @ttm_bo_put instead.
  */
 void ttm_bo_unref(struct ttm_buffer_object **bo);
 
Signature · 6 lines
2.14.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

PATCH 2/3 drm/ttm: Replace ttm_bo_reference() with ttm_bo_get()

In reply to Thomas Zimmermann
---
 drivers/gpu/drm/ttm/ttm_bo_util.c |  3 ++-
 drivers/gpu/drm/ttm/ttm_bo_vm.c   | 10 ++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/gpu/drm/ttm/ttm_bo_util.c +2 -1
index f2c167702eef..897c799832f6 100644
@@ -492,8 +492,9 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
 	if (!fbo)
 		return -ENOMEM;
 
+	ttm_bo_get(bo);
 	fbo->base = *bo;
-	fbo->bo = ttm_bo_reference(bo);
+	fbo->bo = bo;
 
 	/**
 	 * Fix up members that we shouldn't copy directly:
drivers/gpu/drm/ttm/ttm_bo_vm.c +6 -4
index c7ece7613a6a..4a4c0cb34433 100644
@@ -67,7 +67,7 @@ static int ttm_bo_vm_fault_idle(struct ttm_buffer_object *bo,
 		if (vmf->flags & FAULT_FLAG_RETRY_NOWAIT)
 			goto out_unlock;
 
-		ttm_bo_reference(bo);
+		ttm_bo_get(bo);
 		up_read(&vmf->vma->vm_mm->mmap_sem);
 		(void) dma_fence_wait(bo->moving, true);
 		ttm_bo_unreserve(bo);
@@ -136,7 +136,7 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
 
 		if (vmf->flags & FAULT_FLAG_ALLOW_RETRY) {
 			if (!(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
-				ttm_bo_reference(bo);
+				ttm_bo_get(bo);
 				up_read(&vmf->vma->vm_mm->mmap_sem);
 				(void) ttm_bo_wait_unreserved(bo);
 				ttm_bo_unref(&bo);
@@ -303,7 +303,7 @@ static void ttm_bo_vm_open(struct vm_area_struct *vma)
 
 	WARN_ON(bo->bdev->dev_mapping != vma->vm_file->f_mapping);
 
-	(void)ttm_bo_reference(bo);
+	ttm_bo_get(bo);
 }
 
 static void ttm_bo_vm_close(struct vm_area_struct *vma)
@@ -472,8 +472,10 @@ int ttm_fbdev_mmap(struct vm_area_struct *vma, struct ttm_buffer_object *bo)
 	if (vma->vm_pgoff != 0)
 		return -EACCES;
 
+	ttm_bo_get(bo);
+
 	vma->vm_ops = &ttm_bo_vm_ops;
-	vma->vm_private_data = ttm_bo_reference(bo);
+	vma->vm_private_data = bo;
 	vma->vm_flags |= VM_MIXEDMAP;
 	vma->vm_flags |= VM_IO | VM_DONTEXPAND;
 	return 0;
Signature · 6 lines
2.14.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

PATCH 3/3 drm/ttm: Replace ttm_bo_unref() with ttm_bo_put()

In reply to Thomas Zimmermann

A call to ttm_bo_unref() clears the supplied pointer to NULL, while ttm_bo_put() does not. None of the converted call sites requires the pointer to become NULL, so the respective assign operations has been left out from the patch.

---
 drivers/gpu/drm/ttm/ttm_bo.c      | 2 +-
 drivers/gpu/drm/ttm/ttm_bo_util.c | 8 ++++----
 drivers/gpu/drm/ttm/ttm_bo_vm.c   | 8 ++++----
 3 files changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
index 43d9aea82c39..395fb4316d06 100644
@@ -1207,7 +1207,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
 		if (!resv)
 			ttm_bo_unreserve(bo);
 
-		ttm_bo_unref(&bo);
+		ttm_bo_put(bo);
 		return ret;
 	}
 
drivers/gpu/drm/ttm/ttm_bo_util.c +4 -4
index 897c799832f6..046a6dda690a 100644
@@ -463,7 +463,7 @@ static void ttm_transfered_destroy(struct ttm_buffer_object *bo)
 	struct ttm_transfer_obj *fbo;
 
 	fbo = container_of(bo, struct ttm_transfer_obj, base);
-	ttm_bo_unref(&fbo->bo);
+	ttm_bo_put(fbo->bo);
 	kfree(fbo);
 }
 
@@ -731,7 +731,7 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
 			bo->ttm = NULL;
 
 		ttm_bo_unreserve(ghost_obj);
-		ttm_bo_unref(&ghost_obj);
+		ttm_bo_put(ghost_obj);
 	}
 
 	*old_mem = *new_mem;
@@ -787,7 +787,7 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
 			bo->ttm = NULL;
 
 		ttm_bo_unreserve(ghost_obj);
-		ttm_bo_unref(&ghost_obj);
+		ttm_bo_put(ghost_obj);
 
 	} else if (from->flags & TTM_MEMTYPE_FLAG_FIXED) {
 
@@ -852,7 +852,7 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo)
 	bo->ttm = NULL;
 
 	ttm_bo_unreserve(ghost);
-	ttm_bo_unref(&ghost);
+	ttm_bo_put(ghost);
 
 	return 0;
 }
drivers/gpu/drm/ttm/ttm_bo_vm.c +4 -4
index 4a4c0cb34433..b4f69b354fce 100644
@@ -71,7 +71,7 @@ static int ttm_bo_vm_fault_idle(struct ttm_buffer_object *bo,
 		up_read(&vmf->vma->vm_mm->mmap_sem);
 		(void) dma_fence_wait(bo->moving, true);
 		ttm_bo_unreserve(bo);
-		ttm_bo_unref(&bo);
+		ttm_bo_put(bo);
 		goto out_unlock;
 	}
 
@@ -139,7 +139,7 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
 				ttm_bo_get(bo);
 				up_read(&vmf->vma->vm_mm->mmap_sem);
 				(void) ttm_bo_wait_unreserved(bo);
-				ttm_bo_unref(&bo);
+				ttm_bo_put(bo);
 			}
 
 			return VM_FAULT_RETRY;
@@ -310,7 +310,7 @@ static void ttm_bo_vm_close(struct vm_area_struct *vma)
 {
 	struct ttm_buffer_object *bo = (struct ttm_buffer_object *)vma->vm_private_data;
 
-	ttm_bo_unref(&bo);
+	ttm_bo_put(bo);
 	vma->vm_private_data = NULL;
 }
 
@@ -462,7 +462,7 @@ int ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma,
 	vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
 	return 0;
 out_unref:
-	ttm_bo_unref(&bo);
+	ttm_bo_put(bo);
 	return ret;
 }
 EXPORT_SYMBOL(ttm_bo_mmap);
Signature · 6 lines
2.14.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw
In reply to Thomas Zimmermann

Am 21.06.2018 um 15:21 schrieb Thomas Zimmermann:

Quoted 4 lines

TTM buffer objects provide ttm_bo_reference() and ttm_bo_unref() for managing reference counters. This patch set introduces ttm_bo_get() and ttm_ot_put(), which follow Linux kernel conventions.

Quoted 8 lines

A call to ttm_bo_unref() clears the supplied pointer to NULL. This is unnecessary in most cases and occationally callers have to work around this behaviour. ttm_bo_put() only releases the reference, but keeps the pointer's value.

This patch set introduces ttm_bo_get() and ttm_bo_put(), and converts TTM to the new functions. The old functions remain in place until all callers have been converted.

Thanks, series is Reviewed-by: Christian König <[email protected]> and I'm going to pick it up for our internal TTM branch.

It is appreciated that you do this only one driver/component at a time and not in a massive change.

Are you planning to stick with applying that to the individual drivers using it?

Thanks,
Christian.

Quoted 12 lines

Thomas Zimmermann (3):
drm/ttm: Introduce ttm_bo_get() and ttm_bo_put() for ref counting drm/ttm: Replace ttm_bo_reference() with ttm_bo_get() drm/ttm: Replace ttm_bo_unref() with ttm_bo_put()

  drivers/gpu/drm/ttm/ttm_bo.c      | 10 ++++++++--
  drivers/gpu/drm/ttm/ttm_bo_util.c | 11 ++++++-----
  drivers/gpu/drm/ttm/ttm_bo_vm.c   | 18 ++++++++++--------
  include/drm/ttm/ttm_bo_api.h      | 25 ++++++++++++++++++++++++-
  4 files changed, 48 insertions(+), 16 deletions(-)
Quoted 7 lines

--
2.14.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw

Hi

Quoted 8 lines
Quoted 3 lines

This patch set introduces ttm_bo_get() and ttm_bo_put(), and converts TTM to the new functions. The old functions remain in place until all callers have been converted.

Thanks, series is Reviewed-by: Christian König <[email protected]> and I'm going to pick it up for our internal TTM branch.

Quoted 5 lines

It is appreciated that you do this only one driver/component at a time and not in a massive change.

Are you planning to stick with applying that to the individual drivers using it?

Thank you so much for the prompt response. I actually do have the driver patches done, but wanted to get the cleaned up interfaces merged first.

Best regards
Thomas

BTW <[email protected]> is in MAINTAINERS, but returns a 'delivery failed' message from the mail server.

Quoted 24 lines

Thanks,
Christian.

Quoted 19 lines

Thomas Zimmermann (3):
   drm/ttm: Introduce ttm_bo_get() and ttm_bo_put() for ref counting drm/ttm: Replace ttm_bo_reference() with ttm_bo_get() drm/ttm: Replace ttm_bo_unref() with ttm_bo_put()

  drivers/gpu/drm/ttm/ttm_bo.c      | 10 ++++++++-- drivers/gpu/drm/ttm/ttm_bo_util.c | 11 ++++++----- drivers/gpu/drm/ttm/ttm_bo_vm.c   | 18 ++++++++++-------- include/drm/ttm/ttm_bo_api.h      | 25 ++++++++++++++++++++++++-

  4 files changed, 48 insertions(+), 16 deletions(-)
Signature · 6 lines
2.14.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw
In reply to Christian König

Am 21.06.2018 16:53, schrieb Christian König:

Quoted 4 lines

Am 21.06.2018 um 15:21 schrieb Thomas Zimmermann:

Quoted 3 lines

TTM buffer objects provide ttm_bo_reference() and ttm_bo_unref() for managing reference counters. This patch set introduces ttm_bo_get() and ttm_ot_put(), which follow Linux kernel conventions.

           ^^^^^^^^^^^^^^

I hope this typo is only in explanation text...;-)

Greetings,
Dieter

Quoted 41 lines

A call to ttm_bo_unref() clears the supplied pointer to NULL. This is

Quoted 7 lines

unnecessary in most cases and occationally callers have to work around this behaviour. ttm_bo_put() only releases the reference, but keeps the pointer's value.

This patch set introduces ttm_bo_get() and ttm_bo_put(), and converts TTM to the new functions. The old functions remain in place until all callers have been converted.

Thanks, series is Reviewed-by: Christian König <[email protected]> and I'm going to pick it up for our internal TTM branch.

It is appreciated that you do this only one driver/component at a time and not in a massive change.

Are you planning to stick with applying that to the individual drivers using it?

Thanks,
Christian.

Quoted 12 lines

Thomas Zimmermann (3):
drm/ttm: Introduce ttm_bo_get() and ttm_bo_put() for ref counting drm/ttm: Replace ttm_bo_reference() with ttm_bo_get() drm/ttm: Replace ttm_bo_unref() with ttm_bo_put()

  drivers/gpu/drm/ttm/ttm_bo.c      | 10 ++++++++--
  drivers/gpu/drm/ttm/ttm_bo_util.c | 11 ++++++-----
  drivers/gpu/drm/ttm/ttm_bo_vm.c   | 18 ++++++++++--------
  include/drm/ttm/ttm_bo_api.h      | 25 ++++++++++++++++++++++++-
  4 files changed, 48 insertions(+), 16 deletions(-)
Quoted 7 lines

--
2.14.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#7 lore raw

Hi

Am 21.06.2018 um 18:29 schrieb Dieter Nützel:

Quoted 7 lines

Am 21.06.2018 16:53, schrieb Christian König:

Quoted 4 lines

Am 21.06.2018 um 15:21 schrieb Thomas Zimmermann:

Quoted 3 lines

TTM buffer objects provide ttm_bo_reference() and ttm_bo_unref() for managing reference counters. This patch set introduces ttm_bo_get() and ttm_ot_put(), which follow Linux kernel conventions.

           ^^^^^^^^^^^^^^
I hope this typo is only in explanation text...;-)

s/ttm_ot_put/ttm_bo_put

I guess I'm used to typing 'output'.

Regarding the quality of the patches: I built them with all drivers enabled and tested them on a local machine.

Best regards
Thomas

Quoted 50 lines

Greetings,
Dieter

Quoted 46 lines

A call to ttm_bo_unref() clears the supplied pointer to NULL. This is

Quoted 7 lines

unnecessary in most cases and occationally callers have to work around this behaviour. ttm_bo_put() only releases the reference, but keeps the pointer's value.

This patch set introduces ttm_bo_get() and ttm_bo_put(), and converts TTM to the new functions. The old functions remain in place until all callers have been converted.

Thanks, series is Reviewed-by: Christian König <[email protected]> and I'm going to pick it up for our internal TTM branch.

It is appreciated that you do this only one driver/component at a time and not in a massive change.

Are you planning to stick with applying that to the individual drivers using it?

Thanks,
Christian.

Quoted 6 lines

Thomas Zimmermann (3):
   drm/ttm: Introduce ttm_bo_get() and ttm_bo_put() for ref counting drm/ttm: Replace ttm_bo_reference() with ttm_bo_get() drm/ttm: Replace ttm_bo_unref() with ttm_bo_put()

Quoted 13 lines

  drivers/gpu/drm/ttm/ttm_bo.c      | 10 ++++++++-- drivers/gpu/drm/ttm/ttm_bo_util.c | 11 ++++++----- drivers/gpu/drm/ttm/ttm_bo_vm.c   | 18 ++++++++++-------- include/drm/ttm/ttm_bo_api.h      | 25 ++++++++++++++++++++++++-

  4 files changed, 48 insertions(+), 16 deletions(-)
Signature · 6 lines
2.14.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel