From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tyler Smith <74526874+tylertms@users.noreply.github.com> Date: Wed, 4 Nov 2026 04:55:35 -0500 Subject: [PATCH] fix(nouveau): ring a timed-out channel again when it never fetched the job --- drivers/gpu/drm/nouveau/nouveau_exec.c | 29 +++++++++++++++++++++++++ drivers/gpu/drm/nouveau/nouveau_sched.c | 2 ++ drivers/gpu/drm/nouveau/nouveau_sched.h | 3 +++ 3 files changed, 34 insertions(+) diff --git a/drivers/gpu/drm/nouveau/nouveau_exec.c b/drivers/gpu/drm/nouveau/nouveau_exec.c index a08ab1cfea9be872f4f26573313a26346f83b80b..9d32b0810f8bdf556234117599a72ee35517b905 100644 --- a/drivers/gpu/drm/nouveau/nouveau_exec.c +++ b/drivers/gpu/drm/nouveau/nouveau_exec.c @@ -5,6 +5,7 @@ #include "nouveau_mem.h" #include "nouveau_dma.h" #include "nouveau_exec.h" +#include "nouveau_fence.h" #include "nouveau_abi16.h" #include "nouveau_chan.h" #include "nouveau_sched.h" @@ -177,6 +178,33 @@ nouveau_exec_job_free(struct nouveau_job *job) kfree(exec_job); } +static bool +nouveau_exec_job_unfetched(struct nouveau_job *job) +{ + struct nouveau_exec_job *exec_job = to_nouveau_exec_job(job); + struct nouveau_channel *chan = exec_job->chan; + struct nouveau_fence_chan *fctx = chan->fence; + struct nvif_chan *gpfifo = &chan->chan; + u32 get = gpfifo->func->gpfifo.read_get(gpfifo); + u64 until; + + NV_PRINTK(warn, job->cli, "channel %d timed out: gpfifo get %u put %u, fence %u\n", + chan->chid, get, gpfifo->gpfifo.cur, fctx ? fctx->read(chan) : 0); + if (get == gpfifo->gpfifo.cur || atomic_read(&chan->killed)) + return false; + + /* The GPU never fetched entries it was rung for: ring again. */ + until = ktime_get_ns() + 100 * NSEC_PER_MSEC; + gpfifo->func->gpfifo.kick(gpfifo); + while (gpfifo->func->gpfifo.read_get(gpfifo) != gpfifo->gpfifo.cur && + ktime_get_ns() < until) + cpu_relax(); + if (gpfifo->func->gpfifo.read_get(gpfifo) != gpfifo->gpfifo.cur) + return false; + NV_PRINTK(warn, job->cli, "channel %d ran its job after a second doorbell\n", chan->chid); + return true; +} + static enum drm_gpu_sched_stat nouveau_exec_job_timeout(struct nouveau_job *job) { @@ -198,6 +226,7 @@ static const struct nouveau_job_ops nouveau_exec_job_ops = { .run = nouveau_exec_job_run, .free = nouveau_exec_job_free, .timeout = nouveau_exec_job_timeout, + .unfetched = nouveau_exec_job_unfetched, }; int diff --git a/drivers/gpu/drm/nouveau/nouveau_sched.c b/drivers/gpu/drm/nouveau/nouveau_sched.c index c94ab7dc29e9fc5bc43542daaa8c3c7f37e84a1a..e613907b2efeeb72b136fd205b04c72287ec14b3 100644 --- a/drivers/gpu/drm/nouveau/nouveau_sched.c +++ b/drivers/gpu/drm/nouveau/nouveau_sched.c @@ -378,6 +378,8 @@ nouveau_sched_timedout_job(struct drm_sched_job *sched_job) NV_PRINTK(warn, job->cli, "Job completed without its completion interrupt.\n"); return DRM_GPU_SCHED_STAT_NO_HANG; } + if (job->ops->unfetched && job->ops->unfetched(job)) + return DRM_GPU_SCHED_STAT_NO_HANG; drm_sched_stop(sched, sched_job); diff --git a/drivers/gpu/drm/nouveau/nouveau_sched.h b/drivers/gpu/drm/nouveau/nouveau_sched.h index 51ce8dcf62858bd9844baf1c1553cf8f73233305..5a6c514a0839a5a8c3bdad05f88e259c63586698 100644 --- a/drivers/gpu/drm/nouveau/nouveau_sched.h +++ b/drivers/gpu/drm/nouveau/nouveau_sched.h @@ -82,6 +82,9 @@ struct nouveau_job { struct dma_fence *(*run)(struct nouveau_job *); void (*free)(struct nouveau_job *); enum drm_gpu_sched_stat (*timeout)(struct nouveau_job *); + /* Before a timeout stops the scheduler: whether the job runs + * after its channel is rung again, having never fetched it. */ + bool (*unfetched)(struct nouveau_job *); } *ops; };