Skip to content

Commit ff7c60c

Browse files
danvetairlied
authored andcommitted
drm/ttm: fix fence locking in ttm_buffer_object_transfer, 2nd try
This fixes up commit e8e8962 Author: Daniel Vetter <daniel.vetter@ffwll.ch> Date: Tue Dec 18 22:25:11 2012 +0100 drm/ttm: fix fence locking in ttm_buffer_object_transfer which leaves behind a might_sleep in atomic context, since the fence_lock spinlock is held over a kmalloc(GFP_KERNEL) call. The fix is to revert the above commit and only take the lock where we need it, around the call to ->sync_obj_ref. v2: Fixup things noticed by Maarten Lankhorst: - Brown paper bag locking bug. - No need for kzalloc if we clear the entire thing on the next line. - check for bo->sync_obj (totally unlikely race, but still someone else could have snuck in) and clear fbo->sync_obj if it's cleared already. Reported-by: Dave Airlie <airlied@gmail.com> Cc: Jerome Glisse <jglisse@redhat.com> Cc: Maarten Lankhorst <maarten.lankhorst@canonical.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent 6bacaa9 commit ff7c60c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

drivers/gpu/drm/ttm/ttm_bo_util.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
429429
struct ttm_bo_device *bdev = bo->bdev;
430430
struct ttm_bo_driver *driver = bdev->driver;
431431

432-
fbo = kzalloc(sizeof(*fbo), GFP_KERNEL);
432+
fbo = kmalloc(sizeof(*fbo), GFP_KERNEL);
433433
if (!fbo)
434434
return -ENOMEM;
435435

@@ -448,7 +448,12 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
448448
fbo->vm_node = NULL;
449449
atomic_set(&fbo->cpu_writers, 0);
450450

451-
fbo->sync_obj = driver->sync_obj_ref(bo->sync_obj);
451+
spin_lock(&bdev->fence_lock);
452+
if (bo->sync_obj)
453+
fbo->sync_obj = driver->sync_obj_ref(bo->sync_obj);
454+
else
455+
fbo->sync_obj = NULL;
456+
spin_unlock(&bdev->fence_lock);
452457
kref_init(&fbo->list_kref);
453458
kref_init(&fbo->kref);
454459
fbo->destroy = &ttm_transfered_destroy;
@@ -661,13 +666,11 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
661666
*/
662667

663668
set_bit(TTM_BO_PRIV_FLAG_MOVING, &bo->priv_flags);
664-
665-
/* ttm_buffer_object_transfer accesses bo->sync_obj */
666-
ret = ttm_buffer_object_transfer(bo, &ghost_obj);
667669
spin_unlock(&bdev->fence_lock);
668670
if (tmp_obj)
669671
driver->sync_obj_unref(&tmp_obj);
670672

673+
ret = ttm_buffer_object_transfer(bo, &ghost_obj);
671674
if (ret)
672675
return ret;
673676

0 commit comments

Comments
 (0)