* [PATCH v3 0/2] drm/v3d: Fix indirect CSD jobs with zeroed workgroups
@ 2026-06-02 11:57 Maíra Canal
2026-06-02 11:57 ` [PATCH v3 1/2] drm/v3d: Fix vaddr leak when indirect CSD has " Maíra Canal
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Maíra Canal @ 2026-06-02 11:57 UTC (permalink / raw)
To: Melissa Wen, Iago Toral Quiroga, Jose Maria Casanova Crespo
Cc: kernel-dev, dri-devel, stable, Maíra Canal
Hi,
Indirect CSD lets userspace defer the workgroup counts to a GPU buffer
that is only filled at runtime, so the counts are unknown at submission
time and can legitimately turn out to be zero.
However, exercing this case exposed two issues in the CSD path.
1. Virtual address leaks when the indirect CSD has zeroed workgroups.
2. CSD jobs with zeroed workgroups shouldn't be submitted to hardware.
This series intends to address both issues.
Best regards,
- Maíra
---
v1 -> v2: https://lore.kernel.org/r/20260530-v3d-fix-indirect-csd-v1-0-15533948663f@igalia.com
- [2/2] Don't check the whole cfg[0-2], check only the number of workgroups (Iago Toral)
- [2/2] Add a comment about how the HW interprets 0 (Iago Toral)
v2 -> v3: https://lore.kernel.org/r/20260601-v3d-fix-indirect-csd-v2-0-aaebf035b936@igalia.com
- [1/2, 2/2] Add Iago's R-b (Iago Toral)
- [2/2] Adjust the comment to make it more accurate (Iago Toral)
---
Maíra Canal (2):
drm/v3d: Fix vaddr leak when indirect CSD has zeroed workgroups
drm/v3d: Skip CSD when it has zeroed workgroups
drivers/gpu/drm/v3d/v3d_sched.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
---
base-commit: ae0383e5a9a4b12d68c76c4769857def4665deff
change-id: 20260516-v3d-fix-indirect-csd-6806cf20a57a
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 1/2] drm/v3d: Fix vaddr leak when indirect CSD has zeroed workgroups
2026-06-02 11:57 [PATCH v3 0/2] drm/v3d: Fix indirect CSD jobs with zeroed workgroups Maíra Canal
@ 2026-06-02 11:57 ` Maíra Canal
2026-06-04 2:49 ` Claude review: " Claude Code Review Bot
2026-06-02 11:57 ` [PATCH v3 2/2] drm/v3d: Skip CSD when it " Maíra Canal
2026-06-04 2:49 ` Claude review: drm/v3d: Fix indirect CSD jobs with " Claude Code Review Bot
2 siblings, 1 reply; 6+ messages in thread
From: Maíra Canal @ 2026-06-02 11:57 UTC (permalink / raw)
To: Melissa Wen, Iago Toral Quiroga, Jose Maria Casanova Crespo
Cc: kernel-dev, dri-devel, stable, Maíra Canal
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.
Cc: stable@vger.kernel.org
Fixes: 18b8413b25b7 ("drm/v3d: Create a CPU job extension for a indirect CSD job")
Suggested-by: Jose Maria Casanova Crespo <jmcasanova@igalia.com>
Signed-off-by: Maíra Canal <mcanal@igalia.com>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
---
drivers/gpu/drm/v3d/v3d_sched.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/v3d/v3d_sched.c b/drivers/gpu/drm/v3d/v3d_sched.c
index 94bf628dc91c..47f83936cd73 100644
--- a/drivers/gpu/drm/v3d/v3d_sched.c
+++ b/drivers/gpu/drm/v3d/v3d_sched.c
@@ -403,7 +403,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;
@@ -428,6 +428,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);
}
--
2.54.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 2/2] drm/v3d: Skip CSD when it has zeroed workgroups
2026-06-02 11:57 [PATCH v3 0/2] drm/v3d: Fix indirect CSD jobs with zeroed workgroups Maíra Canal
2026-06-02 11:57 ` [PATCH v3 1/2] drm/v3d: Fix vaddr leak when indirect CSD has " Maíra Canal
@ 2026-06-02 11:57 ` Maíra Canal
2026-06-04 2:49 ` Claude review: " Claude Code Review Bot
2026-06-04 2:49 ` Claude review: drm/v3d: Fix indirect CSD jobs with " Claude Code Review Bot
2 siblings, 1 reply; 6+ messages in thread
From: Maíra Canal @ 2026-06-02 11:57 UTC (permalink / raw)
To: Melissa Wen, Iago Toral Quiroga, Jose Maria Casanova Crespo
Cc: kernel-dev, dri-devel, stable, Maíra Canal
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.
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>
Signed-off-by: Maíra Canal <mcanal@igalia.com>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
---
drivers/gpu/drm/v3d/v3d_sched.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/gpu/drm/v3d/v3d_sched.c b/drivers/gpu/drm/v3d/v3d_sched.c
index 47f83936cd73..6678d62e5bd0 100644
--- a/drivers/gpu/drm/v3d/v3d_sched.c
+++ b/drivers/gpu/drm/v3d/v3d_sched.c
@@ -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);
--
2.54.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Claude review: drm/v3d: Fix indirect CSD jobs with zeroed workgroups
2026-06-02 11:57 [PATCH v3 0/2] drm/v3d: Fix indirect CSD jobs with zeroed workgroups Maíra Canal
2026-06-02 11:57 ` [PATCH v3 1/2] drm/v3d: Fix vaddr leak when indirect CSD has " Maíra Canal
2026-06-02 11:57 ` [PATCH v3 2/2] drm/v3d: Skip CSD when it " Maíra Canal
@ 2026-06-04 2:49 ` Claude Code Review Bot
2 siblings, 0 replies; 6+ messages in thread
From: Claude Code Review Bot @ 2026-06-04 2:49 UTC (permalink / raw)
To: dri-devel-reviews
Overall Series Review
Subject: drm/v3d: Fix indirect CSD jobs with zeroed workgroups
Author: =?utf-8?q?Ma=C3=ADra_Canal?= <mcanal@igalia.com>
Patches: 3
Reviewed: 2026-06-04T12:49:57.798267
---
This is a clean, well-motivated two-patch bugfix series for the V3D DRM driver's indirect CSD (compute shader dispatch) path. When userspace defers workgroup counts to a GPU buffer and those counts turn out to be zero, two bugs are exposed: (1) a vaddr leak from an early return that skips cleanup, and (2) the hardware misinterpreting 0 as 65536, causing incorrect shader execution instead of a no-op.
Both patches are small, focused, correctly ordered (fix the leak first so it doesn't mask the skip), carry proper Fixes/Cc-stable tags, and have been reviewed (Iago's R-b). The series is in good shape and ready to be applied.
**Verdict: No issues found. The series looks good.**
---
Generated by Claude Code Patch Reviewer
^ permalink raw reply [flat|nested] 6+ messages in thread
* Claude review: drm/v3d: Fix vaddr leak when indirect CSD has zeroed workgroups
2026-06-02 11:57 ` [PATCH v3 1/2] drm/v3d: Fix vaddr leak when indirect CSD has " Maíra Canal
@ 2026-06-04 2:49 ` Claude Code Review Bot
0 siblings, 0 replies; 6+ messages in thread
From: Claude Code Review Bot @ 2026-06-04 2:49 UTC (permalink / raw)
To: dri-devel-reviews
Patch Review
**Status: Good**
This patch fixes a resource leak in `v3d_rewrite_csd_job_wg_counts_from_indirect()`. Looking at the existing code in the kernel tree (`v3d_sched.c:400-406`):
```c
v3d_get_bo_vaddr(bo);
v3d_get_bo_vaddr(indirect);
wg_counts = (uint32_t *)(bo->vaddr + indirect_csd->offset);
if (wg_counts[0] == 0 || wg_counts[1] == 0 || wg_counts[2] == 0)
return;
```
The bare `return` at line 406 skips the cleanup at lines 431-432 (`v3d_put_bo_vaddr(indirect)` / `v3d_put_bo_vaddr(bo)`), leaking both mappings. The fix correctly replaces `return` with `goto unmap_bo`, which jumps to the cleanup path:
```c
if (wg_counts[0] == 0 || wg_counts[1] == 0 || wg_counts[2] == 0)
goto unmap_bo;
```
```c
unmap_bo:
v3d_put_bo_vaddr(indirect);
v3d_put_bo_vaddr(bo);
```
The label placement is correct — it sits right before both `v3d_put_bo_vaddr` calls, matching the acquisition order (bo, indirect acquired; indirect, bo released). The label name `unmap_bo` is slightly ambiguous since it unmaps both BOs, but this is a minor style nit that doesn't affect correctness.
One observation: when the zero-workgroup path is taken, `args->cfg[0..4]` are left untouched — they retain whatever userspace submitted. This is fine because patch 2 ensures the CSD job is never submitted to hardware when counts are zero.
---
Generated by Claude Code Patch Reviewer
^ permalink raw reply [flat|nested] 6+ messages in thread
* Claude review: drm/v3d: Skip CSD when it has zeroed workgroups
2026-06-02 11:57 ` [PATCH v3 2/2] drm/v3d: Skip CSD when it " Maíra Canal
@ 2026-06-04 2:49 ` Claude Code Review Bot
0 siblings, 0 replies; 6+ messages in thread
From: Claude Code Review Bot @ 2026-06-04 2:49 UTC (permalink / raw)
To: dri-devel-reviews
Patch Review
**Status: Good**
This patch adds a check in `v3d_csd_job_run()` to skip hardware submission when any workgroup dimension is zero. The check is placed after the existing error check and before setting `active_job`:
```c
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;
```
The use of `V3D_GET_FIELD` with the proper field macros (bits [31:16] per `v3d_regs.h:416-429`) is the right approach, extracting only the workgroup count bits rather than checking the whole register value. This correctly handles `cfg[]` values that might have non-zero bits in the lower half but a zero workgroup count in the upper half.
The comment explaining the hardware behavior (0 is interpreted as 65536) is accurate and provides good justification for why this check is needed.
The placement before `v3d->queue[V3D_CSD].active_job = &job->base` is correct — by returning `NULL` before setting `active_job`, the function avoids leaving the queue in a state where it thinks a job is active but no fence was created and no hardware submission occurred. This matches the existing pattern used by the error-path check above it (lines 350-353 in the current tree).
The `Fixes` tag references the original CSD support commit, which is appropriate since the zero-workgroup case was always a latent bug — it just wasn't reachable until indirect CSD was added.
---
Generated by Claude Code Patch Reviewer
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-06-04 2:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-02 11:57 [PATCH v3 0/2] drm/v3d: Fix indirect CSD jobs with zeroed workgroups Maíra Canal
2026-06-02 11:57 ` [PATCH v3 1/2] drm/v3d: Fix vaddr leak when indirect CSD has " Maíra Canal
2026-06-04 2:49 ` Claude review: " Claude Code Review Bot
2026-06-02 11:57 ` [PATCH v3 2/2] drm/v3d: Skip CSD when it " Maíra Canal
2026-06-04 2:49 ` Claude review: " Claude Code Review Bot
2026-06-04 2:49 ` Claude review: drm/v3d: Fix indirect CSD jobs with " Claude Code Review Bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox