@@ -415,24 +415,20 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo)
415415 spin_lock (& glob -> lru_lock );
416416 ret = __ttm_bo_reserve (bo , false, true, false, NULL );
417417
418- spin_lock (& bdev -> fence_lock );
419- (void ) ttm_bo_wait (bo , false, false, true);
420- if (!ret && !bo -> sync_obj ) {
421- spin_unlock (& bdev -> fence_lock );
422- put_count = ttm_bo_del_from_lru (bo );
418+ if (!ret ) {
419+ (void ) ttm_bo_wait (bo , false, false, true);
423420
424- spin_unlock ( & glob -> lru_lock );
425- ttm_bo_cleanup_memtype_use (bo );
421+ if (! bo -> sync_obj ) {
422+ put_count = ttm_bo_del_from_lru (bo );
426423
427- ttm_bo_list_ref_sub (bo , put_count , true);
424+ spin_unlock (& glob -> lru_lock );
425+ ttm_bo_cleanup_memtype_use (bo );
428426
429- return ;
430- }
431- if (bo -> sync_obj )
432- sync_obj = driver -> sync_obj_ref (bo -> sync_obj );
433- spin_unlock (& bdev -> fence_lock );
427+ ttm_bo_list_ref_sub (bo , put_count , true);
434428
435- if (!ret ) {
429+ return ;
430+ }
431+ sync_obj = driver -> sync_obj_ref (bo -> sync_obj );
436432
437433 /*
438434 * Make NO_EVICT bos immediately available to
@@ -481,7 +477,6 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo,
481477 int put_count ;
482478 int ret ;
483479
484- spin_lock (& bdev -> fence_lock );
485480 ret = ttm_bo_wait (bo , false, false, true);
486481
487482 if (ret && !no_wait_gpu ) {
@@ -493,7 +488,6 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo,
493488 * no new sync objects can be attached.
494489 */
495490 sync_obj = driver -> sync_obj_ref (bo -> sync_obj );
496- spin_unlock (& bdev -> fence_lock );
497491
498492 __ttm_bo_unreserve (bo );
499493 spin_unlock (& glob -> lru_lock );
@@ -523,11 +517,9 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo,
523517 * remove sync_obj with ttm_bo_wait, the wait should be
524518 * finished, and no new wait object should have been added.
525519 */
526- spin_lock (& bdev -> fence_lock );
527520 ret = ttm_bo_wait (bo , false, false, true);
528521 WARN_ON (ret );
529522 }
530- spin_unlock (& bdev -> fence_lock );
531523
532524 if (ret || unlikely (list_empty (& bo -> ddestroy ))) {
533525 __ttm_bo_unreserve (bo );
@@ -665,9 +657,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, bool interruptible,
665657 struct ttm_placement placement ;
666658 int ret = 0 ;
667659
668- spin_lock (& bdev -> fence_lock );
669660 ret = ttm_bo_wait (bo , false, interruptible , no_wait_gpu );
670- spin_unlock (& bdev -> fence_lock );
671661
672662 if (unlikely (ret != 0 )) {
673663 if (ret != - ERESTARTSYS ) {
@@ -958,7 +948,6 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
958948{
959949 int ret = 0 ;
960950 struct ttm_mem_reg mem ;
961- struct ttm_bo_device * bdev = bo -> bdev ;
962951
963952 lockdep_assert_held (& bo -> resv -> lock .base );
964953
@@ -967,9 +956,7 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
967956 * Have the driver move function wait for idle when necessary,
968957 * instead of doing it here.
969958 */
970- spin_lock (& bdev -> fence_lock );
971959 ret = ttm_bo_wait (bo , false, interruptible , no_wait_gpu );
972- spin_unlock (& bdev -> fence_lock );
973960 if (ret )
974961 return ret ;
975962 mem .num_pages = bo -> num_pages ;
@@ -1459,7 +1446,6 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
14591446 bdev -> glob = glob ;
14601447 bdev -> need_dma32 = need_dma32 ;
14611448 bdev -> val_seq = 0 ;
1462- spin_lock_init (& bdev -> fence_lock );
14631449 mutex_lock (& glob -> device_list_mutex );
14641450 list_add_tail (& bdev -> device_list , & glob -> device_list );
14651451 mutex_unlock (& glob -> device_list_mutex );
@@ -1517,7 +1503,6 @@ int ttm_bo_wait(struct ttm_buffer_object *bo,
15171503 bool lazy , bool interruptible , bool no_wait )
15181504{
15191505 struct ttm_bo_driver * driver = bo -> bdev -> driver ;
1520- struct ttm_bo_device * bdev = bo -> bdev ;
15211506 void * sync_obj ;
15221507 int ret = 0 ;
15231508
@@ -1526,53 +1511,33 @@ int ttm_bo_wait(struct ttm_buffer_object *bo,
15261511 if (likely (bo -> sync_obj == NULL ))
15271512 return 0 ;
15281513
1529- while (bo -> sync_obj ) {
1530-
1514+ if (bo -> sync_obj ) {
15311515 if (driver -> sync_obj_signaled (bo -> sync_obj )) {
1532- void * tmp_obj = bo -> sync_obj ;
1533- bo -> sync_obj = NULL ;
1516+ driver -> sync_obj_unref (& bo -> sync_obj );
15341517 clear_bit (TTM_BO_PRIV_FLAG_MOVING , & bo -> priv_flags );
1535- spin_unlock (& bdev -> fence_lock );
1536- driver -> sync_obj_unref (& tmp_obj );
1537- spin_lock (& bdev -> fence_lock );
1538- continue ;
1518+ return 0 ;
15391519 }
15401520
15411521 if (no_wait )
15421522 return - EBUSY ;
15431523
15441524 sync_obj = driver -> sync_obj_ref (bo -> sync_obj );
1545- spin_unlock (& bdev -> fence_lock );
15461525 ret = driver -> sync_obj_wait (sync_obj ,
15471526 lazy , interruptible );
1548- if (unlikely (ret != 0 )) {
1549- driver -> sync_obj_unref (& sync_obj );
1550- spin_lock (& bdev -> fence_lock );
1551- return ret ;
1552- }
1553- spin_lock (& bdev -> fence_lock );
1554- if (likely (bo -> sync_obj == sync_obj )) {
1555- void * tmp_obj = bo -> sync_obj ;
1556- bo -> sync_obj = NULL ;
1527+
1528+ if (likely (ret == 0 )) {
15571529 clear_bit (TTM_BO_PRIV_FLAG_MOVING ,
15581530 & bo -> priv_flags );
1559- spin_unlock (& bdev -> fence_lock );
1560- driver -> sync_obj_unref (& sync_obj );
1561- driver -> sync_obj_unref (& tmp_obj );
1562- spin_lock (& bdev -> fence_lock );
1563- } else {
1564- spin_unlock (& bdev -> fence_lock );
1565- driver -> sync_obj_unref (& sync_obj );
1566- spin_lock (& bdev -> fence_lock );
1531+ driver -> sync_obj_unref (& bo -> sync_obj );
15671532 }
1533+ driver -> sync_obj_unref (& sync_obj );
15681534 }
1569- return 0 ;
1535+ return ret ;
15701536}
15711537EXPORT_SYMBOL (ttm_bo_wait );
15721538
15731539int ttm_bo_synccpu_write_grab (struct ttm_buffer_object * bo , bool no_wait )
15741540{
1575- struct ttm_bo_device * bdev = bo -> bdev ;
15761541 int ret = 0 ;
15771542
15781543 /*
@@ -1582,9 +1547,7 @@ int ttm_bo_synccpu_write_grab(struct ttm_buffer_object *bo, bool no_wait)
15821547 ret = ttm_bo_reserve (bo , true, no_wait , false, NULL );
15831548 if (unlikely (ret != 0 ))
15841549 return ret ;
1585- spin_lock (& bdev -> fence_lock );
15861550 ret = ttm_bo_wait (bo , false, true, no_wait );
1587- spin_unlock (& bdev -> fence_lock );
15881551 if (likely (ret == 0 ))
15891552 atomic_inc (& bo -> cpu_writers );
15901553 ttm_bo_unreserve (bo );
@@ -1641,9 +1604,7 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink)
16411604 * Wait for GPU, then move to system cached.
16421605 */
16431606
1644- spin_lock (& bo -> bdev -> fence_lock );
16451607 ret = ttm_bo_wait (bo , false, false, false);
1646- spin_unlock (& bo -> bdev -> fence_lock );
16471608
16481609 if (unlikely (ret != 0 ))
16491610 goto out ;
0 commit comments