[-next,12/18] drm/ttm: Export ttm_bo_reference_unless_doomed()
diff mbox series

Message ID 20180926161839.4549-12-thellstrom@vmware.com
State New
Headers show
Series
  • [-next,01/18] drm/vmwgfx: Add a validation module v2
Related show

Commit Message

Thomas Hellstrom Sept. 26, 2018, 4:18 p.m. UTC
Export ttm_bo_reference_unless_doomed() to be used when looking up buffer
objects that are removed from the lookup structure in the destructor.

Cc: Christian König <christian.koenig@amd.com>
Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Sinclair Yeh <syeh@vmware.com>
---
 drivers/gpu/drm/ttm/ttm_bo_vm.c |  3 +--
 include/drm/ttm/ttm_bo_api.h    | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

Comments

Koenig, Christian Sept. 26, 2018, 4:35 p.m. UTC | #1
Am 26.09.2018 um 18:18 schrieb Thomas Hellstrom:
> Export ttm_bo_reference_unless_doomed() to be used when looking up buffer
> objects that are removed from the lookup structure in the destructor.
>
> Cc: Christian König <christian.koenig@amd.com>
> Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
> Reviewed-by: Sinclair Yeh <syeh@vmware.com>
> ---
>   drivers/gpu/drm/ttm/ttm_bo_vm.c |  3 +--
>   include/drm/ttm/ttm_bo_api.h    | 18 ++++++++++++++++++
>   2 files changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> index 6fe91c1b692d..ec4b09366213 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> @@ -409,8 +409,7 @@ static struct ttm_buffer_object *ttm_bo_vm_lookup(struct ttm_bo_device *bdev,
>   	node = drm_vma_offset_lookup_locked(&bdev->vma_manager, offset, pages);
>   	if (likely(node)) {
>   		bo = container_of(node, struct ttm_buffer_object, vma_node);
> -		if (!kref_get_unless_zero(&bo->kref))
> -			bo = NULL;
> +		bo = ttm_bo_reference_unless_doomed(bo);
>   	}
>   
>   	drm_vma_offset_unlock_lookup(&bdev->vma_manager);
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index 8c19470785e2..b6bf6b086576 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -312,6 +312,24 @@ ttm_bo_reference(struct ttm_buffer_object *bo)
>   	return bo;
>   }
>   
> +/**
> + * ttm_bo_reference_unless_doomed - reference a struct ttm_buffer_object unless
> + * its refcount has already reached zero.
> + * @bo: The buffer object.
> + *
> + * Used to reference a TTM buffer object in lookups where the object is removed
> + * from the lookup structure during the destructor and for RCU lookups.
> + *
> + * Returns: @bo if the referencing was successful, NULL otherwise.
> + */
> +static inline __must_check struct ttm_buffer_object *
> +ttm_bo_reference_unless_doomed(struct ttm_buffer_object *bo)

Please name that ttm_bo_get_rcu(), we are in the process of renaming 
ttm_bo_reference into ttm_bo_get as well.

Christian.

> +{
> +	if (!kref_get_unless_zero(&bo->kref))
> +		return NULL;
> +	return bo;
> +}
> +
>   /**
>    * ttm_bo_wait - wait for buffer idle.
>    *
Thomas Hellstrom Sept. 26, 2018, 4:43 p.m. UTC | #2
On 09/26/2018 06:35 PM, Christian König wrote:
> Am 26.09.2018 um 18:18 schrieb Thomas Hellstrom:
>> Export ttm_bo_reference_unless_doomed() to be used when looking up 
>> buffer
>> objects that are removed from the lookup structure in the destructor.
>>
>> Cc: Christian König <christian.koenig@amd.com>
>> Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
>> Reviewed-by: Sinclair Yeh <syeh@vmware.com>
>> ---
>>   drivers/gpu/drm/ttm/ttm_bo_vm.c |  3 +--
>>   include/drm/ttm/ttm_bo_api.h    | 18 ++++++++++++++++++
>>   2 files changed, 19 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c 
>> b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>> index 6fe91c1b692d..ec4b09366213 100644
>> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
>> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>> @@ -409,8 +409,7 @@ static struct ttm_buffer_object 
>> *ttm_bo_vm_lookup(struct ttm_bo_device *bdev,
>>       node = drm_vma_offset_lookup_locked(&bdev->vma_manager, offset, 
>> pages);
>>       if (likely(node)) {
>>           bo = container_of(node, struct ttm_buffer_object, vma_node);
>> -        if (!kref_get_unless_zero(&bo->kref))
>> -            bo = NULL;
>> +        bo = ttm_bo_reference_unless_doomed(bo);
>>       }
>>         drm_vma_offset_unlock_lookup(&bdev->vma_manager);
>> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
>> index 8c19470785e2..b6bf6b086576 100644
>> --- a/include/drm/ttm/ttm_bo_api.h
>> +++ b/include/drm/ttm/ttm_bo_api.h
>> @@ -312,6 +312,24 @@ ttm_bo_reference(struct ttm_buffer_object *bo)
>>       return bo;
>>   }
>>   +/**
>> + * ttm_bo_reference_unless_doomed - reference a struct 
>> ttm_buffer_object unless
>> + * its refcount has already reached zero.
>> + * @bo: The buffer object.
>> + *
>> + * Used to reference a TTM buffer object in lookups where the object 
>> is removed
>> + * from the lookup structure during the destructor and for RCU lookups.
>> + *
>> + * Returns: @bo if the referencing was successful, NULL otherwise.
>> + */
>> +static inline __must_check struct ttm_buffer_object *
>> +ttm_bo_reference_unless_doomed(struct ttm_buffer_object *bo)
>
> Please name that ttm_bo_get_rcu(), we are in the process of renaming 
> ttm_bo_reference into ttm_bo_get as well.

Could we call it ttm_bo_get_unless_doomed() or ttm_bo_get_unless_zero() 
to be even more consistent. (It's not restricted to rcu as the VM usage 
shows). Also "doomed" is more relevant for objects, "zero" is more 
relevant for the refcount itself?

/Thomas



>
> Christian.
>
>> +{
>> +    if (!kref_get_unless_zero(&bo->kref))
>> +        return NULL;
>> +    return bo;
>> +}
>> +
>>   /**
>>    * ttm_bo_wait - wait for buffer idle.
>>    *
>
Koenig, Christian Sept. 26, 2018, 4:49 p.m. UTC | #3
Am 26.09.2018 um 18:43 schrieb Thomas Hellstrom:
> On 09/26/2018 06:35 PM, Christian König wrote:
>> Am 26.09.2018 um 18:18 schrieb Thomas Hellstrom:
>>> Export ttm_bo_reference_unless_doomed() to be used when looking up 
>>> buffer
>>> objects that are removed from the lookup structure in the destructor.
>>>
>>> Cc: Christian König <christian.koenig@amd.com>
>>> Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
>>> Reviewed-by: Sinclair Yeh <syeh@vmware.com>
>>> ---
>>>   drivers/gpu/drm/ttm/ttm_bo_vm.c |  3 +--
>>>   include/drm/ttm/ttm_bo_api.h    | 18 ++++++++++++++++++
>>>   2 files changed, 19 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c 
>>> b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>> index 6fe91c1b692d..ec4b09366213 100644
>>> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>> @@ -409,8 +409,7 @@ static struct ttm_buffer_object 
>>> *ttm_bo_vm_lookup(struct ttm_bo_device *bdev,
>>>       node = drm_vma_offset_lookup_locked(&bdev->vma_manager, 
>>> offset, pages);
>>>       if (likely(node)) {
>>>           bo = container_of(node, struct ttm_buffer_object, vma_node);
>>> -        if (!kref_get_unless_zero(&bo->kref))
>>> -            bo = NULL;
>>> +        bo = ttm_bo_reference_unless_doomed(bo);
>>>       }
>>> drm_vma_offset_unlock_lookup(&bdev->vma_manager);
>>> diff --git a/include/drm/ttm/ttm_bo_api.h 
>>> b/include/drm/ttm/ttm_bo_api.h
>>> index 8c19470785e2..b6bf6b086576 100644
>>> --- a/include/drm/ttm/ttm_bo_api.h
>>> +++ b/include/drm/ttm/ttm_bo_api.h
>>> @@ -312,6 +312,24 @@ ttm_bo_reference(struct ttm_buffer_object *bo)
>>>       return bo;
>>>   }
>>>   +/**
>>> + * ttm_bo_reference_unless_doomed - reference a struct 
>>> ttm_buffer_object unless
>>> + * its refcount has already reached zero.
>>> + * @bo: The buffer object.
>>> + *
>>> + * Used to reference a TTM buffer object in lookups where the 
>>> object is removed
>>> + * from the lookup structure during the destructor and for RCU 
>>> lookups.
>>> + *
>>> + * Returns: @bo if the referencing was successful, NULL otherwise.
>>> + */
>>> +static inline __must_check struct ttm_buffer_object *
>>> +ttm_bo_reference_unless_doomed(struct ttm_buffer_object *bo)
>>
>> Please name that ttm_bo_get_rcu(), we are in the process of renaming 
>> ttm_bo_reference into ttm_bo_get as well.
>
> Could we call it ttm_bo_get_unless_doomed() or 
> ttm_bo_get_unless_zero() to be even more consistent. (It's not 
> restricted to rcu as the VM usage shows). Also "doomed" is more 
> relevant for objects, "zero" is more relevant for the refcount itself?

ttm_bo_get_unless_zero() is fine with me as well.

Christian.

>
> /Thomas
>
>
>
>>
>> Christian.
>>
>>> +{
>>> +    if (!kref_get_unless_zero(&bo->kref))
>>> +        return NULL;
>>> +    return bo;
>>> +}
>>> +
>>>   /**
>>>    * ttm_bo_wait - wait for buffer idle.
>>>    *
>>
>

Patch
diff mbox series

diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index 6fe91c1b692d..ec4b09366213 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -409,8 +409,7 @@  static struct ttm_buffer_object *ttm_bo_vm_lookup(struct ttm_bo_device *bdev,
 	node = drm_vma_offset_lookup_locked(&bdev->vma_manager, offset, pages);
 	if (likely(node)) {
 		bo = container_of(node, struct ttm_buffer_object, vma_node);
-		if (!kref_get_unless_zero(&bo->kref))
-			bo = NULL;
+		bo = ttm_bo_reference_unless_doomed(bo);
 	}
 
 	drm_vma_offset_unlock_lookup(&bdev->vma_manager);
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 8c19470785e2..b6bf6b086576 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -312,6 +312,24 @@  ttm_bo_reference(struct ttm_buffer_object *bo)
 	return bo;
 }
 
+/**
+ * ttm_bo_reference_unless_doomed - reference a struct ttm_buffer_object unless
+ * its refcount has already reached zero.
+ * @bo: The buffer object.
+ *
+ * Used to reference a TTM buffer object in lookups where the object is removed
+ * from the lookup structure during the destructor and for RCU lookups.
+ *
+ * Returns: @bo if the referencing was successful, NULL otherwise.
+ */
+static inline __must_check struct ttm_buffer_object *
+ttm_bo_reference_unless_doomed(struct ttm_buffer_object *bo)
+{
+	if (!kref_get_unless_zero(&bo->kref))
+		return NULL;
+	return bo;
+}
+
 /**
  * ttm_bo_wait - wait for buffer idle.
  *