Skip to content

Commit 8473bfd

Browse files
ChristianKoenigAMDalexdeucher
authored andcommitted
drm/amdgpu: fix error handling in amdgpu_vm_init
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]> Signed-off-by: Alex Deucher <[email protected]> Cc: [email protected]
1 parent 2565030 commit 8473bfd

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,8 @@ long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout)
21392139
* Returns:
21402140
* 0 for success, error for failure.
21412141
*/
2142-
int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp_id)
2142+
int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
2143+
int32_t xcp_id)
21432144
{
21442145
struct amdgpu_bo *root_bo;
21452146
struct amdgpu_bo_vm *root;
@@ -2158,6 +2159,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp
21582159
INIT_LIST_HEAD(&vm->done);
21592160
INIT_LIST_HEAD(&vm->pt_freed);
21602161
INIT_WORK(&vm->pt_free_work, amdgpu_vm_pt_free_work);
2162+
INIT_KFIFO(vm->faults);
21612163

21622164
r = amdgpu_vm_init_entities(adev, vm);
21632165
if (r)
@@ -2192,34 +2194,33 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp
21922194
false, &root, xcp_id);
21932195
if (r)
21942196
goto error_free_delayed;
2195-
root_bo = &root->bo;
2197+
2198+
root_bo = amdgpu_bo_ref(&root->bo);
21962199
r = amdgpu_bo_reserve(root_bo, true);
2197-
if (r)
2198-
goto error_free_root;
2200+
if (r) {
2201+
amdgpu_bo_unref(&root->shadow);
2202+
amdgpu_bo_unref(&root_bo);
2203+
goto error_free_delayed;
2204+
}
21992205

2206+
amdgpu_vm_bo_base_init(&vm->root, vm, root_bo);
22002207
r = dma_resv_reserve_fences(root_bo->tbo.base.resv, 1);
22012208
if (r)
2202-
goto error_unreserve;
2203-
2204-
amdgpu_vm_bo_base_init(&vm->root, vm, root_bo);
2209+
goto error_free_root;
22052210

22062211
r = amdgpu_vm_pt_clear(adev, vm, root, false);
22072212
if (r)
2208-
goto error_unreserve;
2213+
goto error_free_root;
22092214

22102215
amdgpu_bo_unreserve(vm->root.bo);
2211-
2212-
INIT_KFIFO(vm->faults);
2216+
amdgpu_bo_unref(&root_bo);
22132217

22142218
return 0;
22152219

2216-
error_unreserve:
2217-
amdgpu_bo_unreserve(vm->root.bo);
2218-
22192220
error_free_root:
2220-
amdgpu_bo_unref(&root->shadow);
2221+
amdgpu_vm_pt_free_root(adev, vm);
2222+
amdgpu_bo_unreserve(vm->root.bo);
22212223
amdgpu_bo_unref(&root_bo);
2222-
vm->root.bo = NULL;
22232224

22242225
error_free_delayed:
22252226
dma_fence_put(vm->last_tlb_flush);

0 commit comments

Comments
 (0)