diff options
author | Marek Olšák <marek.olsak@amd.com> | 2015-05-05 14:52:00 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2015-06-03 21:03:27 -0400 |
commit | 0147ee0f5921af606ac0f822107b69b53dd29358 (patch) | |
tree | a922251df2e25ab013a3c15501da6322cf800341 | |
parent | f11358daa93a8ae9fdee5cfe6ef7a0ed0027edee (diff) |
drm/amdgpu: make the CTX ioctl thread-safe
The existing locks were protecting the list, but not the elements.
v2: rename hlock to lock
Signed-off-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Jammy Zhou <Jammy.Zhou@amd.com>
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 20 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 2 |
3 files changed, 12 insertions, 12 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index 65246abcee27..cef3a43ab0aa 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h | |||
@@ -1056,7 +1056,7 @@ struct amdgpu_ctx_mgr { | |||
1056 | struct amdgpu_device *adev; | 1056 | struct amdgpu_device *adev; |
1057 | struct idr ctx_handles; | 1057 | struct idr ctx_handles; |
1058 | /* lock for IDR system */ | 1058 | /* lock for IDR system */ |
1059 | struct mutex hlock; | 1059 | struct mutex lock; |
1060 | }; | 1060 | }; |
1061 | 1061 | ||
1062 | /* | 1062 | /* |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c index ffb13a66e288..0dc3a4ebd5d3 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | |||
@@ -33,9 +33,7 @@ static void amdgpu_ctx_do_release(struct kref *ref) | |||
33 | ctx = container_of(ref, struct amdgpu_ctx, refcount); | 33 | ctx = container_of(ref, struct amdgpu_ctx, refcount); |
34 | mgr = &ctx->fpriv->ctx_mgr; | 34 | mgr = &ctx->fpriv->ctx_mgr; |
35 | 35 | ||
36 | mutex_lock(&mgr->hlock); | ||
37 | idr_remove(&mgr->ctx_handles, ctx->id); | 36 | idr_remove(&mgr->ctx_handles, ctx->id); |
38 | mutex_unlock(&mgr->hlock); | ||
39 | kfree(ctx); | 37 | kfree(ctx); |
40 | } | 38 | } |
41 | 39 | ||
@@ -49,20 +47,20 @@ int amdgpu_ctx_alloc(struct amdgpu_device *adev, struct amdgpu_fpriv *fpriv, uin | |||
49 | if (!ctx) | 47 | if (!ctx) |
50 | return -ENOMEM; | 48 | return -ENOMEM; |
51 | 49 | ||
52 | mutex_lock(&mgr->hlock); | 50 | mutex_lock(&mgr->lock); |
53 | r = idr_alloc(&mgr->ctx_handles, ctx, 0, 0, GFP_KERNEL); | 51 | r = idr_alloc(&mgr->ctx_handles, ctx, 0, 0, GFP_KERNEL); |
54 | if (r < 0) { | 52 | if (r < 0) { |
55 | mutex_unlock(&mgr->hlock); | 53 | mutex_unlock(&mgr->lock); |
56 | kfree(ctx); | 54 | kfree(ctx); |
57 | return r; | 55 | return r; |
58 | } | 56 | } |
59 | mutex_unlock(&mgr->hlock); | ||
60 | *id = (uint32_t)r; | 57 | *id = (uint32_t)r; |
61 | 58 | ||
62 | memset(ctx, 0, sizeof(*ctx)); | 59 | memset(ctx, 0, sizeof(*ctx)); |
63 | ctx->id = *id; | 60 | ctx->id = *id; |
64 | ctx->fpriv = fpriv; | 61 | ctx->fpriv = fpriv; |
65 | kref_init(&ctx->refcount); | 62 | kref_init(&ctx->refcount); |
63 | mutex_unlock(&mgr->lock); | ||
66 | 64 | ||
67 | return 0; | 65 | return 0; |
68 | } | 66 | } |
@@ -72,13 +70,14 @@ int amdgpu_ctx_free(struct amdgpu_device *adev, struct amdgpu_fpriv *fpriv, uint | |||
72 | struct amdgpu_ctx *ctx; | 70 | struct amdgpu_ctx *ctx; |
73 | struct amdgpu_ctx_mgr *mgr = &fpriv->ctx_mgr; | 71 | struct amdgpu_ctx_mgr *mgr = &fpriv->ctx_mgr; |
74 | 72 | ||
75 | rcu_read_lock(); | 73 | mutex_lock(&mgr->lock); |
76 | ctx = idr_find(&mgr->ctx_handles, id); | 74 | ctx = idr_find(&mgr->ctx_handles, id); |
77 | rcu_read_unlock(); | ||
78 | if (ctx) { | 75 | if (ctx) { |
79 | kref_put(&ctx->refcount, amdgpu_ctx_do_release); | 76 | kref_put(&ctx->refcount, amdgpu_ctx_do_release); |
77 | mutex_unlock(&mgr->lock); | ||
80 | return 0; | 78 | return 0; |
81 | } | 79 | } |
80 | mutex_unlock(&mgr->lock); | ||
82 | return -EINVAL; | 81 | return -EINVAL; |
83 | } | 82 | } |
84 | 83 | ||
@@ -87,14 +86,15 @@ int amdgpu_ctx_query(struct amdgpu_device *adev, struct amdgpu_fpriv *fpriv, uin | |||
87 | struct amdgpu_ctx *ctx; | 86 | struct amdgpu_ctx *ctx; |
88 | struct amdgpu_ctx_mgr *mgr = &fpriv->ctx_mgr; | 87 | struct amdgpu_ctx_mgr *mgr = &fpriv->ctx_mgr; |
89 | 88 | ||
90 | rcu_read_lock(); | 89 | mutex_lock(&mgr->lock); |
91 | ctx = idr_find(&mgr->ctx_handles, id); | 90 | ctx = idr_find(&mgr->ctx_handles, id); |
92 | rcu_read_unlock(); | ||
93 | if (ctx) { | 91 | if (ctx) { |
94 | /* state should alter with CS activity */ | 92 | /* state should alter with CS activity */ |
95 | *state = ctx->state; | 93 | *state = ctx->state; |
94 | mutex_unlock(&mgr->lock); | ||
96 | return 0; | 95 | return 0; |
97 | } | 96 | } |
97 | mutex_unlock(&mgr->lock); | ||
98 | return -EINVAL; | 98 | return -EINVAL; |
99 | } | 99 | } |
100 | 100 | ||
@@ -111,7 +111,7 @@ void amdgpu_ctx_fini(struct amdgpu_fpriv *fpriv) | |||
111 | DRM_ERROR("ctx (id=%ul) is still alive\n",ctx->id); | 111 | DRM_ERROR("ctx (id=%ul) is still alive\n",ctx->id); |
112 | } | 112 | } |
113 | 113 | ||
114 | mutex_destroy(&mgr->hlock); | 114 | mutex_destroy(&mgr->lock); |
115 | } | 115 | } |
116 | 116 | ||
117 | int amdgpu_ctx_ioctl(struct drm_device *dev, void *data, | 117 | int amdgpu_ctx_ioctl(struct drm_device *dev, void *data, |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c index 2d50c6dbdcbb..02c450d0be1a 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | |||
@@ -497,7 +497,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) | |||
497 | idr_init(&fpriv->bo_list_handles); | 497 | idr_init(&fpriv->bo_list_handles); |
498 | 498 | ||
499 | /* init context manager */ | 499 | /* init context manager */ |
500 | mutex_init(&fpriv->ctx_mgr.hlock); | 500 | mutex_init(&fpriv->ctx_mgr.lock); |
501 | idr_init(&fpriv->ctx_mgr.ctx_handles); | 501 | idr_init(&fpriv->ctx_mgr.ctx_handles); |
502 | fpriv->ctx_mgr.adev = adev; | 502 | fpriv->ctx_mgr.adev = adev; |
503 | 503 | ||