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: Wed, 27 May 2026 14:42:32 +1000	[thread overview]
Message-ID: <review-patch13-20260526145137.160554-14-robin.clark@oss.qualcomm.com> (raw)
In-Reply-To: <20260526145137.160554-14-robin.clark@oss.qualcomm.com>

Patch Review

This is the main patch. Several observations:

**Include style**: The new includes use quotes (`"linux/anon_inodes.h"`) rather than angle brackets (`<linux/anon_inodes.h>`). While this works (the compiler searches different paths), the MSM driver overwhelmingly uses angle brackets for kernel headers. This should probably be made consistent with the rest of the driver.

```c
+#include "drm/drm_file.h"
+#include "drm/msm_drm.h"
+#include "linux/anon_inodes.h"
+#include "linux/gfp_types.h"
+#include "linux/poll.h"
+#include "linux/slab.h"
```

**UAPI definition**: The ioctl is `DRM_IOW` (write-only from userspace perspective), and the fd is returned as the ioctl return value. The comment in the header explains why - if `DRM_IOWR` were used, a faulting `copy_to_user()` in `drm_ioctl()` would leak the fd. This is a correct and well-documented design choice.

**Stream read path**: `msm_perfcntrs_stream_read()` correctly handles both blocking and non-blocking modes. The `fifo_count_to_end()` macro uses `smp_load_acquire()` on the head, and `smp_store_release()` on the tail update, which is correct for the single-producer/single-consumer circ_buf pattern.

**Ioctl validation**: Thorough. Checks for invalid flags, group_stride, nr_groups, permission (perfmon_capable for stream), buffer size limits (128M max), and per-group validation including duplicate group detection. The `E2BIG` handling with `MSM_PERFCNTR_UPDATE` to return available counts is a nice touch.

**Potential issue - `nr_counters` zero-group detection**: The code uses `nr_counters[idx] = g.nr_countables + 1` with the comment `/* +1 to catch duplicate zero sized groups */`. This means a group with 0 countables sets `nr_counters[idx] = 1`, and the duplicate check `if (nr_counters[idx])` will catch it. At commit time, it subtracts the +1 back: `perfcntrs->groups[i]->allocated_counters = nr_counters[i] - 1`. This is correct but a bit subtle. Groups that are not mentioned at all have `nr_counters[i] = 0`, so subtracting 1 would underflow to `UINT8_MAX` (since `nr_counters` is `uint8_t*`). However, the loop only iterates over `gpu->num_perfcntr_groups`, and the subtract only happens for indices where `nr_counters[i]` was set. Wait - actually the commit loop iterates over ALL groups:

```c
for (unsigned i = 0; i < gpu->num_perfcntr_groups; i++)
    perfcntrs->groups[i]->allocated_counters = nr_counters[i] - 1;
```

This means for groups NOT mentioned in the ioctl, `nr_counters[i]` is 0, and `0 - 1` wraps to 255 for a `uint8_t`. But `allocated_counters` is likely a `uint32_t` or `unsigned`, so it would wrap to `UINT32_MAX`/`UINT_MAX`. This is a **bug** - groups not specified by the user would get `allocated_counters` set to a very large value.

**Wait** - looking more carefully, this only runs in the `MSM_PERFCNTR_STREAM` path, and there `nr_groups` is validated to be non-zero, but it's possible that fewer groups are specified than exist. The fix should probably be:

```c
for (unsigned i = 0; i < gpu->num_perfcntr_groups; i++)
    perfcntrs->groups[i]->allocated_counters = nr_counters[i] ? nr_counters[i] - 1 : 0;
```

**sel_worker / locking**: The comment about why `cancel_work_sync()` can't be used in the suspend path (lock ordering with `gpu->lock` and `perfcntr_lock`) is well-explained. Using async `cancel_work()` in suspend but `cancel_work_sync()` in release (after dropping `perfcntr_lock`) is correct.

**sample_worker runtime PM**: The sample worker expects the GPU to be powered (comment at line ~8097). The timer and kthread work are canceled in suspend. However, there's a subtle race: what if the timer fires and queues sample_work just before suspend cancels it? The `kthread_cancel_work_sync()` in suspend should handle this, since it waits for any in-flight execution to complete.

---
Generated by Claude Code Patch Reviewer

  reply	other threads:[~2026-05-27  4:42 UTC|newest]

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