aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMonk Liu2017-08-08 02:34:20 -0500
committerAlex Deucher2017-08-08 11:00:11 -0500
commit2a89ae5d7a7d5845226ed85146140ff4c8788d59 (patch)
treed8a7d5caec863950ba1c1a2c4a91b407fcc18ced /amdgpu/amdgpu_internal.h
parent4d244155945f5531b4d9735bbe73c887aac81070 (diff)
downloadexternal-libdrm-2a89ae5d7a7d5845226ed85146140ff4c8788d59.tar.gz
external-libdrm-2a89ae5d7a7d5845226ed85146140ff4c8788d59.tar.xz
external-libdrm-2a89ae5d7a7d5845226ed85146140ff4c8788d59.zip
amdgpu: fix race issue between two bo functions(v2)
there is race issue between two threads on amdgpu_bo_reference and amdgpu_bo_import, this patch tends to fix it by moving the pthread_mutex_lock out of bo_free_internal and move to bo_reference to cover the update_reference part. The mutex_unlock in bo_import should also cover bo refcount increasement. Reviewed-by: Christian K├Ânig <christian.koenig@amd.com> Signed-off-by: Monk Liu <monk.liu@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'amdgpu/amdgpu_internal.h')
-rw-r--r--amdgpu/amdgpu_internal.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/amdgpu/amdgpu_internal.h b/amdgpu/amdgpu_internal.h
index e68246bf..28d1f38f 100644
--- a/amdgpu/amdgpu_internal.h
+++ b/amdgpu/amdgpu_internal.h
@@ -206,8 +206,17 @@ static inline bool update_references(atomic_t *dst, atomic_t *src)
206static inline void amdgpu_bo_reference(struct amdgpu_bo **dst, 206static inline void amdgpu_bo_reference(struct amdgpu_bo **dst,
207 struct amdgpu_bo *src) 207 struct amdgpu_bo *src)
208{ 208{
209 if (update_references(&(*dst)->refcount, &src->refcount)) 209 pthread_mutex_t *mlock;
210 amdgpu_bo_free_internal(*dst); 210 struct amdgpu_bo* bo = *dst;
211
212 assert(bo != NULL);
213 mlock = &bo->dev->bo_table_mutex;
214 pthread_mutex_lock(mlock);
215
216 if (update_references(&bo->refcount, src?&src->refcount:NULL))
217 amdgpu_bo_free_internal(bo);
218
219 pthread_mutex_unlock(mlock);
211 *dst = src; 220 *dst = src;
212} 221}
213 222