FAILED: patch "[PATCH] drm/v3d: Skip CSD when it has zeroed workgroups" failed to apply to 6.12-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 7f93fad5ea0affc9e1505dd0f7596c0fdb496213
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026061521-hardship-pebbly-50b5@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 7f93fad5ea0affc9e1505dd0f7596c0fdb496213 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ma=C3=ADra=20Canal?= <[email protected]>
Date: Tue, 2 Jun 2026 14:50:15 -0300
Subject: [PATCH] drm/v3d: Skip CSD when it has zeroed workgroups
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
A compute shader dispatch encodes its workgroup counts in the CFG0..CFG2 registers. Kicking off a dispatch with a zero count in any of the three dimensions is invalid. First, the hardware will process 0 as 65536, while the user-space driver exposes a maximum of 65535. Over that, a submission with a zeroed workgroup dimension should be a no-op.
These zeroed counts can reach the dispatch path through an indirect CSD job, whose workgroup counts are only known once the indirect buffer is read and may legitimately be zero, but such scenario should only result in a no-op.
Overwrite the indirect CSD job workgroup counts with the indirect BO ones, even if they are zeroed, and don't submit the job to the hardware when any of the workgroup counts is zero, so the job completes immediately instead of running the shader.
drivers/gpu/drm/v3d/v3d_sched.c +13 -3
@@ -352,6 +352,16 @@ v3d_csd_job_run(struct drm_sched_job *sched_job)return NULL ; } +/* The HW interprets a workgroup size of 0 as 65536; however, the +* user-space driver exposes a maximum of 65535. Therefore, a 0 in +* any dimension means that we have no workgroups and the compute +* shader should not be dispatched. +*/ +if (!V3D_GET_FIELD (job->args.cfg[0 ],V3D_CSD_QUEUED_CFG0_NUM_WGS_X ) || + !V3D_GET_FIELD (job->args.cfg[1 ],V3D_CSD_QUEUED_CFG1_NUM_WGS_Y ) || + !V3D_GET_FIELD (job->args.cfg[2 ],V3D_CSD_QUEUED_CFG2_NUM_WGS_Z )) +return NULL ; + v3d->queue[V3D_CSD ].active_job = &job->base;v3d_invalidate_caches (v3d);
@@ -402,13 +412,13 @@ v3d_rewrite_csd_job_wg_counts_from_indirect(struct v3d_cpu_job *job) wg_counts = (uint32_t *)(bo->vaddr + indirect_csd->offset); -if (wg_counts[0 ] ==0 || wg_counts[1 ] ==0 || wg_counts[2 ] ==0 ) - goto unmap_bo; - args->cfg[0 ] = wg_counts[0 ] <<V3D_CSD_CFG012_WG_COUNT_SHIFT ; args->cfg[1 ] = wg_counts[1 ] <<V3D_CSD_CFG012_WG_COUNT_SHIFT ; args->cfg[2 ] = wg_counts[2 ] <<V3D_CSD_CFG012_WG_COUNT_SHIFT ; +if (wg_counts[0 ] ==0 || wg_counts[1 ] ==0 || wg_counts[2 ] ==0 ) + goto unmap_bo; + num_batches =DIV_ROUND_UP (indirect_csd->wg_size,16 ) * (wg_counts[0 ] * wg_counts[1 ] * wg_counts[2 ]);
Sasha Levin
maintainerPATCH 1/3 drm/v3d: Store the active job inside the queue's state
From: Maíra Canal <[email protected]>
[ Upstream commit 0d3768826d38c0ac740f8b45cd13346630535f2b ]
Instead of storing the queue's active job in four different variables, store the active job inside the queue's state. This way, it's possible to access all active jobs using an index based in enum v3d_queue.
Stable-dep-of: 7f93fad5ea0a ("drm/v3d: Skip CSD when it has zeroed workgroups")
--- drivers/gpu/drm/v3d/v3d_drv.h | 7 ++-- drivers/gpu/drm/v3d/v3d_gem.c | 7 ++-- drivers/gpu/drm/v3d/v3d_irq.c | 62 +++++++++++++-------------------- drivers/gpu/drm/v3d/v3d_sched.c | 26 +++++++++----- 4 files changed, 48 insertions(+), 54 deletions(-)
drivers/gpu/drm/v3d/v3d_drv.h +3 -4
@@ -59,6 +59,9 @@ struct v3d_queue_state {/* Stores the GPU stats for this queue in the global context. */ struct v3d_stats stats; + +/* Currently active job for this queue */ +struct v3d_job *active_job; };/* Performance monitor object. The perform lifetime is controlled by userspace
@@ -147,10 +150,6 @@ struct v3d_dev {struct work_struct overflow_mem_work; -struct v3d_bin_job *bin_job; -struct v3d_render_job *render_job; -struct v3d_tfu_job *tfu_job; -struct v3d_csd_job *csd_job;struct v3d_cpu_job *cpu_job;struct v3d_queue_state queue[V3D_MAX_QUEUES ];
drivers/gpu/drm/v3d/v3d_gem.c +3 -4
@@ -304,16 +304,15 @@ void v3d_gem_destroy(struct drm_device *dev) {struct v3d_dev *v3d =to_v3d_dev (dev); +enum v3d_queue q;v3d_sched_fini (v3d);/* Waiting for jobs to finish would need to be done before * unregistering V3D. */ -WARN_ON (v3d->bin_job); -WARN_ON (v3d->render_job); -WARN_ON (v3d->tfu_job); -WARN_ON (v3d->csd_job); +for (q =0 ; q <V3D_MAX_QUEUES ; q++) +WARN_ON (v3d->queue[q].active_job);drm_mm_takedown (&v3d->mm);
drivers/gpu/drm/v3d/v3d_irq.c +24 -38
105 lines not on this page · raw message
drivers/gpu/drm/v3d/v3d_sched.c +18 -8
@@ -208,14 +208,18 @@ static struct dma_fence *v3d_bin_job_run(struct drm_sched_job *sched_job)struct dma_fence *fence;unsigned long irqflags; -if (unlikely (job->base.base.s_fence->finished.error)) +if (unlikely (job->base.base.s_fence->finished.error)) { +spin_lock_irqsave (&v3d->job_lock, irqflags); + v3d->queue[V3D_BIN ].active_job =NULL ; +spin_unlock_irqrestore (&v3d->job_lock, irqflags);return NULL ; + }/* Lock required around bin_job update vs * v3d_overflow_mem_work(). */ spin_lock_irqsave (&v3d->job_lock, irqflags); - v3d->bin_job = job; + v3d->queue[V3D_BIN ].active_job = &job->base;/* Clear out the overflow allocation, so we don't * reuse the overflow attached to a previous job. */
@@ -263,10 +267,12 @@ static struct dma_fence *v3d_render_job_run(struct drm_sched_job *sched_job)struct drm_device *dev = &v3d->drm;struct dma_fence *fence; -if (unlikely (job->base.base.s_fence->finished.error)) +if (unlikely (job->base.base.s_fence->finished.error)) { + v3d->queue[V3D_RENDER ].active_job =NULL ;return NULL ; + } - v3d->render_job = job; + v3d->queue[V3D_RENDER ].active_job = &job->base;/* Can we avoid this flush? We need to be careful of * scheduling, though -- imagine job0 rendering to texture and
@@ -309,10 +315,12 @@ v3d_tfu_job_run(struct drm_sched_job *sched_job)struct drm_device *dev = &v3d->drm;struct dma_fence *fence; -if (unlikely (job->base.base.s_fence->finished.error)) +if (unlikely (job->base.base.s_fence->finished.error)) { + v3d->queue[V3D_TFU ].active_job =NULL ;return NULL ; + } - v3d->tfu_job = job; + v3d->queue[V3D_TFU ].active_job = &job->base; fence =v3d_fence_create (v3d,V3D_TFU );if (IS_ERR (fence))
@@ -355,10 +363,12 @@ v3d_csd_job_run(struct drm_sched_job *sched_job)struct dma_fence *fence;int i, csd_cfg0_reg; -if (unlikely (job->base.base.s_fence->finished.error)) +if (unlikely (job->base.base.s_fence->finished.error)) { + v3d->queue[V3D_CSD ].active_job =NULL ;return NULL ; + } - v3d->csd_job = job; + v3d->queue[V3D_CSD ].active_job = &job->base;v3d_invalidate_caches (v3d);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 drm/v3d: Fix vaddr leak when indirect CSD has zeroed workgroups
From: Maíra Canal <[email protected]>
[ Upstream commit ae7676952790f421c40918e2586a2c9f12a682b6 ]
v3d_rewrite_csd_job_wg_counts_from_indirect() maps both the indirect buffer and the workgroup buffer and is expected to release them before returning. When any of the workgroup counts read from the buffer is zero, the function bailed out early and skipped the cleanup, leaking the vaddr mappings of both BOs.
Jump to the cleanup path instead of returning directly, so the mappings are always dropped.
Stable-dep-of: 7f93fad5ea0a ("drm/v3d: Skip CSD when it has zeroed workgroups")
--- drivers/gpu/drm/v3d/v3d_sched.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/v3d/v3d_sched.c +2 -1
@@ -419,7 +419,7 @@ v3d_rewrite_csd_job_wg_counts_from_indirect(struct v3d_cpu_job *job) wg_counts = (uint32_t *)(bo->vaddr + indirect_csd->offset);if (wg_counts[0 ] ==0 || wg_counts[1 ] ==0 || wg_counts[2 ] ==0 ) -return ; + goto unmap_bo; args->cfg[0 ] = wg_counts[0 ] <<V3D_CSD_CFG012_WG_COUNT_SHIFT ; args->cfg[1 ] = wg_counts[1 ] <<V3D_CSD_CFG012_WG_COUNT_SHIFT ;
@@ -444,6 +444,7 @@ v3d_rewrite_csd_job_wg_counts_from_indirect(struct v3d_cpu_job *job) } } +unmap_bo:v3d_put_bo_vaddr (indirect);v3d_put_bo_vaddr (bo); }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 drm/v3d: Skip CSD when it has zeroed workgroups
In reply to Sasha LevinFrom: Maíra Canal <[email protected]>
[ Upstream commit 7f93fad5ea0affc9e1505dd0f7596c0fdb496213 ]
A compute shader dispatch encodes its workgroup counts in the CFG0..CFG2 registers. Kicking off a dispatch with a zero count in any of the three dimensions is invalid. First, the hardware will process 0 as 65536, while the user-space driver exposes a maximum of 65535. Over that, a submission with a zeroed workgroup dimension should be a no-op.
These zeroed counts can reach the dispatch path through an indirect CSD job, whose workgroup counts are only known once the indirect buffer is read and may legitimately be zero, but such scenario should only result in a no-op.
Overwrite the indirect CSD job workgroup counts with the indirect BO ones, even if they are zeroed, and don't submit the job to the hardware when any of the workgroup counts is zero, so the job completes immediately instead of running the shader.
--- drivers/gpu/drm/v3d/v3d_sched.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/gpu/drm/v3d/v3d_sched.c +13 -3
@@ -368,6 +368,16 @@ v3d_csd_job_run(struct drm_sched_job *sched_job)return NULL ; } +/* The HW interprets a workgroup size of 0 as 65536; however, the +* user-space driver exposes a maximum of 65535. Therefore, a 0 in +* any dimension means that we have no workgroups and the compute +* shader should not be dispatched. +*/ +if (!V3D_GET_FIELD (job->args.cfg[0 ],V3D_CSD_QUEUED_CFG0_NUM_WGS_X ) || + !V3D_GET_FIELD (job->args.cfg[1 ],V3D_CSD_QUEUED_CFG1_NUM_WGS_Y ) || + !V3D_GET_FIELD (job->args.cfg[2 ],V3D_CSD_QUEUED_CFG2_NUM_WGS_Z )) +return NULL ; + v3d->queue[V3D_CSD ].active_job = &job->base;v3d_invalidate_caches (v3d);
@@ -418,13 +428,13 @@ v3d_rewrite_csd_job_wg_counts_from_indirect(struct v3d_cpu_job *job) wg_counts = (uint32_t *)(bo->vaddr + indirect_csd->offset); -if (wg_counts[0 ] ==0 || wg_counts[1 ] ==0 || wg_counts[2 ] ==0 ) - goto unmap_bo; - args->cfg[0 ] = wg_counts[0 ] <<V3D_CSD_CFG012_WG_COUNT_SHIFT ; args->cfg[1 ] = wg_counts[1 ] <<V3D_CSD_CFG012_WG_COUNT_SHIFT ; args->cfg[2 ] = wg_counts[2 ] <<V3D_CSD_CFG012_WG_COUNT_SHIFT ; +if (wg_counts[0 ] ==0 || wg_counts[1 ] ==0 || wg_counts[2 ] ==0 ) + goto unmap_bo; + num_batches =DIV_ROUND_UP (indirect_csd->wg_size,16 ) * (wg_counts[0 ] * wg_counts[1 ] * wg_counts[2 ]);
Signature · 1 line
2.53.0