drm/amdgpu: enable eviction fence
authorShashank Sharma <shashank.sharma@amd.com>
Wed, 20 Nov 2024 17:45:33 +0000 (18:45 +0100)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 8 Apr 2025 20:48:19 +0000 (16:48 -0400)
This patch enables attachment and detachment of eviction fences.
This is just a fork of eviction fence enabling code from the first
patch of the series so that the CI testing can happen on fully
fledged code.

Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Christian Koenig <christian.koenig@amd.com>
Reviewed-by: Christian Koenig <christian.koenig@amd.com>
Signed-off-by: Shashank Sharma <shashank.sharma@amd.com>
Signed-off-by: Arvind Yadav <arvind.yadav@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_gem.c

index 8358dc6b68ad33fd84502efcf4fab330dbb5e122..167951aee502d223de0ec85d7ecef2a37d297139 100644 (file)
@@ -177,6 +177,8 @@ void amdgpu_eviction_fence_destroy(struct amdgpu_eviction_fence_mgr *evf_mgr)
        if (!ev_fence)
                return;
 
+       dma_fence_wait(&ev_fence->base, false);
+
        /* Last unref of ev_fence */
        dma_fence_put(&evf_mgr->ev_fence->base);
 }
index 682b76cad359cb5103236643680cebaa5aece185..6850a6954a716a2aac94b2476eb55ca5668dedbf 100644 (file)
@@ -294,6 +294,13 @@ static int amdgpu_gem_object_open(struct drm_gem_object *obj,
        else
                ++bo_va->ref_count;
 
+       /* attach gfx eviction fence */
+       r = amdgpu_eviction_fence_attach(&fpriv->evf_mgr, abo);
+       if (r) {
+               DRM_DEBUG_DRIVER("Failed to attach eviction fence to BO\n");
+               return r;
+       }
+
        amdgpu_bo_unreserve(abo);
 
        /* Validate and add eviction fence to DMABuf imports with dynamic
@@ -344,6 +351,9 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,
        struct drm_exec exec;
        long r;
 
+       if (!amdgpu_vm_is_bo_always_valid(vm, bo))
+               amdgpu_eviction_fence_detach(&fpriv->evf_mgr, bo);
+
        drm_exec_init(&exec, DRM_EXEC_IGNORE_DUPLICATES, 0);
        drm_exec_until_all_locked(&exec) {
                r = drm_exec_prepare_obj(&exec, &bo->tbo.base, 1);