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: Thu, 23 Apr 2026 09:13:16 +1000 [thread overview]
Message-ID: <review-patch13-20260420222621.417276-14-robin.clark@oss.qualcomm.com> (raw)
In-Reply-To: <20260420222621.417276-14-robin.clark@oss.qualcomm.com>
Patch Review
The main ioctl implementation. Well-structured with clear separation between validation, allocation, and setup phases. The fd-based stream with `DRM_IOW` (returning fd via ioctl return value) is a nice design choice, well-documented in the UAPI header.
**Bug -- stack buffer overflow via `group_stride`**:
```c
struct drm_msm_perfcntr_group g = {0};
void __user *userptr =
u64_to_user_ptr(args->groups + (i * args->group_stride));
if (copy_from_user(&g, userptr, args->group_stride))
return -EFAULT;
```
If `args->group_stride > sizeof(struct drm_msm_perfcntr_group)`, this `copy_from_user` writes past the end of the stack variable `g`. The `group_stride` field exists for future extensibility (to allow adding fields to the struct), but there's no check that it doesn't exceed `sizeof(g)`. Fix:
```c
if (copy_from_user(&g, userptr, min((size_t)args->group_stride, sizeof(g))))
```
**Missing validation on `bufsz_shift`**: There's no upper bound check on `args->bufsz_shift`. A malicious user could pass `bufsz_shift = 30` to try to allocate 1GB of kernel memory:
```c
void *buf __free(kfree) =
kmalloc(1 << args->bufsz_shift, GFP_KERNEL);
```
Add a reasonable upper bound (e.g., `if (args->bufsz_shift > 20)` for a 1MB cap), or at least use `kmalloc()` with `__GFP_NOWARN` to avoid log spam from failed huge allocations.
**Typo in commit message**: "on exist of IFPC" should be "on exit of IFPC".
**Typo in error message** (line 7030):
```c
return UERR(EBUSY, dev, "groups[%d]: to few counters available", i);
```
Should be "too few".
**`strncmp` for group name matching** in `get_group_idx()`:
```c
if (!strncmp(group->name, name, len))
```
where `len = sizeof(g.group_name)` which is 16. This compares at most 16 bytes, but if a group name is exactly 16 bytes (no null terminator), `strncmp` would match a prefix. Since group names are likely short (e.g., "CP", "SP"), this is unlikely to be a practical issue, but `strnlen` + exact match would be more robust.
**Lock ordering**: `get_available_counters()` acquires `gpu->dev->filelist_mutex` while `gpu->perfcntr_lock` is already held. Verify this doesn't conflict with any path that takes these locks in the opposite order (e.g., `drm_file` open/close paths that might touch perfcntr state).
**Race on stream teardown**: In `msm_perfcntrs_stream_release()`, between dropping `perfcntr_lock` and calling `cancel_work_sync(&stream->sel_work)`, `sel_worker` could be scheduled and run. The worker checks `stream != gpu->perfcntrs->stream` under lock, which would be true (since we set it to NULL), so it would bail out via `break`. This is safe -- good design with the documented comment.
**Missing `EPOLLERR`/`EPOLLHUP`**: The `poll` implementation only returns `EPOLLIN`. It might be useful to signal `EPOLLHUP` when the stream is being torn down, but this is a minor enhancement, not a bug.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-04-22 23:13 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-20 22:25 [PATCH 00/13] drm/msm: Add PERFCNTR_CONFIG ioctl Rob Clark
2026-04-20 22:25 ` [PATCH 01/13] drm/msm: Remove obsolete perf infrastructure Rob Clark
2026-04-20 23:49 ` Dmitry Baryshkov
2026-04-21 13:07 ` Rob Clark
2026-04-21 15:39 ` Dmitry Baryshkov
2026-04-21 20:48 ` Rob Clark
2026-04-22 0:41 ` Dmitry Baryshkov
2026-04-22 14:41 ` Rob Clark
2026-04-22 23:13 ` Claude review: " Claude Code Review Bot
2026-04-20 22:25 ` [PATCH 02/13] drm/msm/adreno: Sync registers from mesa Rob Clark
2026-04-20 23:50 ` Dmitry Baryshkov
2026-04-22 23:13 ` Claude review: " Claude Code Review Bot
2026-04-20 22:25 ` [PATCH 03/13] drm/msm/registers: Sync gen_header.py " Rob Clark
2026-04-22 3:39 ` Dmitry Baryshkov
2026-04-22 13:36 ` Rob Clark
2026-04-22 23:13 ` Claude review: " Claude Code Review Bot
2026-04-20 22:25 ` [PATCH 04/13] drm/msm/registers: Add perfcntr json Rob Clark
2026-04-22 3:34 ` Dmitry Baryshkov
2026-04-22 23:13 ` Claude review: " Claude Code Review Bot
2026-04-20 22:25 ` [PATCH 05/13] drm/msm: Allow CAP_PERFMON for setting SYSPROF Rob Clark
2026-04-21 1:55 ` Dmitry Baryshkov
2026-04-22 23:13 ` Claude review: " Claude Code Review Bot
2026-04-20 22:25 ` [PATCH 06/13] drm/msm: Add a6xx+ perfcntr tables Rob Clark
2026-04-22 23:13 ` Claude review: " Claude Code Review Bot
2026-04-20 22:25 ` [PATCH 07/13] drm/msm: Add sysprof accessors Rob Clark
2026-04-22 23:13 ` Claude review: " Claude Code Review Bot
2026-04-20 22:25 ` [PATCH 08/13] drm/msm/a6xx: Add yield & flush helper Rob Clark
2026-04-22 23:13 ` Claude review: " Claude Code Review Bot
2026-04-20 22:25 ` [PATCH 09/13] drm/msm: Add per-context perfcntr state Rob Clark
2026-04-22 3:37 ` Dmitry Baryshkov
2026-04-22 14:13 ` Rob Clark
2026-04-22 23:13 ` Claude review: " Claude Code Review Bot
2026-04-20 22:25 ` [PATCH 10/13] drm/msm: Add basic perfcntr infrastructure Rob Clark
2026-04-22 23:13 ` Claude review: " Claude Code Review Bot
2026-04-20 22:25 ` [PATCH 11/13] drm/msm/a6xx+: Add support to configure perfcntrs Rob Clark
2026-04-22 23:13 ` Claude review: " Claude Code Review Bot
2026-04-20 22:25 ` [PATCH 12/13] drm/msm/a8xx: Add perfcntr flush sequence Rob Clark
2026-04-22 23:13 ` Claude review: " Claude Code Review Bot
2026-04-20 22:25 ` [PATCH 13/13] drm/msm: Add PERFCNTR_CONFIG ioctl Rob Clark
2026-04-22 3:41 ` Dmitry Baryshkov
2026-04-22 14:20 ` Rob Clark
2026-04-22 17:48 ` Dmitry Baryshkov
2026-04-22 23:13 ` Claude Code Review Bot [this message]
2026-04-22 1:54 ` [PATCH 00/13] " Dmitry Baryshkov
2026-04-22 17:29 ` Rob Clark
2026-04-22 23:13 ` Claude review: " Claude Code Review Bot
-- strict thread matches above, loose matches on Subject: below --
2026-05-04 19:06 [PATCH v3 00/16] " Rob Clark
2026-05-04 19:06 ` [PATCH v3 13/16] " Rob Clark
2026-05-04 22:06 ` Claude review: " Claude Code Review Bot
2026-05-04 22:06 ` 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-20260420222621.417276-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