drm/amdgpu: update mappings not managed by KFD
authorFelix Kuehling <Felix.Kuehling@amd.com>
Wed, 16 Mar 2022 22:46:56 +0000 (18:46 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 17 Nov 2023 14:29:53 +0000 (09:29 -0500)
When restoring after an eviction, use amdgpu_vm_handle_moved to update
BO VA mappings in KFD VMs that are not managed through the KFD API. This
should allow using the render node API to create more flexible memory
mappings in KFD VMs.

v2: rebase on drm_exec changes (Alex)

Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Acked-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

index 41fbc4fd0fac303176d7ecb386f81d8af8cac2c6..b98c0969d3be82642d95b1bf94084063e580cee3 100644 (file)
@@ -2825,12 +2825,6 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef)
        if (ret)
                goto validate_map_fail;
 
-       ret = process_sync_pds_resv(process_info, &sync_obj);
-       if (ret) {
-               pr_debug("Memory eviction: Failed to sync to PD BO moving fence. Try again\n");
-               goto validate_map_fail;
-       }
-
        /* Validate BOs and map them to GPUVM (update VM page tables). */
        list_for_each_entry(mem, &process_info->kfd_bo_list,
                            validate_list) {
@@ -2881,6 +2875,19 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef)
        if (failed_size)
                pr_debug("0x%lx/0x%lx in system\n", failed_size, total_size);
 
+       /* Update mappings not managed by KFD */
+       list_for_each_entry(peer_vm, &process_info->vm_list_head,
+                       vm_list_node) {
+               struct amdgpu_device *adev = amdgpu_ttm_adev(
+                       peer_vm->root.bo->tbo.bdev);
+
+               ret = amdgpu_vm_handle_moved(adev, peer_vm, &exec.ticket);
+               if (ret) {
+                       pr_debug("Memory eviction: handle moved failed. Try again\n");
+                       goto validate_map_fail;
+               }
+       }
+
        /* Update page directories */
        ret = process_update_pds(process_info, &sync_obj);
        if (ret) {
@@ -2888,6 +2895,15 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef)
                goto validate_map_fail;
        }
 
+       /* Sync with fences on all the page tables. They implicitly depend on any
+        * move fences from amdgpu_vm_handle_moved above.
+        */
+       ret = process_sync_pds_resv(process_info, &sync_obj);
+       if (ret) {
+               pr_debug("Memory eviction: Failed to sync to PD BO moving fence. Try again\n");
+               goto validate_map_fail;
+       }
+
        /* Wait for validate and PT updates to finish */
        amdgpu_sync_wait(&sync_obj, false);