Merge tag 'amd-drm-next-5.19-2022-04-29' of https://gitlab.freedesktop.org/agd5f...
[linux-2.6-microblaze.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_cs.c
index 67bd506..2982b54 100644 (file)
@@ -55,8 +55,8 @@ static int amdgpu_cs_user_fence_chunk(struct amdgpu_cs_parser *p,
        bo = amdgpu_bo_ref(gem_to_amdgpu_bo(gobj));
        p->uf_entry.priority = 0;
        p->uf_entry.tv.bo = &bo->tbo;
-       /* One for TTM and one for the CS job */
-       p->uf_entry.tv.num_shared = 2;
+       /* One for TTM and two for the CS job */
+       p->uf_entry.tv.num_shared = 3;
 
        drm_gem_object_put(gobj);
 
@@ -128,6 +128,8 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_cs
                goto free_chunk;
        }
 
+       mutex_lock(&p->ctx->lock);
+
        /* skip guilty context job */
        if (atomic_read(&p->ctx->guilty) == 1) {
                ret = -ECANCELED;
@@ -574,14 +576,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
                struct amdgpu_bo *bo = ttm_to_amdgpu_bo(e->tv.bo);
 
                e->bo_va = amdgpu_vm_bo_find(vm, bo);
-
-               if (bo->tbo.base.dma_buf && !amdgpu_bo_explicit_sync(bo)) {
-                       e->chain = dma_fence_chain_alloc();
-                       if (!e->chain) {
-                               r = -ENOMEM;
-                               goto error_validate;
-                       }
-               }
        }
 
        /* Move fence waiting after getting reservation lock of
@@ -642,13 +636,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
        }
 
 error_validate:
-       if (r) {
-               amdgpu_bo_list_for_each_entry(e, p->bo_list) {
-                       dma_fence_chain_free(e->chain);
-                       e->chain = NULL;
-               }
+       if (r)
                ttm_eu_backoff_reservation(&p->ticket, &p->validated);
-       }
 
 out_free_user_pages:
        if (r) {
@@ -700,17 +689,9 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
 {
        unsigned i;
 
-       if (error && backoff) {
-               struct amdgpu_bo_list_entry *e;
-
-               amdgpu_bo_list_for_each_entry(e, parser->bo_list) {
-                       dma_fence_chain_free(e->chain);
-                       e->chain = NULL;
-               }
-
+       if (error && backoff)
                ttm_eu_backoff_reservation(&parser->ticket,
                                           &parser->validated);
-       }
 
        for (i = 0; i < parser->num_post_deps; i++) {
                drm_syncobj_put(parser->post_deps[i].syncobj);
@@ -721,6 +702,7 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
        dma_fence_put(parser->fence);
 
        if (parser->ctx) {
+               mutex_unlock(&parser->ctx->lock);
                amdgpu_ctx_put(parser->ctx);
        }
        if (parser->bo_list)
@@ -1169,6 +1151,9 @@ static int amdgpu_cs_dependencies(struct amdgpu_device *adev,
 {
        int i, r;
 
+       /* TODO: Investigate why we still need the context lock */
+       mutex_unlock(&p->ctx->lock);
+
        for (i = 0; i < p->nchunks; ++i) {
                struct amdgpu_cs_chunk *chunk;
 
@@ -1179,32 +1164,34 @@ static int amdgpu_cs_dependencies(struct amdgpu_device *adev,
                case AMDGPU_CHUNK_ID_SCHEDULED_DEPENDENCIES:
                        r = amdgpu_cs_process_fence_dep(p, chunk);
                        if (r)
-                               return r;
+                               goto out;
                        break;
                case AMDGPU_CHUNK_ID_SYNCOBJ_IN:
                        r = amdgpu_cs_process_syncobj_in_dep(p, chunk);
                        if (r)
-                               return r;
+                               goto out;
                        break;
                case AMDGPU_CHUNK_ID_SYNCOBJ_OUT:
                        r = amdgpu_cs_process_syncobj_out_dep(p, chunk);
                        if (r)
-                               return r;
+                               goto out;
                        break;
                case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT:
                        r = amdgpu_cs_process_syncobj_timeline_in_dep(p, chunk);
                        if (r)
-                               return r;
+                               goto out;
                        break;
                case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL:
                        r = amdgpu_cs_process_syncobj_timeline_out_dep(p, chunk);
                        if (r)
-                               return r;
+                               goto out;
                        break;
                }
        }
 
-       return 0;
+out:
+       mutex_lock(&p->ctx->lock);
+       return r;
 }
 
 static void amdgpu_cs_post_dependencies(struct amdgpu_cs_parser *p)
@@ -1284,24 +1271,9 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
 
        amdgpu_vm_move_to_lru_tail(p->adev, &fpriv->vm);
 
-       amdgpu_bo_list_for_each_entry(e, p->bo_list) {
-               struct dma_resv *resv = e->tv.bo->base.resv;
-               struct dma_fence_chain *chain = e->chain;
-
-               if (!chain)
-                       continue;
-
-               /*
-                * Work around dma_resv shortcomings by wrapping up the
-                * submission in a dma_fence_chain and add it as exclusive
-                * fence.
-                */
-               dma_fence_chain_init(chain, dma_resv_excl_fence(resv),
-                                    dma_fence_get(p->fence), 1);
-
-               rcu_assign_pointer(resv->fence_excl, &chain->base);
-               e->chain = NULL;
-       }
+       /* Make sure all BOs are remembered as writers */
+       amdgpu_bo_list_for_each_entry(e, p->bo_list)
+               e->tv.num_shared = 0;
 
        ttm_eu_fence_buffer_objects(&p->ticket, &p->validated, p->fence);
        mutex_unlock(&p->adev->notifier_lock);
@@ -1380,6 +1352,7 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
                goto out;
 
        r = amdgpu_cs_submit(&parser, cs);
+
 out:
        amdgpu_cs_parser_fini(&parser, r, reserved_buffers);