From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: drm/msm: Add PERFCNTR_CONFIG ioctl
Date: Tue, 05 May 2026 08:06:04 +1000 [thread overview]
Message-ID: <review-patch13-20260504190751.61052-14-robin.clark@oss.qualcomm.com> (raw)
In-Reply-To: <20260504190751.61052-14-robin.clark@oss.qualcomm.com>
Patch Review
This is the core patch. Several observations:
**Issue: No upper bound on `bufsz_shift`.**
```c
stream->fifo_size = 1 << args->bufsz_shift;
...
void *buf = kmalloc(1 << args->bufsz_shift, GFP_KERNEL);
```
A malicious/buggy user could pass `bufsz_shift = 30` and try to allocate 1 GB. The ioctl requires `perfmon_capable()` for STREAM mode so this is somewhat mitigated, but a bounds check would be prudent. Also, if `bufsz_shift` is 0 and STREAM is not set, `fifo_size` would be 1 which is odd but harmless since the FIFO is never used.
**Issue: `guard(pm_runtime_active_auto)` does not check return value.**
```c
guard(pm_runtime_active_auto)(&gpu->pdev->dev);
```
This expands to `pm_runtime_get_sync()` which can fail. The guard pattern doesn't allow checking the return value. If the device fails to resume, the ioctl will proceed with a powered-off GPU. Consider using an explicit `pm_runtime_get_sync()` with error checking, or at minimum documenting why this is acceptable.
**Good: UAPI design.** The `DRM_IOW` direction is correctly chosen — the comment explains that returning the fd as a return value (rather than via an output parameter) avoids the `copy_to_user` fault-after-fd-creation problem. The `MSM_PERFCNTR_UPDATE` flag for returning available counter counts on `E2BIG` is a nice touch for discoverability.
**Good: Locking discipline.** The `perfcntr_lock` protects counter allocation state, `read_lock` protects FIFO consumer side, and the single-producer pattern (kthread worker) avoids needing locks on the producer side. The `sel_work` is correctly dispatched on the scheduler's submit_wq to serialize with GEM_SUBMITs.
**Minor: `UERR(ETOOSMALL, ...)`.** Is `ETOOSMALL` a standard errno? I believe the correct name is `ETOOMANYREFS` or similar — this may be a custom MSM driver macro. If `UERR` handles non-standard names, fine; otherwise this should be `EINVAL` or a more standard error.
**Minor: `group_stride` validation.** The stride is validated to be non-zero when `nr_groups > 0`, but there's no check that `group_stride >= sizeof(struct drm_msm_perfcntr_group)`. A too-small stride would cause `copy_from_user` to read partial data. However, since `copy_from_user` uses `args->group_stride` as the size, a smaller stride would just read fewer fields — the zero-initialization of `g` mitigates this.
**Minor: `scoped_guard` with `break`.** In `sel_worker`:
```c
scoped_guard (mutex, &gpu->lock) {
guard(mutex)(&gpu->perfcntr_lock);
if (stream != gpu->perfcntrs->stream)
break;
...
}
```
Using `break` to exit a `scoped_guard` block is valid but unusual — it works because `scoped_guard` expands to a loop-like construct. This is fine but may surprise readers.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-05-04 22:06 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-04 19:06 [PATCH v3 00/16] drm/msm: Add PERFCNTR_CONFIG ioctl Rob Clark
2026-05-04 19:06 ` [PATCH v3 01/16] drm/msm: Remove obsolete perf infrastructure Rob Clark
2026-05-04 22:06 ` Claude review: " Claude Code Review Bot
2026-05-04 19:06 ` [PATCH v3 02/16] drm/msm: Allow CAP_PERFMON for setting SYSPROF Rob Clark
2026-05-04 22:06 ` Claude review: " Claude Code Review Bot
2026-05-04 19:06 ` [PATCH v3 04/16] drm/msm/registers: Sync gen_header.py from mesa Rob Clark
2026-05-04 22:06 ` Claude review: " Claude Code Review Bot
2026-05-04 19:06 ` [PATCH v3 05/16] drm/msm/registers: Add perfcntr json Rob Clark
2026-05-04 22:06 ` Claude review: " Claude Code Review Bot
2026-05-04 19:06 ` [PATCH v3 06/16] drm/msm: Add a6xx+ perfcntr tables Rob Clark
2026-05-04 22:06 ` Claude review: " Claude Code Review Bot
2026-05-04 19:06 ` [PATCH v3 07/16] drm/msm: Add sysprof accessors Rob Clark
2026-05-04 22:06 ` Claude review: " Claude Code Review Bot
2026-05-04 19:06 ` [PATCH v3 08/16] drm/msm/a6xx: Add yield & flush helper Rob Clark
2026-05-04 22:06 ` Claude review: " Claude Code Review Bot
2026-05-04 19:06 ` [PATCH v3 09/16] drm/msm: Add per-context perfcntr state Rob Clark
2026-05-04 22:06 ` Claude review: " Claude Code Review Bot
2026-05-04 19:06 ` [PATCH v3 10/16] drm/msm: Add basic perfcntr infrastructure Rob Clark
2026-05-04 22:06 ` Claude review: " Claude Code Review Bot
2026-05-04 19:06 ` [PATCH v3 11/16] drm/msm/a6xx+: Add support to configure perfcntrs Rob Clark
2026-05-04 22:06 ` Claude review: " Claude Code Review Bot
2026-05-04 19:06 ` [PATCH v3 12/16] drm/msm/a8xx: Add perfcntr flush sequence Rob Clark
2026-05-04 22:06 ` Claude review: " Claude Code Review Bot
2026-05-04 19:06 ` [PATCH v3 13/16] drm/msm: Add PERFCNTR_CONFIG ioctl Rob Clark
2026-05-04 22:06 ` Claude Code Review Bot [this message]
2026-05-04 19:06 ` [PATCH v3 14/16] drm/msm/a6xx: Increase pwrup_reglist size Rob Clark
2026-05-04 22:06 ` Claude review: " Claude Code Review Bot
2026-05-04 19:06 ` [PATCH v3 15/16] drm/msm/a6xx: Append SEL regs to dyn pwrup reglist Rob Clark
2026-05-04 22:06 ` Claude review: " Claude Code Review Bot
2026-05-04 19:06 ` [PATCH v3 16/16] drm/msm/a6xx: Allow IFPC with perfcntr stream Rob Clark
2026-05-04 22:06 ` Claude review: " Claude Code Review Bot
2026-05-04 22:06 ` Claude review: drm/msm: Add PERFCNTR_CONFIG ioctl Claude Code Review Bot
-- strict thread matches above, loose matches on Subject: below --
2026-04-20 22:25 [PATCH 00/13] " Rob Clark
2026-04-20 22:25 ` [PATCH 13/13] " Rob Clark
2026-04-22 23:13 ` Claude review: " Claude Code Review Bot
2026-04-22 23:13 ` 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-patch13-20260504190751.61052-14-robin.clark@oss.qualcomm.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