drm/scheduler: Fix hang when sched_entity released
authorjsg <jsg@openbsd.org>
Mon, 19 Jul 2021 10:01:10 +0000 (10:01 +0000)
committerjsg <jsg@openbsd.org>
Mon, 19 Jul 2021 10:01:10 +0000 (10:01 +0000)
From Andrey Grodzovsky
5ed8c298b2e140c640af8813a490fb4d77165e97 in linux 5.10.y/5.10.51
c61cdbdbffc169dc7f1e6fe94dfffaf574fe672a in mainline linux

sys/dev/pci/drm/scheduler/sched_entity.c
sys/dev/pci/drm/scheduler/sched_main.c

index 23ef960..3127cba 100644 (file)
@@ -113,7 +113,8 @@ static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity)
        rmb(); /* for list_empty to work without lock */
 
        if (list_empty(&entity->list) ||
-           spsc_queue_count(&entity->job_queue) == 0)
+           spsc_queue_count(&entity->job_queue) == 0 ||
+           entity->stopped)
                return true;
 
        return false;
index 682744c..8ebcab5 100644 (file)
@@ -895,9 +895,33 @@ EXPORT_SYMBOL(drm_sched_init);
  */
 void drm_sched_fini(struct drm_gpu_scheduler *sched)
 {
+       struct drm_sched_entity *s_entity;
+       int i;
+
        if (sched->thread)
                kthread_stop(sched->thread);
 
+       for (i = DRM_SCHED_PRIORITY_COUNT - 1; i >= DRM_SCHED_PRIORITY_MIN; i--) {
+               struct drm_sched_rq *rq = &sched->sched_rq[i];
+
+               if (!rq)
+                       continue;
+
+               spin_lock(&rq->lock);
+               list_for_each_entry(s_entity, &rq->entities, list)
+                       /*
+                        * Prevents reinsertion and marks job_queue as idle,
+                        * it will removed from rq in drm_sched_entity_fini
+                        * eventually
+                        */
+                       s_entity->stopped = true;
+               spin_unlock(&rq->lock);
+
+       }
+
+       /* Wakeup everyone stuck in drm_sched_entity_flush for this scheduler */
+       wake_up_all(&sched->job_scheduled);
+
        /* Confirm no work left behind accessing device structures */
        cancel_delayed_work_sync(&sched->work_tdr);