1 // SPDX-License-Identifier: MIT
3 * Copyright © 2021 Intel Corporation
6 #include <drm/ttm/ttm_tt.h>
10 #include "intel_memory_region.h"
11 #include "intel_region_ttm.h"
13 #include "gem/i915_gem_object.h"
14 #include "gem/i915_gem_region.h"
15 #include "gem/i915_gem_ttm.h"
16 #include "gem/i915_gem_ttm_move.h"
18 #include "gt/intel_engine_pm.h"
19 #include "gt/intel_gt.h"
20 #include "gt/intel_migrate.h"
23 * DOC: Selftest failure modes for failsafe migration:
25 * For fail_gpu_migration, the gpu blit scheduled is always a clear blit
26 * rather than a copy blit, and then we force the failure paths as if
27 * the blit fence returned an error.
29 * For fail_work_allocation we fail the kmalloc of the async worker, we
30 * sync the gpu blit. If it then fails, or fail_gpu_migration is set to
31 * true, then a memcpy operation is performed sync.
33 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
34 static bool fail_gpu_migration;
35 static bool fail_work_allocation;
36 static bool ban_memcpy;
38 void i915_ttm_migrate_set_failure_modes(bool gpu_migration,
41 fail_gpu_migration = gpu_migration;
42 fail_work_allocation = work_allocation;
45 void i915_ttm_migrate_set_ban_memcpy(bool ban)
51 static enum i915_cache_level
52 i915_ttm_cache_level(struct drm_i915_private *i915, struct ttm_resource *res,
55 return ((HAS_LLC(i915) || HAS_SNOOP(i915)) &&
56 !i915_ttm_gtt_binds_lmem(res) &&
57 ttm->caching == ttm_cached) ? I915_CACHE_LLC :
61 static struct intel_memory_region *
62 i915_ttm_region(struct ttm_device *bdev, int ttm_mem_type)
64 struct drm_i915_private *i915 = container_of(bdev, typeof(*i915), bdev);
66 /* There's some room for optimization here... */
67 GEM_BUG_ON(ttm_mem_type != I915_PL_SYSTEM &&
68 ttm_mem_type < I915_PL_LMEM0);
69 if (ttm_mem_type == I915_PL_SYSTEM)
70 return intel_memory_region_lookup(i915, INTEL_MEMORY_SYSTEM,
73 return intel_memory_region_lookup(i915, INTEL_MEMORY_LOCAL,
74 ttm_mem_type - I915_PL_LMEM0);
78 * i915_ttm_adjust_domains_after_move - Adjust the GEM domains after a
80 * @obj: The gem object
82 void i915_ttm_adjust_domains_after_move(struct drm_i915_gem_object *obj)
84 struct ttm_buffer_object *bo = i915_gem_to_ttm(obj);
86 if (i915_ttm_cpu_maps_iomem(bo->resource) || bo->ttm->caching != ttm_cached) {
87 obj->write_domain = I915_GEM_DOMAIN_WC;
88 obj->read_domains = I915_GEM_DOMAIN_WC;
90 obj->write_domain = I915_GEM_DOMAIN_CPU;
91 obj->read_domains = I915_GEM_DOMAIN_CPU;
96 * i915_ttm_adjust_gem_after_move - Adjust the GEM state after a TTM move
97 * @obj: The gem object
99 * Adjusts the GEM object's region, mem_flags and cache coherency after a
102 void i915_ttm_adjust_gem_after_move(struct drm_i915_gem_object *obj)
104 struct ttm_buffer_object *bo = i915_gem_to_ttm(obj);
105 unsigned int cache_level;
106 unsigned int mem_flags;
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.
117 mem_flags = I915_BO_FLAG_STRUCT_PAGE;
118 mem_type = I915_PL_SYSTEM;
119 cache_level = I915_CACHE_NONE;
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,
129 * If object was moved to an allowable region, update the object
130 * region to consider it migrated. Note that if it's currently not
131 * in an allowable region, it's evicted and we don't update the
134 if (intel_region_to_ttm_type(obj->mm.region) != mem_type) {
135 for (i = 0; i < obj->mm.n_placements; ++i) {
136 struct intel_memory_region *mr = obj->mm.placements[i];
138 if (intel_region_to_ttm_type(mr) == mem_type &&
139 mr != obj->mm.region) {
140 i915_gem_object_release_memory_region(obj);
141 i915_gem_object_init_memory_region(obj, mr);
147 obj->mem_flags &= ~(I915_BO_FLAG_STRUCT_PAGE | I915_BO_FLAG_IOMEM);
148 obj->mem_flags |= mem_flags;
150 i915_gem_object_set_cache_coherency(obj, cache_level);
154 * i915_ttm_move_notify - Prepare an object for move
155 * @bo: The ttm buffer object.
157 * This function prepares an object for move by removing all GPU bindings,
158 * removing all CPU mapings and finally releasing the pages sg-table.
160 * Return: 0 if successful, negative error code on error.
162 int i915_ttm_move_notify(struct ttm_buffer_object *bo)
164 struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
168 * Note: The async unbinding here will actually transform the
169 * blocking wait for unbind into a wait before finally submitting
170 * evict / migration blit and thus stall the migration timeline
171 * which may not be good for overall throughput. We should make
172 * sure we await the unbind fences *after* the migration blit
173 * instead of *before* as we currently do.
175 ret = i915_gem_object_unbind(obj, I915_GEM_OBJECT_UNBIND_ACTIVE |
176 I915_GEM_OBJECT_UNBIND_ASYNC);
180 ret = __i915_gem_object_put_pages(obj);
187 static struct dma_fence *i915_ttm_accel_move(struct ttm_buffer_object *bo,
189 struct ttm_resource *dst_mem,
190 struct ttm_tt *dst_ttm,
191 struct sg_table *dst_st,
192 const struct i915_deps *deps)
194 struct drm_i915_private *i915 = container_of(bo->bdev, typeof(*i915),
196 struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
197 struct i915_request *rq;
198 struct ttm_tt *src_ttm = bo->ttm;
199 enum i915_cache_level src_level, dst_level;
202 if (!to_gt(i915)->migrate.context || intel_gt_is_wedged(to_gt(i915)))
203 return ERR_PTR(-EINVAL);
205 /* With fail_gpu_migration, we always perform a GPU clear. */
206 if (I915_SELFTEST_ONLY(fail_gpu_migration))
209 dst_level = i915_ttm_cache_level(i915, dst_mem, dst_ttm);
211 if (bo->type == ttm_bo_type_kernel &&
212 !I915_SELFTEST_ONLY(fail_gpu_migration))
213 return ERR_PTR(-EINVAL);
215 intel_engine_pm_get(to_gt(i915)->migrate.context->engine);
216 ret = intel_context_migrate_clear(to_gt(i915)->migrate.context, deps,
217 dst_st->sgl, dst_level,
218 i915_ttm_gtt_binds_lmem(dst_mem),
221 struct i915_refct_sgt *src_rsgt =
222 i915_ttm_resource_get_st(obj, bo->resource);
224 if (IS_ERR(src_rsgt))
225 return ERR_CAST(src_rsgt);
227 src_level = i915_ttm_cache_level(i915, bo->resource, src_ttm);
228 intel_engine_pm_get(to_gt(i915)->migrate.context->engine);
229 ret = intel_context_migrate_copy(to_gt(i915)->migrate.context,
230 deps, src_rsgt->table.sgl,
232 i915_ttm_gtt_binds_lmem(bo->resource),
233 dst_st->sgl, dst_level,
234 i915_ttm_gtt_binds_lmem(dst_mem),
237 i915_refct_sgt_put(src_rsgt);
240 intel_engine_pm_put(to_gt(i915)->migrate.context->engine);
243 i915_request_wait(rq, 0, MAX_SCHEDULE_TIMEOUT);
244 i915_request_put(rq);
247 return ret ? ERR_PTR(ret) : &rq->fence;
251 * struct i915_ttm_memcpy_arg - argument for the bo memcpy functionality.
252 * @_dst_iter: Storage space for the destination kmap iterator.
253 * @_src_iter: Storage space for the source kmap iterator.
254 * @dst_iter: Pointer to the destination kmap iterator.
255 * @src_iter: Pointer to the source kmap iterator.
256 * @clear: Whether to clear instead of copy.
257 * @src_rsgt: Refcounted scatter-gather list of source memory.
258 * @dst_rsgt: Refcounted scatter-gather list of destination memory.
260 struct i915_ttm_memcpy_arg {
262 struct ttm_kmap_iter_tt tt;
263 struct ttm_kmap_iter_iomap io;
266 struct ttm_kmap_iter *dst_iter;
267 struct ttm_kmap_iter *src_iter;
268 unsigned long num_pages;
270 struct i915_refct_sgt *src_rsgt;
271 struct i915_refct_sgt *dst_rsgt;
275 * struct i915_ttm_memcpy_work - Async memcpy worker under a dma-fence.
276 * @fence: The dma-fence.
277 * @work: The work struct use for the memcpy work.
278 * @lock: The fence lock. Not used to protect anything else ATM.
279 * @irq_work: Low latency worker to signal the fence since it can't be done
280 * from the callback for lockdep reasons.
281 * @cb: Callback for the accelerated migration fence.
282 * @arg: The argument for the memcpy functionality.
283 * @i915: The i915 pointer.
284 * @obj: The GEM object.
285 * @memcpy_allowed: Instead of processing the @arg, and falling back to memcpy
286 * or memset, we wedge the device and set the @obj unknown_state, to prevent
287 * further access to the object with the CPU or GPU. On some devices we might
288 * only be permitted to use the blitter engine for such operations.
290 struct i915_ttm_memcpy_work {
291 struct dma_fence fence;
292 struct work_struct work;
294 struct irq_work irq_work;
295 struct dma_fence_cb cb;
296 struct i915_ttm_memcpy_arg arg;
297 struct drm_i915_private *i915;
298 struct drm_i915_gem_object *obj;
302 static void i915_ttm_move_memcpy(struct i915_ttm_memcpy_arg *arg)
304 ttm_move_memcpy(arg->clear, arg->num_pages,
305 arg->dst_iter, arg->src_iter);
308 static void i915_ttm_memcpy_init(struct i915_ttm_memcpy_arg *arg,
309 struct ttm_buffer_object *bo, bool clear,
310 struct ttm_resource *dst_mem,
311 struct ttm_tt *dst_ttm,
312 struct i915_refct_sgt *dst_rsgt)
314 struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
315 struct intel_memory_region *dst_reg, *src_reg;
317 dst_reg = i915_ttm_region(bo->bdev, dst_mem->mem_type);
318 src_reg = i915_ttm_region(bo->bdev, bo->resource->mem_type);
319 GEM_BUG_ON(!dst_reg || !src_reg);
321 arg->dst_iter = !i915_ttm_cpu_maps_iomem(dst_mem) ?
322 ttm_kmap_iter_tt_init(&arg->_dst_iter.tt, dst_ttm) :
323 ttm_kmap_iter_iomap_init(&arg->_dst_iter.io, &dst_reg->iomap,
324 &dst_rsgt->table, dst_reg->region.start);
326 arg->src_iter = !i915_ttm_cpu_maps_iomem(bo->resource) ?
327 ttm_kmap_iter_tt_init(&arg->_src_iter.tt, bo->ttm) :
328 ttm_kmap_iter_iomap_init(&arg->_src_iter.io, &src_reg->iomap,
329 &obj->ttm.cached_io_rsgt->table,
330 src_reg->region.start);
332 arg->num_pages = bo->base.size >> PAGE_SHIFT;
334 arg->dst_rsgt = i915_refct_sgt_get(dst_rsgt);
335 arg->src_rsgt = clear ? NULL :
336 i915_ttm_resource_get_st(obj, bo->resource);
339 static void i915_ttm_memcpy_release(struct i915_ttm_memcpy_arg *arg)
341 i915_refct_sgt_put(arg->src_rsgt);
342 i915_refct_sgt_put(arg->dst_rsgt);
345 static void __memcpy_work(struct work_struct *work)
347 struct i915_ttm_memcpy_work *copy_work =
348 container_of(work, typeof(*copy_work), work);
349 struct i915_ttm_memcpy_arg *arg = ©_work->arg;
353 * FIXME: We need to take a closer look here. We should be able to plonk
354 * this into the fence critical section.
356 if (!copy_work->memcpy_allowed) {
360 for_each_gt(gt, copy_work->i915, id)
361 intel_gt_set_wedged(gt);
364 cookie = dma_fence_begin_signalling();
366 if (copy_work->memcpy_allowed) {
367 i915_ttm_move_memcpy(arg);
370 * Prevent further use of the object. Any future GTT binding or
371 * CPU access is not allowed once we signal the fence. Outside
372 * of the fence critical section, we then also then wedge the gpu
373 * to indicate the device is not functional.
375 * The below dma_fence_signal() is our write-memory-barrier.
377 copy_work->obj->mm.unknown_state = true;
380 dma_fence_end_signalling(cookie);
382 dma_fence_signal(©_work->fence);
384 i915_ttm_memcpy_release(arg);
385 i915_gem_object_put(copy_work->obj);
386 dma_fence_put(©_work->fence);
389 static void __memcpy_irq_work(struct irq_work *irq_work)
391 struct i915_ttm_memcpy_work *copy_work =
392 container_of(irq_work, typeof(*copy_work), irq_work);
393 struct i915_ttm_memcpy_arg *arg = ©_work->arg;
395 dma_fence_signal(©_work->fence);
396 i915_ttm_memcpy_release(arg);
397 i915_gem_object_put(copy_work->obj);
398 dma_fence_put(©_work->fence);
401 static void __memcpy_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
403 struct i915_ttm_memcpy_work *copy_work =
404 container_of(cb, typeof(*copy_work), cb);
406 if (unlikely(fence->error || I915_SELFTEST_ONLY(fail_gpu_migration))) {
407 INIT_WORK(©_work->work, __memcpy_work);
408 queue_work(system_unbound_wq, ©_work->work);
410 init_irq_work(©_work->irq_work, __memcpy_irq_work);
411 irq_work_queue(©_work->irq_work);
415 static const char *get_driver_name(struct dma_fence *fence)
417 return "i915_ttm_memcpy_work";
420 static const char *get_timeline_name(struct dma_fence *fence)
425 static const struct dma_fence_ops dma_fence_memcpy_ops = {
426 .get_driver_name = get_driver_name,
427 .get_timeline_name = get_timeline_name,
430 static struct dma_fence *
431 i915_ttm_memcpy_work_arm(struct i915_ttm_memcpy_work *work,
432 struct dma_fence *dep)
436 spin_lock_init(&work->lock);
437 dma_fence_init(&work->fence, &dma_fence_memcpy_ops, &work->lock, 0, 0);
438 dma_fence_get(&work->fence);
439 ret = dma_fence_add_callback(dep, &work->cb, __memcpy_cb);
442 dma_fence_wait(dep, false);
444 return ERR_PTR(I915_SELFTEST_ONLY(fail_gpu_migration) ? -EINVAL :
451 static bool i915_ttm_memcpy_allowed(struct ttm_buffer_object *bo,
452 struct ttm_resource *dst_mem)
454 if (i915_gem_object_needs_ccs_pages(i915_ttm_to_gem(bo)))
457 if (!(i915_ttm_resource_mappable(bo->resource) &&
458 i915_ttm_resource_mappable(dst_mem)))
461 return I915_SELFTEST_ONLY(ban_memcpy) ? false : true;
464 static struct dma_fence *
465 __i915_ttm_move(struct ttm_buffer_object *bo,
466 const struct ttm_operation_ctx *ctx, bool clear,
467 struct ttm_resource *dst_mem, struct ttm_tt *dst_ttm,
468 struct i915_refct_sgt *dst_rsgt, bool allow_accel,
469 const struct i915_deps *move_deps)
471 const bool memcpy_allowed = i915_ttm_memcpy_allowed(bo, dst_mem);
472 struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
473 struct drm_i915_private *i915 = to_i915(bo->base.dev);
474 struct i915_ttm_memcpy_work *copy_work = NULL;
475 struct i915_ttm_memcpy_arg _arg, *arg = &_arg;
476 struct dma_fence *fence = ERR_PTR(-EINVAL);
479 fence = i915_ttm_accel_move(bo, clear, dst_mem, dst_ttm,
480 &dst_rsgt->table, move_deps);
483 * We only need to intercept the error when moving to lmem.
484 * When moving to system, TTM or shmem will provide us with
487 if (!IS_ERR(fence) && !i915_ttm_gtt_binds_lmem(dst_mem) &&
488 !I915_SELFTEST_ONLY(fail_gpu_migration ||
489 fail_work_allocation))
493 /* If we've scheduled gpu migration. Try to arm error intercept. */
494 if (!IS_ERR(fence)) {
495 struct dma_fence *dep = fence;
497 if (!I915_SELFTEST_ONLY(fail_work_allocation))
498 copy_work = kzalloc(sizeof(*copy_work), GFP_KERNEL);
501 copy_work->i915 = i915;
502 copy_work->memcpy_allowed = memcpy_allowed;
503 copy_work->obj = i915_gem_object_get(obj);
504 arg = ©_work->arg;
506 i915_ttm_memcpy_init(arg, bo, clear, dst_mem,
509 fence = i915_ttm_memcpy_work_arm(copy_work, dep);
511 dma_fence_wait(dep, false);
512 fence = ERR_PTR(I915_SELFTEST_ONLY(fail_gpu_migration) ?
513 -EINVAL : fence->error);
520 int err = PTR_ERR(fence);
522 if (err == -EINTR || err == -ERESTARTSYS || err == -EAGAIN)
526 err = i915_deps_sync(move_deps, ctx);
532 /* Error intercept failed or no accelerated migration to start with */
534 if (memcpy_allowed) {
536 i915_ttm_memcpy_init(arg, bo, clear, dst_mem, dst_ttm,
538 i915_ttm_move_memcpy(arg);
539 i915_ttm_memcpy_release(arg);
542 i915_gem_object_put(copy_work->obj);
545 return memcpy_allowed ? NULL : ERR_PTR(-EIO);
547 if (!fence && copy_work) {
548 i915_ttm_memcpy_release(arg);
549 i915_gem_object_put(copy_work->obj);
557 * i915_ttm_move - The TTM move callback used by i915.
558 * @bo: The buffer object.
559 * @evict: Whether this is an eviction.
560 * @dst_mem: The destination ttm resource.
561 * @hop: If we need multihop, what temporary memory type to move to.
563 * Return: 0 if successful, negative error code otherwise.
565 int i915_ttm_move(struct ttm_buffer_object *bo, bool evict,
566 struct ttm_operation_ctx *ctx,
567 struct ttm_resource *dst_mem,
568 struct ttm_place *hop)
570 struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
571 struct ttm_resource_manager *dst_man =
572 ttm_manager_type(bo->bdev, dst_mem->mem_type);
573 struct dma_fence *migration_fence = NULL;
574 struct ttm_tt *ttm = bo->ttm;
575 struct i915_refct_sgt *dst_rsgt;
579 if (GEM_WARN_ON(i915_ttm_is_ghost_object(bo))) {
580 ttm_bo_move_null(bo, dst_mem);
585 if (dst_mem->mem_type != TTM_PL_SYSTEM) {
586 hop->mem_type = TTM_PL_SYSTEM;
587 hop->flags = TTM_PL_FLAG_TEMPORARY;
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.
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.
606 ttm_bo_move_null(bo, dst_mem);
610 ret = i915_ttm_move_notify(bo);
614 if (obj->mm.madv != I915_MADV_WILLNEED) {
616 ttm_resource_free(bo, &dst_mem);
620 /* Populate ttm with pages if needed. Typically system memory. */
621 if (ttm && (dst_man->use_tt || (ttm->page_flags & TTM_TT_FLAG_SWAPPED))) {
622 ret = ttm_tt_populate(bo->bdev, ttm, ctx);
627 dst_rsgt = i915_ttm_resource_get_st(obj, dst_mem);
628 if (IS_ERR(dst_rsgt))
629 return PTR_ERR(dst_rsgt);
631 clear = !i915_ttm_cpu_maps_iomem(bo->resource) && (!ttm || !ttm_tt_is_populated(ttm));
632 if (!(clear && ttm && !(ttm->page_flags & TTM_TT_FLAG_ZERO_ALLOC))) {
633 struct i915_deps deps;
635 i915_deps_init(&deps, GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN);
636 ret = i915_deps_add_resv(&deps, bo->base.resv, ctx);
638 i915_refct_sgt_put(dst_rsgt);
642 migration_fence = __i915_ttm_move(bo, ctx, clear, dst_mem, ttm,
643 dst_rsgt, true, &deps);
644 i915_deps_fini(&deps);
647 /* We can possibly get an -ERESTARTSYS here */
648 if (IS_ERR(migration_fence)) {
649 i915_refct_sgt_put(dst_rsgt);
650 return PTR_ERR(migration_fence);
653 if (migration_fence) {
654 if (I915_SELFTEST_ONLY(evict && fail_gpu_migration))
655 ret = -EIO; /* never feed non-migrate fences into ttm */
657 ret = ttm_bo_move_accel_cleanup(bo, migration_fence, evict,
660 dma_fence_wait(migration_fence, false);
661 ttm_bo_move_sync_cleanup(bo, dst_mem);
663 dma_fence_put(migration_fence);
665 ttm_bo_move_sync_cleanup(bo, dst_mem);
668 i915_ttm_adjust_domains_after_move(obj);
669 i915_ttm_free_cached_io_rsgt(obj);
671 if (i915_ttm_gtt_binds_lmem(dst_mem) || i915_ttm_cpu_maps_iomem(dst_mem)) {
672 obj->ttm.cached_io_rsgt = dst_rsgt;
673 obj->ttm.get_io_page.sg_pos = dst_rsgt->table.sgl;
674 obj->ttm.get_io_page.sg_idx = 0;
676 i915_refct_sgt_put(dst_rsgt);
679 i915_ttm_adjust_lru(obj);
680 i915_ttm_adjust_gem_after_move(obj);
685 * i915_gem_obj_copy_ttm - Copy the contents of one ttm-based gem object to
687 * @dst: The destination object
688 * @src: The source object
689 * @allow_accel: Allow using the blitter. Otherwise TTM memcpy is used.
690 * @intr: Whether to perform waits interruptible:
692 * Note: The caller is responsible for assuring that the underlying
693 * TTM objects are populated if needed and locked.
695 * Return: Zero on success. Negative error code on error. If @intr == true,
696 * then it may return -ERESTARTSYS or -EINTR.
698 int i915_gem_obj_copy_ttm(struct drm_i915_gem_object *dst,
699 struct drm_i915_gem_object *src,
700 bool allow_accel, bool intr)
702 struct ttm_buffer_object *dst_bo = i915_gem_to_ttm(dst);
703 struct ttm_buffer_object *src_bo = i915_gem_to_ttm(src);
704 struct ttm_operation_ctx ctx = {
705 .interruptible = intr,
707 struct i915_refct_sgt *dst_rsgt;
708 struct dma_fence *copy_fence;
709 struct i915_deps deps;
712 assert_object_held(dst);
713 assert_object_held(src);
714 i915_deps_init(&deps, GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN);
716 ret = dma_resv_reserve_fences(src_bo->base.resv, 1);
720 ret = dma_resv_reserve_fences(dst_bo->base.resv, 1);
724 ret = i915_deps_add_resv(&deps, dst_bo->base.resv, &ctx);
728 ret = i915_deps_add_resv(&deps, src_bo->base.resv, &ctx);
732 dst_rsgt = i915_ttm_resource_get_st(dst, dst_bo->resource);
733 copy_fence = __i915_ttm_move(src_bo, &ctx, false, dst_bo->resource,
734 dst_bo->ttm, dst_rsgt, allow_accel,
737 i915_deps_fini(&deps);
738 i915_refct_sgt_put(dst_rsgt);
739 if (IS_ERR_OR_NULL(copy_fence))
740 return PTR_ERR_OR_ZERO(copy_fence);
742 dma_resv_add_fence(dst_bo->base.resv, copy_fence, DMA_RESV_USAGE_WRITE);
743 dma_resv_add_fence(src_bo->base.resv, copy_fence, DMA_RESV_USAGE_READ);
744 dma_fence_put(copy_fence);