[PATCH 1/2] drm/amd/amdgpu: lock reservation object while creating shadow bo

Nicolai Hähnle nhaehnle at gmail.com
Wed Jan 11 14:09:27 UTC 2017


On 11.01.2017 12:56, Christian König wrote:
> Am 11.01.2017 um 08:31 schrieb Nicolai Hähnle:
>> From: Nicolai Hähnle <nicolai.haehnle at amd.com>
>>
>> ttm_bo_init checks that the reservation object is locked. This is
>> the caller's responsibility when resv != NULL. Otherwise, the inline
>> reservation object of the newly allocated buffer is used and must
>> explicitly be locked. Using a trylock is fine, since nobody else
>> has a reference to the reservation lock.
>
> Good, catch. But while using trylock is fine, why do you need to use it
> in the first place?

Or is this a question about trylock vs. lock?

Actually, now that I think about this again, perhaps the following 
sequence would be possible:

1. Create the main bo in amdgpu_bo_create.
2. Other thread, for whatever reason, tries to make space and evict the 
bo, and probably locks the reservation for that?
3. amdgpu_bo_create continues, calls the trylock which now fails.

Nicolai

>
> Regards,
> Christian.
>
>>
>> Signed-off-by: Nicolai Hähnle <nicolai.haehnle at amd.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 11 +++++++++++
>>   1 file changed, 11 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> index 11c12c4d..357eed9 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> @@ -465,21 +465,32 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
>>       amdgpu_ttm_placement_init(adev, &placement,
>>                     placements, domain, flags);
>>         r = amdgpu_bo_create_restricted(adev, size, byte_align, kernel,
>>                       domain, flags, sg, &placement,
>>                       resv, bo_ptr);
>>       if (r)
>>           return r;
>>         if (amdgpu_need_backup(adev) && (flags &
>> AMDGPU_GEM_CREATE_SHADOW)) {
>> +        if (!resv) {
>> +            bool locked;
>> +
>> +            locked = ww_mutex_trylock(&(*bo_ptr)->tbo.resv->lock);
>> +            WARN_ON(!locked);
>> +        }
>> +
>>           r = amdgpu_bo_create_shadow(adev, size, byte_align, (*bo_ptr));
>> +
>> +        if (!resv)
>> +            ww_mutex_unlock(&(*bo_ptr)->tbo.resv->lock);
>> +
>>           if (r)
>>               amdgpu_bo_unref(bo_ptr);
>>       }
>>         return r;
>>   }
>>     int amdgpu_bo_backup_to_shadow(struct amdgpu_device *adev,
>>                      struct amdgpu_ring *ring,
>>                      struct amdgpu_bo *bo,
>
>


More information about the amd-gfx mailing list