Skip to contentSkip to conversation

drm/amdgpu: amdgpu_ctx_add_fence can't fail

PATCH In review Christian König 3 participants 5 messages Aug 24, 2018 – Aug 27, 2018 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu: amdgpu_ctx_add_fence can't fail

No more waiting for a fence done here.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 10 +---------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c |  8 +++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h |  6 +++---
 3 files changed, 7 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -9
index fd3902983195..80ad23061f1c 100644
@@ -1217,15 +1217,7 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
 	job->owner = p->filp;
 	p->fence = dma_fence_get(&job->base.s_fence->finished);
 
-	r = amdgpu_ctx_add_fence(p->ctx, entity, p->fence, &seq);
-	if (r) {
-		dma_fence_put(p->fence);
-		dma_fence_put(&job->base.s_fence->finished);
-		amdgpu_job_free(job);
-		amdgpu_mn_unlock(p->mn);
-		return r;
-	}
-
+	amdgpu_ctx_add_fence(p->ctx, entity, p->fence, &seq);
 	amdgpu_cs_post_dependencies(p);
 
 	if ((job->preamble_status & AMDGPU_PREAMBLE_IB_PRESENT) &&
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +3 -5
index 987b7f256463..f9b54236102d 100644
@@ -434,9 +434,9 @@ int amdgpu_ctx_put(struct amdgpu_ctx *ctx)
 	return 0;
 }
 
-int amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx,
-			 struct drm_sched_entity *entity,
-			 struct dma_fence *fence, uint64_t* handle)
+void amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx,
+			  struct drm_sched_entity *entity,
+			  struct dma_fence *fence, uint64_t* handle)
 {
 	struct amdgpu_ctx_entity *centity = to_amdgpu_ctx_entity(entity);
 	uint64_t seq = centity->sequence;
@@ -458,8 +458,6 @@ int amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx,
 	dma_fence_put(other);
 	if (handle)
 		*handle = seq;
-
-	return 0;
 }
 
 struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +3 -3
index d67c1d285a4f..b3b012c0a7da 100644
@@ -65,9 +65,9 @@ int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
 
 int amdgpu_ctx_get_entity(struct amdgpu_ctx *ctx, u32 hw_ip, u32 instance,
 			  u32 ring, struct drm_sched_entity **entity);
-int amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx,
-			 struct drm_sched_entity *entity,
-			 struct dma_fence *fence, uint64_t *seq);
+void amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx,
+			  struct drm_sched_entity *entity,
+			  struct dma_fence *fence, uint64_t *seq);
 struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
 				       struct drm_sched_entity *entity,
 				       uint64_t seq);
Signature · 6 lines
2.17.1

_______________________________________________
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): 20180824125016.1315-1-christian.koenig-5C7GfCeVMHo@public.gmane.org

#2 lore raw

PATCH 2/2 drm/amdgpu: fix holding mn_lock while allocating memory

We can't hold the mn_lock while allocating memory.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 30 +++++++++++++++-----------
 1 file changed, 18 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +18 -12
index 80ad23061f1c..34d18d9dfcbd 100644
@@ -1194,26 +1194,23 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
 
 	int r;
 
+	job = p->job;
+	p->job = NULL;
+
+	r = drm_sched_job_init(&job->base, entity, p->filp);
+	if (r)
+		goto error_unlock;
+
 	amdgpu_mn_lock(p->mn);
 	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
 		struct amdgpu_bo *bo = e->robj;
 
 		if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
-			amdgpu_mn_unlock(p->mn);
-			return -ERESTARTSYS;
+			r = -ERESTARTSYS;
+			goto error_abort;
 		}
 	}
 
-	job = p->job;
-	p->job = NULL;
-
-	r = drm_sched_job_init(&job->base, entity, p->filp);
-	if (r) {
-		amdgpu_job_free(job);
-		amdgpu_mn_unlock(p->mn);
-		return r;
-	}
-
 	job->owner = p->filp;
 	p->fence = dma_fence_get(&job->base.s_fence->finished);
 
@@ -1243,6 +1240,15 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
 	amdgpu_mn_unlock(p->mn);
 
 	return 0;
+
+error_abort:
+	dma_fence_put(&job->base.s_fence->finished);
+	job->base.s_fence = NULL;
+
+error_unlock:
+	amdgpu_job_free(job);
+	amdgpu_mn_unlock(p->mn);
+	return r;
 }
 
 int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
Signature · 6 lines
2.17.1

_______________________________________________
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): 20180824125016.1315-2-christian.koenig-5C7GfCeVMHo@public.gmane.org

#4 lore raw

Re: [PATCH 2/2] drm/amdgpu: fix holding mn_lock while allocating memory

Quoted 1 line · Christian König

We can't hold the mn_lock while allocating memory.

if you could add some comments from what you discussed with Michal to explain why, it would be better. With that fixed, Acked-by: Chunming Zhou <[email protected]>

David

Quoted 52 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 30 +++++++++++++++-----------
  1 file changed, 18 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +11 -12
index 80ad23061f1c..34d18d9dfcbd 100644
@@ -1194,26 +1194,23 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
 
  	int r;
 
+	job = p->job;
+	p->job = NULL;
+
+	r = drm_sched_job_init(&job->base, entity, p->filp);
+	if (r)
+		goto error_unlock;
+
  	amdgpu_mn_lock(p->mn);
  	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
  		struct amdgpu_bo *bo = e->robj;
 
  		if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
-			amdgpu_mn_unlock(p->mn);
-			return -ERESTARTSYS;
+			r = -ERESTARTSYS;
+			goto error_abort;
  		}
  	}
 
-	job = p->job;
-	p->job = NULL;
-
-	r = drm_sched_job_init(&job->base, entity, p->filp);
-	if (r) {
-		amdgpu_job_free(job);
-		amdgpu_mn_unlock(p->mn);
-		return r;
-	}
-
  	job->owner = p->filp;
  	p->fence = dma_fence_get(&job->base.s_fence->finished);
 
@@ -1243,6 +1240,15 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
  	amdgpu_mn_unlock(p->mn);
 
  	return 0;
+
+error_abort:

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_submit(struct amdgpu_cs_parser *p, · line 1254

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +7 -0
+	dma_fence_put(&job->base.s_fence->finished);
+	job->base.s_fence = NULL;
+
+error_unlock:
+	amdgpu_job_free(job);
+	amdgpu_mn_unlock(p->mn);
+	return r;
  }
 
  int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)

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

Reviewed-by
#5 lore raw
In reply to a message not in the archive
Quoted 3 lines · Christian König

No more waiting for a fence done here.

Quoted 60 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 10 +---------
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c |  8 +++-----
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h |  6 +++---
  3 files changed, 7 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -9
index fd3902983195..80ad23061f1c 100644
@@ -1217,15 +1217,7 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
  	job->owner = p->filp;
  	p->fence = dma_fence_get(&job->base.s_fence->finished);
 
-	r = amdgpu_ctx_add_fence(p->ctx, entity, p->fence, &seq);
-	if (r) {
-		dma_fence_put(p->fence);
-		dma_fence_put(&job->base.s_fence->finished);
-		amdgpu_job_free(job);
-		amdgpu_mn_unlock(p->mn);
-		return r;
-	}
-
+	amdgpu_ctx_add_fence(p->ctx, entity, p->fence, &seq);
  	amdgpu_cs_post_dependencies(p);
 
  	if ((job->preamble_status & AMDGPU_PREAMBLE_IB_PRESENT) &&
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +3 -5
index 987b7f256463..f9b54236102d 100644
@@ -434,9 +434,9 @@ int amdgpu_ctx_put(struct amdgpu_ctx *ctx)
  	return 0;
  }
 
-int amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx,
-			 struct drm_sched_entity *entity,
-			 struct dma_fence *fence, uint64_t* handle)
+void amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx,
+			  struct drm_sched_entity *entity,
+			  struct dma_fence *fence, uint64_t* handle)
  {
  	struct amdgpu_ctx_entity *centity = to_amdgpu_ctx_entity(entity);
  	uint64_t seq = centity->sequence;
@@ -458,8 +458,6 @@ int amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx,
  	dma_fence_put(other);
  	if (handle)
  		*handle = seq;
-
-	return 0;
  }
 
  struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +0 -0
index d67c1d285a4f..b3b012c0a7da 100644
@@ -65,9 +65,9 @@ int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
 
  int amdgpu_ctx_get_entity(struct amdgpu_ctx *ctx, u32 hw_ip, u32 instance,

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h int amdgpu_ctx_put(struct amdgpu_ctx *ctx); · line 73

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +3 -3
  			  u32 ring, struct drm_sched_entity **entity);
-int amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx,
-			 struct drm_sched_entity *entity,
-			 struct dma_fence *fence, uint64_t *seq);
+void amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx,
+			  struct drm_sched_entity *entity,
+			  struct dma_fence *fence, uint64_t *seq);
  struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
  				       struct drm_sched_entity *entity,
  				       uint64_t seq);

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

Reviewed-by Junwei Zhang
#6 lore raw
In reply to a message not in the archive
Quoted 3 lines · Christian König

No more waiting for a fence done here.

Quoted 61 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 10 +---------
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c |  8 +++-----
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h |  6 +++---
  3 files changed, 7 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -9
index fd3902983195..80ad23061f1c 100644
@@ -1217,15 +1217,7 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
  	job->owner = p->filp;
  	p->fence = dma_fence_get(&job->base.s_fence->finished);
 
-	r = amdgpu_ctx_add_fence(p->ctx, entity, p->fence, &seq);
-	if (r) {
-		dma_fence_put(p->fence);
-		dma_fence_put(&job->base.s_fence->finished);
-		amdgpu_job_free(job);
-		amdgpu_mn_unlock(p->mn);
-		return r;
-	}
-
+	amdgpu_ctx_add_fence(p->ctx, entity, p->fence, &seq);
  	amdgpu_cs_post_dependencies(p);
 
  	if ((job->preamble_status & AMDGPU_PREAMBLE_IB_PRESENT) &&
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +3 -5
index 987b7f256463..f9b54236102d 100644
@@ -434,9 +434,9 @@ int amdgpu_ctx_put(struct amdgpu_ctx *ctx)
  	return 0;
  }
 
-int amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx,
-			 struct drm_sched_entity *entity,
-			 struct dma_fence *fence, uint64_t* handle)
+void amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx,
+			  struct drm_sched_entity *entity,
+			  struct dma_fence *fence, uint64_t* handle)
  {
  	struct amdgpu_ctx_entity *centity = to_amdgpu_ctx_entity(entity);
  	uint64_t seq = centity->sequence;
@@ -458,8 +458,6 @@ int amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx,
  	dma_fence_put(other);
  	if (handle)
  		*handle = seq;
-
-	return 0;
  }
 
  struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +0 -0
index d67c1d285a4f..b3b012c0a7da 100644
@@ -65,9 +65,9 @@ int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
 
  int amdgpu_ctx_get_entity(struct amdgpu_ctx *ctx, u32 hw_ip, u32 instance,

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h int amdgpu_ctx_put(struct amdgpu_ctx *ctx); · line 73

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +3 -3
  			  u32 ring, struct drm_sched_entity **entity);
-int amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx,
-			 struct drm_sched_entity *entity,
-			 struct dma_fence *fence, uint64_t *seq);
+void amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx,
+			  struct drm_sched_entity *entity,
+			  struct dma_fence *fence, uint64_t *seq);
  struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
  				       struct drm_sched_entity *entity,
  				       uint64_t seq);

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