Skip to content

Commit

Permalink
drm/scheduler: Fix lockup in drm_sched_entity_kill()
Browse files Browse the repository at this point in the history
The drm_sched_entity_kill() is invoked twice by drm_sched_entity_destroy()
while userspace process is exiting or being killed. First time it's invoked
when sched entity is flushed and second time when entity is released. This
causes a lockup within wait_for_completion(entity_idle) due to how completion
API works.

Calling wait_for_completion() more times than complete() was invoked is a
error condition that causes lockup because completion internally uses
counter for complete/wait calls. The complete_all() must be used instead
in such cases.

This patch fixes lockup of Panfrost driver that is reproducible by killing
any application in a middle of 3d drawing operation.

Fixes: 2fdb8a8 ("drm/scheduler: rework entity flush, kill and fini")
Signed-off-by: Dmitry Osipenko <[email protected]>
Reviewed-by: Christian König <[email protected]>
Tested-by: Guilherme G. Piccoli <[email protected]> # Steam Deck
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
  • Loading branch information
digetx committed Jan 2, 2023
1 parent 523dfa9 commit 03dec92
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion drivers/gpu/drm/scheduler/sched_entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,
init_completion(&entity->entity_idle);

/* We start in an idle state. */
complete(&entity->entity_idle);
complete_all(&entity->entity_idle);

spin_lock_init(&entity->rq_lock);
spsc_queue_init(&entity->job_queue);
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/scheduler/sched_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ static int drm_sched_main(void *param)
sched_job = drm_sched_entity_pop_job(entity);

if (!sched_job) {
complete(&entity->entity_idle);
complete_all(&entity->entity_idle);
continue;
}

Expand All @@ -998,7 +998,7 @@ static int drm_sched_main(void *param)

trace_drm_run_job(sched_job, entity);
fence = sched->ops->run_job(sched_job);
complete(&entity->entity_idle);
complete_all(&entity->entity_idle);
drm_sched_fence_scheduled(s_fence);

if (!IS_ERR_OR_NULL(fence)) {
Expand Down

0 comments on commit 03dec92

Please sign in to comment.