Skip to content

Commit 516198d

Browse files
Christian KönigChristianKoenigAMD
authored andcommitted
drm/i915: audit bo->resource usage v3
Make sure we can at least move and alloc TT objects without backing store. v2: clear the tt object even when no resource is allocated. v3: add Matthews changes for i915 as well. Signed-off-by: Christian König <[email protected]> Reviewed-by: Matthew Auld <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 51affef commit 516198d

File tree

2 files changed

+71
-12
lines changed

2 files changed

+71
-12
lines changed

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,6 @@ static struct ttm_tt *i915_ttm_tt_create(struct ttm_buffer_object *bo,
271271
{
272272
struct drm_i915_private *i915 = container_of(bo->bdev, typeof(*i915),
273273
bdev);
274-
struct ttm_resource_manager *man =
275-
ttm_manager_type(bo->bdev, bo->resource->mem_type);
276274
struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
277275
unsigned long ccs_pages = 0;
278276
enum ttm_caching caching;
@@ -286,8 +284,8 @@ static struct ttm_tt *i915_ttm_tt_create(struct ttm_buffer_object *bo,
286284
if (!i915_tt)
287285
return NULL;
288286

289-
if (obj->flags & I915_BO_ALLOC_CPU_CLEAR &&
290-
man->use_tt)
287+
if (obj->flags & I915_BO_ALLOC_CPU_CLEAR && (!bo->resource ||
288+
ttm_manager_type(bo->bdev, bo->resource->mem_type)->use_tt))
291289
page_flags |= TTM_TT_FLAG_ZERO_ALLOC;
292290

293291
caching = i915_ttm_select_tt_caching(obj);
@@ -1051,7 +1049,26 @@ static vm_fault_t vm_fault_ttm(struct vm_fault *vmf)
10511049
return VM_FAULT_SIGBUS;
10521050
}
10531051

1054-
if (!i915_ttm_resource_mappable(bo->resource)) {
1052+
/*
1053+
* This must be swapped out with shmem ttm_tt (pipeline-gutting).
1054+
* Calling ttm_bo_validate() here with TTM_PL_SYSTEM should only go as
1055+
* far as far doing a ttm_bo_move_null(), which should skip all the
1056+
* other junk.
1057+
*/
1058+
if (!bo->resource) {
1059+
struct ttm_operation_ctx ctx = {
1060+
.interruptible = true,
1061+
.no_wait_gpu = true, /* should be idle already */
1062+
};
1063+
1064+
GEM_BUG_ON(!bo->ttm || !(bo->ttm->page_flags & TTM_TT_FLAG_SWAPPED));
1065+
1066+
ret = ttm_bo_validate(bo, i915_ttm_sys_placement(), &ctx);
1067+
if (ret) {
1068+
dma_resv_unlock(bo->base.resv);
1069+
return VM_FAULT_SIGBUS;
1070+
}
1071+
} else if (!i915_ttm_resource_mappable(bo->resource)) {
10551072
int err = -ENODEV;
10561073
int i;
10571074

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

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,39 @@ void i915_ttm_adjust_gem_after_move(struct drm_i915_gem_object *obj)
103103
{
104104
struct ttm_buffer_object *bo = i915_gem_to_ttm(obj);
105105
unsigned int cache_level;
106+
unsigned int mem_flags;
106107
unsigned int i;
108+
int mem_type;
109+
110+
/*
111+
* We might have been purged (or swapped out) if the resource is NULL,
112+
* in which case the SYSTEM placement is the closest match to describe
113+
* the current domain. If the object is ever used in this state then we
114+
* will require moving it again.
115+
*/
116+
if (!bo->resource) {
117+
mem_flags = I915_BO_FLAG_STRUCT_PAGE;
118+
mem_type = I915_PL_SYSTEM;
119+
cache_level = I915_CACHE_NONE;
120+
} else {
121+
mem_flags = i915_ttm_cpu_maps_iomem(bo->resource) ? I915_BO_FLAG_IOMEM :
122+
I915_BO_FLAG_STRUCT_PAGE;
123+
mem_type = bo->resource->mem_type;
124+
cache_level = i915_ttm_cache_level(to_i915(bo->base.dev), bo->resource,
125+
bo->ttm);
126+
}
107127

108128
/*
109129
* If object was moved to an allowable region, update the object
110130
* region to consider it migrated. Note that if it's currently not
111131
* in an allowable region, it's evicted and we don't update the
112132
* object region.
113133
*/
114-
if (intel_region_to_ttm_type(obj->mm.region) != bo->resource->mem_type) {
134+
if (intel_region_to_ttm_type(obj->mm.region) != mem_type) {
115135
for (i = 0; i < obj->mm.n_placements; ++i) {
116136
struct intel_memory_region *mr = obj->mm.placements[i];
117137

118-
if (intel_region_to_ttm_type(mr) == bo->resource->mem_type &&
138+
if (intel_region_to_ttm_type(mr) == mem_type &&
119139
mr != obj->mm.region) {
120140
i915_gem_object_release_memory_region(obj);
121141
i915_gem_object_init_memory_region(obj, mr);
@@ -125,12 +145,8 @@ void i915_ttm_adjust_gem_after_move(struct drm_i915_gem_object *obj)
125145
}
126146

127147
obj->mem_flags &= ~(I915_BO_FLAG_STRUCT_PAGE | I915_BO_FLAG_IOMEM);
148+
obj->mem_flags |= mem_flags;
128149

129-
obj->mem_flags |= i915_ttm_cpu_maps_iomem(bo->resource) ? I915_BO_FLAG_IOMEM :
130-
I915_BO_FLAG_STRUCT_PAGE;
131-
132-
cache_level = i915_ttm_cache_level(to_i915(bo->base.dev), bo->resource,
133-
bo->ttm);
134150
i915_gem_object_set_cache_coherency(obj, cache_level);
135151
}
136152

@@ -565,6 +581,32 @@ int i915_ttm_move(struct ttm_buffer_object *bo, bool evict,
565581
return 0;
566582
}
567583

584+
if (!bo->resource) {
585+
if (dst_mem->mem_type != TTM_PL_SYSTEM) {
586+
hop->mem_type = TTM_PL_SYSTEM;
587+
hop->flags = TTM_PL_FLAG_TEMPORARY;
588+
return -EMULTIHOP;
589+
}
590+
591+
/*
592+
* This is only reached when first creating the object, or if
593+
* the object was purged or swapped out (pipeline-gutting). For
594+
* the former we can safely skip all of the below since we are
595+
* only using a dummy SYSTEM placement here. And with the latter
596+
* we will always re-enter here with bo->resource set correctly
597+
* (as per the above), since this is part of a multi-hop
598+
* sequence, where at the end we can do the move for real.
599+
*
600+
* The special case here is when the dst_mem is TTM_PL_SYSTEM,
601+
* which doens't require any kind of move, so it should be safe
602+
* to skip all the below and call ttm_bo_move_null() here, where
603+
* the caller in __i915_ttm_get_pages() will take care of the
604+
* rest, since we should have a valid ttm_tt.
605+
*/
606+
ttm_bo_move_null(bo, dst_mem);
607+
return 0;
608+
}
609+
568610
ret = i915_ttm_move_notify(bo);
569611
if (ret)
570612
return ret;

0 commit comments

Comments
 (0)