diff options
author | Andrey Grodzovsky <andrey.grodzovsky@amd.com> | 2017-11-13 14:47:52 -0500 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2017-12-06 12:48:31 -0500 |
commit | cebb52b7bc325863600aff930407bba773010938 (patch) | |
tree | ae833fc3ca280acdf24acb6955d99e604bc9d018 /drivers/gpu/drm/amd/amdgpu | |
parent | 97489129c220ef67195c886f9f2bad9651edd601 (diff) |
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>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 14 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 24 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 15 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h | 4 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 12 |
7 files changed, 37 insertions, 35 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index ecc2e60e5f0c..5e2958a79928 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h | |||
@@ -1121,7 +1121,6 @@ struct amdgpu_job { | |||
1121 | struct amdgpu_vm *vm; | 1121 | struct amdgpu_vm *vm; |
1122 | struct amdgpu_ring *ring; | 1122 | struct amdgpu_ring *ring; |
1123 | struct amdgpu_sync sync; | 1123 | struct amdgpu_sync sync; |
1124 | struct amdgpu_sync dep_sync; | ||
1125 | struct amdgpu_sync sched_sync; | 1124 | struct amdgpu_sync sched_sync; |
1126 | struct amdgpu_ib *ibs; | 1125 | struct amdgpu_ib *ibs; |
1127 | struct dma_fence *fence; /* the hw fence */ | 1126 | struct dma_fence *fence; /* the hw fence */ |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index 93d3cef66503..4cea9ab237ac 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | |||
@@ -786,7 +786,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p) | |||
786 | return r; | 786 | return r; |
787 | 787 | ||
788 | r = amdgpu_sync_fence(adev, &p->job->sync, | 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 | if (r) | 790 | if (r) |
791 | return r; | 791 | return r; |
792 | 792 | ||
@@ -800,7 +800,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p) | |||
800 | return r; | 800 | return r; |
801 | 801 | ||
802 | f = bo_va->last_pt_update; | 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 | if (r) | 804 | if (r) |
805 | return r; | 805 | return r; |
806 | } | 806 | } |
@@ -823,7 +823,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p) | |||
823 | return r; | 823 | return r; |
824 | 824 | ||
825 | f = bo_va->last_pt_update; | 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 | if (r) | 827 | if (r) |
828 | return r; | 828 | return r; |
829 | } | 829 | } |
@@ -834,7 +834,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p) | |||
834 | if (r) | 834 | if (r) |
835 | return r; | 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 | if (r) | 838 | if (r) |
839 | return r; | 839 | return r; |
840 | 840 | ||
@@ -1038,8 +1038,8 @@ static int amdgpu_cs_process_fence_dep(struct amdgpu_cs_parser *p, | |||
1038 | amdgpu_ctx_put(ctx); | 1038 | amdgpu_ctx_put(ctx); |
1039 | return r; | 1039 | return r; |
1040 | } else if (fence) { | 1040 | } else if (fence) { |
1041 | r = amdgpu_sync_fence(p->adev, &p->job->dep_sync, | 1041 | r = amdgpu_sync_fence(p->adev, &p->job->sync, fence, |
1042 | fence); | 1042 | true); |
1043 | dma_fence_put(fence); | 1043 | dma_fence_put(fence); |
1044 | amdgpu_ctx_put(ctx); | 1044 | amdgpu_ctx_put(ctx); |
1045 | if (r) | 1045 | if (r) |
@@ -1058,7 +1058,7 @@ static int amdgpu_syncobj_lookup_and_add_to_sync(struct amdgpu_cs_parser *p, | |||
1058 | if (r) | 1058 | if (r) |
1059 | return r; | 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 | dma_fence_put(fence); | 1062 | dma_fence_put(fence); |
1063 | 1063 | ||
1064 | return r; | 1064 | return r; |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c index 659997bfff30..0cf86eb357d6 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | |||
@@ -164,7 +164,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, | |||
164 | } | 164 | } |
165 | 165 | ||
166 | if (ring->funcs->emit_pipeline_sync && job && | 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 | amdgpu_vm_need_pipeline_sync(ring, job))) { | 168 | amdgpu_vm_need_pipeline_sync(ring, job))) { |
169 | need_pipe_sync = true; | 169 | need_pipe_sync = true; |
170 | dma_fence_put(tmp); | 170 | dma_fence_put(tmp); |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c index 18770a880393..bdc210ac74f8 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | |||
@@ -60,7 +60,6 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs, | |||
60 | (*job)->num_ibs = num_ibs; | 60 | (*job)->num_ibs = num_ibs; |
61 | 61 | ||
62 | amdgpu_sync_create(&(*job)->sync); | 62 | amdgpu_sync_create(&(*job)->sync); |
63 | amdgpu_sync_create(&(*job)->dep_sync); | ||
64 | amdgpu_sync_create(&(*job)->sched_sync); | 63 | amdgpu_sync_create(&(*job)->sched_sync); |
65 | (*job)->vram_lost_counter = atomic_read(&adev->vram_lost_counter); | 64 | (*job)->vram_lost_counter = atomic_read(&adev->vram_lost_counter); |
66 | 65 | ||
@@ -104,7 +103,6 @@ static void amdgpu_job_free_cb(struct amd_sched_job *s_job) | |||
104 | amdgpu_ring_priority_put(job->ring, s_job->s_priority); | 103 | amdgpu_ring_priority_put(job->ring, s_job->s_priority); |
105 | dma_fence_put(job->fence); | 104 | dma_fence_put(job->fence); |
106 | amdgpu_sync_free(&job->sync); | 105 | amdgpu_sync_free(&job->sync); |
107 | amdgpu_sync_free(&job->dep_sync); | ||
108 | amdgpu_sync_free(&job->sched_sync); | 106 | amdgpu_sync_free(&job->sched_sync); |
109 | kfree(job); | 107 | kfree(job); |
110 | } | 108 | } |
@@ -115,7 +113,6 @@ void amdgpu_job_free(struct amdgpu_job *job) | |||
115 | 113 | ||
116 | dma_fence_put(job->fence); | 114 | dma_fence_put(job->fence); |
117 | amdgpu_sync_free(&job->sync); | 115 | amdgpu_sync_free(&job->sync); |
118 | amdgpu_sync_free(&job->dep_sync); | ||
119 | amdgpu_sync_free(&job->sched_sync); | 116 | amdgpu_sync_free(&job->sched_sync); |
120 | kfree(job); | 117 | kfree(job); |
121 | } | 118 | } |
@@ -149,17 +146,18 @@ static struct dma_fence *amdgpu_job_dependency(struct amd_sched_job *sched_job, | |||
149 | { | 146 | { |
150 | struct amdgpu_job *job = to_amdgpu_job(sched_job); | 147 | struct amdgpu_job *job = to_amdgpu_job(sched_job); |
151 | struct amdgpu_vm *vm = job->vm; | 148 | struct amdgpu_vm *vm = job->vm; |
152 | 149 | bool explicit = false; | |
153 | struct dma_fence *fence = amdgpu_sync_get_fence(&job->dep_sync); | ||
154 | int r; | 150 | int r; |
155 | 151 | struct dma_fence *fence = amdgpu_sync_get_fence(&job->sync, &explicit); | |
156 | if (amd_sched_dependency_optimized(fence, s_entity)) { | 152 | |
157 | r = amdgpu_sync_fence(job->adev, &job->sched_sync, fence); | 153 | if (fence && explicit) { |
158 | if (r) | 154 | if (amd_sched_dependency_optimized(fence, s_entity)) { |
159 | DRM_ERROR("Error adding fence to sync (%d)\n", r); | 155 | r = amdgpu_sync_fence(job->adev, &job->sched_sync, fence, false); |
156 | if (r) | ||
157 | DRM_ERROR("Error adding fence to sync (%d)\n", r); | ||
158 | } | ||
160 | } | 159 | } |
161 | if (!fence) | 160 | |
162 | fence = amdgpu_sync_get_fence(&job->sync); | ||
163 | while (fence == NULL && vm && !job->vm_id) { | 161 | while (fence == NULL && vm && !job->vm_id) { |
164 | struct amdgpu_ring *ring = job->ring; | 162 | struct amdgpu_ring *ring = job->ring; |
165 | 163 | ||
@@ -169,7 +167,7 @@ static struct dma_fence *amdgpu_job_dependency(struct amd_sched_job *sched_job, | |||
169 | if (r) | 167 | if (r) |
170 | DRM_ERROR("Error getting VM ID (%d)\n", r); | 168 | DRM_ERROR("Error getting VM ID (%d)\n", r); |
171 | 169 | ||
172 | fence = amdgpu_sync_get_fence(&job->sync); | 170 | fence = amdgpu_sync_get_fence(&job->sync, NULL); |
173 | } | 171 | } |
174 | 172 | ||
175 | return fence; | 173 | return fence; |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c index a4bf21f8f1c1..f3d1a25b660f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | |||
@@ -35,6 +35,7 @@ | |||
35 | struct amdgpu_sync_entry { | 35 | struct amdgpu_sync_entry { |
36 | struct hlist_node node; | 36 | struct hlist_node node; |
37 | struct dma_fence *fence; | 37 | struct dma_fence *fence; |
38 | bool explicit; | ||
38 | }; | 39 | }; |
39 | 40 | ||
40 | static struct kmem_cache *amdgpu_sync_slab; | 41 | static struct kmem_cache *amdgpu_sync_slab; |
@@ -141,7 +142,7 @@ static bool amdgpu_sync_add_later(struct amdgpu_sync *sync, struct dma_fence *f) | |||
141 | * | 142 | * |
142 | */ | 143 | */ |
143 | int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync, | 144 | int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync, |
144 | struct dma_fence *f) | 145 | struct dma_fence *f, bool explicit) |
145 | { | 146 | { |
146 | struct amdgpu_sync_entry *e; | 147 | struct amdgpu_sync_entry *e; |
147 | 148 | ||
@@ -159,6 +160,8 @@ int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync, | |||
159 | if (!e) | 160 | if (!e) |
160 | return -ENOMEM; | 161 | return -ENOMEM; |
161 | 162 | ||
163 | e->explicit = explicit; | ||
164 | |||
162 | hash_add(sync->fences, &e->node, f->context); | 165 | hash_add(sync->fences, &e->node, f->context); |
163 | e->fence = dma_fence_get(f); | 166 | e->fence = dma_fence_get(f); |
164 | return 0; | 167 | return 0; |
@@ -189,7 +192,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, | |||
189 | 192 | ||
190 | /* always sync to the exclusive fence */ | 193 | /* always sync to the exclusive fence */ |
191 | f = reservation_object_get_excl(resv); | 194 | f = reservation_object_get_excl(resv); |
192 | r = amdgpu_sync_fence(adev, sync, f); | 195 | r = amdgpu_sync_fence(adev, sync, f, false); |
193 | 196 | ||
194 | if (explicit_sync) | 197 | if (explicit_sync) |
195 | return r; | 198 | return r; |
@@ -220,7 +223,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, | |||
220 | continue; | 223 | continue; |
221 | } | 224 | } |
222 | 225 | ||
223 | r = amdgpu_sync_fence(adev, sync, f); | 226 | r = amdgpu_sync_fence(adev, sync, f, false); |
224 | if (r) | 227 | if (r) |
225 | break; | 228 | break; |
226 | } | 229 | } |
@@ -275,19 +278,21 @@ struct dma_fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync, | |||
275 | * amdgpu_sync_get_fence - get the next fence from the sync object | 278 | * amdgpu_sync_get_fence - get the next fence from the sync object |
276 | * | 279 | * |
277 | * @sync: sync object to use | 280 | * @sync: sync object to use |
281 | * @explicit: true if the next fence is explicit | ||
278 | * | 282 | * |
279 | * Get and removes the next fence from the sync object not signaled yet. | 283 | * Get and removes the next fence from the sync object not signaled yet. |
280 | */ | 284 | */ |
281 | struct dma_fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync) | 285 | struct dma_fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync, bool *explicit) |
282 | { | 286 | { |
283 | struct amdgpu_sync_entry *e; | 287 | struct amdgpu_sync_entry *e; |
284 | struct hlist_node *tmp; | 288 | struct hlist_node *tmp; |
285 | struct dma_fence *f; | 289 | struct dma_fence *f; |
286 | int i; | 290 | int i; |
287 | |||
288 | hash_for_each_safe(sync->fences, i, tmp, e, node) { | 291 | hash_for_each_safe(sync->fences, i, tmp, e, node) { |
289 | 292 | ||
290 | f = e->fence; | 293 | f = e->fence; |
294 | if (explicit) | ||
295 | *explicit = e->explicit; | ||
291 | 296 | ||
292 | hash_del(&e->node); | 297 | hash_del(&e->node); |
293 | kmem_cache_free(amdgpu_sync_slab, e); | 298 | kmem_cache_free(amdgpu_sync_slab, e); |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h index 70d7e3a279a0..7aba38d5c9df 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h | |||
@@ -41,7 +41,7 @@ struct amdgpu_sync { | |||
41 | 41 | ||
42 | void amdgpu_sync_create(struct amdgpu_sync *sync); | 42 | void amdgpu_sync_create(struct amdgpu_sync *sync); |
43 | int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync, | 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 | int amdgpu_sync_resv(struct amdgpu_device *adev, | 45 | int amdgpu_sync_resv(struct amdgpu_device *adev, |
46 | struct amdgpu_sync *sync, | 46 | struct amdgpu_sync *sync, |
47 | struct reservation_object *resv, | 47 | struct reservation_object *resv, |
@@ -49,7 +49,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, | |||
49 | bool explicit_sync); | 49 | bool explicit_sync); |
50 | struct dma_fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync, | 50 | struct dma_fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync, |
51 | struct amdgpu_ring *ring); | 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 | int amdgpu_sync_wait(struct amdgpu_sync *sync, bool intr); | 53 | int amdgpu_sync_wait(struct amdgpu_sync *sync, bool intr); |
54 | void amdgpu_sync_free(struct amdgpu_sync *sync); | 54 | void amdgpu_sync_free(struct amdgpu_sync *sync); |
55 | int amdgpu_sync_init(void); | 55 | int amdgpu_sync_init(void); |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index 7de519b86b78..3ecdbdfb04dd 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | |||
@@ -488,7 +488,7 @@ static int amdgpu_vm_grab_reserved_vmid_locked(struct amdgpu_vm *vm, | |||
488 | id->pd_gpu_addr = 0; | 488 | id->pd_gpu_addr = 0; |
489 | tmp = amdgpu_sync_peek_fence(&id->active, ring); | 489 | tmp = amdgpu_sync_peek_fence(&id->active, ring); |
490 | if (tmp) { | 490 | if (tmp) { |
491 | r = amdgpu_sync_fence(adev, sync, tmp); | 491 | r = amdgpu_sync_fence(adev, sync, tmp, false); |
492 | return r; | 492 | return r; |
493 | } | 493 | } |
494 | } | 494 | } |
@@ -496,7 +496,7 @@ static int amdgpu_vm_grab_reserved_vmid_locked(struct amdgpu_vm *vm, | |||
496 | /* Good we can use this VMID. Remember this submission as | 496 | /* Good we can use this VMID. Remember this submission as |
497 | * user of the VMID. | 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 | if (r) | 500 | if (r) |
501 | goto out; | 501 | goto out; |
502 | 502 | ||
@@ -583,7 +583,7 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, | |||
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 | dma_fence_put(&array->base); | 587 | dma_fence_put(&array->base); |
588 | if (r) | 588 | if (r) |
589 | goto error; | 589 | goto error; |
@@ -626,7 +626,7 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, | |||
626 | /* Good we can use this VMID. Remember this submission as | 626 | /* Good we can use this VMID. Remember this submission as |
627 | * user of the VMID. | 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 | if (r) | 630 | if (r) |
631 | goto error; | 631 | goto error; |
632 | 632 | ||
@@ -646,7 +646,7 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, | |||
646 | id = idle; | 646 | id = idle; |
647 | 647 | ||
648 | /* Remember this submission as user of the VMID */ | 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 | if (r) | 650 | if (r) |
651 | goto error; | 651 | goto error; |
652 | 652 | ||
@@ -1657,7 +1657,7 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev, | |||
1657 | addr = 0; | 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 | if (r) | 1661 | if (r) |
1662 | goto error_free; | 1662 | goto error_free; |
1663 | 1663 | ||