Skip to content

Commit 58c7ee0

Browse files
matt-auldChristianKoenigAMD
authored andcommitted
drm/i915/ttm: audit remaining bo->resource
In the near future TTM will have NULL bo->resource when the object is initially created, plus after calling into pipeline-gutting. Try to handle the remaining cases. In practice NULL bo->resource should be taken to mean swapped-out or purged object. v2 (Andrzej): - Rather make i915_ttm_cpu_maps_iomem() return false with NULL resource. References: 516198d ("drm/i915: audit bo->resource usage v3") Signed-off-by: Matthew Auld <[email protected]> Cc: Nirmoy Das <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Reviewed-by: Nirmoy Das <[email protected]> Reviewed-by: Andrzej Hajda <[email protected]> Acked-by: Christian König <[email protected]> Signed-off-by: Christian König <[email protected]>
1 parent fde789e commit 58c7ee0

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

drivers/gpu/drm/i915/gem/i915_gem_ttm.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ static int i915_ttm_shrink(struct drm_i915_gem_object *obj, unsigned int flags)
472472
struct ttm_placement place = {};
473473
int ret;
474474

475-
if (!bo->ttm || bo->resource->mem_type != TTM_PL_SYSTEM)
475+
if (!bo->ttm || i915_ttm_cpu_maps_iomem(bo->resource))
476476
return 0;
477477

478478
GEM_BUG_ON(!i915_tt->is_shmem);
@@ -511,7 +511,13 @@ static void i915_ttm_delete_mem_notify(struct ttm_buffer_object *bo)
511511
{
512512
struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
513513

514-
if (bo->resource && !i915_ttm_is_ghost_object(bo)) {
514+
/*
515+
* This gets called twice by ttm, so long as we have a ttm resource or
516+
* ttm_tt then we can still safely call this. Due to pipeline-gutting,
517+
* we maybe have NULL bo->resource, but in that case we should always
518+
* have a ttm alive (like if the pages are swapped out).
519+
*/
520+
if ((bo->resource || bo->ttm) && !i915_ttm_is_ghost_object(bo)) {
515521
__i915_gem_object_pages_fini(obj);
516522
i915_ttm_free_cached_io_rsgt(obj);
517523
}

drivers/gpu/drm/i915/gem/i915_gem_ttm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static inline bool i915_ttm_gtt_binds_lmem(struct ttm_resource *mem)
9898
static inline bool i915_ttm_cpu_maps_iomem(struct ttm_resource *mem)
9999
{
100100
/* Once / if we support GGTT, this is also false for cached ttm_tts */
101-
return mem->mem_type != I915_PL_SYSTEM;
101+
return mem && mem->mem_type != I915_PL_SYSTEM;
102102
}
103103

104104
bool i915_ttm_resource_mappable(struct ttm_resource *res);

drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,10 @@ int i915_gem_obj_copy_ttm(struct drm_i915_gem_object *dst,
711711

712712
assert_object_held(dst);
713713
assert_object_held(src);
714+
715+
if (GEM_WARN_ON(!src_bo->resource || !dst_bo->resource))
716+
return -EINVAL;
717+
714718
i915_deps_init(&deps, GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN);
715719

716720
ret = dma_resv_reserve_fences(src_bo->base.resv, 1);

drivers/gpu/drm/i915/gem/i915_gem_ttm_pm.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static int i915_ttm_backup(struct i915_gem_apply_to_region *apply,
5353
unsigned int flags;
5454
int err = 0;
5555

56-
if (bo->resource->mem_type == I915_PL_SYSTEM || obj->ttm.backup)
56+
if (!i915_ttm_cpu_maps_iomem(bo->resource) || obj->ttm.backup)
5757
return 0;
5858

5959
if (pm_apply->allow_gpu && i915_gem_object_evictable(obj))
@@ -187,7 +187,10 @@ static int i915_ttm_restore(struct i915_gem_apply_to_region *apply,
187187
return err;
188188

189189
/* Content may have been swapped. */
190-
err = ttm_tt_populate(backup_bo->bdev, backup_bo->ttm, &ctx);
190+
if (!backup_bo->resource)
191+
err = ttm_bo_validate(backup_bo, i915_ttm_sys_placement(), &ctx);
192+
if (!err)
193+
err = ttm_tt_populate(backup_bo->bdev, backup_bo->ttm, &ctx);
191194
if (!err) {
192195
err = i915_gem_obj_copy_ttm(obj, backup, pm_apply->allow_gpu,
193196
false);

0 commit comments

Comments
 (0)