drm/v3d: Propagate a failed job's error to dependent jobs
Subsystems (3)
PATCH 1/1 drm/v3d: Propagate a failed job's error to dependent jobs
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.
--- 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(-)
drivers/gpu/drm/v3d/v3d_drv.h +7 -0
@@ -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. */
drivers/gpu/drm/v3d/v3d_sched.c +32 -6
@@ -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);
drivers/gpu/drm/v3d/v3d_submit.c +38 -4
72 lines not on this page · raw message
Signature · 1 line
2.53.0
Maíra Canal
maintainerHi Tarel,
This patch doesn't make any sense.
Quoted 7 lines · Tarel Ethridge
A job that hangs is dropped after the GPU reset and its finished fence gets an error.
drm_scheddoes not carry that error over to a job that depends on it, and therun_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.
DRM sched not propagating dependency errors is intentional. A fence error reports the failure of that job, not of every job waiting on it. If this behavior were desired, it would belong in drm_sched, not the driver.
Quoted 6 lines
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.
Quoted 8 lines
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 returnsVK_ERROR_DEVICE_LOST(with a Mesa
If you really want this feature in Mesa, you should implement the vk_device::check_status hook using DRM_V3D_PARAM_CONTEXT_RESET_COUNTER.
Quoted 2 lines
change that reads the fence status). That test used an equivalent change on a 6.12 kernel; this version is only compile-tested.
Upstream development must happen in an upstream branch.
Best regards,
- Maíra
Quoted 198 lines
Signed-off-by Tarel Ethridge <[email protected]>--- 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(-)drivers/gpu/drm/v3d/v3d_drv.h +7
-0@@ -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. */ drivers/gpu/drm/v3d/v3d_sched.c +32
-6@@ -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);drivers/gpu/drm/v3d/v3d_submit.c +38
-4@@ -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++) {
Maíra Canal
maintainerQuoted 29 lines · Maíra Canal
Hi Tarel,
This patch doesn't make any sense.
Quoted 7 lines · Tarel Ethridge
A job that hangs is dropped after the GPU reset and its finished fence gets an error.
drm_scheddoes not carry that error over to a job that depends on it, and therun_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.DRM sched not propagating dependency errors is intentional. A fence error reports the failure of that job, not of every job waiting on it. If this behavior were desired, it would belong in
drm_sched, not the driver.Quoted 11 lines
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.
Quoted 6 lines
Quoted 3 lines
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 returnsVK_ERROR_DEVICE_LOST(with a MesaIf you really want this feature in Mesa, you should implement the
vk_device::check_statushook usingDRM_V3D_PARAM_CONTEXT_RESET_COUNTER.
I believe this hook can actually be quite useful, so I implemented it in Mesa and opened an MR [1].
Feel free to test it and provide feedback.
[1] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/46593
Best regards,
- Maíra
Quoted 203 lines
Quoted 3 lines
change that reads the fence status). That test used an equivalent change on a 6.12 kernel; this version is only compile-tested.
Upstream development must happen in an upstream branch.
Best regards,
- MaíraQuoted 193 lines
Signed-off-by Tarel Ethridge <[email protected]>---
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(-)drivers/gpu/drm/v3d/v3d_drv.h +7
-0@@ -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. */ drivers/gpu/drm/v3d/v3d_sched.c +2
-0@@ -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.
+ */drivers/gpu/drm/v3d/v3d_sched.c +20
-0+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(structdrm_sched_job*sched_job) {
structv3d_bin_job*job =to_bin_job(sched_job);drivers/gpu/drm/v3d/v3d_sched.c +6
-6@@ -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);drivers/gpu/drm/v3d/v3d_submit.c +5
-0@@ -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.
+ */drivers/gpu/drm/v3d/v3d_submit.c +8
-0+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;drivers/gpu/drm/v3d/v3d_submit.c +10
-0+ + 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;drivers/gpu/drm/v3d/v3d_submit.c +4
-0+ + 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)drivers/gpu/drm/v3d/v3d_submit.c +1
-2@@ -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;}
drivers/gpu/drm/v3d/v3d_submit.c +2
-2@@ -232,8 +263,8 @@ v3d_job_add_syncobjs(struct v3d_job *job, structdrm_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]-
Quoted 1 line
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++) {
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] drm/v3d: unbounded user in_sync_count passed to kcalloc() in v3d_job_add_syncobj_dep() - [Medium]…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] drm/v3d: unbounded user in_sync_count passed to kcalloc() in v3d_job_add_syncobj_dep()
- [Medium] drm/v3d: duplicate unlocked syncobj lookup and TOCTOU race in v3d_job_add_syncobj_dep()
--
commit 306a08e6c3987e679232c1d45332551d2561d4dd
Author: Tarel Ethridge <[email protected]>
drm/v3d: Propagate a failed job's error to dependent jobs
This commit records a job's syncobj dependency fences and the previous job's done_fence on struct v3d_job so that run_job() callbacks can propagate any error from those fences to the job's finished fence.
Quoted 4 lines
drivers/gpu/drm/v3d_submit.c renamed from drivers/gpu/drm/v3d/v3d_submit.c +0
-0
[ ... ]
Quoted 18 lines
drivers/gpu/drm/v3d_submit.c renamed from drivers/gpu/drm/v3d/v3d_submit.c +14
-0@@ -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; +
drivers/gpu/drm/v3d_submit.c void v3d_job_put(struct v3d_job *job) · line 233
Quoted 10 lines
drivers/gpu/drm/v3d_submit.c renamed from drivers/gpu/drm/v3d/v3d_submit.c +10
-0+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;
[Severity: Medium]
Can the second drm_syncobj_find_fence() lookup observe a different fence than the one drm_sched_job_add_syncobj_dependency() just added?
drm_sched_job_add_syncobj_dependency() resolves handle via drm_syncobj_find_fence() and releases the syncobj locks before v3d_job_add_syncobj_dep() looks up handle a second time. If another thread or an in-flight CPU query job replaces or resets the syncobj fence in between, job->dep_fences records a different fence (or none at all) than job->base.dependencies, so v3d_job_failed() either misses the error from the fence the scheduler waited on or checks an unrelated newer fence.
Looking up the fence once with drm_syncobj_find_fence(), saving an extra reference with dma_fence_get() in job->dep_fences, and passing the fence to drm_sched_job_add_dependency() would avoid both the race and the duplicate lookup.
Quoted 18 lines
drivers/gpu/drm/v3d_submit.c renamed from drivers/gpu/drm/v3d/v3d_submit.c +5
-2+ +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; }
drivers/gpu/drm/v3d_submit.c v3d_job_add_syncobjs(struct v3d_job *job, struct drm_file *file_priv, · line 267
Quoted 7 lines
drivers/gpu/drm/v3d_submit.c renamed from drivers/gpu/drm/v3d/v3d_submit.c +2
-2@@ -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);
[Severity: Medium]
Can passing the unvalidated se->in_sync_count as max_deps to kcalloc() trigger a page allocator warning or high-order allocation stall from userspace?
v3d_get_multisync_submit_deps() copies multisync.in_sync_count directly from userspace without bounds checking. On the first valid non-zero in.handle, v3d_job_add_syncobj_dep() allocates job->dep_fences for the entire se->in_sync_count via kcalloc(..., GFP_KERNEL) before the rest of the user array is copied, so a single valid handle with a large in_sync_count triggers WARN_ON_ONCE_GFP(size > KMALLOC_MAX_SIZE, flags) in the slab allocator.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1