Re: 答复: [PATCH] drm/amdgpu:fix race condition

Christian König deathsimple at vodafone.de
Mon Apr 10 07:29:23 UTC 2017


Am 10.04.2017 um 09:26 schrieb Liu, Monk:
>> That is unnecessary the "if (seq + amdgpu_sched_jobs < cring->sequence) {" will catch this case.
> But what if user land pass in seq 0 on purpose , but the latest cring->sequence value is only 3 ?
> Without this "if (seq == 0)" the logic seems goes to a wrong direction

If cring->sequence is only 3 cring->fences[0] will be NULL, so we will 
just return NULL anyway (We might want to add a comment explaining that).

Christian.

>
> BR Monk
>
> -----邮件原件-----
> 发件人: Christian König [mailto:deathsimple at vodafone.de]
> 发送时间: Monday, April 10, 2017 3:22 PM
> 收件人: Liu, Monk <Monk.Liu at amd.com>; amd-gfx at lists.freedesktop.org
> 主题: Re: [PATCH] drm/amdgpu:fix race condition
>
> Am 10.04.2017 um 09:18 schrieb Monk Liu:
>> sequence is protected by spinlock so don't access sequence in paramter
>> seq when invoking this function.
>>
>> ~0 means to get the latest sequence number and 0 means none to get.
>>
>> Change-Id: Ib7a03f3cf5594deeb4ad333cc59b47a6bddfd1ad
>> Signed-off-by: Monk Liu <Monk.Liu at amd.com>
>> ---
>>    drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 7 +++++++
>>    1 file changed, 7 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
>> index 6d86eae..71d5f25 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
>> @@ -277,6 +277,13 @@ struct fence *amdgpu_ctx_get_fence(struct
>> amdgpu_ctx *ctx,
>>    
>>    	spin_lock(&ctx->ring_lock);
>>    
>> +	if (seq == ~0) {
> That must be ~0ull, otherwise you would be checking a 32bit value here.
>
> Additional to that please define something in amdgpu_drm.h for that value.
>
>> +		seq = ctx->rings[ring->idx].sequence - 1;
>> +	} else if(seq == 0) {
>> +		spin_unlock(&ctx->ring_lock);
>> +		return NULL;
>> +	}
>> +
> That is unnecessary the "if (seq + amdgpu_sched_jobs < cring->sequence) {" will catch this case.
>
> Regards,
> Christian.
>
>>    	if (seq >= cring->sequence) {
>>    		spin_unlock(&ctx->ring_lock);
>>    		return ERR_PTR(-EINVAL);
>



More information about the amd-gfx mailing list