From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: Re: [PATCH v2 5/7] drm/panfrost: Make reset sequence deal with an active HWPerf session
Date: Fri, 05 Jun 2026 06:16:24 +1000 [thread overview]
Message-ID: <review-patch5-20260604174918.2BC551F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260604174918.2BC551F00893@smtp.kernel.org>
Patch Review
**Verdict: Has a bug. Needs revision.**
**Bug — missing negative sign on EAGAIN:**
```c
if (atomic_cmpxchg(&perfcnt->hw_reset_happened, 1, 0)) {
ret = EAGAIN; // <-- BUG: should be -EAGAIN
goto err_disable;
}
```
This returns a positive `EAGAIN` (11) which will be interpreted as success by the ioctl layer. It must be `-EAGAIN`.
**Race condition concern with `reset.pending` check:**
```c
if (atomic_read(&pfdev->reset.pending)) {
ret = -EAGAIN;
goto err_vunmap;
}
```
This check races with the reset path — `reset.pending` could be set immediately after this read. The comment acknowledges this and there's a second check later via `hw_reset_happened`, but the second check has the same TOCTOU issue. Between `panfrost_mmu_as_get()` and the `atomic_cmpxchg` of `hw_reset_happened`, a reset could happen that sets `hw_reset_happened=1`, and the cmpxchg will catch that. So the design intent is sound, except for the missing negation bug above.
**`err_disable` error path is incomplete:**
When hitting the `err_disable` label, the code calls `panfrost_perfcnt_gpu_disable(pfdev)` then falls through to `err_vunmap`. But at this point, `panfrost_mmu_as_get` has already succeeded (line before the `err_disable` goto target was added). The error path doesn't call `panfrost_mmu_as_put()`, so the AS reference will be leaked. The code should either:
1. Add `panfrost_mmu_as_put(pfdev, perfcnt->mapping->mmu)` before `err_disable` falls through to `err_vunmap`, or
2. Have `err_disable` jump to a label after `panfrost_mmu_as_put`.
Wait, looking more carefully: the `err_disable` label is placed right before `err_vunmap`, and `panfrost_mmu_as_get` was called *before* the block with the `atomic_cmpxchg`. So after `err_disable`, we skip `panfrost_mmu_as_put`. This is an AS reference leak.
**`panfrost_perfcnt_reset` called without lock:**
```c
void panfrost_perfcnt_reset(struct panfrost_device *pfdev)
{
...
panfrost_perfcnt_gpu_disable(pfdev);
atomic_set(&perfcnt->hw_reset_happened, 1);
}
```
This writes GPU registers without holding the perfcnt lock. If a perfcnt enable/dump is happening concurrently, the GPU register writes could interleave. The comment explains the reasoning (deadlock avoidance due to GFP_KERNEL allocations under lock), which is fair, but it means the GPU register writes in `panfrost_perfcnt_gpu_disable` are racing with the enable path's GPU register writes. This is probably tolerable since we're about to do a GPU soft reset anyway (the next call after `panfrost_perfcnt_reset` is `panfrost_gpu_soft_reset`), but it should be documented.
**`panfrost_perfcnt_disable_locked` — skipping `as_put` on reset:**
```c
if (!atomic_read(&perfcnt->hw_reset_happened))
panfrost_mmu_as_put(pfdev, perfcnt->mapping->mmu);
```
This correctly avoids the WARN when the reset already zeroed the as_count. However, after this, `atomic_read(&perfcnt->hw_reset_happened)` is never cleared back to 0 in the disable path. It's cleared in `perfcnt_enable_locked` via `atomic_cmpxchg`. What if the user disables perfcnt and never re-enables? The flag stays set forever, which is fine since the struct outlives file close.
But what about `panfrost_perfcnt_close()`? It calls `panfrost_perfcnt_disable_locked()` which will skip `as_put` if `hw_reset_happened` is set. Then `panfrost_perfcnt_close` does `pm_runtime_put_autosuspend` at the end. This seems consistent.
---
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-06-04 20:16 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 17:35 [PATCH v2 0/7] RPM, perfcnt and other minor fixes for Panfrost Adrián Larumbe
2026-06-04 17:35 ` [PATCH v2 1/7] drm/panfrost: Check another bo field for cache option query Adrián Larumbe
2026-06-04 17:57 ` Boris Brezillon
2026-06-04 20:16 ` Claude review: " Claude Code Review Bot
2026-06-04 17:35 ` [PATCH v2 2/7] drm/panfrost: Prevent division by 0 Adrián Larumbe
2026-06-04 17:44 ` sashiko-bot
2026-06-04 20:16 ` Claude review: " Claude Code Review Bot
2026-06-04 18:02 ` Boris Brezillon
2026-06-04 17:35 ` [PATCH v2 3/7] drm/panfrost: Move shrinker initialization and unplug one level down Adrián Larumbe
2026-06-04 18:04 ` Boris Brezillon
2026-06-04 20:16 ` Claude review: " Claude Code Review Bot
2026-06-04 17:35 ` [PATCH v2 4/7] drm/panfrost: Move perfcnt GPU disable sequence into a helper Adrián Larumbe
2026-06-04 17:47 ` sashiko-bot
2026-06-04 20:16 ` Claude review: " Claude Code Review Bot
2026-06-04 18:05 ` Boris Brezillon
2026-06-04 17:35 ` [PATCH v2 5/7] drm/panfrost: Make reset sequence deal with an active HWPerf session Adrián Larumbe
2026-06-04 17:49 ` sashiko-bot
2026-06-04 20:16 ` Claude Code Review Bot [this message]
2026-06-04 18:26 ` Boris Brezillon
2026-06-04 17:35 ` [PATCH v2 6/7] drm/panfrost: Fix PM usage_count mishandling Adrián Larumbe
2026-06-04 17:50 ` sashiko-bot
2026-06-04 20:16 ` Claude review: " Claude Code Review Bot
2026-06-04 18:36 ` Boris Brezillon
2026-06-04 17:35 ` [PATCH v2 7/7] drm/panfrost: Explicitly enable MMU interrupts at device init Adrián Larumbe
2026-06-04 17:55 ` sashiko-bot
2026-06-04 20:16 ` Claude review: " Claude Code Review Bot
2026-06-04 20:16 ` Claude review: RPM, perfcnt and other minor fixes for Panfrost 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-patch5-20260604174918.2BC551F00893@smtp.kernel.org \
--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