]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amdgpu: fix adding eviction fence
authorChristian König <christian.koenig@amd.com>
Wed, 28 Jan 2026 15:07:03 +0000 (16:07 +0100)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 17 Mar 2026 21:46:26 +0000 (17:46 -0400)
We can't add the eviction fence without validating the BO.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Sunil Khatri <sunil.khatri@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.h
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c

index 72df5368a9e6d340a42aa50e8585fd22d660a051..55e8b9cc2f9f3227c4d1779412c8c2c5d31724ad 100644 (file)
@@ -79,14 +79,27 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)
        mutex_unlock(&uq_mgr->userq_mutex);
 }
 
-void amdgpu_evf_mgr_attach_fence(struct amdgpu_eviction_fence_mgr *evf_mgr,
-                                struct amdgpu_bo *bo)
+int amdgpu_evf_mgr_attach_fence(struct amdgpu_eviction_fence_mgr *evf_mgr,
+                               struct amdgpu_bo *bo)
 {
        struct dma_fence *ev_fence = amdgpu_evf_mgr_get_fence(evf_mgr);
+       struct ttm_operation_ctx ctx = { false, false };
        struct dma_resv *resv = bo->tbo.base.resv;
+       int ret;
+
+       if (!dma_fence_is_signaled(ev_fence)) {
+
+               amdgpu_bo_placement_from_domain(bo, bo->allowed_domains);
+               ret = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
+               if (!ret)
+                       dma_resv_add_fence(resv, ev_fence,
+                                          DMA_RESV_USAGE_BOOKKEEP);
+       } else {
+               ret = 0;
+       }
 
-       dma_resv_add_fence(resv, ev_fence, DMA_RESV_USAGE_BOOKKEEP);
        dma_fence_put(ev_fence);
+       return ret;
 }
 
 int amdgpu_evf_mgr_rearm(struct amdgpu_eviction_fence_mgr *evf_mgr,
index 132a13a5dc1c1b26a2bd0d9b4902f1ca0e9f88c1..2a750add4e7b56cbcf74a69191a0f7cff5987c78 100644 (file)
@@ -58,8 +58,8 @@ amdgpu_evf_mgr_get_fence(struct amdgpu_eviction_fence_mgr *evf_mgr)
        return ev_fence;
 }
 
-void amdgpu_evf_mgr_attach_fence(struct amdgpu_eviction_fence_mgr *evf_mgr,
-                                struct amdgpu_bo *bo);
+int amdgpu_evf_mgr_attach_fence(struct amdgpu_eviction_fence_mgr *evf_mgr,
+                               struct amdgpu_bo *bo);
 int amdgpu_evf_mgr_rearm(struct amdgpu_eviction_fence_mgr *evf_mgr,
                         struct drm_exec *exec);
 void amdgpu_evf_mgr_detach_fence(struct amdgpu_eviction_fence_mgr *evf_mgr,
index ae5c4b355359d3a1ed948aa4a91b792506f2a829..01dc73309d73c478244e93c734e0f00bf66ce830 100644 (file)
@@ -258,12 +258,15 @@ static int amdgpu_gem_object_open(struct drm_gem_object *obj,
 
        amdgpu_vm_bo_update_shared(abo);
        bo_va = amdgpu_vm_bo_find(vm, abo);
-       if (!bo_va)
+       if (!bo_va) {
                bo_va = amdgpu_vm_bo_add(adev, vm, abo);
-       else
+               r = amdgpu_evf_mgr_attach_fence(&fpriv->evf_mgr, abo);
+               if (r)
+                       goto out_unlock;
+       } else {
                ++bo_va->ref_count;
+       }
 
-       amdgpu_evf_mgr_attach_fence(&fpriv->evf_mgr, abo);
        drm_exec_fini(&exec);
 
        /* Validate and add eviction fence to DMABuf imports with dynamic