Commit 58c7ee06 authored by Matthew Auld's avatar Matthew Auld Committed by Christian König

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: 516198d3 ("drm/i915: audit bo->resource usage v3")
Signed-off-by: default avatarMatthew Auld <matthew.auld@intel.com>
Cc: Nirmoy Das <nirmoy.das@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230130101230.25347-2-matthew.auld@intel.comReviewed-by: default avatarNirmoy Das <nirmoy.das@intel.com>
Reviewed-by: default avatarAndrzej Hajda <andrzej.hajda@intel.com>
Acked-by: default avatarChristian König <ckoenig.leichtzumerken@gmail.com>
Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
parent fde789e8
...@@ -472,7 +472,7 @@ static int i915_ttm_shrink(struct drm_i915_gem_object *obj, unsigned int flags) ...@@ -472,7 +472,7 @@ static int i915_ttm_shrink(struct drm_i915_gem_object *obj, unsigned int flags)
struct ttm_placement place = {}; struct ttm_placement place = {};
int ret; int ret;
if (!bo->ttm || bo->resource->mem_type != TTM_PL_SYSTEM) if (!bo->ttm || i915_ttm_cpu_maps_iomem(bo->resource))
return 0; return 0;
GEM_BUG_ON(!i915_tt->is_shmem); GEM_BUG_ON(!i915_tt->is_shmem);
...@@ -511,7 +511,13 @@ static void i915_ttm_delete_mem_notify(struct ttm_buffer_object *bo) ...@@ -511,7 +511,13 @@ static void i915_ttm_delete_mem_notify(struct ttm_buffer_object *bo)
{ {
struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo); struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
if (bo->resource && !i915_ttm_is_ghost_object(bo)) { /*
* This gets called twice by ttm, so long as we have a ttm resource or
* ttm_tt then we can still safely call this. Due to pipeline-gutting,
* we maybe have NULL bo->resource, but in that case we should always
* have a ttm alive (like if the pages are swapped out).
*/
if ((bo->resource || bo->ttm) && !i915_ttm_is_ghost_object(bo)) {
__i915_gem_object_pages_fini(obj); __i915_gem_object_pages_fini(obj);
i915_ttm_free_cached_io_rsgt(obj); i915_ttm_free_cached_io_rsgt(obj);
} }
......
...@@ -98,7 +98,7 @@ static inline bool i915_ttm_gtt_binds_lmem(struct ttm_resource *mem) ...@@ -98,7 +98,7 @@ static inline bool i915_ttm_gtt_binds_lmem(struct ttm_resource *mem)
static inline bool i915_ttm_cpu_maps_iomem(struct ttm_resource *mem) static inline bool i915_ttm_cpu_maps_iomem(struct ttm_resource *mem)
{ {
/* Once / if we support GGTT, this is also false for cached ttm_tts */ /* Once / if we support GGTT, this is also false for cached ttm_tts */
return mem->mem_type != I915_PL_SYSTEM; return mem && mem->mem_type != I915_PL_SYSTEM;
} }
bool i915_ttm_resource_mappable(struct ttm_resource *res); bool i915_ttm_resource_mappable(struct ttm_resource *res);
......
...@@ -711,6 +711,10 @@ int i915_gem_obj_copy_ttm(struct drm_i915_gem_object *dst, ...@@ -711,6 +711,10 @@ int i915_gem_obj_copy_ttm(struct drm_i915_gem_object *dst,
assert_object_held(dst); assert_object_held(dst);
assert_object_held(src); assert_object_held(src);
if (GEM_WARN_ON(!src_bo->resource || !dst_bo->resource))
return -EINVAL;
i915_deps_init(&deps, GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN); i915_deps_init(&deps, GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN);
ret = dma_resv_reserve_fences(src_bo->base.resv, 1); ret = dma_resv_reserve_fences(src_bo->base.resv, 1);
......
...@@ -53,7 +53,7 @@ static int i915_ttm_backup(struct i915_gem_apply_to_region *apply, ...@@ -53,7 +53,7 @@ static int i915_ttm_backup(struct i915_gem_apply_to_region *apply,
unsigned int flags; unsigned int flags;
int err = 0; int err = 0;
if (bo->resource->mem_type == I915_PL_SYSTEM || obj->ttm.backup) if (!i915_ttm_cpu_maps_iomem(bo->resource) || obj->ttm.backup)
return 0; return 0;
if (pm_apply->allow_gpu && i915_gem_object_evictable(obj)) if (pm_apply->allow_gpu && i915_gem_object_evictable(obj))
...@@ -187,6 +187,9 @@ static int i915_ttm_restore(struct i915_gem_apply_to_region *apply, ...@@ -187,6 +187,9 @@ static int i915_ttm_restore(struct i915_gem_apply_to_region *apply,
return err; return err;
/* Content may have been swapped. */ /* Content may have been swapped. */
if (!backup_bo->resource)
err = ttm_bo_validate(backup_bo, i915_ttm_sys_placement(), &ctx);
if (!err)
err = ttm_tt_populate(backup_bo->bdev, backup_bo->ttm, &ctx); err = ttm_tt_populate(backup_bo->bdev, backup_bo->ttm, &ctx);
if (!err) { if (!err) {
err = i915_gem_obj_copy_ttm(obj, backup, pm_apply->allow_gpu, err = i915_gem_obj_copy_ttm(obj, backup, pm_apply->allow_gpu,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment