If ctx id is removed before ctx itself, the dependecy from umd couldnot be found although ctx is still alive. Change-Id: I129ce74f5524f74ef95a343444ba3fd9c0afdba5 Signed-off-by: Chunming Zhou <David1.Zhou at amd.com> --- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index 049e1d6..6d770c2 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h @@ -1030,6 +1030,7 @@ struct amdgpu_ctx { spinlock_t ring_lock; struct fence **fences; struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS]; + uint32_t idx; }; struct amdgpu_ctx *amdgpu_ctx_get(uint32_t id); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c index 35761bd..01d5612 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c @@ -75,6 +75,9 @@ static void amdgpu_ctx_fini(struct amdgpu_ctx *ctx) if (!adev) return; + mutex_lock(&amdgpu_ctx_lock); + idr_remove(&amdgpu_ctx_idr, ctx->idx); + mutex_unlock(&amdgpu_ctx_lock); for (i = 0; i < AMDGPU_MAX_RINGS; ++i) for (j = 0; j < amdgpu_sched_jobs; ++j) @@ -84,6 +87,7 @@ static void amdgpu_ctx_fini(struct amdgpu_ctx *ctx) for (i = 0; i < adev->num_rings; i++) amd_sched_entity_fini(&adev->rings[i]->sched, &ctx->rings[i].entity); + kfree(ctx); } static int amdgpu_ctx_alloc(struct amdgpu_device *adev, @@ -111,6 +115,7 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev, *id = 0; kfree(ctx); } + ctx->idx = *id; mutex_unlock(&amdgpu_ctx_lock); return r; } @@ -122,8 +127,6 @@ static void amdgpu_ctx_do_release(struct kref *ref) ctx = container_of(ref, struct amdgpu_ctx, refcount); amdgpu_ctx_fini(ctx); - - kfree(ctx); } static int amdgpu_ctx_free(uint32_t id) @@ -133,7 +136,6 @@ static int amdgpu_ctx_free(uint32_t id) mutex_lock(&amdgpu_ctx_lock); ctx = idr_find(&amdgpu_ctx_idr, id); if (ctx) { - idr_remove(&amdgpu_ctx_idr, id); kref_put(&ctx->refcount, amdgpu_ctx_do_release); mutex_unlock(&amdgpu_ctx_lock); return 0; -- 1.9.1