Re: [PATCH v2] rust: irq: make Registration compatible with lifetime-bound drivers

"Gary Guo" <[email protected]> Tue, 21 Jul 2026 21:30:32 +0100
Newsgroups dev.linux.lists.driver-core,org.kernel.vger.linux-kernel,org.kernel.vger.linux-pci,org.kernel.vger.rust-for-linux
Message-ID <[email protected]>
On Sun Jul 19, 2026 at 4:36 PM BST, Danilo Krummrich wrote:
> Adapt the IRQ registration to work with the Higher-Ranked Lifetime Types
> (HRT) device driver architecture introduced in commit 2c7c65933600
> ("Merge patch series "rust: device: Higher-Ranked Lifetime Types for
> device drivers"").
> 
> With HRT, driver structs carry a lifetime parameter tied to the device
> binding scope, allowing device resources such as pci::Bar<'bar> to be
> held directly rather than through Devres indirection. However, the IRQ
> abstraction required Handler: Sync + 'static, preventing handlers from
> embedding lifetime-parameterized resources.
> 
> Remove the 'static bound from Handler and ThreadedHandler and replace
> the Devres<RegistrationInner> indirection with direct request_irq() /
> free_irq() calls in the constructor and PinnedDrop.  Registration<'a, T>
> stores the IrqRequest<'a>, which structurally ties it to the device
> binding scope.
> 
> Also remove the &Device<Bound> parameter from the handler callbacks,
> since handlers that need device access can embed it in their own type.
> 
> IRQ handlers can now directly own device resources:
> 
> 	struct IrqHandler<'irq> {
> 	    bar: pci::Bar<'irq, BAR_SIZE>,
> 	}
> 
> 	impl irq::Handler for IrqHandler<'_> {
> 	    fn handle(&self) -> IrqReturn {
> 	        let stat = self.bar.read(regs::STAT);
> 	        ...
> 	    }
> 	}
> 
> This eliminates the indirection previously required for IRQ handlers to
> access device resources and aligns with the broader goal of expressing
> every registration scoped to a driver binding through compile-time
> lifetime bounds.
> 
> Reviewed-by: Daniel Almeida <[email protected]>
> Signed-off-by: Danilo Krummrich <[email protected]>

Reviewed-by: Gary Guo <[email protected]>

> ---
> Changes in v2:
>   - Move request_irq() / request_threaded_irq() to _: blocks.
>   - Add INVARIANT missing comments and missing #[inline] annotations.
> ---
>  rust/kernel/irq/request.rs | 432 ++++++++++++++++++-------------------
>  rust/kernel/pci/irq.rs     |  26 ++-
>  rust/kernel/platform.rs    |  48 +++--
>  3 files changed, 255 insertions(+), 251 deletions(-)