Skip to content

Commit a00e7e3

Browse files
Thomas Hellströmlucasdemarchi
authored andcommitted
drm/xe: Rework rebinding
Instead of handling the vm's rebind fence separately, which is error prone if they are not strictly ordered, attach rebind fences as kernel fences to the vm's resv. Fixes: dd08ebf ("drm/xe: Introduce a new DRM driver for Intel GPUs") Cc: Rodrigo Vivi <[email protected]> Cc: Matthew Brost <[email protected]> Cc: <[email protected]> # v6.8+ Signed-off-by: Thomas Hellström <[email protected]> Reviewed-by: Matthew Brost <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit 5a091af) Signed-off-by: Lucas De Marchi <[email protected]>
1 parent 3c88b8f commit a00e7e3

File tree

5 files changed

+14
-51
lines changed

5 files changed

+14
-51
lines changed

drivers/gpu/drm/xe/xe_exec.c

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
152152
struct drm_exec *exec = &vm_exec.exec;
153153
u32 i, num_syncs = 0, num_ufence = 0;
154154
struct xe_sched_job *job;
155-
struct dma_fence *rebind_fence;
156155
struct xe_vm *vm;
157156
bool write_locked, skip_retry = false;
158157
ktime_t end = 0;
@@ -294,35 +293,11 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
294293
* Rebind any invalidated userptr or evicted BOs in the VM, non-compute
295294
* VM mode only.
296295
*/
297-
rebind_fence = xe_vm_rebind(vm, false);
298-
if (IS_ERR(rebind_fence)) {
299-
err = PTR_ERR(rebind_fence);
296+
err = xe_vm_rebind(vm, false);
297+
if (err)
300298
goto err_put_job;
301-
}
302-
303-
/*
304-
* We store the rebind_fence in the VM so subsequent execs don't get
305-
* scheduled before the rebinds of userptrs / evicted BOs is complete.
306-
*/
307-
if (rebind_fence) {
308-
dma_fence_put(vm->rebind_fence);
309-
vm->rebind_fence = rebind_fence;
310-
}
311-
if (vm->rebind_fence) {
312-
if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
313-
&vm->rebind_fence->flags)) {
314-
dma_fence_put(vm->rebind_fence);
315-
vm->rebind_fence = NULL;
316-
} else {
317-
dma_fence_get(vm->rebind_fence);
318-
err = drm_sched_job_add_dependency(&job->drm,
319-
vm->rebind_fence);
320-
if (err)
321-
goto err_put_job;
322-
}
323-
}
324299

325-
/* Wait behind munmap style rebinds */
300+
/* Wait behind rebinds */
326301
if (!xe_vm_in_lr_mode(vm)) {
327302
err = drm_sched_job_add_resv_dependencies(&job->drm,
328303
xe_vm_resv(vm),

drivers/gpu/drm/xe/xe_pt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ __xe_pt_bind_vma(struct xe_tile *tile, struct xe_vma *vma, struct xe_exec_queue
12991299
}
13001300

13011301
/* add shared fence now for pagetable delayed destroy */
1302-
dma_resv_add_fence(xe_vm_resv(vm), fence, !rebind &&
1302+
dma_resv_add_fence(xe_vm_resv(vm), fence, rebind ||
13031303
last_munmap_rebind ?
13041304
DMA_RESV_USAGE_KERNEL :
13051305
DMA_RESV_USAGE_BOOKKEEP);

drivers/gpu/drm/xe/xe_vm.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,6 @@ static void preempt_rebind_work_func(struct work_struct *w)
522522
{
523523
struct xe_vm *vm = container_of(w, struct xe_vm, preempt.rebind_work);
524524
struct drm_exec exec;
525-
struct dma_fence *rebind_fence;
526525
unsigned int fence_count = 0;
527526
LIST_HEAD(preempt_fences);
528527
ktime_t end = 0;
@@ -568,18 +567,11 @@ static void preempt_rebind_work_func(struct work_struct *w)
568567
if (err)
569568
goto out_unlock;
570569

571-
rebind_fence = xe_vm_rebind(vm, true);
572-
if (IS_ERR(rebind_fence)) {
573-
err = PTR_ERR(rebind_fence);
570+
err = xe_vm_rebind(vm, true);
571+
if (err)
574572
goto out_unlock;
575-
}
576-
577-
if (rebind_fence) {
578-
dma_fence_wait(rebind_fence, false);
579-
dma_fence_put(rebind_fence);
580-
}
581573

582-
/* Wait on munmap style VM unbinds */
574+
/* Wait on rebinds and munmap style VM unbinds */
583575
wait = dma_resv_wait_timeout(xe_vm_resv(vm),
584576
DMA_RESV_USAGE_KERNEL,
585577
false, MAX_SCHEDULE_TIMEOUT);
@@ -773,32 +765,32 @@ xe_vm_bind_vma(struct xe_vma *vma, struct xe_exec_queue *q,
773765
struct xe_sync_entry *syncs, u32 num_syncs,
774766
bool first_op, bool last_op);
775767

776-
struct dma_fence *xe_vm_rebind(struct xe_vm *vm, bool rebind_worker)
768+
int xe_vm_rebind(struct xe_vm *vm, bool rebind_worker)
777769
{
778-
struct dma_fence *fence = NULL;
770+
struct dma_fence *fence;
779771
struct xe_vma *vma, *next;
780772

781773
lockdep_assert_held(&vm->lock);
782774
if (xe_vm_in_lr_mode(vm) && !rebind_worker)
783-
return NULL;
775+
return 0;
784776

785777
xe_vm_assert_held(vm);
786778
list_for_each_entry_safe(vma, next, &vm->rebind_list,
787779
combined_links.rebind) {
788780
xe_assert(vm->xe, vma->tile_present);
789781

790782
list_del_init(&vma->combined_links.rebind);
791-
dma_fence_put(fence);
792783
if (rebind_worker)
793784
trace_xe_vma_rebind_worker(vma);
794785
else
795786
trace_xe_vma_rebind_exec(vma);
796787
fence = xe_vm_bind_vma(vma, NULL, NULL, 0, false, false);
797788
if (IS_ERR(fence))
798-
return fence;
789+
return PTR_ERR(fence);
790+
dma_fence_put(fence);
799791
}
800792

801-
return fence;
793+
return 0;
802794
}
803795

804796
static void xe_vma_free(struct xe_vma *vma)
@@ -1589,7 +1581,6 @@ static void vm_destroy_work_func(struct work_struct *w)
15891581
XE_WARN_ON(vm->pt_root[id]);
15901582

15911583
trace_xe_vm_free(vm);
1592-
dma_fence_put(vm->rebind_fence);
15931584
kfree(vm);
15941585
}
15951586

drivers/gpu/drm/xe/xe_vm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ int __xe_vm_userptr_needs_repin(struct xe_vm *vm);
207207

208208
int xe_vm_userptr_check_repin(struct xe_vm *vm);
209209

210-
struct dma_fence *xe_vm_rebind(struct xe_vm *vm, bool rebind_worker);
210+
int xe_vm_rebind(struct xe_vm *vm, bool rebind_worker);
211211

212212
int xe_vm_invalidate_vma(struct xe_vma *vma);
213213

drivers/gpu/drm/xe/xe_vm_types.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,6 @@ struct xe_vm {
177177
*/
178178
struct list_head rebind_list;
179179

180-
/** @rebind_fence: rebind fence from execbuf */
181-
struct dma_fence *rebind_fence;
182-
183180
/**
184181
* @destroy_work: worker to destroy VM, needed as a dma_fence signaling
185182
* from an irq context can be last put and the destroy needs to be able

0 commit comments

Comments
 (0)