drm/nouveau: sched: fix leaking memory of timedout job
Subsystems (3)
PATCH 1/1 drm/nouveau: sched: fix leaking memory of timedout job
Always stop and re-start the scheduler in order to let the scheduler free up the timedout job in case it got signaled. In case of exec jobs the job type specific callback will take care to signal all fences and tear down the channel.
--- drivers/gpu/drm/nouveau/nouveau_exec.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-)
drivers/gpu/drm/nouveau/nouveau_exec.c +1 -1
@@ -185,7 +185,7 @@ nouveau_exec_job_timeout(struct nouveau_job *job)nouveau_sched_entity_fini (job->entity); -return DRM_GPU_SCHED_STAT_ENODEV ; +return DRM_GPU_SCHED_STAT_NOMINAL ; }static struct nouveau_job_ops nouveau_exec_job_ops = {
drivers/gpu/drm/nouveau/nouveau_sched.c +9 -3
@@ -375,14 +375,20 @@ nouveau_sched_run_job(struct drm_sched_job *sched_job)static enum drm_gpu_sched_stat nouveau_sched_timedout_job (struct drm_sched_job *sched_job) { +struct drm_gpu_scheduler *sched = sched_job->sched;struct nouveau_job *job =to_nouveau_job (sched_job); +enum drm_gpu_sched_stat stat =DRM_GPU_SCHED_STAT_NOMINAL ; -NV_PRINTK (warn, job->cli,"Job timed out.\n" ); +drm_sched_stop (sched, sched_job);if (job->ops->timeout) -return job->ops->timeout (job); + stat = job->ops->timeout (job); +else +NV_PRINTK (warn, job->cli,"Generic job timeout.\n" ); + +drm_sched_start (sched, true); -return DRM_GPU_SCHED_STAT_ENODEV ; +return stat; } static void
Signature · 1 line
2.41.0
Lyude Paul
maintainerBTW - Would you like me to review work like this? I'm totally happy to do that, although I'm not terribly familiar with these parts of nouveau/drm (but I'm always willing to learn, and would like to know more about these areas anyway :)
…if the answer is yes, this patch looks fine to me so far - I guess the one question I have that might have an obvious answer - how are jobs without an job->ops->timeout callback cleaned up?
Quoted 53 lines · Danilo Krummrich
Always stop and re-start the scheduler in order to let the scheduler free up the timedout job in case it got signaled. In case of exec jobs the job type specific callback will take care to signal all fences and tear down the channel.
Fixes b88baab82871 ("drm/nouveau: implement new VM_BIND uAPI")Signed-off-by Danilo Krummrich <[email protected]>--- drivers/gpu/drm/nouveau/nouveau_exec.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-)drivers/gpu/drm/nouveau/nouveau_exec.c +1
-1@@ -185,7 +185,7 @@ nouveau_exec_job_timeout(struct nouveau_job *job)nouveau_sched_entity_fini (job->entity); -return DRM_GPU_SCHED_STAT_ENODEV ; +return DRM_GPU_SCHED_STAT_NOMINAL ; }static struct nouveau_job_ops nouveau_exec_job_ops = {drivers/gpu/drm/nouveau/nouveau_sched.c +9
-3@@ -375,14 +375,20 @@ nouveau_sched_run_job(struct drm_sched_job *sched_job)static enum drm_gpu_sched_stat nouveau_sched_timedout_job (struct drm_sched_job *sched_job) { +struct drm_gpu_scheduler *sched = sched_job->sched;struct nouveau_job *job =to_nouveau_job (sched_job); +enum drm_gpu_sched_stat stat =DRM_GPU_SCHED_STAT_NOMINAL ; -NV_PRINTK (warn, job->cli,"Job timed out.\n" ); +drm_sched_stop (sched, sched_job);if (job->ops->timeout) -return job->ops->timeout (job); + stat = job->ops->timeout (job); +else +NV_PRINTK (warn, job->cli,"Generic job timeout.\n" ); + +drm_sched_start (sched, true); -return DRM_GPU_SCHED_STAT_ENODEV ; +return stat; } static void
Signature · 3 lines
Cheers, Lyude Paul (she/her) Software Engineer at Red Hat
Quoted 4 lines · Lyude Paul
BTW - Would you like me to review work like this? I'm totally happy to do that, although I'm not terribly familiar with these parts of nouveau/drm (but I'm always willing to learn, and would like to know more about these areas anyway :)
Of course, that's absolutely welcome. :)
Quoted 4 lines
…if the answer is yes, this patch looks fine to me so far - I guess the one question I have that might have an obvious answer - how are jobs without an
job->ops->timeoutcallback cleaned up?
Currently there are only two types of jobs, EXEC jobs and VM_BIND jobs. EXEC jobs do have the callback, where on timeout the fence context is killed and hence pending fences for this channel are signaled with an error code. Queued up jobs from the channel's corresponding entity are discarded.
VM_BIND jobs still execute on the CPU and can't really time out. Well, technically, they actually could, since drm_sched_job_begin() is called before the run_job() callback. However, this would require mapping / unmapping stuff taking an absolutely unreasonable amount of time. But even then it'd be safe because drm_sched_stop() would block until the run_job() callback returns and subsequently the job would be cleaned up by drm_sched_stop() since we'd pass it to drm_sched_stop() as 'bad' job.
However, I'm also working on a series [1] to make use of the DRM_SCHED_POLICY_SINGLE_ENTITY work from Matt [2] in order to properly support the firmware scheduler.
[1] https://gitlab.freedesktop.org/nouvelles/kernel/-/commits/sched-single-entity/
[2] https://lore.kernel.org/dri-devel/[email protected]/
Quoted 56 lines · Danilo Krummrich
Quoted 53 lines
Always stop and re-start the scheduler in order to let the scheduler free up the timedout job in case it got signaled. In case of exec jobs the job type specific callback will take care to signal all fences and tear down the channel.
Fixes b88baab82871 ("drm/nouveau: implement new VM_BIND uAPI")Signed-off-by Danilo Krummrich <[email protected]>--- drivers/gpu/drm/nouveau/nouveau_exec.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-)drivers/gpu/drm/nouveau/nouveau_exec.c +1
-1@@ -185,7 +185,7 @@ nouveau_exec_job_timeout(struct nouveau_job *job)nouveau_sched_entity_fini (job->entity); -return DRM_GPU_SCHED_STAT_ENODEV ; +return DRM_GPU_SCHED_STAT_NOMINAL ; }static struct nouveau_job_ops nouveau_exec_job_ops = {drivers/gpu/drm/nouveau/nouveau_sched.c +9
-3@@ -375,14 +375,20 @@ nouveau_sched_run_job(struct drm_sched_job *sched_job)static enum drm_gpu_sched_stat nouveau_sched_timedout_job (struct drm_sched_job *sched_job) { +struct drm_gpu_scheduler *sched = sched_job->sched;struct nouveau_job *job =to_nouveau_job (sched_job); +enum drm_gpu_sched_stat stat =DRM_GPU_SCHED_STAT_NOMINAL ; -NV_PRINTK (warn, job->cli,"Job timed out.\n" ); +drm_sched_stop (sched, sched_job);if (job->ops->timeout) -return job->ops->timeout (job); + stat = job->ops->timeout (job); +else +NV_PRINTK (warn, job->cli,"Generic job timeout.\n" ); + +drm_sched_start (sched, true); -return DRM_GPU_SCHED_STAT_ENODEV ; +return stat; } static void
Quoted 5 lines · Danilo Krummrich
Always stop and re-start the scheduler in order to let the scheduler free up the timedout job in case it got signaled. In case of exec jobs the job type specific callback will take care to signal all fences and tear down the channel.
Quoted 52 lines
Fixes b88baab82871 ("drm/nouveau: implement new VM_BIND uAPI")Signed-off-by Danilo Krummrich <[email protected]>--- drivers/gpu/drm/nouveau/nouveau_exec.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-)drivers/gpu/drm/nouveau/nouveau_exec.c +1
-1@@ -185,7 +185,7 @@ nouveau_exec_job_timeout(struct nouveau_job *job)nouveau_sched_entity_fini (job->entity); -return DRM_GPU_SCHED_STAT_ENODEV ; +return DRM_GPU_SCHED_STAT_NOMINAL ; }static struct nouveau_job_ops nouveau_exec_job_ops = {drivers/gpu/drm/nouveau/nouveau_sched.c +9
-4@@ -375,14 +375,20 @@ nouveau_sched_run_job(struct drm_sched_job *sched_job)static enum drm_gpu_sched_stat nouveau_sched_timedout_job (struct drm_sched_job *sched_job) { +struct drm_gpu_scheduler *sched = sched_job->sched;struct nouveau_job *job =to_nouveau_job (sched_job); +enum drm_gpu_sched_stat stat =DRM_GPU_SCHED_STAT_NOMINAL ; -NV_PRINTK (warn, job->cli,"Job timed out.\n" ); +drm_sched_stop (sched, sched_job);if (job->ops->timeout) -return job->ops->timeout (job); + stat = job->ops->timeout (job); +else +NV_PRINTK (warn, job->cli,"Generic job timeout.\n" ); + +drm_sched_start (sched, true); -return DRM_GPU_SCHED_STAT_ENODEV ; +return stat; } static void --2.41.0