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: rust: gpuvm: add GpuVm::obtain()
Date: Sun, 22 Mar 2026 03:35:23 +1000	[thread overview]
Message-ID: <review-patch3-20260320-gpuvm-rust-v5-3-76fd44f17a87@google.com> (raw)
In-Reply-To: <20260320-gpuvm-rust-v5-3-76fd44f17a87@google.com>

Patch Review

Introduces `GpuVmBo<T>`, `GpuVmBoAlloc<T>`, and the `obtain()` path.

**Key concern — resv lock in `obtain()`:**
```rust
if ptr::eq(ptr, me.as_raw()) && me.gpuvm().is_extobj(me.obj()) {
    let resv_lock = me.gpuvm().raw_resv();
    // TODO: Use a proper lock guard here once a dma_resv lock abstraction exists.
    unsafe { bindings::dma_resv_lock(resv_lock, ptr::null_mut()) };
    unsafe { bindings::drm_gpuvm_bo_extobj_add(ptr) };
    unsafe { bindings::dma_resv_unlock(resv_lock) };
}
```
Passing `null` for `ww_acquire_ctx` means this cannot participate in deadlock avoidance. If a driver calls `obtain()` while already holding another resv lock in a ww transaction, this will deadlock. The TODO acknowledges this but it should be documented more prominently as a limitation, possibly with a `// WARNING` or a doc comment on `obtain()` itself.

**`GpuVmBoAlloc::Drop` — could use `drm_gpuvm_bo_destroy_not_in_lists()`:**
```rust
fn drop(&mut self) {
    // TODO: Call drm_gpuvm_bo_destroy_not_in_lists() directly.
    unsafe { bindings::drm_gpuvm_bo_put_deferred(self.as_raw()) };
}
```
The TODO is noted. Using `drm_gpuvm_bo_put_deferred` here works but does unnecessary refcount work for an object known to have refcount=1 and not be in any lists.

**ALLOC_FN optimization is clever:**
```rust
pub(super) const ALLOC_FN: Option<unsafe extern "C" fn() -> *mut bindings::drm_gpuvm_bo> = {
    ...
    if base.size() != rust.size() || base.align() != rust.align() {
        Some(Self::vm_bo_alloc)
    } else {
        None
    }
};
```
This correctly avoids overriding when the Rust wrapper has no extra fields. However, the `FREE_FN` check uses `needs_drop::<Self>()` which is independent — when `VmBoData` has a trivial type but non-default layout, you'd get `ALLOC_FN = Some` but `FREE_FN = None`, meaning the C side would `kfree()` a larger allocation which is fine since it was `kmalloc`'d. This works correctly.

---
Generated by Claude Code Patch Reviewer

  reply	other threads:[~2026-03-21 17:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-20 16:08 [PATCH v5 0/6] Rust GPUVM immediate mode Alice Ryhl
2026-03-20 16:08 ` [PATCH v5 1/6] rust: drm: add base GPUVM immediate mode abstraction Alice Ryhl
2026-03-21 17:35   ` Claude review: " Claude Code Review Bot
2026-03-20 16:08 ` [PATCH v5 2/6] rust: helpers: Add bindings/wrappers for dma_resv_lock Alice Ryhl
2026-03-21 17:35   ` Claude review: " Claude Code Review Bot
2026-03-20 16:08 ` [PATCH v5 3/6] rust: gpuvm: add GpuVm::obtain() Alice Ryhl
2026-03-21 17:35   ` Claude Code Review Bot [this message]
2026-03-20 16:08 ` [PATCH v5 4/6] rust: gpuvm: add GpuVa struct Alice Ryhl
2026-03-21 17:35   ` Claude review: " Claude Code Review Bot
2026-03-20 16:08 ` [PATCH v5 5/6] rust: gpuvm: add GpuVmCore::sm_unmap() Alice Ryhl
2026-03-21 17:35   ` Claude review: " Claude Code Review Bot
2026-03-20 16:08 ` [PATCH v5 6/6] rust: gpuvm: add GpuVmCore::sm_map() Alice Ryhl
2026-03-21 17:35   ` Claude review: " Claude Code Review Bot
2026-03-21 17:35 ` Claude review: Rust GPUVM immediate mode 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-patch3-20260320-gpuvm-rust-v5-3-76fd44f17a87@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