From mboxrd@z Thu Jan 1 00:00:00 1970 From: Claude Code Review Bot To: dri-devel-reviews@example.com Subject: Claude review: gpu: nova-core: use lifetime for Bar Date: Wed, 27 May 2026 15:28:22 +1000 Message-ID: In-Reply-To: <20260525225838.276108-2-dakr@kernel.org> References: <20260525225838.276108-1-dakr@kernel.org> <20260525225838.276108-2-dakr@kernel.org> X-Mailer: Claude Code Patch Reviewer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Patch Review This is the key patch. It changes `NovaCore` to hold `pci::Bar<'bound, BAR0= _SIZE>` directly instead of `Arc>`, and `Gpu` to borrow `&'gpu= Bar0` (now aliased to `kernel::io::Mmio`) instead of owning a c= lone of the Arc. **The unsafe self-referential initialization:** ```rust gpu <- Gpu::new(pdev, unsafe { &*core::ptr::from_ref(bar) }), ``` This is the most important part of the series. The safety comment explains: ```rust // SAFETY: `bar` is initialized before this expression is evaluated // (`try_pin_init!()` initializes fields in declaration order), lives at a = pinned // stable address, and is dropped after `gpu` (struct field drop order). ``` The safety argument has three parts: 1. **Declaration-order initialization** =E2=80=94 `bar` is declared before = `gpu` in the struct, so `try_pin_init!` initializes it first. This is corre= ct per `pin_init` semantics. 2. **Pinned stable address** =E2=80=94 The struct is `#[pin_data]` and the = result is pinned, so `bar` won't move after initialization. 3. **Drop order** =E2=80=94 Rust drops struct fields in declaration order, = so `gpu` (declared after `bar`) is dropped before `bar`. This ensures the `= &'gpu Bar0` reference in `Gpu` remains valid during `Gpu::drop`. This reasoning is sound. The TODO comment about self-referential pin-init s= yntax is appropriate =E2=80=94 this is a known pattern that lacks safe abst= raction today. **Type alias change:** ```rust -pub(crate) type Bar0 =3D pci::Bar<'static, BAR0_SIZE>; +pub(crate) type Bar0 =3D kernel::io::Mmio; ``` This makes sense: `Gpu` and other consumers don't need the PCI bar metadata= , just the MMIO mapping. The `pci::Bar<'bound>` is stored in `NovaCore`, an= d the borrowed `Bar0` (=3D `Mmio`) is what gets passed around. **Gpu::unbind simplification:** ```rust - pub(crate) fn unbind(&self, dev: &device::Device>) { - kernel::warn_on!(self - .bar - .access(dev) - .inspect(|bar| self.sysmem_flush.unregister(bar)) - .is_err()); + pub(crate) fn unbind(&self) { + self.sysmem_flush.unregister(self.bar); } ``` Good =E2=80=94 the runtime `.access(dev)` check is no longer needed because= the lifetime guarantees the bar is valid. No issues found. --- Generated by Claude Code Patch Reviewer