AMD General

Regards,
      Prike

> -----Original Message-----
> From: amd-gfx <[email protected]> On Behalf Of
> [email protected]
> Sent: Tuesday, August 25, 2026 7:30 AM
> To: [email protected]
> Cc: Koenig, Christian <[email protected]>; Deucher, Alexander
> <[email protected]>; Prosyak, Vitaly <[email protected]>;
> Khatri, Sunil <[email protected]>
> Subject: [PATCH 1/5] drm/amdgpu: reserve dma_resv slot before adding eviction
> fence
>
> 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);

We may not need to explicitly reserve the dma_resv slot here, the slot should 
ideally be reserved at the call site (e.g., 
amdgpu_userq_vm_validate_and_restore_queue()). I observed this issue as well, 
but we should still audit all callers to identify exactly where the reservation 
is missing.

If this patch is needed as a workaround in the meantime, the 
dma_resv_reserve_fences() call can be placed directly before 
dma_resv_add_fence() as follows.

    amdgpu_bo_placement_from_domain(bo, bo->allowed_domains);
                ret = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
-               if (!ret)
+               if (!ret) {
+                       dma_resv_reserve_fences(resv, 1);
                        dma_resv_add_fence(resv, ev_fence,
                                           DMA_RESV_USAGE_BOOKKEEP);
+               }


>               if (!ret)
>                       dma_resv_add_fence(resv, ev_fence,
>                                          DMA_RESV_USAGE_BOOKKEEP);
> --
> 2.54.0

Reply via email to