From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: rust: gpuvm: add GpuVm::obtain()
Date: Sun, 12 Apr 2026 11:16:41 +1000 [thread overview]
Message-ID: <review-patch2-20260409-gpuvm-rust-v6-2-b16e6ada7261@google.com> (raw)
In-Reply-To: <20260409-gpuvm-rust-v6-2-b16e6ada7261@google.com>
Patch Review
Introduces `GpuVmBo<T>`, `GpuVmBoAlloc<T>`, and the `obtain()` flow for creating/looking-up VM-BO associations.
**Observations:**
1. **`dma_resv_lock` return value not checked in `obtain()`**:
```rust
unsafe { bindings::dma_resv_lock(resv_lock, ptr::null_mut()) };
```
`dma_resv_lock()` returns `int` (can return `-EALREADY` when ctx is NULL and the lock is already held, or 0 on success). In this case, `ctx` is NULL, so `-EDEADLK` won't occur, but the return value is still silently discarded. While in practice with a NULL context the call should always succeed (or indicate the lock is already held, which for a ww_mutex with NULL ctx shouldn't happen), it would be more robust to at least debug-assert the return value is 0. The TODO comment acknowledges this needs a proper lock guard, but the unchecked return is worth noting.
2. **`ALLOC_FN` / `FREE_FN` const evaluation**: The clever const-time comparison of `Layout::new::<bindings::drm_gpuvm_bo>()` vs `Layout::new::<Self>()` to decide whether a custom allocator is needed is elegant. When `T::VmBoData` is a ZST with no extra alignment, the default C `kzalloc(sizeof(drm_gpuvm_bo))` is used, avoiding unnecessary indirection.
3. **`vm_bo_alloc` returns null on allocation failure**:
```rust
unsafe extern "C" fn vm_bo_alloc() -> *mut bindings::drm_gpuvm_bo {
let raw_ptr = KBox::<Self>::new_uninit(GFP_KERNEL | __GFP_ZERO)
.map(KBox::into_raw)
.unwrap_or(ptr::null_mut());
raw_ptr.cast()
}
```
Returning null on allocation failure is correct -- the C code checks for NULL from `vm_bo_alloc`.
4. **`GpuVmBoAlloc::new` calls `drm_gpuvm_bo_create` then initializes `data`**: If `value.__pinned_init()` fails (which can't actually fail since it uses the infallible `PinInit` protocol via `let Ok(()) = ...`), the data wouldn't be initialized but the `drm_gpuvm_bo` was already created. The `let Ok(()) = ...` pattern is the right approach for infallible initializers.
5. **`GpuVmBoAlloc::obtain` race condition fix**: The v6 changelog mentions calling `extobj_add` even when `ptr != me` (i.e., an existing VM-BO was returned). This is correct:
```rust
// Note that we must call `extobj_add` even if `ptr != me` to avoid a race condition
```
Without this, two concurrent `obtain()` calls could result in the first thread's VM-BO being used before its `extobj_add` completes.
6. **`GpuVmBoAlloc` Drop impl**: Uses `drm_gpuvm_bo_put_deferred` which is correct for immediate mode, matching the `dec_ref` implementation.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-04-12 1:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-09 15:26 [PATCH v6 0/5] Rust GPUVM immediate mode Alice Ryhl
2026-04-09 15:26 ` [PATCH v6 1/5] rust: drm: add base GPUVM immediate mode abstraction Alice Ryhl
2026-04-12 1:16 ` Claude review: " Claude Code Review Bot
2026-04-09 15:26 ` [PATCH v6 2/5] rust: gpuvm: add GpuVm::obtain() Alice Ryhl
2026-04-12 1:16 ` Claude Code Review Bot [this message]
2026-04-09 15:26 ` [PATCH v6 3/5] rust: gpuvm: add GpuVa struct Alice Ryhl
2026-04-12 1:16 ` Claude review: " Claude Code Review Bot
2026-04-09 15:26 ` [PATCH v6 4/5] rust: gpuvm: add GpuVmCore::sm_unmap() Alice Ryhl
2026-04-12 1:16 ` Claude review: " Claude Code Review Bot
2026-04-09 15:26 ` [PATCH v6 5/5] rust: gpuvm: add GpuVmCore::sm_map() Alice Ryhl
2026-04-12 1:16 ` Claude review: " Claude Code Review Bot
2026-04-12 1:16 ` Claude review: Rust GPUVM immediate mode Claude Code Review Bot
-- strict thread matches above, loose matches on Subject: below --
2026-03-20 16:08 [PATCH v5 0/6] " Alice Ryhl
2026-03-20 16:08 ` [PATCH v5 3/6] rust: gpuvm: add GpuVm::obtain() Alice Ryhl
2026-03-21 17:35 ` 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-patch2-20260409-gpuvm-rust-v6-2-b16e6ada7261@google.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