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: drm: gem: Introduce shmem::Object::sg_table()
Date: Thu, 04 Jun 2026 12:29:54 +1000	[thread overview]
Message-ID: <review-patch6-20260602172807.1051806-7-lyude@redhat.com> (raw)
In-Reply-To: <20260602172807.1051806-7-lyude@redhat.com>

Patch Review

The most complex patch. Several observations:

**Missing C-side function**: `SGTableMap::drop` calls:
```rust
unsafe { bindings::__drm_gem_shmem_free_sgt_locked(obj.as_raw_shmem()) };
```
This function does not exist in the current drm-next tree. It presumably lives in the "first half" of the series already pushed to drm-rust-next. If it's missing from the base, this won't compile. This should be verified against the actual base tree.

**Import restructuring**: The patch changes `device` from `crate::drm::device` to `crate::device`:
```rust
+    device::{
+        self,
+        Bound, //
+    },
     drm::{
+        driver,
+        gem,
+        private::Sealed,
         Device, //
     },
```
This changes the meaning of `device::Device<T::Driver>` in the existing `dev()` method. On the actual drm-rust-next base, this may already be reconciled. Worth verifying.

**Double-checked locking in `sg_table()`**: The pattern is correct:
```rust
if let Some(sgt_res) = self.sgt_res.as_ref() {  // fast path (Acquire)
    break 'out sgt_res;
}
let _guard = self.sgt_lock.lock();               // slow path
if let Some(sgt_res) = self.sgt_res.as_ref() {  // re-check
    break 'out sgt_res;
}
self.sgt_res.populate(...);                       // Release
```
The `SetOnce` uses `Acquire` on read and `Release` on write, which provides the necessary happens-before guarantees for the double-checked locking pattern.

**SGTableMap lifetime safety**: `SGTableMap` holds `NonNull<Object<T>>` without an `ARef`:
```rust
pub struct SGTableMap<T: DriverObject> {
    obj: NonNull<Object<T>>,
}
```
This is safe because `SGTableMap` is stored inside the `Object<T>` itself (via `sgt_res`), so the object outlives the mapping. The `free_callback` explicitly resets `sgt_res` before releasing the GEM object:
```rust
unsafe { &mut (*this).sgt_res }.reset();   // drops SGTableMap first
unsafe { bindings::drm_gem_shmem_release(base) };  // then releases GEM
let _ = unsafe { KBox::from_raw(this) };   // then frees memory
```
This ordering is correct and critical.

**Device identity check**:
```rust
if dev.as_raw() != self.dev().as_ref().as_raw() {
    return Err(EINVAL);
}
```
Comparing raw device pointers to verify the caller passed the correct device is a good defensive check. The test `fail_sg_table_on_wrong_dev` verifies this works.

**`SGTableMap::new` discards the sg_table pointer**:
```rust
fn new(obj: &Object<T>) -> impl Init<Self, Error> {
    from_err_ptr(unsafe { bindings::drm_gem_shmem_get_pages_sgt(obj.as_raw_shmem()) })?;
    Ok(Self { obj: obj.into() })
}
```
The returned `sg_table*` is discarded. This is correct because `drm_gem_shmem_get_pages_sgt` stores the SGT internally in `shmem->sgt`, which is what `SGTableMap::deref` reads later.

**Minor style**: The `#[pin]` attribute appears before the doc comment on `sgt_lock`:
```rust
+    #[pin]
+    /// Lock for protecting initialization of `sgt_res`.
+    sgt_lock: Mutex<()>,
```
Convention is doc comments before attributes, though both orderings are valid Rust.

**Test coverage**: The `fail_sg_table_on_wrong_dev` test is good but limited — as the TODOs note, testing the success path requires mock DMA ops. The comment is honest about this limitation, which is appreciated.

---
Generated by Claude Code Patch Reviewer

  reply	other threads:[~2026-06-04  2:29 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-02 17:24 [PATCH v16 0/6] Rust bindings for gem shmem Lyude Paul
2026-06-02 17:25 ` [PATCH v16 1/6] rust: drm: gem/shmem: Add DmaResvGuard helper Lyude Paul
2026-06-04  2:29   ` Claude review: " Claude Code Review Bot
2026-06-02 17:25 ` [PATCH v16 2/6] rust: drm: gem: Add vmap functions to shmem bindings Lyude Paul
2026-06-04  2:29   ` Claude review: " Claude Code Review Bot
2026-06-02 17:25 ` [PATCH v16 3/6] rust: sync: Add SetOnce::reset() Lyude Paul
2026-06-04  2:29   ` Claude review: " Claude Code Review Bot
2026-06-02 17:25 ` [PATCH v16 4/6] rust: gem: shmem: Fix Default implementation for ObjectConfig Lyude Paul
2026-06-04  2:29   ` Claude review: " Claude Code Review Bot
2026-06-02 17:25 ` [PATCH v16 5/6] rust: faux: Allow retrieving a bound Device Lyude Paul
2026-06-04  2:29   ` Claude review: " Claude Code Review Bot
2026-06-02 17:25 ` [PATCH v16 6/6] rust: drm: gem: Introduce shmem::Object::sg_table() Lyude Paul
2026-06-04  2:29   ` Claude Code Review Bot [this message]
2026-06-04  2:29 ` Claude review: Rust bindings for gem shmem Claude Code Review Bot
  -- strict thread matches above, loose matches on Subject: below --
2026-06-04 19:24 [PATCH v18 0/4] " Lyude Paul
2026-06-04 19:24 ` [PATCH v18 4/4] rust: drm: gem: Introduce shmem::Object::sg_table() Lyude Paul
2026-06-04 20:03   ` Claude review: " Claude Code Review Bot
2026-06-03 19:42 [PATCH v17 0/6] Rust bindings for gem shmem Lyude Paul
2026-06-03 19:42 ` [PATCH v17 6/6] rust: drm: gem: Introduce shmem::Object::sg_table() Lyude Paul
2026-06-04  1:29   ` Claude review: " Claude Code Review Bot
2026-05-29 18:33 [PATCH v15 0/6] Rust bindings for gem shmem Lyude Paul
2026-05-29 18:34 ` [PATCH v15 6/6] rust: drm: gem: Introduce shmem::Object::sg_table() Lyude Paul
2026-06-04  6:06   ` Claude review: " Claude Code Review Bot
2026-05-26 21:28 [PATCH v14 0/6] rust: drm: gem: shmem: Add sg_table() function Lyude Paul
2026-05-26 21:28 ` [PATCH v14 6/6] rust: drm: gem: Introduce shmem::Object::sg_table() Lyude Paul
2026-05-27  4:05   ` 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-patch6-20260602172807.1051806-7-lyude@redhat.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