From: Vitaly Prosyak <[email protected]>

dma_resv_add_fence() requires the caller to pre-allocate space with
dma_resv_reserve_fences(). amdgpu_evf_mgr_attach_fence() omits this
call, so when ttm_bo_validate() consumes all pre-allocated slots the
subsequent dma_resv_add_fence() triggers:

  kernel BUG at drivers/dma-buf/dma-resv.c:319!
  BUG_ON(fobj->num_fences >= fobj->max_fences)
  Workqueue: events amdgpu_userq_restore_worker

Add dma_resv_reserve_fences(resv, 1) after ttm_bo_validate() and before
dma_resv_add_fence() to guarantee a free slot.

Cc: Christian Koenig <[email protected]>
Cc: Alex Deucher <[email protected]>
Cc: Sunil Khatri <[email protected]>
Signed-off-by: Vitaly Prosyak <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c
index 4c5e38dea4c2..26b52378e053 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c
@@ -105,6 +105,8 @@ int amdgpu_evf_mgr_attach_fence(struct 
amdgpu_eviction_fence_mgr *evf_mgr,
 
                amdgpu_bo_placement_from_domain(bo, bo->allowed_domains);
                ret = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
+               if (!ret)
+                       ret = dma_resv_reserve_fences(resv, 1);
                if (!ret)
                        dma_resv_add_fence(resv, ev_fence,
                                           DMA_RESV_USAGE_BOOKKEEP);
-- 
2.54.0

Reply via email to