Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu: add optional fence out-parameter to amdgpu_vm_clear_freed

We will add the fence to freed buffer objects in a later commit, to ensure
that the underlying memory can only be re-used after all references in
page tables have been cleared.

Signed-off-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Reviewed-by: Chunming Zhou <david1.zhou@amd.com>
Reviewed-by: Junwei Zhang <Jerry.Zhang@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Nicolai Hähnle and committed by
Alex Deucher
f3467818 923d26db

+20 -10
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
··· 785 785 if (r) 786 786 return r; 787 787 788 - r = amdgpu_vm_clear_freed(adev, vm); 788 + r = amdgpu_vm_clear_freed(adev, vm, NULL); 789 789 if (r) 790 790 return r; 791 791
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
··· 540 540 if (r) 541 541 goto error; 542 542 543 - r = amdgpu_vm_clear_freed(adev, vm); 543 + r = amdgpu_vm_clear_freed(adev, vm, NULL); 544 544 if (r) 545 545 goto error; 546 546
+16 -7
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
··· 1382 1382 * 1383 1383 * @adev: amdgpu_device pointer 1384 1384 * @vm: requested vm 1385 + * @fence: optional resulting fence (unchanged if no work needed to be done 1386 + * or if an error occurred) 1385 1387 * 1386 1388 * Make sure all freed BOs are cleared in the PT. 1387 1389 * Returns 0 for success. ··· 1391 1389 * PTs have to be reserved and mutex must be locked! 1392 1390 */ 1393 1391 int amdgpu_vm_clear_freed(struct amdgpu_device *adev, 1394 - struct amdgpu_vm *vm) 1392 + struct amdgpu_vm *vm, 1393 + struct dma_fence **fence) 1395 1394 { 1396 1395 struct amdgpu_bo_va_mapping *mapping; 1397 - struct dma_fence *fence = NULL; 1396 + struct dma_fence *f = NULL; 1398 1397 int r; 1399 1398 1400 1399 while (!list_empty(&vm->freed)) { ··· 1404 1401 list_del(&mapping->list); 1405 1402 1406 1403 r = amdgpu_vm_bo_split_mapping(adev, NULL, 0, NULL, vm, mapping, 1407 - 0, 0, &fence); 1408 - amdgpu_vm_free_mapping(adev, vm, mapping, fence); 1404 + 0, 0, &f); 1405 + amdgpu_vm_free_mapping(adev, vm, mapping, f); 1409 1406 if (r) { 1410 - dma_fence_put(fence); 1407 + dma_fence_put(f); 1411 1408 return r; 1412 1409 } 1413 - 1414 1410 } 1415 - dma_fence_put(fence); 1411 + 1412 + if (fence && f) { 1413 + dma_fence_put(*fence); 1414 + *fence = f; 1415 + } else { 1416 + dma_fence_put(f); 1417 + } 1418 + 1416 1419 return 0; 1417 1420 1418 1421 }
+2 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
··· 190 190 int amdgpu_vm_update_page_directory(struct amdgpu_device *adev, 191 191 struct amdgpu_vm *vm); 192 192 int amdgpu_vm_clear_freed(struct amdgpu_device *adev, 193 - struct amdgpu_vm *vm); 193 + struct amdgpu_vm *vm, 194 + struct dma_fence **fence); 194 195 int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm, 195 196 struct amdgpu_sync *sync); 196 197 int amdgpu_vm_bo_update(struct amdgpu_device *adev,