From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: drm/v3d: Serialize jobs across queues when a perfmon is attached
Date: Thu, 04 Jun 2026 14:44:43 +1000 [thread overview]
Message-ID: <review-patch3-20260531-v3d-perfmon-lifetime-v2-3-60ed4485a203@igalia.com> (raw)
In-Reply-To: <20260531-v3d-perfmon-lifetime-v2-3-60ed4485a203@igalia.com>
Patch Review
**Status**: The design is sound but there's a subtle concern worth discussing.
The approach is straightforward: when a non-global perfmon-carrying job is submitted, it depends on all in-flight jobs across all queues (via `last_hw_fence[]`). Conversely, when a non-perfmon job is submitted while a perfmon job is in-flight, it depends on `perfmon_state.fence`.
**The `v3d_serialize_for_perfmon()` function:**
```c
static int
v3d_serialize_for_perfmon(struct v3d_job *job)
{
...
lockdep_assert_held(&v3d->sched_lock);
scoped_guard(spinlock_irqsave, &v3d->perfmon_state.lock)
is_global_perfmon = !!v3d->global_perfmon;
if (is_global_perfmon)
goto publish;
...
```
**Observation 1 — TOCTOU on `global_perfmon` check**: The `is_global_perfmon` flag is read under the perfmon spinlock, but after dropping it, the global perfmon state could change before we act on it. However, `sched_lock` is held, which serializes all submissions. The global perfmon can only be set/cleared by the SET_GLOBAL ioctl, which doesn't hold `sched_lock`. So there's a theoretical window where:
- Thread A: holds `sched_lock`, reads `is_global_perfmon = false`, proceeds to add fence dependencies
- Thread B: concurrently calls SET_GLOBAL, installs a global perfmon
This seems low-risk in practice (the global perfmon is a privileged operation and the window is tiny), and the `sched_lock` assertion confirms submission serialization. But it's worth considering whether the SET_GLOBAL ioctl should also acquire `sched_lock` to close this gap. Given that the global perfmon case doesn't need serialization (concurrency is desired), the worst case is unnecessary serialization of one submission, not a correctness bug.
**Observation 2 — `last_hw_fence` update always happens (the `publish` label)**:
```c
publish:
dma_fence_put(v3d->perfmon_state.last_hw_fence[job->queue]);
v3d->perfmon_state.last_hw_fence[job->queue] = dma_fence_get(job->done_fence);
if (job->perfmon && !is_global_perfmon) {
dma_fence_put(v3d->perfmon_state.fence);
v3d->perfmon_state.fence = dma_fence_get(job->done_fence);
}
```
This correctly updates `last_hw_fence` for *every* job (needed so future perfmon jobs can wait on all in-flight work). The `perfmon_state.fence` is only set for perfmon-carrying jobs. This is sound.
**Observation 3 — `done_fence` vs `irq_fence`**: The code uses `job->done_fence` for the serialization fences. This is the scheduler's finished fence, which signals when the job completes. This is the correct fence to use (rather than `irq_fence` which is the HW interrupt fence).
**Observation 4 — WARN_ON_ONCE in `v3d_perfmon_start()`**:
```c
if (WARN_ON_ONCE(v3d->perfmon_state.active))
return;
```
Good defensive check. With cross-queue serialization working correctly, there should never be an active perfmon when a new perfmon-carrying job starts. If this fires, it means serialization failed.
**Observation 5 — Cleanup in `v3d_gem_destroy()`**:
```c
for (q = 0; q < V3D_MAX_QUEUES; q++) {
WARN_ON(v3d->queue[q].active_job);
v3d_stats_put(v3d->queue[q].stats);
dma_fence_put(v3d->perfmon_state.last_hw_fence[q]);
}
dma_fence_put(v3d->perfmon_state.fence);
```
Correct cleanup of the new fence references.
**No blocking issues.**
---
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-06-04 4:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-31 20:18 [PATCH v2 0/4] drm/v3d: Fix perfmon locking and cross-queue isolation Maíra Canal
2026-05-31 20:18 ` [PATCH v2 1/4] drm/v3d: Fix global performance monitor reference counting Maíra Canal
2026-06-04 4:44 ` Claude review: " Claude Code Review Bot
2026-05-31 20:18 ` [PATCH v2 2/4] drm/v3d: Refactor perfmon locking Maíra Canal
2026-06-01 11:52 ` Iago Toral
2026-06-01 12:03 ` Maíra Canal
2026-06-04 4:44 ` Claude review: " Claude Code Review Bot
2026-05-31 20:18 ` [PATCH v2 3/4] drm/v3d: Serialize jobs across queues when a perfmon is attached Maíra Canal
2026-06-02 7:35 ` Iago Toral
2026-06-02 10:49 ` Maíra Canal
2026-06-02 11:10 ` Iago Toral
2026-06-04 4:44 ` Claude Code Review Bot [this message]
2026-05-31 20:18 ` [PATCH v2 4/4] drm/v3d: Drop the queue argument from v3d_job_add_syncobjs() Maíra Canal
2026-06-04 4:44 ` Claude review: " Claude Code Review Bot
2026-06-04 4:44 ` Claude review: drm/v3d: Fix perfmon locking and cross-queue isolation Claude Code Review 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=review-patch3-20260531-v3d-perfmon-lifetime-v2-3-60ed4485a203@igalia.com \
--to=claude-review@example.com \
--cc=dri-devel-reviews@example.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox