]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/v3d: Skip CSD when it has zeroed workgroups
authorMaíra Canal <mcanal@igalia.com>
Tue, 2 Jun 2026 17:50:15 +0000 (14:50 -0300)
committerMaíra Canal <mcanal@igalia.com>
Wed, 3 Jun 2026 11:19:54 +0000 (08:19 -0300)
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.

Cc: stable@vger.kernel.org
Fixes: d223f98f0209 ("drm/v3d: Add support for compute shader dispatch.")
Suggested-by: Jose Maria Casanova Crespo <jmcasanova@igalia.com>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Link: https://patch.msgid.link/20260602-v3d-fix-indirect-csd-v4-2-654309e32bc0@igalia.com
Signed-off-by: Maíra Canal <mcanal@igalia.com>
drivers/gpu/drm/v3d/v3d_sched.c

index 47f83936cd7362bba3883a9ea3401eba473eb951..8a635a9ec0461671261f45d8e91d1e9f1ad284e0 100644 (file)
@@ -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]);