drm/amdgpu: fix and cleanup amdgpu_gem_object_close v2
Subsystems (2)
PATCH 1/2 drm/amdgpu: fix and cleanup amdgpu_gem_object_close v2
The problem is that we can't add the clear fence to the BO when there is an exclusive fence on it since we can't guarantee the the clear fence will complete after the exclusive one.
To fix this refactor the function and also add the exclusive fence as shared to the resv object.
v2: fix warning
v3: add excl fence as shared instead
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 41 ++++++++++++++----------- 1 file changed, 23 insertions(+), 18 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +23 -18
@@ -161,16 +161,17 @@ void amdgpu_gem_object_close(struct drm_gem_object *obj,struct amdgpu_bo_list_entry vm_pd;struct list_head list, duplicates; +struct dma_fence *fence =NULL ;struct ttm_validate_buffer tv;struct ww_acquire_ctx ticket;struct amdgpu_bo_va *bo_va; -int r; +long r;INIT_LIST_HEAD (&list);INIT_LIST_HEAD (&duplicates); tv.bo = &bo->tbo; - tv.num_shared =1 ; + tv.num_shared =2 ;list_add (&tv.head, &list);amdgpu_vm_get_pd_bo (vm, &list, &vm_pd);
@@ -178,28 +179,32 @@ void amdgpu_gem_object_close(struct drm_gem_object *obj, r =ttm_eu_reserve_buffers (&ticket, &list, false, &duplicates);if (r) {dev_err (adev->dev,"leaking bo va because " -"we fail to reserve bo (%d)\n" , r); +"we fail to reserve bo (%ld)\n" , r);return ; } bo_va =amdgpu_vm_bo_find (vm, bo); -if (bo_va && --bo_va->ref_count ==0 ) { -amdgpu_vm_bo_rmv (adev, bo_va); +if (!bo_va || --bo_va->ref_count) + goto out_unlock; -if (amdgpu_vm_ready (vm)) { -struct dma_fence *fence =NULL ; +amdgpu_vm_bo_rmv (adev, bo_va); +if (!amdgpu_vm_ready (vm)) + goto out_unlock; - r =amdgpu_vm_clear_freed (adev, vm, &fence); -if (unlikely (r)) { -dev_err (adev->dev,"failed to clear page " -"tables on GEM object close (%d)\n" , r); - } + fence =dma_resv_get_excl (bo->tbo.base.resv); +amdgpu_bo_fence (bo, fence, true); + fence =NULL ; -if (fence) { -amdgpu_bo_fence (bo, fence, true); -dma_fence_put (fence); - } - } - } + r =amdgpu_vm_clear_freed (adev, vm, &fence); +if (r || !fence) + goto out_unlock; + +amdgpu_bo_fence (bo, fence, true); +dma_fence_put (fence); + +out_unlock: +if (unlikely (r <0 )) +dev_err (adev->dev,"failed to clear page " +"tables on GEM object close (%ld)\n" , r);ttm_eu_backoff_reservation (&ticket, &list); }
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 2/2 drm/amdgpu: partial revert VM sync changes
We still need to add the VM update fences to the root PD.
So make sure to never sync to those implicitely.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +5 -0
@@ -249,6 +249,11 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync, owner != AMDGPU_FENCE_OWNER_UNDEFINED)continue ; +/* Never sync to VM updates either. */ +if (fence_owner ==AMDGPU_FENCE_OWNER_VM && + owner !=AMDGPU_FENCE_OWNER_UNDEFINED ) +continue ; +/* Ignore fences depending on the sync mode */ switch (mode) {case AMDGPU_SYNC_ALWAYS :
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 94 lines
2020年3月30日 18:50,Christian König <[email protected]> 写道:
The problem is that we can't add the clear fence to the BO when there is an exclusive fence on it since we can't guarantee the the clear fence will complete after the exclusive one.
To fix this refactor the function and also add the exclusive fence as shared to the resv object.
v2: fix warning
v3: add excl fence as shared insteadSigned-off-by Christian König <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c| 41 ++++++++++++++-----------1 file changed, 23 insertions(+), 18 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +23
-18@@ -161,16 +161,17 @@ void amdgpu_gem_object_close(struct drm_gem_object *obj,struct amdgpu_bo_list_entry vm_pd;struct list_head list, duplicates; +struct dma_fence *fence =NULL ;struct ttm_validate_buffer tv;struct ww_acquire_ctx ticket;struct amdgpu_bo_va *bo_va; -int r; +long r;INIT_LIST_HEAD (&list);INIT_LIST_HEAD (&duplicates); tv.bo = &bo->tbo; - tv.num_shared =1 ; + tv.num_shared =2 ;list_add (&tv.head, &list);amdgpu_vm_get_pd_bo (vm, &list, &vm_pd);@@ -178,28 +179,32 @@ void amdgpu_gem_object_close(struct drm_gem_object *obj, r =ttm_eu_reserve_buffers (&ticket, &list, false, &duplicates);if (r) {dev_err (adev->dev,"leaking bo va because " -"we fail to reserve bo (%d)\n" , r); +"we fail to reserve bo (%ld)\n" , r);return ; } bo_va =amdgpu_vm_bo_find (vm, bo); -if (bo_va && --bo_va->ref_count ==0 ) { -amdgpu_vm_bo_rmv (adev, bo_va); +if (!bo_va || --bo_va->ref_count) + goto out_unlock; -if (amdgpu_vm_ready (vm)) { -struct dma_fence *fence =NULL ; +amdgpu_vm_bo_rmv (adev, bo_va); +if (!amdgpu_vm_ready (vm)) + goto out_unlock; - r =amdgpu_vm_clear_freed (adev, vm, &fence); -if (unlikely (r)) { -dev_err (adev->dev,"failed to clear page " -"tables on GEM object close (%d)\n" , r); - } + fence =dma_resv_get_excl (bo->tbo.base.resv); +amdgpu_bo_fence (bo, fence, true); + fence =NULL ; -if (fence) { -amdgpu_bo_fence (bo, fence, true); -dma_fence_put (fence); - } - } - } + r =amdgpu_vm_clear_freed (adev, vm, &fence); +if (r || !fence) + goto out_unlock; + +amdgpu_bo_fence (bo, fence, true); +dma_fence_put (fence); + +out_unlock: +if (unlikely (r <0 )) +dev_err (adev->dev,"failed to clear page " +"tables on GEM object close (%ld)\n" , r);ttm_eu_backoff_reservation (&ticket, &list); }Signature · 1 line
2.17.1
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx