All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tarel Ethridge <tarelerulz@gmail.com>
To: mwen@igalia.com, mcanal@igalia.com
Cc: dri-devel@lists.freedesktop.org, Tarel Ethridge <tarelerulz@gmail.com>
Subject: [PATCH] drm/v3d: Propagate a failed job's error to dependent jobs
Date: Fri, 20 Nov 2026 19:55:51 -0800	[thread overview]
Message-ID: <20261121035551.8048-1-tarelerulz@gmail.com> (raw)

A job that hangs is dropped after the GPU reset and its finished fence
gets an error. drm_sched does not carry that error over to a job that
depends on it, and the run_job() callbacks only look at their own
finished fence. A dependent job therefore runs and signals success, so
the syncobj userspace waits on reports success although the work was
never completed.

This affects two kinds of dependency: the previous job of the same
submission (for example the cache clean job after a compute job, whose
done fence is the one attached to the out syncobj), and syncobjs the job
waits on, which is how userspace such as Mesa v3dv chains the no-op job
that signals a VkFence to an earlier submission.

Remember the done fence of the previous job of the submission and the
fences of the syncobjs the job waits on. In run_job(), copy an error from
any of them to the job's own finished fence. The job is then skipped by
the existing error check and its fence reports the failure.

Tested on a Raspberry Pi 400 (V3D 4.2) with a compute shader that never
finishes: before the change vkWaitForFences returns success after the
reset, with the change it returns VK_ERROR_DEVICE_LOST (with a Mesa
change that reads the fence status). That test used an equivalent change
on a 6.12 kernel; this version is only compile-tested.

Signed-off-by: Tarel Ethridge <tarelerulz@gmail.com>
---
 drivers/gpu/drm/v3d/v3d_drv.h    |  7 ++++++
 drivers/gpu/drm/v3d/v3d_sched.c  | 38 ++++++++++++++++++++++++-----
 drivers/gpu/drm/v3d/v3d_submit.c | 42 +++++++++++++++++++++++++++++---
 3 files changed, 77 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/v3d/v3d_drv.h b/drivers/gpu/drm/v3d/v3d_drv.h
index 3bccb35ed..d5502b895 100644
--- a/drivers/gpu/drm/v3d/v3d_drv.h
+++ b/drivers/gpu/drm/v3d/v3d_drv.h
@@ -367,6 +367,13 @@ struct v3d_job {
 	 */
 	struct dma_fence *done_fence;
 
+	/* Done fence of the previous job of the submission, if any. */
+	struct dma_fence *prev_fence;
+
+	/* Fences of the syncobjs this job waits on, as found at submit. */
+	struct dma_fence **dep_fences;
+	u32 dep_count;
+
 	/* Pointer to a performance monitor object if the user requested it,
 	 * NULL otherwise.
 	 */
diff --git a/drivers/gpu/drm/v3d/v3d_sched.c b/drivers/gpu/drm/v3d/v3d_sched.c
index f29d79b15..62b7b8987 100644
--- a/drivers/gpu/drm/v3d/v3d_sched.c
+++ b/drivers/gpu/drm/v3d/v3d_sched.c
@@ -165,6 +165,32 @@ v3d_job_update_stats(struct v3d_job *job)
 	preempt_enable();
 }
 
+/*
+ * drm_sched does not propagate a failed dependency to the job that waits on
+ * it, and the jobs of a submission run on different queues. Take the error of
+ * the previous job of the submission, or of a syncobj it waited on, so that
+ * this job is skipped and the fence userspace waits for reports the failure.
+ */
+static bool v3d_job_failed(struct v3d_job *job)
+{
+	struct dma_fence *finished = &job->base.s_fence->finished;
+	int err, i;
+
+	for (i = 0; i < job->dep_count && !finished->error; i++) {
+		err = dma_fence_get_status(job->dep_fences[i]);
+		if (err < 0)
+			dma_fence_set_error(finished, err);
+	}
+
+	if (job->prev_fence) {
+		err = dma_fence_get_status(job->prev_fence);
+		if (err < 0)
+			dma_fence_set_error(finished, err);
+	}
+
+	return finished->error;
+}
+
 static struct dma_fence *v3d_bin_job_run(struct drm_sched_job *sched_job)
 {
 	struct v3d_bin_job *job = to_bin_job(sched_job);
@@ -174,7 +200,7 @@ static struct dma_fence *v3d_bin_job_run(struct drm_sched_job *sched_job)
 	struct dma_fence *fence = NULL;
 	unsigned long irqflags;
 
-	if (unlikely(job->base.base.s_fence->finished.error))
+	if (unlikely(v3d_job_failed(&job->base)))
 		goto out_clean_job;
 
 	/* Lock required around bin_job update vs
@@ -235,7 +261,7 @@ static struct dma_fence *v3d_render_job_run(struct drm_sched_job *sched_job)
 	struct drm_device *dev = &v3d->drm;
 	struct dma_fence *fence = NULL;
 
-	if (unlikely(job->base.base.s_fence->finished.error))
+	if (unlikely(v3d_job_failed(&job->base)))
 		goto out_clean_job;
 
 	v3d->queue[V3D_RENDER].active_job = &job->base;
@@ -285,7 +311,7 @@ v3d_tfu_job_run(struct drm_sched_job *sched_job)
 	struct drm_device *dev = &v3d->drm;
 	struct dma_fence *fence = NULL;
 
-	if (unlikely(job->base.base.s_fence->finished.error))
+	if (unlikely(v3d_job_failed(&job->base)))
 		goto out_clean_job;
 
 	v3d->queue[V3D_TFU].active_job = &job->base;
@@ -351,7 +377,7 @@ v3d_csd_job_run(struct drm_sched_job *sched_job)
 	struct dma_fence *fence = NULL;
 	int i, csd_cfg0_reg;
 
-	if (unlikely(job->base.base.s_fence->finished.error))
+	if (unlikely(v3d_job_failed(&job->base)))
 		goto out_clean_job;
 
 	/* The HW interprets a workgroup size of 0 as 65536; however, the
@@ -662,7 +688,7 @@ v3d_cpu_job_run(struct drm_sched_job *sched_job)
 	struct v3d_cpu_job *job = to_cpu_job(sched_job);
 	struct v3d_dev *v3d = job->base.v3d;
 
-	if (unlikely(job->base.base.s_fence->finished.error))
+	if (unlikely(v3d_job_failed(&job->base)))
 		return NULL;
 
 	if (job->job_type >= ARRAY_SIZE(cpu_job_function)) {
@@ -688,7 +714,7 @@ v3d_cache_clean_job_run(struct drm_sched_job *sched_job)
 	struct v3d_job *job = to_v3d_job(sched_job);
 	struct v3d_dev *v3d = job->v3d;
 
-	if (unlikely(job->base.s_fence->finished.error))
+	if (unlikely(v3d_job_failed(job)))
 		return NULL;
 
 	v3d_job_start_stats(job);
diff --git a/drivers/gpu/drm/v3d/v3d_submit.c b/drivers/gpu/drm/v3d/v3d_submit.c
index eada30a31..3f464128c 100644
--- a/drivers/gpu/drm/v3d/v3d_submit.c
+++ b/drivers/gpu/drm/v3d/v3d_submit.c
@@ -141,6 +141,10 @@ v3d_job_free(struct kref *ref)
 
 	dma_fence_put(job->irq_fence);
 	dma_fence_put(job->done_fence);
+	dma_fence_put(job->prev_fence);
+	for (i = 0; i < job->dep_count; i++)
+		dma_fence_put(job->dep_fences[i]);
+	kfree(job->dep_fences);
 
 	if (job->perfmon)
 		v3d_perfmon_put(job->perfmon);
@@ -203,6 +207,34 @@ void v3d_job_put(struct v3d_job *job)
 	kref_put(&job->refcount, job->free);
 }
 
+/* Remember the fence a syncobj dependency waits on, so that run_job() can
+ * tell whether the work this job depends on failed.
+ */
+static int
+v3d_job_add_syncobj_dep(struct v3d_job *job, struct drm_file *file_priv,
+			u32 handle, u32 max_deps)
+{
+	struct dma_fence *fence = NULL;
+	int ret;
+
+	ret = drm_sched_job_add_syncobj_dependency(&job->base, file_priv, handle, 0);
+	if (ret)
+		return ret;
+
+	if (!job->dep_fences) {
+		job->dep_fences = kcalloc(max_deps, sizeof(*job->dep_fences),
+					  GFP_KERNEL);
+		if (!job->dep_fences)
+			return -ENOMEM;
+	}
+
+	if (job->dep_count < max_deps &&
+	    !drm_syncobj_find_fence(file_priv, handle, 0, 0, &fence) && fence)
+		job->dep_fences[job->dep_count++] = fence;
+
+	return 0;
+}
+
 static int
 v3d_job_add_syncobjs(struct v3d_job *job, struct drm_file *file_priv,
 		     u32 in_sync, struct v3d_submit_ext *se)
@@ -214,8 +246,7 @@ v3d_job_add_syncobjs(struct v3d_job *job, struct drm_file *file_priv,
 	if (!has_multisync) {
 		/* Ignore syncobj if its handle is zero */
 		if (in_sync)
-			ret = drm_sched_job_add_syncobj_dependency(&job->base, file_priv,
-								   in_sync, 0);
+			ret = v3d_job_add_syncobj_dep(job, file_priv, in_sync, 1);
 		return ret;
 	}
 
@@ -232,8 +263,8 @@ v3d_job_add_syncobjs(struct v3d_job *job, struct drm_file *file_priv,
 
 			/* Ignore syncobj if its handle is zero */
 			if (in.handle) {
-				ret = drm_sched_job_add_syncobj_dependency(&job->base,
-									   file_priv, in.handle, 0);
+				ret = v3d_job_add_syncobj_dep(job, file_priv, in.handle,
+							      se->in_sync_count);
 				if (ret)
 					return ret;
 			}
@@ -494,6 +525,9 @@ v3d_submit_jobs(struct v3d_submit *submit, struct drm_syncobj *sync_out,
 						   dma_fence_get(submit->jobs[i - 1]->done_fence));
 		if (ret)
 			goto err;
+
+		submit->jobs[i]->prev_fence =
+			dma_fence_get(submit->jobs[i - 1]->done_fence);
 	}
 
 	for (int i = 0; i < submit->job_count; i++) {
-- 
2.53.0


             reply	other threads:[~2026-11-22 17:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21  3:55 Tarel Ethridge [this message]
2026-11-21 11:56 ` [PATCH] drm/v3d: Propagate a failed job's error to dependent jobs Maíra Canal
2026-11-21 15:09   ` Maíra Canal
2026-11-22 17:29 ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261121035551.8048-1-tarelerulz@gmail.com \
    --to=tarelerulz@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=mcanal@igalia.com \
    --cc=mwen@igalia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.