From: Benno Lossin <benno.lossin@proton.me>
To: Danilo Krummrich <dakr@kernel.org>
Cc: bhelgaas@google.com, kwilczynski@kernel.org,
gregkh@linuxfoundation.org, rafael@kernel.org,
abdiel.janulgue@gmail.com, ojeda@kernel.org,
alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net,
bjorn3_gh@protonmail.com, a.hindborg@kernel.org,
aliceryhl@google.com, tmgross@umich.edu,
daniel.almeida@collabora.com, robin.murphy@arm.com,
linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 6/9] rust: device: implement Bound device context
Date: Mon, 14 Apr 2025 11:10:50 +0000 [thread overview]
Message-ID: <D96BDR2E04KF.1CSIS0TVB0YI6@proton.me> (raw)
In-Reply-To: <Z_zp-AvQ6FMv0ZRK@pollux>
On Mon Apr 14, 2025 at 12:56 PM CEST, Danilo Krummrich wrote:
> On Mon, Apr 14, 2025 at 10:49:49AM +0000, Benno Lossin wrote:
>> On Sun Apr 13, 2025 at 7:37 PM CEST, Danilo Krummrich wrote:
>> > The Bound device context indicates that a device is bound to a driver.
>> > It must be used for APIs that require the device to be bound, such as
>> > Devres or dma::CoherentAllocation.
>> >
>> > Implement Bound and add the corresponding Deref hierarchy, as well as the
>> > corresponding ARef conversion for this device context.
>> >
>> > Signed-off-by: Danilo Krummrich <dakr@kernel.org>
>> > ---
>> > rust/kernel/device.rs | 16 +++++++++++++++-
>> > 1 file changed, 15 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
>> > index 487211842f77..585a3fcfeea3 100644
>> > --- a/rust/kernel/device.rs
>> > +++ b/rust/kernel/device.rs
>> > @@ -232,13 +232,19 @@ pub trait DeviceContext: private::Sealed {}
>> > /// any of the bus callbacks, such as `probe()`.
>> > pub struct Core;
>> >
>> > +/// The [`Bound`] context is the context of a bus specific device reference when it is guranteed to
>> > +/// be bound for the duration of its lifetime.
>> > +pub struct Bound;
>>
>> One question about this: is it possible for me to
>> 1. have access to a `ARef<Device<Bound>>` (or `Core`) via some callback,
>> 2. store a clone of the `ARef` in some datastructure,
>> 3. wait for the device to become unbound,
>> 4. use a `Bound`-only context function and blow something up?
>
> You can never get an ARef<Device> that has a different device context than
> Normal.
>
> A device must only ever implement AlwaysRefCounted for Device (i.e.
> Device<Normal>).
Ah yes, I thought there was something there, that's perfect. Might also
be a good idea to write this down before it becomes tribal knowledge :)
---
Cheers,
Benno
next prev parent reply other threads:[~2025-04-14 11:10 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-13 17:36 [PATCH v2 0/9] Implement "Bound" device context Danilo Krummrich
2025-04-13 17:36 ` [PATCH v2 1/9] rust: device: implement impl_device_context_deref! Danilo Krummrich
2025-04-13 19:38 ` Christian Schrefl
2025-04-14 10:41 ` Benno Lossin
2025-04-13 17:36 ` [PATCH v2 2/9] rust: device: implement impl_device_context_into_aref! Danilo Krummrich
2025-04-14 10:26 ` Benno Lossin
2025-04-13 17:36 ` [PATCH v2 3/9] rust: device: implement device context for Device Danilo Krummrich
2025-04-14 10:31 ` Benno Lossin
2025-04-15 20:47 ` Bjorn Helgaas
2025-04-13 17:36 ` [PATCH v2 4/9] rust: platform: preserve device context in AsRef Danilo Krummrich
2025-04-14 10:32 ` Benno Lossin
2025-04-13 17:37 ` [PATCH v2 5/9] rust: pci: " Danilo Krummrich
2025-04-14 10:33 ` Benno Lossin
2025-04-13 17:37 ` [PATCH v2 6/9] rust: device: implement Bound device context Danilo Krummrich
2025-04-14 10:44 ` Benno Lossin
2025-04-14 11:13 ` Danilo Krummrich
2025-04-14 12:15 ` Benno Lossin
2025-04-14 10:49 ` Benno Lossin
2025-04-14 10:56 ` Danilo Krummrich
2025-04-14 11:10 ` Benno Lossin [this message]
2025-04-15 20:44 ` Bjorn Helgaas
2025-04-13 17:37 ` [PATCH v2 7/9] rust: pci: move iomap_region() to impl Device<Bound> Danilo Krummrich
2025-04-14 10:44 ` Benno Lossin
2025-04-15 20:43 ` Bjorn Helgaas
2025-04-13 17:37 ` [PATCH v2 8/9] rust: devres: require a bound device Danilo Krummrich
2025-04-13 17:37 ` [PATCH v2 9/9] rust: dma: " Danilo Krummrich
2025-04-17 15:14 ` [PATCH v2 0/9] Implement "Bound" device context Danilo Krummrich
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=D96BDR2E04KF.1CSIS0TVB0YI6@proton.me \
--to=benno.lossin@proton.me \
--cc=a.hindborg@kernel.org \
--cc=abdiel.janulgue@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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;
as well as URLs for NNTP newsgroup(s).