drm/amdgpu: fix error handling in amdgpu_vm_init
Subsystems (2)
PATCH 1/1 drm/amdgpu: fix error handling in amdgpu_vm_init
When clearing the root PD fails we need to properly release it again.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 31 +++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +16 -15
@@ -2042,7 +2042,8 @@ long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout)* Returns: * 0 for success, error for failure. */ -int amdgpu_vm_init (struct amdgpu_device *adev,struct amdgpu_vm *vm,int32_t xcp_id) +int amdgpu_vm_init (struct amdgpu_device *adev,struct amdgpu_vm *vm, +int32_t xcp_id) {struct amdgpu_bo *root_bo;struct amdgpu_bo_vm *root;
@@ -2061,6 +2062,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcpINIT_LIST_HEAD (&vm->done);INIT_LIST_HEAD (&vm->pt_freed);INIT_WORK (&vm->pt_free_work, amdgpu_vm_pt_free_work); +INIT_KFIFO (vm->faults);/* create scheduler entities for page table updates */ r = drm_sched_entity_init(&vm->immediate, DRM_SCHED_PRIORITY_NORMAL,
@@ -2103,34 +2105,33 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp false, &root, xcp_id);if (r) goto error_free_delayed; - root_bo = &root->bo; + + root_bo =amdgpu_bo_ref (&root->bo); r =amdgpu_bo_reserve (root_bo, true); -if (r) - goto error_free_root; +if (r) { +amdgpu_bo_unref (&root->shadow); +amdgpu_bo_unref (&root_bo); + goto error_free_delayed; + } +amdgpu_vm_bo_base_init (&vm->root, vm, root_bo); r =dma_resv_reserve_fences (root_bo->tbo.base.resv,1 );if (r) - goto error_unreserve; - -amdgpu_vm_bo_base_init (&vm->root, vm, root_bo); + goto error_free_root; r =amdgpu_vm_pt_clear (adev, vm, root, false);if (r) - goto error_unreserve; + goto error_free_root;amdgpu_bo_unreserve (vm->root.bo); - -INIT_KFIFO (vm->faults); +amdgpu_bo_unref (&root_bo);return 0 ; -error_unreserve: -amdgpu_bo_unreserve (vm->root.bo); - error_free_root: -amdgpu_bo_unref (&root->shadow); +amdgpu_vm_pt_free_root (adev, vm); +amdgpu_bo_unreserve (vm->root.bo);amdgpu_bo_unref (&root_bo); - vm->root.bo =NULL ; error_free_delayed:dma_fence_put (vm->last_tlb_flush);
Signature · 1 line
2.34.1
Quoted 4 lines · Christian König
When clearing the root PD fails we need to properly release it again.
Signed-off-by Christian König <[email protected]>
Quoted 77 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 31 +++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +16
-16@@ -2042,7 +2042,8 @@ long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout)* Returns: * 0 for success, error for failure. */ -int amdgpu_vm_init (struct amdgpu_device *adev,struct amdgpu_vm *vm,int32_t xcp_id) +int amdgpu_vm_init (struct amdgpu_device *adev,struct amdgpu_vm *vm, +int32_t xcp_id) {struct amdgpu_bo *root_bo;struct amdgpu_bo_vm *root;@@ -2061,6 +2062,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcpINIT_LIST_HEAD (&vm->done);INIT_LIST_HEAD (&vm->pt_freed);INIT_WORK (&vm->pt_free_work, amdgpu_vm_pt_free_work); +INIT_KFIFO (vm->faults);/* create scheduler entities for page table updates */ r = drm_sched_entity_init(&vm->immediate, DRM_SCHED_PRIORITY_NORMAL,@@ -2103,34 +2105,33 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp false, &root, xcp_id);if (r) goto error_free_delayed; - root_bo = &root->bo; + + root_bo =amdgpu_bo_ref (&root->bo); r =amdgpu_bo_reserve (root_bo, true); -if (r) - goto error_free_root; +if (r) { +amdgpu_bo_unref (&root->shadow); +amdgpu_bo_unref (&root_bo); + goto error_free_delayed; + } +amdgpu_vm_bo_base_init (&vm->root, vm, root_bo); r =dma_resv_reserve_fences (root_bo->tbo.base.resv,1 );if (r) - goto error_unreserve; - -amdgpu_vm_bo_base_init (&vm->root, vm, root_bo); + goto error_free_root; r =amdgpu_vm_pt_clear (adev, vm, root, false);if (r) - goto error_unreserve; + goto error_free_root;amdgpu_bo_unreserve (vm->root.bo); - -INIT_KFIFO (vm->faults); +amdgpu_bo_unref (&root_bo);return 0 ; -error_unreserve: -amdgpu_bo_unreserve (vm->root.bo); - error_free_root: -amdgpu_bo_unref (&root->shadow); +amdgpu_vm_pt_free_root (adev, vm); +amdgpu_bo_unreserve (vm->root.bo);amdgpu_bo_unref (&root_bo); - vm->root.bo =NULL ; error_free_delayed:dma_fence_put (vm->last_tlb_flush); --2.34.1
Quoted 6 lines · Alex Deucher
Quoted 3 lines · Christian König
When clearing the root PD fails we need to properly release it again.
Signed-off-by Christian König <[email protected]>Acked-by Alex Deucher <[email protected]>
Has this been submitted? I see some intermittent failures in the PSDB that may be related to this.
Regards,
Felix
Quoted 78 lines
Quoted 78 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 31 +++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +16
-16@@ -2042,7 +2042,8 @@ long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout)* Returns: * 0 for success, error for failure. */ -int amdgpu_vm_init (struct amdgpu_device *adev,struct amdgpu_vm *vm,int32_t xcp_id) +int amdgpu_vm_init (struct amdgpu_device *adev,struct amdgpu_vm *vm, +int32_t xcp_id) {struct amdgpu_bo *root_bo;struct amdgpu_bo_vm *root;@@ -2061,6 +2062,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcpINIT_LIST_HEAD (&vm->done);INIT_LIST_HEAD (&vm->pt_freed);INIT_WORK (&vm->pt_free_work, amdgpu_vm_pt_free_work); +INIT_KFIFO (vm->faults);/* create scheduler entities for page table updates */ r = drm_sched_entity_init(&vm->immediate, DRM_SCHED_PRIORITY_NORMAL,@@ -2103,34 +2105,33 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp false, &root, xcp_id);if (r) goto error_free_delayed; - root_bo = &root->bo; + + root_bo =amdgpu_bo_ref (&root->bo); r =amdgpu_bo_reserve (root_bo, true); -if (r) - goto error_free_root; +if (r) { +amdgpu_bo_unref (&root->shadow); +amdgpu_bo_unref (&root_bo); + goto error_free_delayed; + } +amdgpu_vm_bo_base_init (&vm->root, vm, root_bo); r =dma_resv_reserve_fences (root_bo->tbo.base.resv,1 );if (r) - goto error_unreserve; - -amdgpu_vm_bo_base_init (&vm->root, vm, root_bo); + goto error_free_root; r =amdgpu_vm_pt_clear (adev, vm, root, false);if (r) - goto error_unreserve; + goto error_free_root;amdgpu_bo_unreserve (vm->root.bo); - -INIT_KFIFO (vm->faults); +amdgpu_bo_unref (&root_bo);return 0 ; -error_unreserve: -amdgpu_bo_unreserve (vm->root.bo); - error_free_root: -amdgpu_bo_unref (&root->shadow); +amdgpu_vm_pt_free_root (adev, vm); +amdgpu_bo_unreserve (vm->root.bo);amdgpu_bo_unref (&root_bo); - vm->root.bo =NULL ; error_free_delayed:dma_fence_put (vm->last_tlb_flush); --2.34.1
Am 01.11.23 um 23:00 schrieb Felix Kuehling:
Quoted 8 lines · Alex Deucher
Quoted 6 lines
Quoted 3 lines · Christian König
When clearing the root PD fails we need to properly release it again.
Signed-off-by Christian König <[email protected]>Acked-by Alex Deucher <[email protected]>Has this been submitted? I see some intermittent failures in the PSDB that may be related to this.
Not yet. But going to push that now
This is just a fix for the error code path. Fixing the underlying problem had more importance.
Regards,
Christian.
Quoted 89 lines
Regards,
FelixQuoted 83 lines
Quoted 83 lines
---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c| 31
+++++++++++++-------------1 file changed, 16 insertions(+), 15 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1@@ -2042,7 +2042,8 @@ long amdgpu_vm_wait_idle(struct amdgpu_vm *vm,long timeout) * Returns: * 0 for success, error for failure. */ -int amdgpu_vm_init (struct amdgpu_device *adev,struct amdgpu_vm *vm, int32_t xcp_id) +int amdgpu_vm_init (struct amdgpu_device *adev,struct amdgpu_vm *vm, + int32_t xcp_id) {struct
amdgpu_bo*root_bo;
structamdgpu_bo_vm*root;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -2061,6 +2062,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev,struct
amdgpu_vm*vm,int32_txcpINIT_LIST_HEAD(&vm->done);INIT_LIST_HEAD(&vm->pt_freed);INIT_WORK(&vm->pt_free_work, amdgpu_vm_pt_free_work); +INIT_KFIFO(vm->faults);/* create scheduler entities for page table updates */
r = drm_sched_entity_init(&vm->immediate,DRM_SCHED_PRIORITY_NORMAL,drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +11
-12@@ -2103,34 +2105,33 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp false, &root, xcp_id); if (r) goto error_free_delayed; - root_bo = &root->bo; + + root_bo = amdgpu_bo_ref(&root->bo); r = amdgpu_bo_reserve(root_bo, true); - if (r) - goto error_free_root; + if (r) { + amdgpu_bo_unref(&root->shadow); + amdgpu_bo_unref(&root_bo); + goto error_free_delayed; + } + amdgpu_vm_bo_base_init(&vm->root, vm, root_bo); r = dma_resv_reserve_fences(root_bo->tbo.base.resv, 1); if (r) - goto error_unreserve; - - amdgpu_vm_bo_base_init(&vm->root, vm, root_bo); + goto error_free_root; r = amdgpu_vm_pt_clear(adev, vm, root, false); if (r) - goto error_unreserve; + goto error_free_root; amdgpu_bo_unreserve(vm->root.bo); - - INIT_KFIFO(vm->faults); + amdgpu_bo_unref(&root_bo); return 0; -error_unreserve: - amdgpu_bo_unreserve(vm->root.bo); -
error_free_root:
-amdgpu_bo_unref(&root->shadow);
+amdgpu_vm_pt_free_root(adev, vm);
+amdgpu_bo_unreserve(vm->root.bo);
amdgpu_bo_unref(&root_bo);
-vm->root.bo= NULL;
error_free_delayed:
dma_fence_put(vm->last_tlb_flush);Signature · 1 line
2.34.1