On Mon, Feb 2, 2026 at 8:37 AM Christian König <[email protected]> wrote: > > We can't add the eviction fence without validating the BO. > > Signed-off-by: Christian König <[email protected]>
Reviewed-by: Alex Deucher <[email protected]> > --- > .../drm/amd/amdgpu/amdgpu_eviction_fence.c | 19 ++++++++++++++++--- > .../drm/amd/amdgpu/amdgpu_eviction_fence.h | 4 ++-- > drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 9 ++++++--- > 3 files changed, 24 insertions(+), 8 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c > index ef4da6f2e2a3..6598823ec619 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c > @@ -82,14 +82,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, > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.h > b/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.h > index 132a13a5dc1c..2a750add4e7b 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.h > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.h > @@ -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, > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > index e28abfd04867..88a21400ae09 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > @@ -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 > -- > 2.43.0 >
