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: Sat, 16 May 2026 10:50:10 +1000	[thread overview]
Message-ID: <review-patch13-20260514134052.361771-14-robin.clark@oss.qualcomm.com> (raw)
In-Reply-To: <20260514134052.361771-14-robin.clark@oss.qualcomm.com>

Patch Review

This is the core ioctl implementation. Several observations:

**Issue: Global counter state modified before validation complete.** In the ioctl, when `MSM_PERFCNTR_STREAM` is set, the code modifies `perfcntrs->groups[idx]->allocated_counters` inside the group loop:
```c
perfcntrs->groups[idx]->allocated_counters = g.nr_countables;
```
But if a later iteration returns an error (e.g., `copy_from_user` fails for countables, or a later group is invalid), the already-modified `allocated_counters` values are not rolled back. This leaves the global perfcntr state corrupted on error. The `__free(kfree)` on `stream` prevents the stream from being installed, but the group state has been partially modified.

**Issue: `get_group_idx` string comparison.** The comparison uses:
```c
if (!strncmp(group->name, name, len))
```
where `len` is `sizeof(g.group_name)` (16). But `group->name` could be shorter than the user-supplied name, in which case `strncmp` would match a prefix. For example, if `group->name` is `"CP"` and the user passes `"CP\0\0\0\0..."`, it works. But if the user passes `"CPFOO\0..."`, `strncmp` would compare the first 16 chars and find a mismatch at index 2. So this is actually fine since both are null-terminated within the 16-byte window. No real bug, but `strcmp` on the kernel-side name against the fixed-size user buffer would be clearer.

**Issue: `msm_perfcntrs_stream_read` does not handle wrap-around.** The read function only reads `fifo_count_to_end()` bytes in a single call:
```c
count = min_t(size_t, count, fifo_count_to_end(stream));
```
If data wraps around the circular buffer, the caller would need multiple `read()` calls to get all available data. This is technically correct (partial reads are allowed), but could surprise userspace if the sample period straddles the wrap point. Most kernel circ_buf readers handle this with a two-phase copy. Not a bug per se, but worth noting.

**Issue: `bufsz_shift` validation.** There's a check that `fifo_size > SZ_128M`, but no lower bound on `bufsz_shift`. A `bufsz_shift` of 0 would give `fifo_size = 1`, which is smaller than the period_size and would be rejected. But `bufsz_shift` of 1 gives `fifo_size = 2`, and a valid period_size check would also catch this. So the validation works transitively through the `fifo_size <= bufsz` check. Fine.

**Observation: UABI fd return.** The ioctl is `DRM_IOW` (write-only from userspace perspective), and the stream fd is returned as the ioctl return value. The comment in the code explains why this is intentional (avoids `copy_to_user` faulting and leaking the fd). This is a reasonable design choice.

**Minor: `#include` style.** The includes use `"drm/drm_file.h"` and `"linux/anon_inodes.h"` with quotes instead of angle brackets. While this works, kernel convention is `<linux/...>` for system headers.

---
Generated by Claude Code Patch Reviewer

  reply	other threads:[~2026-05-16  0:50 UTC|newest]

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