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

drm/amdgpu: Get rid of dep_sync as a seperate object.

Instead mark fence as explicit in it's amdgpu_sync_entry.

v2:
Fix use after free bug and add new parameter description.
Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Andrey Grodzovsky and committed by
Alex Deucher
cebb52b7 97489129

+36 -34
-1
drivers/gpu/drm/amd/amdgpu/amdgpu.h
··· 1121 1121 struct amdgpu_vm *vm; 1122 1122 struct amdgpu_ring *ring; 1123 1123 struct amdgpu_sync sync; 1124 - struct amdgpu_sync dep_sync; 1125 1124 struct amdgpu_sync sched_sync; 1126 1125 struct amdgpu_ib *ibs; 1127 1126 struct dma_fence *fence; /* the hw fence */
+7 -7
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
··· 786 786 return r; 787 787 788 788 r = amdgpu_sync_fence(adev, &p->job->sync, 789 - fpriv->prt_va->last_pt_update); 789 + fpriv->prt_va->last_pt_update, false); 790 790 if (r) 791 791 return r; 792 792 ··· 800 800 return r; 801 801 802 802 f = bo_va->last_pt_update; 803 - r = amdgpu_sync_fence(adev, &p->job->sync, f); 803 + r = amdgpu_sync_fence(adev, &p->job->sync, f, false); 804 804 if (r) 805 805 return r; 806 806 } ··· 823 823 return r; 824 824 825 825 f = bo_va->last_pt_update; 826 - r = amdgpu_sync_fence(adev, &p->job->sync, f); 826 + r = amdgpu_sync_fence(adev, &p->job->sync, f, false); 827 827 if (r) 828 828 return r; 829 829 } ··· 834 834 if (r) 835 835 return r; 836 836 837 - r = amdgpu_sync_fence(adev, &p->job->sync, vm->last_update); 837 + r = amdgpu_sync_fence(adev, &p->job->sync, vm->last_update, false); 838 838 if (r) 839 839 return r; 840 840 ··· 1038 1038 amdgpu_ctx_put(ctx); 1039 1039 return r; 1040 1040 } else if (fence) { 1041 - r = amdgpu_sync_fence(p->adev, &p->job->dep_sync, 1042 - fence); 1041 + r = amdgpu_sync_fence(p->adev, &p->job->sync, fence, 1042 + true); 1043 1043 dma_fence_put(fence); 1044 1044 amdgpu_ctx_put(ctx); 1045 1045 if (r) ··· 1058 1058 if (r) 1059 1059 return r; 1060 1060 1061 - r = amdgpu_sync_fence(p->adev, &p->job->dep_sync, fence); 1061 + r = amdgpu_sync_fence(p->adev, &p->job->sync, fence, true); 1062 1062 dma_fence_put(fence); 1063 1063 1064 1064 return r;
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
··· 164 164 } 165 165 166 166 if (ring->funcs->emit_pipeline_sync && job && 167 - ((tmp = amdgpu_sync_get_fence(&job->sched_sync)) || 167 + ((tmp = amdgpu_sync_get_fence(&job->sched_sync, NULL)) || 168 168 amdgpu_vm_need_pipeline_sync(ring, job))) { 169 169 need_pipe_sync = true; 170 170 dma_fence_put(tmp);
+10 -12
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
··· 60 60 (*job)->num_ibs = num_ibs; 61 61 62 62 amdgpu_sync_create(&(*job)->sync); 63 - amdgpu_sync_create(&(*job)->dep_sync); 64 63 amdgpu_sync_create(&(*job)->sched_sync); 65 64 (*job)->vram_lost_counter = atomic_read(&adev->vram_lost_counter); 66 65 ··· 103 104 amdgpu_ring_priority_put(job->ring, s_job->s_priority); 104 105 dma_fence_put(job->fence); 105 106 amdgpu_sync_free(&job->sync); 106 - amdgpu_sync_free(&job->dep_sync); 107 107 amdgpu_sync_free(&job->sched_sync); 108 108 kfree(job); 109 109 } ··· 113 115 114 116 dma_fence_put(job->fence); 115 117 amdgpu_sync_free(&job->sync); 116 - amdgpu_sync_free(&job->dep_sync); 117 118 amdgpu_sync_free(&job->sched_sync); 118 119 kfree(job); 119 120 } ··· 146 149 { 147 150 struct amdgpu_job *job = to_amdgpu_job(sched_job); 148 151 struct amdgpu_vm *vm = job->vm; 149 - 150 - struct dma_fence *fence = amdgpu_sync_get_fence(&job->dep_sync); 152 + bool explicit = false; 151 153 int r; 154 + struct dma_fence *fence = amdgpu_sync_get_fence(&job->sync, &explicit); 152 155 153 - if (amd_sched_dependency_optimized(fence, s_entity)) { 154 - r = amdgpu_sync_fence(job->adev, &job->sched_sync, fence); 155 - if (r) 156 - DRM_ERROR("Error adding fence to sync (%d)\n", r); 156 + if (fence && explicit) { 157 + if (amd_sched_dependency_optimized(fence, s_entity)) { 158 + r = amdgpu_sync_fence(job->adev, &job->sched_sync, fence, false); 159 + if (r) 160 + DRM_ERROR("Error adding fence to sync (%d)\n", r); 161 + } 157 162 } 158 - if (!fence) 159 - fence = amdgpu_sync_get_fence(&job->sync); 163 + 160 164 while (fence == NULL && vm && !job->vm_id) { 161 165 struct amdgpu_ring *ring = job->ring; 162 166 ··· 167 169 if (r) 168 170 DRM_ERROR("Error getting VM ID (%d)\n", r); 169 171 170 - fence = amdgpu_sync_get_fence(&job->sync); 172 + fence = amdgpu_sync_get_fence(&job->sync, NULL); 171 173 } 172 174 173 175 return fence;
+10 -5
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
··· 35 35 struct amdgpu_sync_entry { 36 36 struct hlist_node node; 37 37 struct dma_fence *fence; 38 + bool explicit; 38 39 }; 39 40 40 41 static struct kmem_cache *amdgpu_sync_slab; ··· 142 141 * 143 142 */ 144 143 int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync, 145 - struct dma_fence *f) 144 + struct dma_fence *f, bool explicit) 146 145 { 147 146 struct amdgpu_sync_entry *e; 148 147 ··· 159 158 e = kmem_cache_alloc(amdgpu_sync_slab, GFP_KERNEL); 160 159 if (!e) 161 160 return -ENOMEM; 161 + 162 + e->explicit = explicit; 162 163 163 164 hash_add(sync->fences, &e->node, f->context); 164 165 e->fence = dma_fence_get(f); ··· 192 189 193 190 /* always sync to the exclusive fence */ 194 191 f = reservation_object_get_excl(resv); 195 - r = amdgpu_sync_fence(adev, sync, f); 192 + r = amdgpu_sync_fence(adev, sync, f, false); 196 193 197 194 if (explicit_sync) 198 195 return r; ··· 223 220 continue; 224 221 } 225 222 226 - r = amdgpu_sync_fence(adev, sync, f); 223 + r = amdgpu_sync_fence(adev, sync, f, false); 227 224 if (r) 228 225 break; 229 226 } ··· 278 275 * amdgpu_sync_get_fence - get the next fence from the sync object 279 276 * 280 277 * @sync: sync object to use 278 + * @explicit: true if the next fence is explicit 281 279 * 282 280 * Get and removes the next fence from the sync object not signaled yet. 283 281 */ 284 - struct dma_fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync) 282 + struct dma_fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync, bool *explicit) 285 283 { 286 284 struct amdgpu_sync_entry *e; 287 285 struct hlist_node *tmp; 288 286 struct dma_fence *f; 289 287 int i; 290 - 291 288 hash_for_each_safe(sync->fences, i, tmp, e, node) { 292 289 293 290 f = e->fence; 291 + if (explicit) 292 + *explicit = e->explicit; 294 293 295 294 hash_del(&e->node); 296 295 kmem_cache_free(amdgpu_sync_slab, e);
+2 -2
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h
··· 41 41 42 42 void amdgpu_sync_create(struct amdgpu_sync *sync); 43 43 int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync, 44 - struct dma_fence *f); 44 + struct dma_fence *f, bool explicit); 45 45 int amdgpu_sync_resv(struct amdgpu_device *adev, 46 46 struct amdgpu_sync *sync, 47 47 struct reservation_object *resv, ··· 49 49 bool explicit_sync); 50 50 struct dma_fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync, 51 51 struct amdgpu_ring *ring); 52 - struct dma_fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync); 52 + struct dma_fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync, bool *explicit); 53 53 int amdgpu_sync_wait(struct amdgpu_sync *sync, bool intr); 54 54 void amdgpu_sync_free(struct amdgpu_sync *sync); 55 55 int amdgpu_sync_init(void);
+6 -6
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
··· 488 488 id->pd_gpu_addr = 0; 489 489 tmp = amdgpu_sync_peek_fence(&id->active, ring); 490 490 if (tmp) { 491 - r = amdgpu_sync_fence(adev, sync, tmp); 491 + r = amdgpu_sync_fence(adev, sync, tmp, false); 492 492 return r; 493 493 } 494 494 } ··· 496 496 /* Good we can use this VMID. Remember this submission as 497 497 * user of the VMID. 498 498 */ 499 - r = amdgpu_sync_fence(ring->adev, &id->active, fence); 499 + r = amdgpu_sync_fence(ring->adev, &id->active, fence, false); 500 500 if (r) 501 501 goto out; 502 502 ··· 583 583 } 584 584 585 585 586 - r = amdgpu_sync_fence(ring->adev, sync, &array->base); 586 + r = amdgpu_sync_fence(ring->adev, sync, &array->base, false); 587 587 dma_fence_put(&array->base); 588 588 if (r) 589 589 goto error; ··· 626 626 /* Good we can use this VMID. Remember this submission as 627 627 * user of the VMID. 628 628 */ 629 - r = amdgpu_sync_fence(ring->adev, &id->active, fence); 629 + r = amdgpu_sync_fence(ring->adev, &id->active, fence, false); 630 630 if (r) 631 631 goto error; 632 632 ··· 646 646 id = idle; 647 647 648 648 /* Remember this submission as user of the VMID */ 649 - r = amdgpu_sync_fence(ring->adev, &id->active, fence); 649 + r = amdgpu_sync_fence(ring->adev, &id->active, fence, false); 650 650 if (r) 651 651 goto error; 652 652 ··· 1657 1657 addr = 0; 1658 1658 } 1659 1659 1660 - r = amdgpu_sync_fence(adev, &job->sync, exclusive); 1660 + r = amdgpu_sync_fence(adev, &job->sync, exclusive, false); 1661 1661 if (r) 1662 1662 goto error_free; 1663 1663