xref: /linux/drivers/gpu/drm/xe/xe_exec.c (revision 5d97dde4d5f751858390b557729a1a12210024c1)
1dd08ebf6SMatthew Brost // SPDX-License-Identifier: MIT
2dd08ebf6SMatthew Brost /*
3dd08ebf6SMatthew Brost  * Copyright © 2022 Intel Corporation
4dd08ebf6SMatthew Brost  */
5dd08ebf6SMatthew Brost 
6ea9f879dSLucas De Marchi #include "xe_exec.h"
7ea9f879dSLucas De Marchi 
8dd08ebf6SMatthew Brost #include <drm/drm_device.h>
9d490ecf5SThomas Hellström #include <drm/drm_exec.h>
10dd08ebf6SMatthew Brost #include <drm/drm_file.h>
1187d8ecf0SJani Nikula #include <uapi/drm/xe_drm.h>
1234f89ac8SNiranjana Vishwanathapura #include <linux/delay.h>
13dd08ebf6SMatthew Brost 
14dd08ebf6SMatthew Brost #include "xe_bo.h"
15dd08ebf6SMatthew Brost #include "xe_device.h"
16c22a4ed0SFrancois Dugast #include "xe_exec_queue.h"
17d16ef1a1SFrancois Dugast #include "xe_hw_engine_group.h"
18dd08ebf6SMatthew Brost #include "xe_macros.h"
198ae8a2e8SMatthew Brost #include "xe_ring_ops_types.h"
20dd08ebf6SMatthew Brost #include "xe_sched_job.h"
21dd08ebf6SMatthew Brost #include "xe_sync.h"
22dd08ebf6SMatthew Brost #include "xe_vm.h"
23dd08ebf6SMatthew Brost 
24dd08ebf6SMatthew Brost /**
25dd08ebf6SMatthew Brost  * DOC: Execbuf (User GPU command submission)
26dd08ebf6SMatthew Brost  *
27dd08ebf6SMatthew Brost  * Execs have historically been rather complicated in DRM drivers (at least in
28dd08ebf6SMatthew Brost  * the i915) because a few things:
29dd08ebf6SMatthew Brost  *
30dd08ebf6SMatthew Brost  * - Passing in a list BO which are read / written to creating implicit syncs
31dd08ebf6SMatthew Brost  * - Binding at exec time
32dd08ebf6SMatthew Brost  * - Flow controlling the ring at exec time
33dd08ebf6SMatthew Brost  *
34dd08ebf6SMatthew Brost  * In XE we avoid all of this complication by not allowing a BO list to be
35dd08ebf6SMatthew Brost  * passed into an exec, using the dma-buf implicit sync uAPI, have binds as
36dd08ebf6SMatthew Brost  * seperate operations, and using the DRM scheduler to flow control the ring.
37dd08ebf6SMatthew Brost  * Let's deep dive on each of these.
38dd08ebf6SMatthew Brost  *
39dd08ebf6SMatthew Brost  * We can get away from a BO list by forcing the user to use in / out fences on
40dd08ebf6SMatthew Brost  * every exec rather than the kernel tracking dependencies of BO (e.g. if the
41dd08ebf6SMatthew Brost  * user knows an exec writes to a BO and reads from the BO in the next exec, it
42dd08ebf6SMatthew Brost  * is the user's responsibility to pass in / out fence between the two execs).
43dd08ebf6SMatthew Brost  *
44dd08ebf6SMatthew Brost  * We do not allow a user to trigger a bind at exec time rather we have a VM
45dd08ebf6SMatthew Brost  * bind IOCTL which uses the same in / out fence interface as exec. In that
46dd08ebf6SMatthew Brost  * sense, a VM bind is basically the same operation as an exec from the user
47dd08ebf6SMatthew Brost  * perspective. e.g. If an exec depends on a VM bind use the in / out fence
48dd08ebf6SMatthew Brost  * interface (struct drm_xe_sync) to synchronize like syncing between two
49dd08ebf6SMatthew Brost  * dependent execs.
50dd08ebf6SMatthew Brost  *
51dd08ebf6SMatthew Brost  * Although a user cannot trigger a bind, we still have to rebind userptrs in
52dd08ebf6SMatthew Brost  * the VM that have been invalidated since the last exec, likewise we also have
53dd08ebf6SMatthew Brost  * to rebind BOs that have been evicted by the kernel. We schedule these rebinds
54dd08ebf6SMatthew Brost  * behind any pending kernel operations on any external BOs in VM or any BOs
55dd08ebf6SMatthew Brost  * private to the VM. This is accomplished by the rebinds waiting on BOs
56dd08ebf6SMatthew Brost  * DMA_RESV_USAGE_KERNEL slot (kernel ops) and kernel ops waiting on all BOs
57*e7518276SMatthew Brost  * slots (inflight execs are in the DMA_RESV_USAGE_BOOKKEEP for private BOs and
58*e7518276SMatthew Brost  * for external BOs).
59dd08ebf6SMatthew Brost  *
60dd08ebf6SMatthew Brost  * Rebinds / dma-resv usage applies to non-compute mode VMs only as for compute
61dd08ebf6SMatthew Brost  * mode VMs we use preempt fences and a rebind worker (TODO: add link).
62dd08ebf6SMatthew Brost  *
63dd08ebf6SMatthew Brost  * There is no need to flow control the ring in the exec as we write the ring at
64dd08ebf6SMatthew Brost  * submission time and set the DRM scheduler max job limit SIZE_OF_RING /
65dd08ebf6SMatthew Brost  * MAX_JOB_SIZE. The DRM scheduler will then hold all jobs until space in the
66dd08ebf6SMatthew Brost  * ring is available.
67dd08ebf6SMatthew Brost  *
68dd08ebf6SMatthew Brost  * All of this results in a rather simple exec implementation.
69dd08ebf6SMatthew Brost  *
70dd08ebf6SMatthew Brost  * Flow
71dd08ebf6SMatthew Brost  * ~~~~
72dd08ebf6SMatthew Brost  *
73dd08ebf6SMatthew Brost  * .. code-block::
74dd08ebf6SMatthew Brost  *
75dd08ebf6SMatthew Brost  *	Parse input arguments
76dd08ebf6SMatthew Brost  *	Wait for any async VM bind passed as in-fences to start
77dd08ebf6SMatthew Brost  *	<----------------------------------------------------------------------|
78dd08ebf6SMatthew Brost  *	Lock global VM lock in read mode                                       |
79dd08ebf6SMatthew Brost  *	Pin userptrs (also finds userptr invalidated since last exec)          |
80dd08ebf6SMatthew Brost  *	Lock exec (VM dma-resv lock, external BOs dma-resv locks)              |
81dd08ebf6SMatthew Brost  *	Validate BOs that have been evicted                                    |
82dd08ebf6SMatthew Brost  *	Create job                                                             |
83dd08ebf6SMatthew Brost  *	Rebind invalidated userptrs + evicted BOs (non-compute-mode)           |
84dd08ebf6SMatthew Brost  *	Add rebind fence dependency to job                                     |
85dd08ebf6SMatthew Brost  *	Add job VM dma-resv bookkeeping slot (non-compute mode)                |
86dd08ebf6SMatthew Brost  *	Add job to external BOs dma-resv write slots (non-compute mode)        |
87dd08ebf6SMatthew Brost  *	Check if any userptrs invalidated since pin ------ Drop locks ---------|
88dd08ebf6SMatthew Brost  *	Install in / out fences for job
89dd08ebf6SMatthew Brost  *	Submit job
90dd08ebf6SMatthew Brost  *	Unlock all
91dd08ebf6SMatthew Brost  */
92dd08ebf6SMatthew Brost 
937ee7dd6fSThomas Hellström /*
947ee7dd6fSThomas Hellström  * Add validation and rebinding to the drm_exec locking loop, since both can
957ee7dd6fSThomas Hellström  * trigger eviction which may require sleeping dma_resv locks.
967ee7dd6fSThomas Hellström  */
xe_exec_fn(struct drm_gpuvm_exec * vm_exec)9724f947d5SThomas Hellström static int xe_exec_fn(struct drm_gpuvm_exec *vm_exec)
98dd08ebf6SMatthew Brost {
9929f424ebSMatthew Auld 	struct xe_vm *vm = container_of(vm_exec->vm, struct xe_vm, gpuvm);
10029f424ebSMatthew Auld 
1017ee7dd6fSThomas Hellström 	/* The fence slot added here is intended for the exec sched job. */
1027ee7dd6fSThomas Hellström 	return xe_vm_validate_rebind(vm, &vm_exec->exec, 1);
103dd08ebf6SMatthew Brost }
104dd08ebf6SMatthew Brost 
xe_exec_ioctl(struct drm_device * dev,void * data,struct drm_file * file)105dd08ebf6SMatthew Brost int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
106dd08ebf6SMatthew Brost {
107dd08ebf6SMatthew Brost 	struct xe_device *xe = to_xe_device(dev);
108dd08ebf6SMatthew Brost 	struct xe_file *xef = to_xe_file(file);
109dd08ebf6SMatthew Brost 	struct drm_xe_exec *args = data;
110dd08ebf6SMatthew Brost 	struct drm_xe_sync __user *syncs_user = u64_to_user_ptr(args->syncs);
111dd08ebf6SMatthew Brost 	u64 __user *addresses_user = u64_to_user_ptr(args->address);
1129b9529ceSFrancois Dugast 	struct xe_exec_queue *q;
113dd08ebf6SMatthew Brost 	struct xe_sync_entry *syncs = NULL;
114dd08ebf6SMatthew Brost 	u64 addresses[XE_HW_ENGINE_MAX_INSTANCE];
11524f947d5SThomas Hellström 	struct drm_gpuvm_exec vm_exec = {.extra.fn = xe_exec_fn};
11624f947d5SThomas Hellström 	struct drm_exec *exec = &vm_exec.exec;
11743a6faa6SAshutosh Dixit 	u32 i, num_syncs, num_ufence = 0;
118dd08ebf6SMatthew Brost 	struct xe_sched_job *job;
119dd08ebf6SMatthew Brost 	struct xe_vm *vm;
12097d0047cSMatthew Brost 	bool write_locked, skip_retry = false;
121d490ecf5SThomas Hellström 	ktime_t end = 0;
122dd08ebf6SMatthew Brost 	int err = 0;
123d16ef1a1SFrancois Dugast 	struct xe_hw_engine_group *group;
124d16ef1a1SFrancois Dugast 	enum xe_hw_engine_group_execution_mode mode, previous_mode;
125dd08ebf6SMatthew Brost 
126b8c1ba83SFrancois Dugast 	if (XE_IOCTL_DBG(xe, args->extensions) ||
127b8c1ba83SFrancois Dugast 	    XE_IOCTL_DBG(xe, args->pad[0] || args->pad[1] || args->pad[2]) ||
128b8c1ba83SFrancois Dugast 	    XE_IOCTL_DBG(xe, args->reserved[0] || args->reserved[1]))
129dd08ebf6SMatthew Brost 		return -EINVAL;
130dd08ebf6SMatthew Brost 
1319b9529ceSFrancois Dugast 	q = xe_exec_queue_lookup(xef, args->exec_queue_id);
1329b9529ceSFrancois Dugast 	if (XE_IOCTL_DBG(xe, !q))
133dd08ebf6SMatthew Brost 		return -ENOENT;
134dd08ebf6SMatthew Brost 
1359b9529ceSFrancois Dugast 	if (XE_IOCTL_DBG(xe, q->flags & EXEC_QUEUE_FLAG_VM))
136dd08ebf6SMatthew Brost 		return -EINVAL;
137dd08ebf6SMatthew Brost 
138eb9702adSMatthew Brost 	if (XE_IOCTL_DBG(xe, args->num_batch_buffer &&
139eb9702adSMatthew Brost 			 q->width != args->num_batch_buffer))
140dd08ebf6SMatthew Brost 		return -EINVAL;
141dd08ebf6SMatthew Brost 
1424468d048SMatthew Brost 	if (XE_IOCTL_DBG(xe, q->ops->reset_status(q))) {
143dd08ebf6SMatthew Brost 		err = -ECANCELED;
1449b9529ceSFrancois Dugast 		goto err_exec_queue;
145dd08ebf6SMatthew Brost 	}
146dd08ebf6SMatthew Brost 
147dd08ebf6SMatthew Brost 	if (args->num_syncs) {
148dd08ebf6SMatthew Brost 		syncs = kcalloc(args->num_syncs, sizeof(*syncs), GFP_KERNEL);
149dd08ebf6SMatthew Brost 		if (!syncs) {
150dd08ebf6SMatthew Brost 			err = -ENOMEM;
1519b9529ceSFrancois Dugast 			goto err_exec_queue;
152dd08ebf6SMatthew Brost 		}
153dd08ebf6SMatthew Brost 	}
154dd08ebf6SMatthew Brost 
1559b9529ceSFrancois Dugast 	vm = q->vm;
156dd08ebf6SMatthew Brost 
15743a6faa6SAshutosh Dixit 	for (num_syncs = 0; num_syncs < args->num_syncs; num_syncs++) {
15843a6faa6SAshutosh Dixit 		err = xe_sync_entry_parse(xe, xef, &syncs[num_syncs],
15943a6faa6SAshutosh Dixit 					  &syncs_user[num_syncs], SYNC_PARSE_FLAG_EXEC |
16053bf60f6SMatthew Brost 					  (xe_vm_in_lr_mode(vm) ?
16153bf60f6SMatthew Brost 					   SYNC_PARSE_FLAG_LR_MODE : 0));
162dd08ebf6SMatthew Brost 		if (err)
163dd08ebf6SMatthew Brost 			goto err_syncs;
164d1df9bfbSMatthew Brost 
16543a6faa6SAshutosh Dixit 		if (xe_sync_is_ufence(&syncs[num_syncs]))
166d1df9bfbSMatthew Brost 			num_ufence++;
167d1df9bfbSMatthew Brost 	}
168d1df9bfbSMatthew Brost 
169d1df9bfbSMatthew Brost 	if (XE_IOCTL_DBG(xe, num_ufence > 1)) {
170d1df9bfbSMatthew Brost 		err = -EINVAL;
171d1df9bfbSMatthew Brost 		goto err_syncs;
172dd08ebf6SMatthew Brost 	}
173dd08ebf6SMatthew Brost 
1749b9529ceSFrancois Dugast 	if (xe_exec_queue_is_parallel(q)) {
175dd08ebf6SMatthew Brost 		err = __copy_from_user(addresses, addresses_user, sizeof(u64) *
1769b9529ceSFrancois Dugast 				       q->width);
177dd08ebf6SMatthew Brost 		if (err) {
178dd08ebf6SMatthew Brost 			err = -EFAULT;
179dd08ebf6SMatthew Brost 			goto err_syncs;
180dd08ebf6SMatthew Brost 		}
181dd08ebf6SMatthew Brost 	}
182dd08ebf6SMatthew Brost 
183d16ef1a1SFrancois Dugast 	group = q->hwe->hw_engine_group;
184d16ef1a1SFrancois Dugast 	mode = xe_hw_engine_group_find_exec_mode(q);
185d16ef1a1SFrancois Dugast 
186d16ef1a1SFrancois Dugast 	if (mode == EXEC_MODE_DMA_FENCE) {
187d16ef1a1SFrancois Dugast 		err = xe_hw_engine_group_get_mode(group, mode, &previous_mode);
188d16ef1a1SFrancois Dugast 		if (err)
189d16ef1a1SFrancois Dugast 			goto err_syncs;
190d16ef1a1SFrancois Dugast 	}
191d16ef1a1SFrancois Dugast 
192dd08ebf6SMatthew Brost retry:
193fdb6a053SThomas Hellström 	if (!xe_vm_in_lr_mode(vm) && xe_vm_userptr_check_repin(vm)) {
194dd08ebf6SMatthew Brost 		err = down_write_killable(&vm->lock);
195dd08ebf6SMatthew Brost 		write_locked = true;
196dd08ebf6SMatthew Brost 	} else {
197dd08ebf6SMatthew Brost 		/* We don't allow execs while the VM is in error state */
198dd08ebf6SMatthew Brost 		err = down_read_interruptible(&vm->lock);
199dd08ebf6SMatthew Brost 		write_locked = false;
200dd08ebf6SMatthew Brost 	}
201dd08ebf6SMatthew Brost 	if (err)
202dd08ebf6SMatthew Brost 		goto err_syncs;
203dd08ebf6SMatthew Brost 
204dd08ebf6SMatthew Brost 	if (write_locked) {
205dd08ebf6SMatthew Brost 		err = xe_vm_userptr_pin(vm);
206dd08ebf6SMatthew Brost 		downgrade_write(&vm->lock);
207dd08ebf6SMatthew Brost 		write_locked = false;
208dd08ebf6SMatthew Brost 		if (err)
209d16ef1a1SFrancois Dugast 			goto err_hw_exec_mode;
210dd08ebf6SMatthew Brost 	}
211dd08ebf6SMatthew Brost 
21258480c1cSJosé Roberto de Souza 	if (!args->num_batch_buffer) {
21358480c1cSJosé Roberto de Souza 		err = xe_vm_lock(vm, true);
21458480c1cSJosé Roberto de Souza 		if (err)
21558480c1cSJosé Roberto de Souza 			goto err_unlock_list;
21658480c1cSJosé Roberto de Souza 
21758480c1cSJosé Roberto de Souza 		if (!xe_vm_in_lr_mode(vm)) {
21858480c1cSJosé Roberto de Souza 			struct dma_fence *fence;
21958480c1cSJosé Roberto de Souza 
22058480c1cSJosé Roberto de Souza 			fence = xe_sync_in_fence_get(syncs, num_syncs, q, vm);
22158480c1cSJosé Roberto de Souza 			if (IS_ERR(fence)) {
22258480c1cSJosé Roberto de Souza 				err = PTR_ERR(fence);
22358480c1cSJosé Roberto de Souza 				goto err_unlock_list;
22458480c1cSJosé Roberto de Souza 			}
22558480c1cSJosé Roberto de Souza 			for (i = 0; i < num_syncs; i++)
2265dffaa1bSNirmoy Das 				xe_sync_entry_signal(&syncs[i], fence);
22758480c1cSJosé Roberto de Souza 			xe_exec_queue_last_fence_set(q, vm, fence);
22858480c1cSJosé Roberto de Souza 			dma_fence_put(fence);
22958480c1cSJosé Roberto de Souza 		}
23058480c1cSJosé Roberto de Souza 
23158480c1cSJosé Roberto de Souza 		xe_vm_unlock(vm);
23258480c1cSJosé Roberto de Souza 		goto err_unlock_list;
23358480c1cSJosé Roberto de Souza 	}
23458480c1cSJosé Roberto de Souza 
23524f947d5SThomas Hellström 	vm_exec.vm = &vm->gpuvm;
23624f947d5SThomas Hellström 	vm_exec.flags = DRM_EXEC_INTERRUPTIBLE_WAIT;
23724f947d5SThomas Hellström 	if (xe_vm_in_lr_mode(vm)) {
238d2197029SDave Airlie 		drm_exec_init(exec, vm_exec.flags, 0);
23924f947d5SThomas Hellström 	} else {
24024f947d5SThomas Hellström 		err = drm_gpuvm_exec_lock(&vm_exec);
24124f947d5SThomas Hellström 		if (err) {
24224f947d5SThomas Hellström 			if (xe_vm_validate_should_retry(exec, err, &end))
243d490ecf5SThomas Hellström 				err = -EAGAIN;
244dd08ebf6SMatthew Brost 			goto err_unlock_list;
245d490ecf5SThomas Hellström 		}
246d490ecf5SThomas Hellström 	}
247dd08ebf6SMatthew Brost 
2489b9529ceSFrancois Dugast 	if (xe_vm_is_closed_or_banned(q->vm)) {
2499d858b69SMatthew Brost 		drm_warn(&xe->drm, "Trying to schedule after vm is closed or banned\n");
2509d858b69SMatthew Brost 		err = -ECANCELED;
251d490ecf5SThomas Hellström 		goto err_exec;
252dd08ebf6SMatthew Brost 	}
253dd08ebf6SMatthew Brost 
2549b9529ceSFrancois Dugast 	if (xe_exec_queue_is_lr(q) && xe_exec_queue_ring_full(q)) {
25597d0047cSMatthew Brost 		err = -EWOULDBLOCK;	/* Aliased to -EAGAIN */
25697d0047cSMatthew Brost 		skip_retry = true;
257d490ecf5SThomas Hellström 		goto err_exec;
2588ae8a2e8SMatthew Brost 	}
2598ae8a2e8SMatthew Brost 
2609b9529ceSFrancois Dugast 	job = xe_sched_job_create(q, xe_exec_queue_is_parallel(q) ?
261dd08ebf6SMatthew Brost 				  addresses : &args->address);
262dd08ebf6SMatthew Brost 	if (IS_ERR(job)) {
263dd08ebf6SMatthew Brost 		err = PTR_ERR(job);
264d490ecf5SThomas Hellström 		goto err_exec;
265dd08ebf6SMatthew Brost 	}
266dd08ebf6SMatthew Brost 
2675a091affSThomas Hellström 	/* Wait behind rebinds */
268fdb6a053SThomas Hellström 	if (!xe_vm_in_lr_mode(vm)) {
269de8390b1SFrancois Dugast 		err = xe_sched_job_add_deps(job,
270b06d47beSMatthew Brost 					    xe_vm_resv(vm),
271dd08ebf6SMatthew Brost 					    DMA_RESV_USAGE_KERNEL);
272dd08ebf6SMatthew Brost 		if (err)
273dd08ebf6SMatthew Brost 			goto err_put_job;
274dd08ebf6SMatthew Brost 	}
275dd08ebf6SMatthew Brost 
276dd08ebf6SMatthew Brost 	for (i = 0; i < num_syncs && !err; i++)
277dd08ebf6SMatthew Brost 		err = xe_sync_entry_add_deps(&syncs[i], job);
278dd08ebf6SMatthew Brost 	if (err)
279dd08ebf6SMatthew Brost 		goto err_put_job;
280dd08ebf6SMatthew Brost 
281fdb6a053SThomas Hellström 	if (!xe_vm_in_lr_mode(vm)) {
282eb9702adSMatthew Brost 		err = xe_sched_job_last_fence_add_dep(job, vm);
283eb9702adSMatthew Brost 		if (err)
284eb9702adSMatthew Brost 			goto err_put_job;
285eb9702adSMatthew Brost 
286dd08ebf6SMatthew Brost 		err = down_read_interruptible(&vm->userptr.notifier_lock);
287dd08ebf6SMatthew Brost 		if (err)
288dd08ebf6SMatthew Brost 			goto err_put_job;
289dd08ebf6SMatthew Brost 
290dd08ebf6SMatthew Brost 		err = __xe_vm_userptr_needs_repin(vm);
291dd08ebf6SMatthew Brost 		if (err)
292dd08ebf6SMatthew Brost 			goto err_repin;
293dd08ebf6SMatthew Brost 	}
294dd08ebf6SMatthew Brost 
295dd08ebf6SMatthew Brost 	/*
296dd08ebf6SMatthew Brost 	 * Point of no return, if we error after this point just set an error on
297dd08ebf6SMatthew Brost 	 * the job and let the DRM scheduler / backend clean up the job.
298dd08ebf6SMatthew Brost 	 */
299dd08ebf6SMatthew Brost 	xe_sched_job_arm(job);
30024f947d5SThomas Hellström 	if (!xe_vm_in_lr_mode(vm))
30124f947d5SThomas Hellström 		drm_gpuvm_resv_add_fence(&vm->gpuvm, exec, &job->drm.s_fence->finished,
302*e7518276SMatthew Brost 					 DMA_RESV_USAGE_BOOKKEEP,
303*e7518276SMatthew Brost 					 DMA_RESV_USAGE_BOOKKEEP);
304dd08ebf6SMatthew Brost 
3055dffaa1bSNirmoy Das 	for (i = 0; i < num_syncs; i++) {
3065dffaa1bSNirmoy Das 		xe_sync_entry_signal(&syncs[i], &job->drm.s_fence->finished);
3075dffaa1bSNirmoy Das 		xe_sched_job_init_user_fence(job, &syncs[i]);
3085dffaa1bSNirmoy Das 	}
309dd08ebf6SMatthew Brost 
3109b9529ceSFrancois Dugast 	if (xe_exec_queue_is_lr(q))
3119b9529ceSFrancois Dugast 		q->ring_ops->emit_job(job);
312eb9702adSMatthew Brost 	if (!xe_vm_in_lr_mode(vm))
313eb9702adSMatthew Brost 		xe_exec_queue_last_fence_set(q, vm, &job->drm.s_fence->finished);
314dd08ebf6SMatthew Brost 	xe_sched_job_push(job);
3158e41443eSThomas Hellström 	xe_vm_reactivate_rebind(vm);
316dd08ebf6SMatthew Brost 
317fdb6a053SThomas Hellström 	if (!err && !xe_vm_in_lr_mode(vm)) {
3187ba4c5f0SMatthew Brost 		spin_lock(&xe->ttm.lru_lock);
3197ba4c5f0SMatthew Brost 		ttm_lru_bulk_move_tail(&vm->lru_bulk_move);
3207ba4c5f0SMatthew Brost 		spin_unlock(&xe->ttm.lru_lock);
3217ba4c5f0SMatthew Brost 	}
3227ba4c5f0SMatthew Brost 
323d16ef1a1SFrancois Dugast 	if (mode == EXEC_MODE_LR)
324d16ef1a1SFrancois Dugast 		xe_hw_engine_group_resume_faulting_lr_jobs(group);
325d16ef1a1SFrancois Dugast 
326dd08ebf6SMatthew Brost err_repin:
327fdb6a053SThomas Hellström 	if (!xe_vm_in_lr_mode(vm))
328dd08ebf6SMatthew Brost 		up_read(&vm->userptr.notifier_lock);
329dd08ebf6SMatthew Brost err_put_job:
330dd08ebf6SMatthew Brost 	if (err)
331dd08ebf6SMatthew Brost 		xe_sched_job_put(job);
332d490ecf5SThomas Hellström err_exec:
33324f947d5SThomas Hellström 	drm_exec_fini(exec);
334dd08ebf6SMatthew Brost err_unlock_list:
335dd08ebf6SMatthew Brost 	up_read(&vm->lock);
33697d0047cSMatthew Brost 	if (err == -EAGAIN && !skip_retry)
337dd08ebf6SMatthew Brost 		goto retry;
338d16ef1a1SFrancois Dugast err_hw_exec_mode:
339d16ef1a1SFrancois Dugast 	if (mode == EXEC_MODE_DMA_FENCE)
340d16ef1a1SFrancois Dugast 		xe_hw_engine_group_put(group);
341dd08ebf6SMatthew Brost err_syncs:
34243a6faa6SAshutosh Dixit 	while (num_syncs--)
34343a6faa6SAshutosh Dixit 		xe_sync_entry_cleanup(&syncs[num_syncs]);
344dd08ebf6SMatthew Brost 	kfree(syncs);
3459b9529ceSFrancois Dugast err_exec_queue:
3469b9529ceSFrancois Dugast 	xe_exec_queue_put(q);
347dd08ebf6SMatthew Brost 
348dd08ebf6SMatthew Brost 	return err;
349dd08ebf6SMatthew Brost }
350