aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu
diff options
context:
space:
mode:
authorMichel Dänzer <michel.daenzer@amd.com>2017-11-03 11:00:35 -0400
committerAlex Deucher <alexander.deucher@amd.com>2017-11-04 09:48:01 -0400
commite1fc12c5d9ad06a2a74e97a91f1b0c5f4c723b50 (patch)
treea138da480d215bdc6608d6c275bdc6874d4bbb92 /drivers/gpu
parent37c5f2c99adf63adf13f1ca309a1ffce25c5589a (diff)
drm/ttm: Always and only destroy bo->ttm_resv in ttm_bo_release_list
Fixes a use-after-free due to a race condition in ttm_bo_cleanup_refs_and_unlock, which allows one task to reserve a BO and destroy its ttm_resv while another task is waiting for it to signal in reservation_object_wait_timeout_rcu. v2: * Always initialize bo->ttm_resv in ttm_bo_init_reserved (Christian König) Fixes: 0d2bd2ae045d "drm/ttm: fix memory leak while individualizing BOs" Reviewed-by: Chunming Zhou <david1.zhou@amd.com> # v1 Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Michel Dänzer <michel.daenzer@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu')
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo.c16
1 files changed, 4 insertions, 12 deletions
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 379ec41d2c69..c088703777e2 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -150,8 +150,7 @@ static void ttm_bo_release_list(struct kref *list_kref)
150 ttm_tt_destroy(bo->ttm); 150 ttm_tt_destroy(bo->ttm);
151 atomic_dec(&bo->glob->bo_count); 151 atomic_dec(&bo->glob->bo_count);
152 dma_fence_put(bo->moving); 152 dma_fence_put(bo->moving);
153 if (bo->resv == &bo->ttm_resv) 153 reservation_object_fini(&bo->ttm_resv);
154 reservation_object_fini(&bo->ttm_resv);
155 mutex_destroy(&bo->wu_mutex); 154 mutex_destroy(&bo->wu_mutex);
156 if (bo->destroy) 155 if (bo->destroy)
157 bo->destroy(bo); 156 bo->destroy(bo);
@@ -402,14 +401,11 @@ static int ttm_bo_individualize_resv(struct ttm_buffer_object *bo)
402 if (bo->resv == &bo->ttm_resv) 401 if (bo->resv == &bo->ttm_resv)
403 return 0; 402 return 0;
404 403
405 reservation_object_init(&bo->ttm_resv);
406 BUG_ON(!reservation_object_trylock(&bo->ttm_resv)); 404 BUG_ON(!reservation_object_trylock(&bo->ttm_resv));
407 405
408 r = reservation_object_copy_fences(&bo->ttm_resv, bo->resv); 406 r = reservation_object_copy_fences(&bo->ttm_resv, bo->resv);
409 if (r) { 407 if (r)
410 reservation_object_unlock(&bo->ttm_resv); 408 reservation_object_unlock(&bo->ttm_resv);
411 reservation_object_fini(&bo->ttm_resv);
412 }
413 409
414 return r; 410 return r;
415} 411}
@@ -457,10 +453,8 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo)
457 if (reservation_object_test_signaled_rcu(&bo->ttm_resv, true)) { 453 if (reservation_object_test_signaled_rcu(&bo->ttm_resv, true)) {
458 ttm_bo_del_from_lru(bo); 454 ttm_bo_del_from_lru(bo);
459 spin_unlock(&glob->lru_lock); 455 spin_unlock(&glob->lru_lock);
460 if (bo->resv != &bo->ttm_resv) { 456 if (bo->resv != &bo->ttm_resv)
461 reservation_object_unlock(&bo->ttm_resv); 457 reservation_object_unlock(&bo->ttm_resv);
462 reservation_object_fini(&bo->ttm_resv);
463 }
464 458
465 ttm_bo_cleanup_memtype_use(bo); 459 ttm_bo_cleanup_memtype_use(bo);
466 return; 460 return;
@@ -560,8 +554,6 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo,
560 } 554 }
561 555
562 ttm_bo_del_from_lru(bo); 556 ttm_bo_del_from_lru(bo);
563 if (!list_empty(&bo->ddestroy) && (bo->resv != &bo->ttm_resv))
564 reservation_object_fini(&bo->ttm_resv);
565 list_del_init(&bo->ddestroy); 557 list_del_init(&bo->ddestroy);
566 kref_put(&bo->list_kref, ttm_bo_ref_bug); 558 kref_put(&bo->list_kref, ttm_bo_ref_bug);
567 559
@@ -1210,8 +1202,8 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
1210 lockdep_assert_held(&bo->resv->lock.base); 1202 lockdep_assert_held(&bo->resv->lock.base);
1211 } else { 1203 } else {
1212 bo->resv = &bo->ttm_resv; 1204 bo->resv = &bo->ttm_resv;
1213 reservation_object_init(&bo->ttm_resv);
1214 } 1205 }
1206 reservation_object_init(&bo->ttm_resv);
1215 atomic_inc(&bo->glob->bo_count); 1207 atomic_inc(&bo->glob->bo_count);
1216 drm_vma_node_reset(&bo->vma_node); 1208 drm_vma_node_reset(&bo->vma_node);
1217 bo->priority = 0; 1209 bo->priority = 0;