public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
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, 07 May 2026 13:19:06 +1000	[thread overview]
Message-ID: <review-patch13-20260506171127.133572-14-robin.clark@oss.qualcomm.com> (raw)
In-Reply-To: <20260506171127.133572-14-robin.clark@oss.qualcomm.com>

Patch Review

**Status: Several issues**

This is the core patch with the UAPI and main ioctl implementation.

**Issue 1: Missing bufsz_shift validation**

```c
stream->fifo_size = 1 << args->bufsz_shift;
```
If `bufsz_shift` is >= 31 (or >= 63 on 64-bit), this is undefined behavior. The later check `stream->fifo_size > SZ_128M` would catch large values, but by then the shift has already been performed. The v4 changelog says "Add upper limit to userspace controlled FIFO size [Claude]" was added, and the `> SZ_128M` check is there, but the shift itself should be validated first:
```c
if (args->bufsz_shift > 27)  /* SZ_128M = 1 << 27 */
    return -EINVAL;
```

**Issue 2: copy_from_user with args->group_stride could under-read**

```c
if (copy_from_user(&g, userptr, args->group_stride))
```
If `args->group_stride < sizeof(struct drm_msm_perfcntr_group)`, this copies fewer bytes than the struct size, leaving parts of `g` at their zero-initialized values. If `args->group_stride > sizeof(struct drm_msm_perfcntr_group)`, this overflows the stack variable `g`. There's no validation that `group_stride` matches `sizeof(struct drm_msm_perfcntr_group)`. This is presumably intentional for extensibility, but the overflow case needs guarding:
```c
if (args->group_stride > sizeof(g))
    return -EINVAL;
```
Or use `min(args->group_stride, sizeof(g))` in the copy.

**Issue 3: State not rolled back on E2BIG for global stream**

When processing groups with `MSM_PERFCNTR_STREAM`, the code writes `allocated_counters` and `countables` into `perfcntrs->groups[idx]` before checking all groups:
```c
perfcntrs->groups[idx]->allocated_counters = g.nr_countables;
...
if (copy_from_user(perfcntrs->groups[idx]->countables, userptr, sz))
    return -EFAULT;
```
If a later group triggers E2BIG, the function returns the error but has already modified `perfcntrs->groups[idx]->allocated_counters` for earlier groups. Since no stream is actually installed (`perfcntrs->stream` remains NULL), this seems harmless in practice -- those `allocated_counters` values are only meaningful when `perfcntrs->stream` is set. But it's messy; a subsequent call with different groups could see stale `allocated_counters` values affecting `get_available_counters()`. Consider clearing the group state on error.

**Issue 4: FIFO read may return 0 bytes without -EAGAIN**

In `msm_perfcntrs_stream_read()`, after waking from the wait for blocking mode:
```c
count = min_t(size_t, count, fifo_count_to_end(stream));
```
If `fifo_count_to_end()` returns 0 (possible if another reader consumed the data, though `read_lock` prevents that for the single-consumer case), the function returns 0, which means EOF to userspace. For a streaming fd, this would be unexpected. Since `read_lock` serializes consumers, this shouldn't happen in practice, but it's a subtle edge case.

**Issue 5: Missing `O_CLOEXEC` on anon_inode_getfd**

```c
stream_fd = anon_inode_getfd("[msm_perfcntrs]", &stream_fops, stream, 0);
```
The flags arg is 0. Most modern kernel code passes `O_CLOEXEC` to prevent fd leaks across exec. Consider using `O_CLOEXEC` by default, or accepting flags from userspace.

**Issue 6: `guard(pm_runtime_active_auto)` scope**

```c
guard(pm_runtime_active_auto)(&gpu->pdev->dev);
guard(mutex)(&gpu->perfcntr_lock);
```
The pm_runtime guard holds a reference for the entire ioctl scope, but it's only needed for the stream case (to ensure the GPU is powered for SEL programming). For the local reservation case, pm_runtime is unnecessary.

**UAPI comment nit:**
```c
 * The data read from the has the following format
```
Missing word: "The data read from the **fd** has the following format".

---
Generated by Claude Code Patch Reviewer

  reply	other threads:[~2026-05-07  3:19 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-06 17:10 [PATCH v3 00/16] drm/msm: Add PERFCNTR_CONFIG ioctl Rob Clark
2026-05-06 17:10 ` [PATCH v4 01/16] drm/msm: Remove obsolete perf infrastructure Rob Clark
2026-05-07  3:19   ` Claude review: " Claude Code Review Bot
2026-05-06 17:10 ` [PATCH v4 02/16] drm/msm: Allow CAP_PERFMON for setting SYSPROF Rob Clark
2026-05-07  3:19   ` Claude review: " Claude Code Review Bot
2026-05-06 17:10 ` [PATCH v4 04/16] drm/msm/registers: Sync gen_header.py from mesa Rob Clark
2026-05-07  3:19   ` Claude review: " Claude Code Review Bot
2026-05-06 17:10 ` [PATCH v4 05/16] drm/msm/registers: Add perfcntr json Rob Clark
2026-05-07  3:19   ` Claude review: " Claude Code Review Bot
2026-05-06 17:10 ` [PATCH v4 06/16] drm/msm: Add a6xx+ perfcntr tables Rob Clark
2026-05-07  3:19   ` Claude review: " Claude Code Review Bot
2026-05-06 17:10 ` [PATCH v4 07/16] drm/msm: Add sysprof accessors Rob Clark
2026-05-07  3:19   ` Claude review: " Claude Code Review Bot
2026-05-06 17:10 ` [PATCH v4 08/16] drm/msm/a6xx: Add yield & flush helper Rob Clark
2026-05-07  3:19   ` Claude review: " Claude Code Review Bot
2026-05-06 17:10 ` [PATCH v4 09/16] drm/msm: Add per-context perfcntr state Rob Clark
2026-05-07  3:19   ` Claude review: " Claude Code Review Bot
2026-05-06 17:10 ` [PATCH v4 10/16] drm/msm: Add basic perfcntr infrastructure Rob Clark
2026-05-07  3:19   ` Claude review: " Claude Code Review Bot
2026-05-06 17:10 ` [PATCH v4 11/16] drm/msm/a6xx+: Add support to configure perfcntrs Rob Clark
2026-05-07  3:19   ` Claude review: " Claude Code Review Bot
2026-05-06 17:10 ` [PATCH v4 12/16] drm/msm/a8xx: Add perfcntr flush sequence Rob Clark
2026-05-07  3:19   ` Claude review: " Claude Code Review Bot
2026-05-06 17:10 ` [PATCH v4 13/16] drm/msm: Add PERFCNTR_CONFIG ioctl Rob Clark
2026-05-07  3:19   ` Claude Code Review Bot [this message]
2026-05-06 17:10 ` [PATCH v4 14/16] drm/msm/a6xx: Increase pwrup_reglist size Rob Clark
2026-05-07  3:19   ` Claude review: " Claude Code Review Bot
2026-05-06 17:10 ` [PATCH v4 15/16] drm/msm/a6xx: Append SEL regs to dyn pwrup reglist Rob Clark
2026-05-07  3:19   ` Claude review: " Claude Code Review Bot
2026-05-06 17:10 ` [PATCH v4 16/16] drm/msm/a6xx: Allow IFPC with perfcntr stream Rob Clark
2026-05-07  3:19   ` Claude review: " Claude Code Review Bot
2026-05-07  3:19 ` Claude review: drm/msm: Add PERFCNTR_CONFIG ioctl Claude Code Review Bot
  -- strict thread matches above, loose matches on Subject: below --
2026-05-14 13:39 [PATCH v6 00/16] " Rob Clark
2026-05-14 13:40 ` [PATCH v6 13/16] " Rob Clark
2026-05-16  0:50   ` Claude review: " Claude Code Review Bot
2026-05-16  0:50 ` Claude Code Review Bot
2026-05-11 12:59 [PATCH v5 00/16] " Rob Clark
2026-05-11 12:59 ` [PATCH v5 13/16] " Rob Clark
2026-05-16  5:20   ` Claude review: " Claude Code Review Bot
2026-05-16  5:20 ` Claude Code Review Bot
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
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-20260506171127.133572-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