1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2013 Red Hat
4 * Author: Rob Clark <robdclark@gmail.com>
7 #include <linux/file.h>
8 #include <linux/sync_file.h>
9 #include <linux/uaccess.h>
11 #include <drm/drm_drv.h>
12 #include <drm/drm_file.h>
13 #include <drm/drm_syncobj.h>
18 #include "msm_gpu_trace.h"
21 * Cmdstream submission:
24 static struct msm_gem_submit *submit_create(struct drm_device *dev,
26 struct msm_gpu_submitqueue *queue, uint32_t nr_bos,
29 static atomic_t ident = ATOMIC_INIT(0);
30 struct msm_gem_submit *submit;
34 sz = struct_size(submit, bos, nr_bos) +
35 ((u64)nr_cmds * sizeof(submit->cmd[0]));
38 return ERR_PTR(-ENOMEM);
40 submit = kzalloc(sz, GFP_KERNEL);
42 return ERR_PTR(-ENOMEM);
44 submit->hw_fence = msm_fence_alloc();
45 if (IS_ERR(submit->hw_fence)) {
46 ret = PTR_ERR(submit->hw_fence);
51 ret = drm_sched_job_init(&submit->base, queue->entity, queue);
53 kfree(submit->hw_fence);
58 kref_init(&submit->ref);
60 submit->aspace = queue->ctx->aspace;
62 submit->cmd = (void *)&submit->bos[nr_bos];
63 submit->queue = queue;
64 submit->pid = get_pid(task_pid(current));
65 submit->ring = gpu->rb[queue->ring_nr];
66 submit->fault_dumped = false;
68 /* Get a unique identifier for the submission for logging purposes */
69 submit->ident = atomic_inc_return(&ident) - 1;
71 INIT_LIST_HEAD(&submit->node);
76 void __msm_gem_submit_destroy(struct kref *kref)
78 struct msm_gem_submit *submit =
79 container_of(kref, struct msm_gem_submit, ref);
82 if (submit->fence_id) {
83 spin_lock(&submit->queue->idr_lock);
84 idr_remove(&submit->queue->fence_idr, submit->fence_id);
85 spin_unlock(&submit->queue->idr_lock);
88 dma_fence_put(submit->user_fence);
89 dma_fence_put(submit->hw_fence);
92 msm_submitqueue_put(submit->queue);
94 for (i = 0; i < submit->nr_cmds; i++)
95 kfree(submit->cmd[i].relocs);
100 static int submit_lookup_objects(struct msm_gem_submit *submit,
101 struct drm_msm_gem_submit *args, struct drm_file *file)
106 for (i = 0; i < args->nr_bos; i++) {
107 struct drm_msm_gem_submit_bo submit_bo;
108 void __user *userptr =
109 u64_to_user_ptr(args->bos + (i * sizeof(submit_bo)));
111 /* make sure we don't have garbage flags, in case we hit
112 * error path before flags is initialized:
114 submit->bos[i].flags = 0;
116 if (copy_from_user(&submit_bo, userptr, sizeof(submit_bo))) {
122 /* at least one of READ and/or WRITE flags should be set: */
123 #define MANDATORY_FLAGS (MSM_SUBMIT_BO_READ | MSM_SUBMIT_BO_WRITE)
125 if ((submit_bo.flags & ~MSM_SUBMIT_BO_FLAGS) ||
126 !(submit_bo.flags & MANDATORY_FLAGS)) {
127 DRM_ERROR("invalid flags: %x\n", submit_bo.flags);
133 submit->bos[i].handle = submit_bo.handle;
134 submit->bos[i].flags = submit_bo.flags;
135 /* in validate_objects() we figure out if this is true: */
136 submit->bos[i].iova = submit_bo.presumed;
139 spin_lock(&file->table_lock);
141 for (i = 0; i < args->nr_bos; i++) {
142 struct drm_gem_object *obj;
144 /* normally use drm_gem_object_lookup(), but for bulk lookup
145 * all under single table_lock just hit object_idr directly:
147 obj = idr_find(&file->object_idr, submit->bos[i].handle);
149 DRM_ERROR("invalid handle %u at index %u\n", submit->bos[i].handle, i);
154 drm_gem_object_get(obj);
156 submit->bos[i].obj = to_msm_bo(obj);
160 spin_unlock(&file->table_lock);
168 static int submit_lookup_cmds(struct msm_gem_submit *submit,
169 struct drm_msm_gem_submit *args, struct drm_file *file)
175 for (i = 0; i < args->nr_cmds; i++) {
176 struct drm_msm_gem_submit_cmd submit_cmd;
177 void __user *userptr =
178 u64_to_user_ptr(args->cmds + (i * sizeof(submit_cmd)));
180 ret = copy_from_user(&submit_cmd, userptr, sizeof(submit_cmd));
186 /* validate input from userspace: */
187 switch (submit_cmd.type) {
188 case MSM_SUBMIT_CMD_BUF:
189 case MSM_SUBMIT_CMD_IB_TARGET_BUF:
190 case MSM_SUBMIT_CMD_CTX_RESTORE_BUF:
193 DRM_ERROR("invalid type: %08x\n", submit_cmd.type);
197 if (submit_cmd.size % 4) {
198 DRM_ERROR("non-aligned cmdstream buffer size: %u\n",
204 submit->cmd[i].type = submit_cmd.type;
205 submit->cmd[i].size = submit_cmd.size / 4;
206 submit->cmd[i].offset = submit_cmd.submit_offset / 4;
207 submit->cmd[i].idx = submit_cmd.submit_idx;
208 submit->cmd[i].nr_relocs = submit_cmd.nr_relocs;
210 userptr = u64_to_user_ptr(submit_cmd.relocs);
212 sz = array_size(submit_cmd.nr_relocs,
213 sizeof(struct drm_msm_gem_submit_reloc));
214 /* check for overflow: */
215 if (sz == SIZE_MAX) {
219 submit->cmd[i].relocs = kmalloc(sz, GFP_KERNEL);
220 if (!submit->cmd[i].relocs) {
224 ret = copy_from_user(submit->cmd[i].relocs, userptr, sz);
235 /* Unwind bo state, according to cleanup_flags. In the success case, only
236 * the lock is dropped at the end of the submit (and active/pin ref is dropped
237 * later when the submit is retired).
239 static void submit_cleanup_bo(struct msm_gem_submit *submit, int i,
240 unsigned cleanup_flags)
242 struct drm_gem_object *obj = &submit->bos[i].obj->base;
243 unsigned flags = submit->bos[i].flags & cleanup_flags;
246 * Clear flags bit before dropping lock, so that the msm_job_run()
247 * path isn't racing with submit_cleanup() (ie. the read/modify/
248 * write is protected by the obj lock in all paths)
250 submit->bos[i].flags &= ~cleanup_flags;
252 if (flags & BO_VMA_PINNED)
253 msm_gem_vma_unpin(submit->bos[i].vma);
255 if (flags & BO_OBJ_PINNED)
256 msm_gem_unpin_locked(obj);
258 if (flags & BO_LOCKED)
259 dma_resv_unlock(obj->resv);
262 static void submit_unlock_unpin_bo(struct msm_gem_submit *submit, int i)
264 unsigned cleanup_flags = BO_VMA_PINNED | BO_OBJ_PINNED | BO_LOCKED;
265 submit_cleanup_bo(submit, i, cleanup_flags);
267 if (!(submit->bos[i].flags & BO_VALID))
268 submit->bos[i].iova = 0;
271 /* This is where we make sure all the bo's are reserved and pin'd: */
272 static int submit_lock_objects(struct msm_gem_submit *submit)
274 int contended, slow_locked = -1, i, ret = 0;
277 for (i = 0; i < submit->nr_bos; i++) {
278 struct msm_gem_object *msm_obj = submit->bos[i].obj;
280 if (slow_locked == i)
285 if (!(submit->bos[i].flags & BO_LOCKED)) {
286 ret = dma_resv_lock_interruptible(msm_obj->base.resv,
290 submit->bos[i].flags |= BO_LOCKED;
294 ww_acquire_done(&submit->ticket);
299 if (ret == -EALREADY) {
300 DRM_ERROR("handle %u at index %u already on submit list\n",
301 submit->bos[i].handle, i);
306 submit_unlock_unpin_bo(submit, i);
309 submit_unlock_unpin_bo(submit, slow_locked);
311 if (ret == -EDEADLK) {
312 struct msm_gem_object *msm_obj = submit->bos[contended].obj;
313 /* we lost out in a seqno race, lock and retry.. */
314 ret = dma_resv_lock_slow_interruptible(msm_obj->base.resv,
317 submit->bos[contended].flags |= BO_LOCKED;
318 slow_locked = contended;
322 /* Not expecting -EALREADY here, if the bo was already
323 * locked, we should have gotten -EALREADY already from
324 * the dma_resv_lock_interruptable() call.
326 WARN_ON_ONCE(ret == -EALREADY);
332 static int submit_fence_sync(struct msm_gem_submit *submit, bool no_implicit)
336 for (i = 0; i < submit->nr_bos; i++) {
337 struct drm_gem_object *obj = &submit->bos[i].obj->base;
338 bool write = submit->bos[i].flags & MSM_SUBMIT_BO_WRITE;
340 /* NOTE: _reserve_shared() must happen before
341 * _add_shared_fence(), which makes this a slightly
342 * strange place to call it. OTOH this is a
343 * convenient can-fail point to hook it in.
345 ret = dma_resv_reserve_fences(obj->resv, 1);
349 /* If userspace has determined that explicit fencing is
350 * used, it can disable implicit sync on the entire
356 /* Otherwise userspace can ask for implicit sync to be
357 * disabled on specific buffers. This is useful for internal
358 * usermode driver managed buffers, suballocation, etc.
360 if (submit->bos[i].flags & MSM_SUBMIT_BO_NO_IMPLICIT)
363 ret = drm_sched_job_add_implicit_dependencies(&submit->base,
373 static int submit_pin_objects(struct msm_gem_submit *submit)
377 submit->valid = true;
379 for (i = 0; i < submit->nr_bos; i++) {
380 struct drm_gem_object *obj = &submit->bos[i].obj->base;
381 struct msm_gem_vma *vma;
383 /* if locking succeeded, pin bo: */
384 vma = msm_gem_get_vma_locked(obj, submit->aspace);
390 ret = msm_gem_pin_vma_locked(obj, vma);
394 submit->bos[i].flags |= BO_OBJ_PINNED | BO_VMA_PINNED;
395 submit->bos[i].vma = vma;
397 if (vma->iova == submit->bos[i].iova) {
398 submit->bos[i].flags |= BO_VALID;
400 submit->bos[i].iova = vma->iova;
401 /* iova changed, so address in cmdstream is not valid: */
402 submit->bos[i].flags &= ~BO_VALID;
403 submit->valid = false;
410 static void submit_attach_object_fences(struct msm_gem_submit *submit)
414 for (i = 0; i < submit->nr_bos; i++) {
415 struct drm_gem_object *obj = &submit->bos[i].obj->base;
417 if (submit->bos[i].flags & MSM_SUBMIT_BO_WRITE)
418 dma_resv_add_fence(obj->resv, submit->user_fence,
419 DMA_RESV_USAGE_WRITE);
420 else if (submit->bos[i].flags & MSM_SUBMIT_BO_READ)
421 dma_resv_add_fence(obj->resv, submit->user_fence,
422 DMA_RESV_USAGE_READ);
426 static int submit_bo(struct msm_gem_submit *submit, uint32_t idx,
427 struct msm_gem_object **obj, uint64_t *iova, bool *valid)
429 if (idx >= submit->nr_bos) {
430 DRM_ERROR("invalid buffer index: %u (out of %u)\n",
431 idx, submit->nr_bos);
436 *obj = submit->bos[idx].obj;
438 *iova = submit->bos[idx].iova;
440 *valid = !!(submit->bos[idx].flags & BO_VALID);
445 /* process the reloc's and patch up the cmdstream as needed: */
446 static int submit_reloc(struct msm_gem_submit *submit, struct msm_gem_object *obj,
447 uint32_t offset, uint32_t nr_relocs, struct drm_msm_gem_submit_reloc *relocs)
449 uint32_t i, last_offset = 0;
457 DRM_ERROR("non-aligned cmdstream buffer: %u\n", offset);
461 /* For now, just map the entire thing. Eventually we probably
462 * to do it page-by-page, w/ kmap() if not vmap()d..
464 ptr = msm_gem_get_vaddr_locked(&obj->base);
468 DBG("failed to map: %d", ret);
472 for (i = 0; i < nr_relocs; i++) {
473 struct drm_msm_gem_submit_reloc submit_reloc = relocs[i];
478 if (submit_reloc.submit_offset % 4) {
479 DRM_ERROR("non-aligned reloc offset: %u\n",
480 submit_reloc.submit_offset);
485 /* offset in dwords: */
486 off = submit_reloc.submit_offset / 4;
488 if ((off >= (obj->base.size / 4)) ||
489 (off < last_offset)) {
490 DRM_ERROR("invalid offset %u at reloc %u\n", off, i);
495 ret = submit_bo(submit, submit_reloc.reloc_idx, NULL, &iova, &valid);
502 iova += submit_reloc.reloc_offset;
504 if (submit_reloc.shift < 0)
505 iova >>= -submit_reloc.shift;
507 iova <<= submit_reloc.shift;
509 ptr[off] = iova | submit_reloc.or;
515 msm_gem_put_vaddr_locked(&obj->base);
520 /* Cleanup submit at end of ioctl. In the error case, this also drops
521 * references, unpins, and drops active refcnt. In the non-error case,
522 * this is done when the submit is retired.
524 static void submit_cleanup(struct msm_gem_submit *submit, bool error)
526 unsigned cleanup_flags = BO_LOCKED;
530 cleanup_flags |= BO_VMA_PINNED | BO_OBJ_PINNED;
532 for (i = 0; i < submit->nr_bos; i++) {
533 struct msm_gem_object *msm_obj = submit->bos[i].obj;
534 submit_cleanup_bo(submit, i, cleanup_flags);
536 drm_gem_object_put(&msm_obj->base);
540 void msm_submit_retire(struct msm_gem_submit *submit)
544 for (i = 0; i < submit->nr_bos; i++) {
545 struct drm_gem_object *obj = &submit->bos[i].obj->base;
547 drm_gem_object_put(obj);
551 struct msm_submit_post_dep {
552 struct drm_syncobj *syncobj;
554 struct dma_fence_chain *chain;
557 static struct drm_syncobj **msm_parse_deps(struct msm_gem_submit *submit,
558 struct drm_file *file,
559 uint64_t in_syncobjs_addr,
560 uint32_t nr_in_syncobjs,
561 size_t syncobj_stride)
563 struct drm_syncobj **syncobjs = NULL;
564 struct drm_msm_gem_submit_syncobj syncobj_desc = {0};
568 syncobjs = kcalloc(nr_in_syncobjs, sizeof(*syncobjs),
569 GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY);
571 return ERR_PTR(-ENOMEM);
573 for (i = 0; i < nr_in_syncobjs; ++i) {
574 uint64_t address = in_syncobjs_addr + i * syncobj_stride;
576 if (copy_from_user(&syncobj_desc,
577 u64_to_user_ptr(address),
578 min(syncobj_stride, sizeof(syncobj_desc)))) {
583 if (syncobj_desc.point &&
584 !drm_core_check_feature(submit->dev, DRIVER_SYNCOBJ_TIMELINE)) {
589 if (syncobj_desc.flags & ~MSM_SUBMIT_SYNCOBJ_FLAGS) {
594 ret = drm_sched_job_add_syncobj_dependency(&submit->base, file,
595 syncobj_desc.handle, syncobj_desc.point);
599 if (syncobj_desc.flags & MSM_SUBMIT_SYNCOBJ_RESET) {
601 drm_syncobj_find(file, syncobj_desc.handle);
610 for (j = 0; j <= i; ++j) {
612 drm_syncobj_put(syncobjs[j]);
620 static void msm_reset_syncobjs(struct drm_syncobj **syncobjs,
621 uint32_t nr_syncobjs)
625 for (i = 0; syncobjs && i < nr_syncobjs; ++i) {
627 drm_syncobj_replace_fence(syncobjs[i], NULL);
631 static struct msm_submit_post_dep *msm_parse_post_deps(struct drm_device *dev,
632 struct drm_file *file,
633 uint64_t syncobjs_addr,
634 uint32_t nr_syncobjs,
635 size_t syncobj_stride)
637 struct msm_submit_post_dep *post_deps;
638 struct drm_msm_gem_submit_syncobj syncobj_desc = {0};
642 post_deps = kcalloc(nr_syncobjs, sizeof(*post_deps),
643 GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY);
645 return ERR_PTR(-ENOMEM);
647 for (i = 0; i < nr_syncobjs; ++i) {
648 uint64_t address = syncobjs_addr + i * syncobj_stride;
650 if (copy_from_user(&syncobj_desc,
651 u64_to_user_ptr(address),
652 min(syncobj_stride, sizeof(syncobj_desc)))) {
657 post_deps[i].point = syncobj_desc.point;
659 if (syncobj_desc.flags) {
664 if (syncobj_desc.point) {
665 if (!drm_core_check_feature(dev,
666 DRIVER_SYNCOBJ_TIMELINE)) {
671 post_deps[i].chain = dma_fence_chain_alloc();
672 if (!post_deps[i].chain) {
678 post_deps[i].syncobj =
679 drm_syncobj_find(file, syncobj_desc.handle);
680 if (!post_deps[i].syncobj) {
687 for (j = 0; j <= i; ++j) {
688 dma_fence_chain_free(post_deps[j].chain);
689 if (post_deps[j].syncobj)
690 drm_syncobj_put(post_deps[j].syncobj);
700 static void msm_process_post_deps(struct msm_submit_post_dep *post_deps,
701 uint32_t count, struct dma_fence *fence)
705 for (i = 0; post_deps && i < count; ++i) {
706 if (post_deps[i].chain) {
707 drm_syncobj_add_point(post_deps[i].syncobj,
709 fence, post_deps[i].point);
710 post_deps[i].chain = NULL;
712 drm_syncobj_replace_fence(post_deps[i].syncobj,
718 int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
719 struct drm_file *file)
721 struct msm_drm_private *priv = dev->dev_private;
722 struct drm_msm_gem_submit *args = data;
723 struct msm_file_private *ctx = file->driver_priv;
724 struct msm_gem_submit *submit = NULL;
725 struct msm_gpu *gpu = priv->gpu;
726 struct msm_gpu_submitqueue *queue;
727 struct msm_ringbuffer *ring;
728 struct msm_submit_post_dep *post_deps = NULL;
729 struct drm_syncobj **syncobjs_to_reset = NULL;
730 int out_fence_fd = -1;
731 bool has_ww_ticket = false;
741 if (unlikely(!ctx->aspace) && !capable(CAP_SYS_RAWIO)) {
742 DRM_ERROR_RATELIMITED("IOMMU support or CAP_SYS_RAWIO required!\n");
746 /* for now, we just have 3d pipe.. eventually this would need to
747 * be more clever to dispatch to appropriate gpu module:
749 if (MSM_PIPE_ID(args->flags) != MSM_PIPE_3D0)
752 if (MSM_PIPE_FLAGS(args->flags) & ~MSM_SUBMIT_FLAGS)
755 if (args->flags & MSM_SUBMIT_SUDO) {
756 if (!IS_ENABLED(CONFIG_DRM_MSM_GPU_SUDO) ||
757 !capable(CAP_SYS_RAWIO))
761 queue = msm_submitqueue_get(ctx, args->queueid);
765 ring = gpu->rb[queue->ring_nr];
767 if (args->flags & MSM_SUBMIT_FENCE_FD_OUT) {
768 out_fence_fd = get_unused_fd_flags(O_CLOEXEC);
769 if (out_fence_fd < 0) {
771 goto out_post_unlock;
775 submit = submit_create(dev, gpu, queue, args->nr_bos, args->nr_cmds);
776 if (IS_ERR(submit)) {
777 ret = PTR_ERR(submit);
778 goto out_post_unlock;
781 trace_msm_gpu_submit(pid_nr(submit->pid), ring->id, submit->ident,
782 args->nr_bos, args->nr_cmds);
784 ret = mutex_lock_interruptible(&queue->lock);
786 goto out_post_unlock;
788 if (args->flags & MSM_SUBMIT_SUDO)
789 submit->in_rb = true;
791 if (args->flags & MSM_SUBMIT_FENCE_FD_IN) {
792 struct dma_fence *in_fence;
794 in_fence = sync_file_get_fence(args->fence_fd);
801 ret = drm_sched_job_add_dependency(&submit->base, in_fence);
806 if (args->flags & MSM_SUBMIT_SYNCOBJ_IN) {
807 syncobjs_to_reset = msm_parse_deps(submit, file,
809 args->nr_in_syncobjs,
810 args->syncobj_stride);
811 if (IS_ERR(syncobjs_to_reset)) {
812 ret = PTR_ERR(syncobjs_to_reset);
817 if (args->flags & MSM_SUBMIT_SYNCOBJ_OUT) {
818 post_deps = msm_parse_post_deps(dev, file,
820 args->nr_out_syncobjs,
821 args->syncobj_stride);
822 if (IS_ERR(post_deps)) {
823 ret = PTR_ERR(post_deps);
828 ret = submit_lookup_objects(submit, args, file);
832 ret = submit_lookup_cmds(submit, args, file);
836 /* copy_*_user while holding a ww ticket upsets lockdep */
837 ww_acquire_init(&submit->ticket, &reservation_ww_class);
838 has_ww_ticket = true;
839 ret = submit_lock_objects(submit);
843 ret = submit_fence_sync(submit, !!(args->flags & MSM_SUBMIT_NO_IMPLICIT));
847 ret = submit_pin_objects(submit);
851 for (i = 0; i < args->nr_cmds; i++) {
852 struct msm_gem_object *msm_obj;
855 ret = submit_bo(submit, submit->cmd[i].idx,
856 &msm_obj, &iova, NULL);
860 if (!submit->cmd[i].size ||
861 ((submit->cmd[i].size + submit->cmd[i].offset) >
862 msm_obj->base.size / 4)) {
863 DRM_ERROR("invalid cmdstream size: %u\n", submit->cmd[i].size * 4);
868 submit->cmd[i].iova = iova + (submit->cmd[i].offset * 4);
873 ret = submit_reloc(submit, msm_obj, submit->cmd[i].offset * 4,
874 submit->cmd[i].nr_relocs, submit->cmd[i].relocs);
881 idr_preload(GFP_KERNEL);
883 spin_lock(&queue->idr_lock);
886 * If using userspace provided seqno fence, validate that the id
887 * is available before arming sched job. Since access to fence_idr
888 * is serialized on the queue lock, the slot should be still avail
889 * after the job is armed
891 if ((args->flags & MSM_SUBMIT_FENCE_SN_IN) &&
892 idr_find(&queue->fence_idr, args->fence)) {
893 spin_unlock(&queue->idr_lock);
899 drm_sched_job_arm(&submit->base);
901 submit->user_fence = dma_fence_get(&submit->base.s_fence->finished);
903 if (args->flags & MSM_SUBMIT_FENCE_SN_IN) {
905 * Userspace has assigned the seqno fence that it wants
906 * us to use. It is an error to pick a fence sequence
907 * number that is not available.
909 submit->fence_id = args->fence;
910 ret = idr_alloc_u32(&queue->fence_idr, submit->user_fence,
911 &submit->fence_id, submit->fence_id,
914 * We've already validated that the fence_id slot is valid,
915 * so if idr_alloc_u32 failed, it is a kernel bug
920 * Allocate an id which can be used by WAIT_FENCE ioctl to map
921 * back to the underlying fence.
923 submit->fence_id = idr_alloc_cyclic(&queue->fence_idr,
924 submit->user_fence, 1,
925 INT_MAX, GFP_NOWAIT);
928 spin_unlock(&queue->idr_lock);
931 if (submit->fence_id < 0) {
932 ret = submit->fence_id;
933 submit->fence_id = 0;
936 if (ret == 0 && args->flags & MSM_SUBMIT_FENCE_FD_OUT) {
937 struct sync_file *sync_file = sync_file_create(submit->user_fence);
941 fd_install(out_fence_fd, sync_file->file);
942 args->fence_fd = out_fence_fd;
946 submit_attach_object_fences(submit);
948 /* The scheduler owns a ref now: */
949 msm_gem_submit_get(submit);
951 msm_rd_dump_submit(priv->rd, submit, NULL);
953 drm_sched_entity_push_job(&submit->base);
955 args->fence = submit->fence_id;
956 queue->last_fence = submit->fence_id;
958 msm_reset_syncobjs(syncobjs_to_reset, args->nr_in_syncobjs);
959 msm_process_post_deps(post_deps, args->nr_out_syncobjs,
964 submit_cleanup(submit, !!ret);
966 ww_acquire_fini(&submit->ticket);
968 mutex_unlock(&queue->lock);
970 if (ret && (out_fence_fd >= 0))
971 put_unused_fd(out_fence_fd);
973 if (!IS_ERR_OR_NULL(submit)) {
974 msm_gem_submit_put(submit);
977 * If the submit hasn't yet taken ownership of the queue
978 * then we need to drop the reference ourself:
980 msm_submitqueue_put(queue);
982 if (!IS_ERR_OR_NULL(post_deps)) {
983 for (i = 0; i < args->nr_out_syncobjs; ++i) {
984 kfree(post_deps[i].chain);
985 drm_syncobj_put(post_deps[i].syncobj);
990 if (!IS_ERR_OR_NULL(syncobjs_to_reset)) {
991 for (i = 0; i < args->nr_in_syncobjs; ++i) {
992 if (syncobjs_to_reset[i])
993 drm_syncobj_put(syncobjs_to_reset[i]);
995 kfree(syncobjs_to_reset);