All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu:fix race condition
@ 2017-04-10  7:18 Monk Liu
       [not found] ` <1491808681-25687-1-git-send-email-Monk.Liu-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Monk Liu @ 2017-04-10  7:18 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW; +Cc: 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@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) {
+		seq = ctx->rings[ring->idx].sequence - 1;
+	} else if(seq == 0) {
+		spin_unlock(&ctx->ring_lock);
+		return NULL;
+	}
+
 	if (seq >= cring->sequence) {
 		spin_unlock(&ctx->ring_lock);
 		return ERR_PTR(-EINVAL);
-- 
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] drm/amdgpu:fix race condition
       [not found] ` <1491808681-25687-1-git-send-email-Monk.Liu-5C7GfCeVMHo@public.gmane.org>
@ 2017-04-10  7:21   ` Christian König
       [not found]     ` <82d5bbc6-5c2c-9707-fbed-d58ab34ab204-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Christian König @ 2017-04-10  7:21 UTC (permalink / raw)
  To: Monk Liu, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

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@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);


_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 7+ messages in thread

* 答复: [PATCH] drm/amdgpu:fix race condition
       [not found]     ` <82d5bbc6-5c2c-9707-fbed-d58ab34ab204-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
@ 2017-04-10  7:23       ` Liu, Monk
  2017-04-10  7:26       ` Liu, Monk
  1 sibling, 0 replies; 7+ messages in thread
From: Liu, Monk @ 2017-04-10  7:23 UTC (permalink / raw)
  To: Christian König, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Oh yeah~~ thanks 

-----邮件原件-----
发件人: Christian König [mailto:deathsimple@vodafone.de] 
发送时间: Monday, April 10, 2017 3:22 PM
收件人: Liu, Monk <Monk.Liu@amd.com>; amd-gfx@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@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);


_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 7+ messages in thread

* 答复: [PATCH] drm/amdgpu:fix race condition
       [not found]     ` <82d5bbc6-5c2c-9707-fbed-d58ab34ab204-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
  2017-04-10  7:23       ` 答复: " Liu, Monk
@ 2017-04-10  7:26       ` Liu, Monk
       [not found]         ` <DM5PR12MB16105F2589A1C93C223E94E884010-2J9CzHegvk++jCVTvoAFKAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  1 sibling, 1 reply; 7+ messages in thread
From: Liu, Monk @ 2017-04-10  7:26 UTC (permalink / raw)
  To: Christian König, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

>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

BR Monk

-----邮件原件-----
发件人: Christian König [mailto:deathsimple@vodafone.de] 
发送时间: Monday, April 10, 2017 3:22 PM
收件人: Liu, Monk <Monk.Liu@amd.com>; amd-gfx@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@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);


_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: 答复: [PATCH] drm/amdgpu:fix race condition
       [not found]         ` <DM5PR12MB16105F2589A1C93C223E94E884010-2J9CzHegvk++jCVTvoAFKAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2017-04-10  7:29           ` Christian König
  0 siblings, 0 replies; 7+ messages in thread
From: Christian König @ 2017-04-10  7:29 UTC (permalink / raw)
  To: Liu, Monk, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

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@vodafone.de]
> 发送时间: Monday, April 10, 2017 3:22 PM
> 收件人: Liu, Monk <Monk.Liu@amd.com>; amd-gfx@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@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);
>

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: 答复: [PATCH] drm/amdgpu:fix race condition
       [not found]       ` <DM5PR12MB1610C70F02FD5904AEF06DD684010-2J9CzHegvk++jCVTvoAFKAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2017-04-10 10:17         ` Christian König
  0 siblings, 0 replies; 7+ messages in thread
From: Christian König @ 2017-04-10 10:17 UTC (permalink / raw)
  To: Liu, Monk, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Am 10.04.2017 um 12:16 schrieb Liu, Monk:
> Is that so ?
>
> Seq is already type of "uint64_t", GCC still compiles ~0 as 0xffffffff, but not 0xffffffffffffffff ?

You mean that it sign extend the value? Good point, that could be as well.

> I'll change to use ~0ull anyway,

Yeah, that should make it a bit more clear what happens here.

Christian.

>
> BR Monk
>
>
> -----邮件原件-----
> 发件人: Christian König [mailto:deathsimple@vodafone.de]
> 发送时间: Monday, April 10, 2017 4:10 PM
> 收件人: Liu, Monk <Monk.Liu@amd.com>; amd-gfx@lists.freedesktop.org
> 主题: Re: [PATCH] drm/amdgpu:fix race condition
>
> Am 10.04.2017 um 09:39 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.
> Well you are still not using ~0ull as I said. Using ~0 here will cause 0xffffffff to be used instead of 0xffffffffffffffff.
>
> Additional to that please add a define into amdgpu_drm.h to document this interface change.
>
> Christian.
>
>> Change-Id: Ib7a03f3cf5594deeb4ad333cc59b47a6bddfd1ad
>> Signed-off-by: Monk Liu <Monk.Liu@amd.com>
>> ---
>>    drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 3 +++
>>    1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
>> index 6d86eae..c24bb90 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
>> @@ -277,6 +277,9 @@ struct fence *amdgpu_ctx_get_fence(struct
>> amdgpu_ctx *ctx,
>>    
>>    	spin_lock(&ctx->ring_lock);
>>    
>> +	if (seq == ~0)
>> +		seq = ctx->rings[ring->idx].sequence - 1;
>> +
>>    	if (seq >= cring->sequence) {
>>    		spin_unlock(&ctx->ring_lock);
>>    		return ERR_PTR(-EINVAL);
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx


_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 7+ messages in thread

* 答复: [PATCH] drm/amdgpu:fix race condition
       [not found]   ` <7761bfd7-c34f-f21a-650e-fcc41d722245-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
@ 2017-04-10 10:16     ` Liu, Monk
       [not found]       ` <DM5PR12MB1610C70F02FD5904AEF06DD684010-2J9CzHegvk++jCVTvoAFKAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Liu, Monk @ 2017-04-10 10:16 UTC (permalink / raw)
  To: Christian König, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Is that so ?

Seq is already type of "uint64_t", GCC still compiles ~0 as 0xffffffff, but not 0xffffffffffffffff ?
I'll change to use ~0ull anyway, 

BR Monk


-----邮件原件-----
发件人: Christian König [mailto:deathsimple@vodafone.de] 
发送时间: Monday, April 10, 2017 4:10 PM
收件人: Liu, Monk <Monk.Liu@amd.com>; amd-gfx@lists.freedesktop.org
主题: Re: [PATCH] drm/amdgpu:fix race condition

Am 10.04.2017 um 09:39 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.

Well you are still not using ~0ull as I said. Using ~0 here will cause 0xffffffff to be used instead of 0xffffffffffffffff.

Additional to that please add a define into amdgpu_drm.h to document this interface change.

Christian.

>
> Change-Id: Ib7a03f3cf5594deeb4ad333cc59b47a6bddfd1ad
> Signed-off-by: Monk Liu <Monk.Liu@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> index 6d86eae..c24bb90 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> @@ -277,6 +277,9 @@ struct fence *amdgpu_ctx_get_fence(struct 
> amdgpu_ctx *ctx,
>   
>   	spin_lock(&ctx->ring_lock);
>   
> +	if (seq == ~0)
> +		seq = ctx->rings[ring->idx].sequence - 1;
> +
>   	if (seq >= cring->sequence) {
>   		spin_unlock(&ctx->ring_lock);
>   		return ERR_PTR(-EINVAL);


_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-04-10 10:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-10  7:18 [PATCH] drm/amdgpu:fix race condition Monk Liu
     [not found] ` <1491808681-25687-1-git-send-email-Monk.Liu-5C7GfCeVMHo@public.gmane.org>
2017-04-10  7:21   ` Christian König
     [not found]     ` <82d5bbc6-5c2c-9707-fbed-d58ab34ab204-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-04-10  7:23       ` 答复: " Liu, Monk
2017-04-10  7:26       ` Liu, Monk
     [not found]         ` <DM5PR12MB16105F2589A1C93C223E94E884010-2J9CzHegvk++jCVTvoAFKAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-04-10  7:29           ` Christian König
2017-04-10  7:39 Monk Liu
2017-04-10  8:09 ` Christian König
     [not found]   ` <7761bfd7-c34f-f21a-650e-fcc41d722245-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-04-10 10:16     ` 答复: " Liu, Monk
     [not found]       ` <DM5PR12MB1610C70F02FD5904AEF06DD684010-2J9CzHegvk++jCVTvoAFKAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-04-10 10:17         ` Christian König

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.