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;
 
  */
 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);