[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DDKGDHEH4QOJ.2QCE60PQ5OJRM@kernel.org>
Date: Fri, 17 Oct 2025 10:26:43 +0200
From: "Benno Lossin" <lossin@...nel.org>
To: "Alexandre Courbot" <acourbot@...dia.com>, "Danilo Krummrich"
<dakr@...nel.org>, <gregkh@...uxfoundation.org>, <rafael@...nel.org>
Cc: <viresh.kumar@...aro.org>, <ira.weiny@...el.com>, <leon@...nel.org>,
<daniel.almeida@...labora.com>, <bhelgaas@...gle.com>,
<kwilczynski@...nel.org>, <abdiel.janulgue@...il.com>,
<robin.murphy@....com>, <ojeda@...nel.org>, <alex.gaynor@...il.com>,
<boqun.feng@...il.com>, <gary@...yguo.net>, <bjorn3_gh@...tonmail.com>,
<a.hindborg@...nel.org>, <aliceryhl@...gle.com>, <tmgross@...ch.edu>,
<rust-for-linux@...r.kernel.org>, <linux-pci@...r.kernel.org>,
<linux-pm@...r.kernel.org>, <nouveau@...ts.freedesktop.org>,
<dri-devel@...ts.freedesktop.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] rust: driver: let probe() return impl PinInit<Self,
Error>
On Fri Oct 17, 2025 at 4:12 AM CEST, Alexandre Courbot wrote:
> On Thu Oct 16, 2025 at 9:55 PM JST, Danilo Krummrich wrote:
>> The driver model defines the lifetime of the private data stored in (and
>> owned by) a bus device to be valid from when the driver is bound to a
>> device (i.e. from successful probe()) until the driver is unbound from
>> the device.
>>
>> This is already taken care of by the Rust implementation of the driver
>> model. However, we still ask drivers to return a Result<Pin<KBox<Self>>>
>> from probe().
>>
>> Unlike in C, where we do not have the concept of initializers, but
>> rather deal with uninitialized memory, drivers can just return an
>> impl PinInit<Self, Error> instead.
>>
>> This contributed to more clarity to the fact that a driver returns it's
>
> nit: s/it's/its
>
>> device private data in probe() and the Rust driver model owns the data,
>> manages the lifetime and - considering the lifetime - provides (safe)
>> accessors for the driver.
>>
>> Hence, let probe() functions return an impl PinInit<Self, Error> instead
>> of Result<Pin<KBox<Self>>>.
>>
>> Signed-off-by: Danilo Krummrich <dakr@...nel.org>
>
> Short anecdote: I was curious about measuring the footprint impact of
> pin initializers, so I did a `size vmlinux` before and after this patch
> to compare the size of the `text` section. This patch removes exactly 60
> bytes of binary code, which I guess corresponds to the duplicated `KBox`
> allocations that are now gone. It's great to confirm once again how Rust
> abstractions are indeed zero-overhead! :)
Thanks for the test! If you find that at any point they aren't, let me
know, then we can fix that :)
---
Cheers,
Benno
Powered by blists - more mailing lists