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 GpuVmCore::sm_unmap()
Date: Sun, 22 Mar 2026 03:35:24 +1000	[thread overview]
Message-ID: <review-patch5-20260320-gpuvm-rust-v5-5-76fd44f17a87@google.com> (raw)
In-Reply-To: <20260320-gpuvm-rust-v5-5-76fd44f17a87@google.com>

Patch Review

Adds unmap/remap callbacks and the `sm_unmap()` entry point.

**`SmData` missing `#[repr(C)]`:**
```rust
struct SmData<'a, 'ctx, T: DriverGpuVm> {
    gpuvm: &'a mut UniqueRefGpuVm<T>,
    user_context: &'a mut T::SmContext<'ctx>,
}
```
In patch 6, `SmMapData` is `#[repr(C)]` and contains `SmData` as its first field, relying on the cast `p.cast::<SmData<...>>()` being valid when `p` actually points to a `SmMapData`. This cast is only sound if `SmData` is at offset 0 in `SmMapData`, which `#[repr(C)]` on `SmMapData` guarantees (first field is at offset 0). So the cast is correct regardless of `SmData`'s repr. However, adding `#[repr(C)]` to `SmData` would be good defensive practice.

**`OpRemap::remap()` always requires 2 `GpuVaAlloc`s:**
```rust
pub fn remap(
    self,
    va_alloc: [GpuVaAlloc<T>; 2],
    prev_data: impl PinInit<T::VaData>,
    next_data: impl PinInit<T::VaData>,
) -> (OpRemapped<'op, T>, OpRemapRet<T>)
```
This always requires 2 pre-allocated VAs even when only 1 (or 0) will be used. The unused one is returned in `OpRemapRet::unused_va`. The `prev_data`/`next_data` initializers are also always required even when not used — this means the caller must construct dummy initializers. This is a usability concern; consider making them `Option<impl PinInit<T::VaData>>` or only initializing when `self.prev()`/`self.next()` is `Some`. However, since `PinInit` for simple types is cheap, this may be an acceptable trade-off for API simplicity.

**`lock_gpuva` returns a `MutexGuard` but uses `from_raw`:**
```rust
pub(super) fn lock_gpuva(&self) -> crate::sync::MutexGuard<'_, ()> {
    let ptr = unsafe { &raw mut (*self.obj().as_raw()).gpuva.lock };
    let mutex = unsafe { crate::sync::Mutex::from_raw(ptr) };
    mutex.lock()
}
```
Using `Mutex::from_raw` on a mutex embedded in a C struct is fine as long as the mutex was initialized by the C side (which it is, as part of GEM object init). The guard borrows `&self` which ensures the GpuVmBo stays alive while the lock is held.

---
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 review: " Claude Code Review Bot
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 Code Review Bot [this message]
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-patch5-20260320-gpuvm-rust-v5-5-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