From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: drm/panthor: Track the number of mmap on a BO
Date: Tue, 10 Mar 2026 12:15:42 +1000 [thread overview]
Message-ID: <review-patch8-20260309151119.290217-9-boris.brezillon@collabora.com> (raw)
In-Reply-To: <20260309151119.290217-9-boris.brezillon@collabora.com>
Patch Review
Tracks mmap count using `refcount_t` to determine reclaimability ordering. The pattern used is:
```c
if (!refcount_inc_not_zero(&bo->cmap.mmap_count)) {
dma_resv_lock(obj->resv, NULL);
if (!refcount_inc_not_zero(&bo->cmap.mmap_count))
refcount_set(&bo->cmap.mmap_count, 1);
dma_resv_unlock(obj->resv);
}
```
This double-check pattern uses the resv lock as the serialization mechanism for the 0→1 transition. The `refcount_set` on the 0→1 path is intentional because `refcount_inc` from zero triggers a WARN with `CONFIG_REFCOUNT_FULL`. The outer `refcount_inc_not_zero` is a fast path to avoid the lock for the common N→N+1 case.
The `panthor_gem_vm_close` uses a similar pattern for the 1→0 transition:
```c
if (refcount_dec_not_one(&bo->cmap.mmap_count))
goto out;
dma_resv_lock(bo->base.resv, NULL);
if (refcount_dec_and_test(&bo->cmap.mmap_count)) {
/* Nothing to do, pages are reclaimed lazily. */
}
dma_resv_unlock(bo->base.resv);
```
**Potential issue**: `refcount_dec_not_one()` returns true when the count was decremented (i.e., went from N>1 to N-1). If it returns false (count was 1), the code takes the lock and calls `refcount_dec_and_test()`. But between `refcount_dec_not_one()` returning false and the lock being acquired, another thread could have incremented the refcount (via mmap). In that case `refcount_dec_and_test()` would decrement but not reach zero, which is fine — but the lock was acquired unnecessarily. The correctness holds because the resv lock serializes the critical state transitions.
One nit: `panthor_gem_vm_open` calls `drm_gem_is_imported()` to skip the mmap_count increment for imported BOs. But `panthor_gem_mmap` redirects to `dma_buf_mmap` for imported BOs and returns early, so the mmap_count would never have been incremented in the first place. The check is defensive but slightly misleading.
No blocking issues.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-03-10 2:15 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-09 15:11 [PATCH v5 0/9] drm/panthor: Add a GEM shrinker Boris Brezillon
2026-03-09 15:11 ` [PATCH v5 1/9] drm/gem: Consider GEM object reclaimable if shrinking fails Boris Brezillon
2026-03-10 2:15 ` Claude review: " Claude Code Review Bot
2026-03-09 15:11 ` [PATCH v5 2/9] drm/panthor: Move panthor_gems_debugfs_init() to panthor_gem.c Boris Brezillon
2026-03-10 2:15 ` Claude review: " Claude Code Review Bot
2026-03-09 15:11 ` [PATCH v5 3/9] drm/panthor: Group panthor_kernel_bo_xxx() helpers Boris Brezillon
2026-03-10 2:15 ` Claude review: " Claude Code Review Bot
2026-03-09 15:11 ` [PATCH v5 4/9] drm/panthor: Don't call drm_gpuvm_bo_extobj_add() if the object is private Boris Brezillon
2026-03-10 2:15 ` Claude review: " Claude Code Review Bot
2026-03-09 15:11 ` [PATCH v5 5/9] drm/panthor: Part ways with drm_gem_shmem_object Boris Brezillon
2026-03-09 15:34 ` Steven Price
2026-03-10 2:15 ` Claude review: " Claude Code Review Bot
2026-03-09 15:11 ` [PATCH v5 6/9] drm/panthor: Lazily allocate pages on mmap() Boris Brezillon
2026-03-10 2:15 ` Claude review: " Claude Code Review Bot
2026-03-09 15:11 ` [PATCH v5 7/9] drm/panthor: Split panthor_vm_prepare_map_op_ctx() to prepare for reclaim Boris Brezillon
2026-03-10 2:15 ` Claude review: " Claude Code Review Bot
2026-03-09 15:11 ` [PATCH v5 8/9] drm/panthor: Track the number of mmap on a BO Boris Brezillon
2026-03-10 2:15 ` Claude Code Review Bot [this message]
2026-03-09 15:11 ` [PATCH v5 9/9] drm/panthor: Add a GEM shrinker Boris Brezillon
2026-03-10 2:15 ` Claude review: " Claude Code Review Bot
2026-03-10 2:15 ` 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-patch8-20260309151119.290217-9-boris.brezillon@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