Skip to content

Commit fc357bc

Browse files
drm/ttm: fix pipelined gutting v2
We need to make sure to allocate the sys_mem resource before the point of no return. v2: add missing return value checking, also handle idle case Signed-off-by: Christian König <[email protected]> Reviewed-by: Thomas Hellström <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 72db41c commit fc357bc

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

drivers/gpu/drm/ttm/ttm_bo_util.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -582,24 +582,30 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo)
582582
{
583583
static const struct ttm_place sys_mem = { .mem_type = TTM_PL_SYSTEM };
584584
struct ttm_buffer_object *ghost;
585+
struct ttm_resource *sys_res;
585586
struct ttm_tt *ttm;
586587
int ret;
587588

589+
ret = ttm_resource_alloc(bo, &sys_mem, &sys_res);
590+
if (ret)
591+
return ret;
592+
588593
/* If already idle, no need for ghost object dance. */
589594
ret = ttm_bo_wait(bo, false, true);
590595
if (ret != -EBUSY) {
591596
if (!bo->ttm) {
592597
/* See comment below about clearing. */
593598
ret = ttm_tt_create(bo, true);
594599
if (ret)
595-
return ret;
600+
goto error_free_sys_mem;
596601
} else {
597602
ttm_tt_unpopulate(bo->bdev, bo->ttm);
598603
if (bo->type == ttm_bo_type_device)
599604
ttm_tt_mark_for_clear(bo->ttm);
600605
}
601606
ttm_resource_free(bo, &bo->resource);
602-
return ttm_resource_alloc(bo, &sys_mem, &bo->resource);
607+
ttm_bo_assign_mem(bo, sys_res);
608+
return 0;
603609
}
604610

605611
/*
@@ -615,13 +621,11 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo)
615621
ret = ttm_tt_create(bo, true);
616622
swap(bo->ttm, ttm);
617623
if (ret)
618-
return ret;
624+
goto error_free_sys_mem;
619625

620626
ret = ttm_buffer_object_transfer(bo, &ghost);
621-
if (ret) {
622-
ttm_tt_destroy(bo->bdev, ttm);
623-
return ret;
624-
}
627+
if (ret)
628+
goto error_destroy_tt;
625629

626630
ret = dma_resv_copy_fences(&ghost->base._resv, bo->base.resv);
627631
/* Last resort, wait for the BO to be idle when we are OOM */
@@ -631,6 +635,14 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo)
631635
dma_resv_unlock(&ghost->base._resv);
632636
ttm_bo_put(ghost);
633637
bo->ttm = ttm;
638+
bo->resource = NULL;
639+
ttm_bo_assign_mem(bo, sys_res);
640+
return 0;
641+
642+
error_destroy_tt:
643+
ttm_tt_destroy(bo->bdev, ttm);
634644

635-
return ttm_resource_alloc(bo, &sys_mem, &bo->resource);
645+
error_free_sys_mem:
646+
ttm_resource_free(bo, &sys_res);
647+
return ret;
636648
}

0 commit comments

Comments
 (0)