Revert "drm/nouveau: Remove waitque for sched teardown"
Subsystems (3)
PATCH 1/1 Revert "drm/nouveau: Remove waitque for sched teardown"
This reverts:
commit bead88002227 ("drm/nouveau: Remove waitque for sched teardown") commit 5f46f5c7af8c ("drm/nouveau: Add new callback for scheduler teardown") commit 89b2675198ab ("drm/nouveau: Make fence container helper usable driver-wide")
from the drm/sched teardown leak fix series:
https://lore.kernel.org/dri-devel/[email protected]/
The aforementioned series removed a blocking waitqueue from nouveau_sched_fini(). It was mistakenly assumed that this waitqueue only prevents jobs from leaking, which the series fixed.
The waitqueue, however, also guarantees that all VM_BIND related jobs are finished in order, cleaning up mappings in the GPU's MMU. These jobs must be executed sequentially. Without the waitqueue, this is no longer guaranteed, because entity and scheduler teardown can race with each other.
Revert all patches related to the waitqueue removal.
--- drivers/gpu/drm/nouveau/nouveau_fence.c | 20 +++++++++++++------- drivers/gpu/drm/nouveau/nouveau_fence.h | 6 ------ drivers/gpu/drm/nouveau/nouveau_sched.c | 20 +++++++++++++------- drivers/gpu/drm/nouveau/nouveau_sched.h | 9 ++++++--- drivers/gpu/drm/nouveau/nouveau_uvmm.c | 8 ++++---- 5 files changed, 36 insertions(+), 27 deletions(-)
drivers/gpu/drm/nouveau/nouveau_fence.c +13 -7
@@ -38,6 +38,12 @@static const struct dma_fence_ops nouveau_fence_ops_uevent;static const struct dma_fence_ops nouveau_fence_ops_legacy; +static inline struct nouveau_fence * +from_fence (struct dma_fence *fence) +{ + return container_of(fence, struct nouveau_fence, base); +} +static inline struct nouveau_fence_chan *nouveau_fctx (struct nouveau_fence *fence) {
@@ -71,7 +77,7 @@ nouveau_local_fence(struct dma_fence *fence, struct nouveau_drm *drm) fence->ops != &nouveau_fence_ops_uevent)return NULL ; -return to_nouveau_fence (fence); +return from_fence (fence); }void
@@ -277,7 +283,7 @@ nouveau_fence_done(struct nouveau_fence *fence)static long nouveau_fence_wait_legacy (struct dma_fence *f,bool intr,long wait) { -struct nouveau_fence *fence =to_nouveau_fence (f); +struct nouveau_fence *fence =from_fence (f);unsigned long sleep_time =NSEC_PER_MSEC /1000 ;unsigned long t = jiffies, timeout = t + wait;
@@ -457,7 +463,7 @@ static const char *nouveau_fence_get_get_driver_name(struct dma_fence *fence)static const char *nouveau_fence_get_timeline_name (struct dma_fence *f) { -struct nouveau_fence *fence =to_nouveau_fence (f); +struct nouveau_fence *fence =from_fence (f);struct nouveau_fence_chan *fctx =nouveau_fctx (fence);return !fctx->dead ? fctx->name :"dead channel" ;
@@ -471,7 +477,7 @@ static const char *nouveau_fence_get_timeline_name(struct dma_fence *f)*/ static bool nouveau_fence_is_signaled (struct dma_fence *f) { -struct nouveau_fence *fence =to_nouveau_fence (f); +struct nouveau_fence *fence =from_fence (f);struct nouveau_fence_chan *fctx =nouveau_fctx (fence);struct nouveau_channel *chan;bool ret = false;
@@ -487,7 +493,7 @@ static bool nouveau_fence_is_signaled(struct dma_fence *f)static bool nouveau_fence_no_signaling (struct dma_fence *f) { -struct nouveau_fence *fence =to_nouveau_fence (f); +struct nouveau_fence *fence =from_fence (f);/* * caller should have a reference on the fence,
@@ -512,7 +518,7 @@ static bool nouveau_fence_no_signaling(struct dma_fence *f)static void nouveau_fence_release (struct dma_fence *f) { -struct nouveau_fence *fence =to_nouveau_fence (f); +struct nouveau_fence *fence =from_fence (f);struct nouveau_fence_chan *fctx =nouveau_fctx (fence);kref_put (&fctx->fence_ref, nouveau_fence_context_put);
@@ -530,7 +536,7 @@ static const struct dma_fence_ops nouveau_fence_ops_legacy = {static bool nouveau_fence_enable_signaling (struct dma_fence *f) { -struct nouveau_fence *fence =to_nouveau_fence (f); +struct nouveau_fence *fence =from_fence (f);struct nouveau_fence_chan *fctx =nouveau_fctx (fence);bool ret;
drivers/gpu/drm/nouveau/nouveau_fence.h +0 -6
@@ -17,12 +17,6 @@ struct nouveau_fence {unsigned long timeout; }; -static inline struct nouveau_fence * -to_nouveau_fence (struct dma_fence *fence) -{ - return container_of(fence, struct nouveau_fence, base); -} -int nouveau_fence_create (struct nouveau_fence **,struct nouveau_channel *);int nouveau_fence_new (struct nouveau_fence **,struct nouveau_channel *);void nouveau_fence_unref (struct nouveau_fence **);
drivers/gpu/drm/nouveau/nouveau_sched.c +13 -7
@@ -122,9 +122,11 @@ nouveau_job_done(struct nouveau_job *job) {struct nouveau_sched *sched = job->sched; -spin_lock (&sched->job_list.lock); +spin_lock (&sched->job.list.lock);list_del (&job->entry); -spin_unlock (&sched->job_list.lock); +spin_unlock (&sched->job.list.lock); + +wake_up (&sched->job.wq); }void
@@ -305,9 +307,9 @@ nouveau_job_submit(struct nouveau_job *job) }/* Submit was successful; add the job to the schedulers job list. */ -spin_lock (&sched->job_list.lock); -list_add (&job->entry, &sched->job_list.head); -spin_unlock (&sched->job_list.lock); +spin_lock (&sched->job.list.lock); +list_add (&job->entry, &sched->job.list.head); +spin_unlock (&sched->job.list.lock);drm_sched_job_arm (&job->base); job->done_fence =dma_fence_get (&job->base.s_fence->finished);
@@ -458,8 +460,9 @@ nouveau_sched_init(struct nouveau_sched *sched, struct nouveau_drm *drm, goto fail_sched;mutex_init (&sched->mutex); -spin_lock_init (&sched->job_list.lock); -INIT_LIST_HEAD (&sched->job_list.head); +spin_lock_init (&sched->job.list.lock); +INIT_LIST_HEAD (&sched->job.list.head); +init_waitqueue_head (&sched->job.wq);return 0 ;
@@ -499,6 +502,9 @@ nouveau_sched_fini(struct nouveau_sched *sched)struct drm_gpu_scheduler *drm_sched = &sched->base;struct drm_sched_entity *entity = &sched->entity; +rmb ();/* for list_empty to work without lock */ +wait_event (sched->job.wq,list_empty (&sched->job.list.head)); +drm_sched_entity_fini (entity);drm_sched_fini (drm_sched);
drivers/gpu/drm/nouveau/nouveau_sched.h +6 -3
@@ -103,9 +103,12 @@ struct nouveau_sched {struct mutex mutex;struct { -struct list_head head; -spinlock_t lock; - } job_list; +struct { +struct list_head head; +spinlock_t lock; + } list; +struct wait_queue_head wq; + } job; }; int nouveau_sched_create(struct nouveau_sched **psched, struct nouveau_drm *drm,
drivers/gpu/drm/nouveau/nouveau_uvmm.c +4 -4
@@ -1019,8 +1019,8 @@ bind_validate_map_sparse(struct nouveau_job *job, u64 addr, u64 range)u64 end = addr + range; again: -spin_lock (&sched->job_list.lock); -list_for_each_entry (__job, &sched->job_list.head, entry) { +spin_lock (&sched->job.list.lock); +list_for_each_entry (__job, &sched->job.list.head, entry) {struct nouveau_uvmm_bind_job *bind_job =to_uvmm_bind_job (__job);list_for_each_op (op, &bind_job->ops) {
@@ -1030,7 +1030,7 @@ bind_validate_map_sparse(struct nouveau_job *job, u64 addr, u64 range)if (!(end <= op_addr || addr >= op_end)) {nouveau_uvmm_bind_job_get (bind_job); -spin_unlock (&sched->job_list.lock); +spin_unlock (&sched->job.list.lock);wait_for_completion (&bind_job->complete);nouveau_uvmm_bind_job_put (bind_job); goto again;
@@ -1038,7 +1038,7 @@ bind_validate_map_sparse(struct nouveau_job *job, u64 addr, u64 range) } } } -spin_unlock (&sched->job_list.lock); +spin_unlock (&sched->job.list.lock); } static int
Signature · 1 line
2.49.0
Danilo Krummrich
maintainerQuoted 1 line · Philipp Stanner
This reverts:
Thanks for sending the revert!
Quoted 3 lines
commit
bead88002227("drm/nouveau: Remove waitque for sched teardown") commit5f46f5c7af8c("drm/nouveau: Add new callback for scheduler teardown") commit89b2675198ab("drm/nouveau: Make fence container helper usable driver-wide")
I think we only need to revert the first two patches, we can keep the last one.
Eventually, we'll take advantage of the scheduler callback for EXEC jobs only, so we can keep this.