On 2026-11-20 09:18, Christian König wrote:
> On 11/20/26 15:08, Benjamin Cheng wrote:
>> On 2026-11-19 10:04, [email protected] wrote:
>>> Thank you for your contribution! Sashiko AI review found 1 potential
>>> issue to consider:
>>> - [High] drm/amdgpu/vm: unreserved fence slot usage in
>>>   amdgpu_vm_update_range()
>>> --
>>>
>>> commit 62a2ba953c5e8b9b18301c84fc57052868fd3e60
>>> Author: Benjamin Cheng <[email protected]>
>>>
>>> drm/amdgpu/vm: stop using amdgpu_bo_fence
>>>
>>> This commit replaces the amdgpu_bo_fence() call in amdgpu_vm_update_range()
>>> with a direct dma_resv_add_fence() call using DMA_RESV_USAGE_BOOKKEEP.
>>>
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>>> index a0e6bb34ae0be..d4d8cb15ffd38 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>>> @@ -1215,7 +1215,8 @@ int amdgpu_vm_update_range(struct amdgpu_device 
>>>> *adev, struct amdgpu_vm *vm,
>>>>    if (!unlocked && !dma_fence_is_signaled(vm->last_unlocked)) {
>>>>            struct dma_fence *tmp = dma_fence_get_stub();
>>>>  
>>>> -          amdgpu_bo_fence(vm->root.bo, vm->last_unlocked, true);
>>>> +          dma_resv_add_fence(vm->root.bo->tbo.base.resv, 
>>>> vm->last_unlocked,
>>>> +                             DMA_RESV_USAGE_BOOKKEEP);
>>>>            swap(vm->last_unlocked, tmp);
>>>>            dma_fence_put(tmp);
>>>>    }
>>> [Severity: High]
>>> Can this dma_resv_add_fence() call consume an unreserved fence slot and
>>> hit BUG_ON(fobj->num_fences >= fobj->max_fences) when vm->root.bo already
>>> holds a newer fence from vm->delayed?
>>>
>>> Callers such as amdgpu_vm_lock_pd() and amdgpu_dma_buf_move_notify()
>>> reserve only two fence slots for VM updates (one for vm->delayed and one
>>> for the TLB flush fence), relying on vm->last_unlocked and locked SDMA
>>> commits sharing the vm->delayed slot.  However, dma_resv_add_fence() only
>>> replaces an unsignaled same-context slot when
>>> dma_fence_is_later_or_same(fence, old) is true.
>> Hi Christian,
>>
>> I think this edge-case deserves to be fixed in dma_resv_add_fence() right?
> That's not an issue in the first place.
>
>> I don't see any reason we need to add another fence to the resv if it 
>> already has a fence from the same context that is later-or-same and 
>> same-or-stronger usage.
> Maybe, but we shouldn't add fences out of order without allocating an extra 
> slot. The point is rather what the AI claims as problem is nonsense.
>
> The last_unlocked fence is either the signaled stub fence in which case it 
> won't be added or a unlocked update which is after the last update already 
> added and before the update we want to create now.

Yeah, I see that now. Thanks a lot for the explanation.

> So all fences from the same context are still added in order, but the AI 
> doesn't seem to understand that.
>
> Regards,
> christian.
>
>> Thanks,
>>
>> Ben
>>
>>
>>> An unlocked update on vm->delayed can leave vm->last_unlocked with a
>>> seqno older than the fence already in vm->root.bo->tbo.base.resv:
>>>
>>> CPU0 (locked update)              CPU1 (SVM MMU notifier)
>>> amdgpu_vm_update_range()
>>>   /* checks vm->last_unlocked */
>>>   amdgpu_vm_ptes_update()
>>>     amdgpu_vm_pt_alloc()
>>>       amdgpu_vm_end_critical()
>>>                                   svm_range_unmap_from_gpu()
>>>                                     amdgpu_vm_update_range(unlocked=true)
>>>                                       /* submits seqno N on vm->delayed */
>>>                                       /* vm->last_unlocked = seqno N */
>>>       amdgpu_vm_begin_critical()
>>>   /* submits seqno N+1 on vm->delayed */
>>>   /* adds seqno N+1 to vm->root.bo */
>>>
>>> amdgpu_vm_update_range()
>>>   dma_resv_add_fence(..., vm->last_unlocked, ...)
>>>     /* seqno N < seqno N+1: allocates a new slot */
>>>     BUG_ON(fobj->num_fences >= fobj->max_fences)
>>>
>>> The same ordering can occur when an unlocked update sets
>>> vm->last_unlocked before amdgpu_vm_update_pdes(), which submits on
>>> vm->delayed and adds its fence to vm->root.bo without flushing
>>> vm->last_unlocked.
>>>

Reply via email to