From mboxrd@z Thu Jan 1 00:00:00 1970 From: Claude Code Review Bot To: dri-devel-reviews@example.com Subject: Claude review: rust: device: Higher-Ranked Lifetime Types for device drivers Date: Tue, 28 Apr 2026 13:47:56 +1000 Message-ID: In-Reply-To: <20260427221155.2144848-1-dakr@kernel.org> References: <20260427221155.2144848-1-dakr@kernel.org> X-Mailer: Claude Code Patch Reviewer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 Overall Series Review Subject: rust: device: Higher-Ranked Lifetime Types for device drivers Author: Danilo Krummrich Patches: 27 Reviewed: 2026-04-28T13:47:56.155146 --- This is a well-architected series introducing Higher-Ranked Lifetime Types (HRT) for Rust device drivers in the Linux kernel. The core idea is compelling: by giving driver structs a lifetime parameter tied to the device binding scope, device resources like PCI BAR mappings and I/O memory regions can be held directly as borrowed references rather than going through `Devres` + `Arc` indirection. This eliminates runtime revocation checks in the common path and makes the type system enforce resource validity at compile time. The series is logically structured in clear layers: (1) C-side reordering enabler, (2) `ForLt` trait infrastructure, (3) `Devres`/device core generalization over `ForLt`, (4) per-bus driver trait lifetime parameterization, (5) resource types (`Bar`, `IoMem`) lifetime parameterization, and (6) reference driver conversions showing the ergonomic wins. **Key strengths:** - The `ForLt` trait design (by Gary Guo) is clever and well-documented, with proper covariance proofs and a workaround for a known Rust compiler soundness bug (rust-lang/rust#152489). - The `drvdata` drop-before-devres reordering (patch 1) is the critical C-side enabler, with clear reasoning. - The driver-facing API becomes significantly cleaner: `self.bar.read32(OFFSET)` vs `self.bar.access(dev)?.read32(OFFSET)`. - The `into_devres()` escape hatch preserves the old semantics when needed. **Key concerns:** 1. **Patch 21 (nova-core HRT Bar) contains an unsafe self-referential pattern** that is fragile and explicitly marked as a TODO. The `unsafe { &*core::ptr::from_ref(bar) }` to create a self-reference within `try_pin_init!` relies on field initialization order guarantees that are not formally part of the `try_pin_init!` contract (only stated in a comment). This needs the upcoming self-referential pin-init support to be sound. 2. **Multiple `transmute` calls for lifetime erasure** (patches 14, 18, 19) need careful auditing. While the reasoning ("lifetimes don't affect layout") is correct in practice, `core::mem::transmute` on types differing only in lifetimes is a pattern that could break if Rust ever adds lifetime-dependent layout (unlikely but worth noting). 3. **Breaking API change in `module_*_driver!` macros** (patches 11, 12, 13, 16, 17): The macro syntax changes from `($($f:tt)*)` to `(type: $type:ty, $($rest:tt)*)`, requiring all out-of-tree drivers to update. This seems intentional but worth calling out. --- Generated by Claude Code Patch Reviewer