Merge tag 'amd-drm-next-5.19-2022-04-15' of https://gitlab.freedesktop.org/agd5f...
[sfrench/cifs-2.6.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_amdkfd_gpuvm.c
index 8b14c55a079319d19f20fd0324d57b69a23a8edd..80b6b8e432fd0a404ec872793cba1569a19d72ad 100644 (file)
@@ -253,53 +253,18 @@ void amdgpu_amdkfd_release_notify(struct amdgpu_bo *bo)
 static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,
                                        struct amdgpu_amdkfd_fence *ef)
 {
-       struct dma_resv *resv = bo->tbo.base.resv;
-       struct dma_resv_list *old, *new;
-       unsigned int i, j, k;
+       struct dma_fence *replacement;
 
        if (!ef)
                return -EINVAL;
 
-       old = dma_resv_shared_list(resv);
-       if (!old)
-               return 0;
-
-       new = kmalloc(struct_size(new, shared, old->shared_max), GFP_KERNEL);
-       if (!new)
-               return -ENOMEM;
-
-       /* Go through all the shared fences in the resevation object and sort
-        * the interesting ones to the end of the list.
+       /* TODO: Instead of block before we should use the fence of the page
+        * table update and TLB flush here directly.
         */
-       for (i = 0, j = old->shared_count, k = 0; i < old->shared_count; ++i) {
-               struct dma_fence *f;
-
-               f = rcu_dereference_protected(old->shared[i],
-                                             dma_resv_held(resv));
-
-               if (f->context == ef->base.context)
-                       RCU_INIT_POINTER(new->shared[--j], f);
-               else
-                       RCU_INIT_POINTER(new->shared[k++], f);
-       }
-       new->shared_max = old->shared_max;
-       new->shared_count = k;
-
-       /* Install the new fence list, seqcount provides the barriers */
-       write_seqcount_begin(&resv->seq);
-       RCU_INIT_POINTER(resv->fence, new);
-       write_seqcount_end(&resv->seq);
-
-       /* Drop the references to the removed fences or move them to ef_list */
-       for (i = j; i < old->shared_count; ++i) {
-               struct dma_fence *f;
-
-               f = rcu_dereference_protected(new->shared[i],
-                                             dma_resv_held(resv));
-               dma_fence_put(f);
-       }
-       kfree_rcu(old, rcu);
-
+       replacement = dma_fence_get_stub();
+       dma_resv_replace_fences(bo->tbo.base.resv, ef->base.context,
+                               replacement, DMA_RESV_USAGE_READ);
+       dma_fence_put(replacement);
        return 0;
 }
 
@@ -1266,7 +1231,7 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
                                  AMDGPU_FENCE_OWNER_KFD, false);
        if (ret)
                goto wait_pd_fail;
-       ret = dma_resv_reserve_shared(vm->root.bo->tbo.base.resv, 1);
+       ret = dma_resv_reserve_fences(vm->root.bo->tbo.base.resv, 1);
        if (ret)
                goto reserve_shared_fail;
        amdgpu_bo_fence(vm->root.bo,
@@ -2480,6 +2445,8 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef)
                struct amdgpu_bo *bo = mem->bo;
                uint32_t domain = mem->domain;
                struct kfd_mem_attachment *attachment;
+               struct dma_resv_iter cursor;
+               struct dma_fence *fence;
 
                total_size += amdgpu_bo_size(bo);
 
@@ -2494,10 +2461,13 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef)
                                goto validate_map_fail;
                        }
                }
-               ret = amdgpu_sync_fence(&sync_obj, bo->tbo.moving);
-               if (ret) {
-                       pr_debug("Memory eviction: Sync BO fence failed. Try again\n");
-                       goto validate_map_fail;
+               dma_resv_for_each_fence(&cursor, bo->tbo.base.resv,
+                                       DMA_RESV_USAGE_KERNEL, fence) {
+                       ret = amdgpu_sync_fence(&sync_obj, fence);
+                       if (ret) {
+                               pr_debug("Memory eviction: Sync BO fence failed. Try again\n");
+                               goto validate_map_fail;
+                       }
                }
                list_for_each_entry(attachment, &mem->attachments, list) {
                        if (!attachment->is_mapped)
@@ -2604,7 +2574,7 @@ int amdgpu_amdkfd_add_gws_to_process(void *info, void *gws, struct kgd_mem **mem
         * Add process eviction fence to bo so they can
         * evict each other.
         */
-       ret = dma_resv_reserve_shared(gws_bo->tbo.base.resv, 1);
+       ret = dma_resv_reserve_fences(gws_bo->tbo.base.resv, 1);
        if (ret)
                goto reserve_shared_fail;
        amdgpu_bo_fence(gws_bo, &process_info->eviction_fence->base, true);