Skip to contentSkip to conversation

drm/amdgpu:fix race condition

PATCH In review Monk Liu 2 participants 5 messages Apr 10, 2017 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Monk Liu

author
#0 lore raw

PATCH 1/1 drm/amdgpu:fix race condition

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
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +7 -0
index 6d86eae..71d5f25 100644
@@ -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);
Signature · 6 lines
2.7.4

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

A message that is not in the archive (sent off-list or not yet received): 1491808681-25687-1-git-send-email-Monk.Liu-5C7GfCeVMHo@public.gmane.org

#2 lore raw

Am 10.04.2017 um 09:18 schrieb Monk Liu:

Quoted 17 lines

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
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0 -0
index 6d86eae..71d5f25 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx, · line 280

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1 -0
@@ -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.

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx, · line 286

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +6 -0
+		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.

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx, · line 289

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0 -0
  	if (seq >= cring->sequence) {
  		spin_unlock(&ctx->ring_lock);
  		return ERR_PTR(-EINVAL);

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

A message that is not in the archive (sent off-list or not yet received): 82d5bbc6-5c2c-9707-fbed-d58ab34ab204-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

author
#4 lore raw

Oh yeah~~ thanks

-----邮件原件-----
发件人: Christian König [mailto:[email protected]] 发送时间: Monday, April 10, 2017 3:22 PM
收件人: Liu, Monk <[email protected]>; [email protected] 主题: Re: [PATCH] drm/amdgpu:fix race condition

Am 10.04.2017 um 09:18 schrieb Monk Liu:

Quoted 17 lines

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
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0 -0
index 6d86eae..71d5f25 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c struct fence *amdgpu_ctx_get_fence(struct · line 281

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1 -0
@@ -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.

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx, · line 286

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +6 -0
+		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.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0 -0
  	if (seq >= cring->sequence) {
  		spin_unlock(&ctx->ring_lock);
  		return ERR_PTR(-EINVAL);

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

author
#5 lore raw
In reply to a message not in the archive
Quoted 1 line

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:[email protected]] 发送时间: Monday, April 10, 2017 3:22 PM
收件人: Liu, Monk <[email protected]>; [email protected] 主题: Re: [PATCH] drm/amdgpu:fix race condition

Am 10.04.2017 um 09:18 schrieb Monk Liu:

Quoted 17 lines

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
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0 -0
index 6d86eae..71d5f25 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c struct fence *amdgpu_ctx_get_fence(struct · line 281

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1 -0
@@ -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.

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx, · line 286

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +6 -0
+		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.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0 -0
  	if (seq >= cring->sequence) {
  		spin_unlock(&ctx->ring_lock);
  		return ERR_PTR(-EINVAL);

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

A message that is not in the archive (sent off-list or not yet received): DM5PR12MB16105F2589A1C93C223E94E884010-2J9CzHegvk++jCVTvoAFKAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#7 lore raw

Am 10.04.2017 um 09:26 schrieb Liu, Monk:

Quoted 3 lines
Quoted 1 line

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.

Quoted 44 lines

BR Monk

-----邮件原件-----
发件人: Christian König [mailto:[email protected]] 发送时间: Monday, April 10, 2017 3:22 PM
收件人: Liu, Monk <[email protected]>; [email protected] 主题: Re: [PATCH] drm/amdgpu:fix race condition

Am 10.04.2017 um 09:18 schrieb Monk Liu:

Quoted 17 lines

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
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 7 +++++++
   1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0 -0
index 6d86eae..71d5f25 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c struct fence *amdgpu_ctx_get_fence(struct · line 281

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1 -0
@@ -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.

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx, · line 286

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +6 -0
+		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.

Quoted 7 lines

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0 -0
   	if (seq >= cring->sequence) {
   		spin_unlock(&ctx->ring_lock);
   		return ERR_PTR(-EINVAL);

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