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

drm/amdgpu: stop adding VM updates fences to the resv obj

Don't add the VM update fences to the resv object and remove
the handling to stop implicitely syncing to them.

Ongoing updates prevent page tables from being evicted and we manually
block for all updates to complete before releasing PDs and PTS.

This way we can do updates even without the resv obj locked.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Christian König and committed by
Alex Deucher
90b69cdc e095fc17

+42 -13
+4 -6
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
··· 240 240 continue; 241 241 242 242 if (amdgpu_sync_same_dev(adev, f)) { 243 - /* VM updates are only interesting 244 - * for other VM updates and moves. 243 + /* VM updates only sync with moves but not with user 244 + * command submissions or KFD evictions fences 245 245 */ 246 - if ((owner != AMDGPU_FENCE_OWNER_UNDEFINED) && 247 - (fence_owner != AMDGPU_FENCE_OWNER_UNDEFINED) && 248 - ((owner == AMDGPU_FENCE_OWNER_VM) != 249 - (fence_owner == AMDGPU_FENCE_OWNER_VM))) 246 + if (owner == AMDGPU_FENCE_OWNER_VM && 247 + fence_owner != AMDGPU_FENCE_OWNER_UNDEFINED) 250 248 continue; 251 249 252 250 /* Ignore fence from the same owner and explicit one as
+26 -4
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
··· 562 562 { 563 563 entry->priority = 0; 564 564 entry->tv.bo = &vm->root.base.bo->tbo; 565 - /* One for the VM updates, one for TTM and one for the CS job */ 566 - entry->tv.num_shared = 3; 565 + /* One for TTM and one for the CS job */ 566 + entry->tv.num_shared = 2; 567 567 entry->user_pages = NULL; 568 568 list_add(&entry->tv.head, validated); 569 569 } ··· 2518 2518 if (!dma_resv_test_signaled_rcu(bo->tbo.base.resv, true)) 2519 2519 return false; 2520 2520 2521 + /* Don't evict VM page tables while they are updated */ 2522 + if (!dma_fence_is_signaled(bo_base->vm->last_direct) || 2523 + !dma_fence_is_signaled(bo_base->vm->last_delayed)) 2524 + return false; 2525 + 2521 2526 return true; 2522 2527 } 2523 2528 ··· 2688 2683 */ 2689 2684 long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout) 2690 2685 { 2691 - return dma_resv_wait_timeout_rcu(vm->root.base.bo->tbo.base.resv, 2692 - true, true, timeout); 2686 + timeout = dma_resv_wait_timeout_rcu(vm->root.base.bo->tbo.base.resv, 2687 + true, true, timeout); 2688 + if (timeout <= 0) 2689 + return timeout; 2690 + 2691 + timeout = dma_fence_wait_timeout(vm->last_direct, true, timeout); 2692 + if (timeout <= 0) 2693 + return timeout; 2694 + 2695 + return dma_fence_wait_timeout(vm->last_delayed, true, timeout); 2693 2696 } 2694 2697 2695 2698 /** ··· 2766 2753 else 2767 2754 vm->update_funcs = &amdgpu_vm_sdma_funcs; 2768 2755 vm->last_update = NULL; 2756 + vm->last_direct = dma_fence_get_stub(); 2757 + vm->last_delayed = dma_fence_get_stub(); 2769 2758 2770 2759 amdgpu_vm_bo_param(adev, vm, adev->vm_manager.root_level, false, &bp); 2771 2760 if (vm_context == AMDGPU_VM_CONTEXT_COMPUTE) ··· 2818 2803 vm->root.base.bo = NULL; 2819 2804 2820 2805 error_free_delayed: 2806 + dma_fence_put(vm->last_direct); 2807 + dma_fence_put(vm->last_delayed); 2821 2808 drm_sched_entity_destroy(&vm->delayed); 2822 2809 2823 2810 error_free_direct: ··· 3019 3002 spin_unlock_irqrestore(&adev->vm_manager.pasid_lock, flags); 3020 3003 vm->pasid = 0; 3021 3004 } 3005 + 3006 + dma_fence_wait(vm->last_direct, false); 3007 + dma_fence_put(vm->last_direct); 3008 + dma_fence_wait(vm->last_delayed, false); 3009 + dma_fence_put(vm->last_delayed); 3022 3010 3023 3011 list_for_each_entry_safe(mapping, tmp, &vm->freed, list) { 3024 3012 if (mapping->flags & AMDGPU_PTE_PRT && prt_fini_needed) {
+4
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
··· 266 266 struct drm_sched_entity direct; 267 267 struct drm_sched_entity delayed; 268 268 269 + /* Last submission to the scheduler entities */ 270 + struct dma_fence *last_direct; 271 + struct dma_fence *last_delayed; 272 + 269 273 unsigned int pasid; 270 274 /* dedicated to vm */ 271 275 struct amdgpu_vmid *reserved_vmid[AMDGPU_MAX_VMHUBS];
+8 -3
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
··· 95 95 static int amdgpu_vm_sdma_commit(struct amdgpu_vm_update_params *p, 96 96 struct dma_fence **fence) 97 97 { 98 - struct amdgpu_bo *root = p->vm->root.base.bo; 99 98 struct amdgpu_ib *ib = p->job->ibs; 100 99 struct drm_sched_entity *entity; 100 + struct dma_fence *f, *tmp; 101 101 struct amdgpu_ring *ring; 102 - struct dma_fence *f; 103 102 int r; 104 103 105 104 entity = p->direct ? &p->vm->direct : &p->vm->delayed; ··· 111 112 if (r) 112 113 goto error; 113 114 114 - amdgpu_bo_fence(root, f, true); 115 + tmp = dma_fence_get(f); 116 + if (p->direct) 117 + swap(p->vm->last_direct, tmp); 118 + else 119 + swap(p->vm->last_delayed, tmp); 120 + dma_fence_put(tmp); 121 + 115 122 if (fence && !p->direct) 116 123 swap(*fence, f); 117 124 dma_fence_put(f);