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. 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. -- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
