From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: drm/gem: Make the GEM LRU lock part of drm_device
Date: Sat, 16 May 2026 14:06:15 +1000 [thread overview]
Message-ID: <review-patch1-20260512-panthor-shrinker-fixes-v3-1-3bf066259471@collabora.com> (raw)
In-Reply-To: <20260512-panthor-shrinker-fixes-v3-1-3bf066259471@collabora.com>
Patch Review
**Race fix (core change) — correct:**
The old `drm_gem_lru_remove()`:
```c
struct drm_gem_lru *lru = obj->lru;
if (!lru)
return;
mutex_lock(lru->lock);
drm_gem_lru_remove_locked(obj);
mutex_unlock(lru->lock);
```
reads `obj->lru` unlocked, then dereferences it for the lock pointer. The new version correctly takes the device-level lock first, then checks `obj->lru` under the lock:
```c
mutex_lock(&obj->dev->gem_lru_mutex);
if (obj->lru)
drm_gem_lru_remove_locked(obj);
mutex_unlock(&obj->dev->gem_lru_mutex);
```
This is the right fix — the lock is now always accessible without first reading the mutable `obj->lru`.
**`drm_gem_lru_scan()` signature change — correct but note:**
The new signature adds `struct drm_device *dev` as the first parameter:
```c
drm_gem_lru_scan(struct drm_device *dev,
struct drm_gem_lru *lru,
...
```
This is necessary because `still_in_lru` is a stack-local LRU with no associated objects, so `obj->dev` can't be used to get the lock before objects are dequeued. The `dev` parameter is the clean solution. All callers in MSM correctly pass `priv->dev`.
**`drm_gem_lru_init()` — simplified correctly:**
The lock pointer is removed from `struct drm_gem_lru` entirely, and `drm_gem_lru_init()` drops its `lock` parameter. All MSM callers (`msm_drv.c`) are updated, and the `mutex_init(&priv->lru.lock)` is removed since the lock now lives in `drm_device`.
**`drm_device` changes — correct:**
The `gem_lru_mutex` is initialized in `drm_dev_init()` and destroyed in `drm_dev_init_release()`, following the same pattern as `filelist_mutex` and `clientlist_mutex`. The field is added at the end of `struct drm_device` after `debugfs_root`, which is fine.
**MSM driver changes — mechanical and correct:**
All MSM files (`msm_gem.c`, `msm_gem_shrinker.c`, `msm_gem_submit.c`, `msm_gem_vma.c`, `msm_ringbuffer.c`) switch from `priv->lru.lock` to `dev->gem_lru_mutex`. The `struct mutex lock` is removed from `struct msm_drm_private::lru`. The lockdep annotation in `msm_drv.c` correctly changes from `might_lock(&priv->lru.lock)` to `might_lock(&ddev->gem_lru_mutex)`.
**Minor observations (non-blocking):**
1. The `@lock` parameter documentation in `drm_gem_lru_init()` kdoc header is stale after this patch — the old doc says `@lock: The lock protecting the LRU` but the parameter is removed. The patch does remove it from the signature but the diff context (line 180 of the mbox) still shows `@lock` in the doc comment context. Looking more carefully, the diff hunk starts at the `@lock` line but doesn't delete it. However, since `@lock` is a parameter doc and the parameter is removed, the kernel doc build would warn. Let me re-check... Actually, looking at the diff more carefully, the hunk at line 179-188 shows the context line ` * @lock: The lock protecting the LRU` followed by the change to `drm_gem_lru_init`, so the `@lock` doc line is retained as context. This would produce a `kernel-doc` warning since the parameter no longer exists. This is minor and could be noted but is non-blocking given the existing R-b tags.
2. The `drm_gem_lru_remove()` now unconditionally takes the mutex even if `obj->lru` is NULL. This is a slight performance change compared to the old early-return path, but it's necessary for correctness and the contention cost is negligible in the NULL case (the lock is immediately released).
3. The panthor driver (`panthor_gem.c:207`) calls `drm_gem_lru_remove()` and will benefit from this fix without any code changes needed on its side, since the API change is in the core `drm_gem_lru_init/scan` signatures, not in `drm_gem_lru_remove`.
**Overall:** Clean, well-explained patch that fixes a real race. The approach of hoisting the lock to `drm_device` is the right call given that both current and upcoming users (MSM, panthor) use a single device-wide lock anyway. The only nit is the stale `@lock` kdoc line for `drm_gem_lru_init`.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-05-16 4:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 6:59 [PATCH v3] drm/gem: Make the GEM LRU lock part of drm_device Boris Brezillon
2026-05-12 17:13 ` Chia-I Wu
2026-05-14 0:55 ` kernel test robot
2026-05-14 3:56 ` kernel test robot
2026-05-14 15:44 ` Steven Price
2026-05-16 4:06 ` Claude Code Review Bot [this message]
2026-05-16 4:06 ` Claude review: " 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-patch1-20260512-panthor-shrinker-fixes-v3-1-3bf066259471@collabora.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