From: Greg KH <gregkh@linuxfoundation.org>
To: Danilo Krummrich <dakr@kernel.org>
Cc: rafael@kernel.org, ojeda@kernel.org, alex.gaynor@gmail.com,
boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com,
benno.lossin@proton.me, a.hindborg@kernel.org,
aliceryhl@google.com, tmgross@umich.edu,
david.m.ertman@intel.com, ira.weiny@intel.com, leon@kernel.org,
kwilczynski@kernel.org, bhelgaas@google.com,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-pci@vger.kernel.org
Subject: Re: [PATCH 0/8] Device: generic accessors for drvdata + Driver::unbind()
Date: Tue, 1 Jul 2025 11:25:41 +0200 [thread overview]
Message-ID: <2025070142-difficult-lucid-d949@gregkh> (raw)
In-Reply-To: <20250621195118.124245-1-dakr@kernel.org>
On Sat, Jun 21, 2025 at 09:43:26PM +0200, Danilo Krummrich wrote:
> This patch series consists of the following three parts.
>
> 1. Introduce the 'Internal' device context (semantically identical to the
> 'Core' device context), but only accessible for bus abstractions.
>
> 2. Introduce generic accessors for a device's driver_data pointer. Those are
> implemented for the 'Internal' device context only, in order to only enable
> bus abstractions to mess with the driver_data pointer of struct device.
>
> 3. Implement the Driver::unbind() callback (details below).
>
> Driver::unbind()
> ----------------
>
> Currently, there's really only one core callback for drivers, which is
> probe().
>
> Now, this isn't entirely true, since there is also the drop() callback of
> the driver type (serving as the driver's private data), which is returned
> by probe() and is dropped in remove().
>
> On the C side remove() mainly serves two purposes:
>
> (1) Tear down the device that is operated by the driver, e.g. call bus
> specific functions, write I/O memory to reset the device, etc.
>
> (2) Release the resources that have been allocated by a driver for a
> specific device.
>
> The drop() callback mentioned above is intended to cover (2) as the Rust
> idiomatic way.
>
> However, it is partially insufficient and inefficient to cover (1)
> properly, since drop() can't be called with additional arguments, such as
> the reference to the corresponding device that has the correct device
> context, i.e. the Core device context.
I'm missing something, why doesn't drop() have access to the device
itself, which has the Core device context? It's the same "object",
right?
> This makes it inefficient (but not impossible) to access device
> resources, e.g. to write device registers, and impossible to call device
> methods, which are only accessible under the Core device context.
>
> In order to solve this, add an additional callback for (1), which we
> call unbind().
>
> The reason for calling it unbind() is that, unlike remove(), it is *only*
> meant to be used to perform teardown operations on the device (1), but
> *not* to release resources (2).
Ick. I get the idea, but unbind() is going to get confusing fast.
Determining what is, and is not, a "resource" is going to be hard over
time. In fact, how would you define it? :)
Is "teardown" only allowed to write to resources, but not free them? If
so, why can't that happen in drop() as the resources are available there.
I'm loath to have a 2-step destroy system here for rust only, and not
for C, as maintaining this over time is going to be rough.
thanks,
greg k-h
next prev parent reply other threads:[~2025-07-01 9:25 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-21 19:43 [PATCH 0/8] Device: generic accessors for drvdata + Driver::unbind() Danilo Krummrich
2025-06-21 19:43 ` [PATCH 1/8] rust: device: introduce device::Internal Danilo Krummrich
2025-07-01 9:26 ` Greg KH
2025-07-01 10:41 ` Danilo Krummrich
2025-07-01 12:32 ` Danilo Krummrich
2025-07-03 15:06 ` Greg KH
2025-06-21 19:43 ` [PATCH 2/8] rust: device: add drvdata accessors Danilo Krummrich
2025-07-01 9:27 ` Greg KH
2025-07-01 10:58 ` Danilo Krummrich
2025-07-01 13:12 ` Danilo Krummrich
2025-07-05 11:15 ` Benno Lossin
2025-07-05 15:06 ` Danilo Krummrich
2025-07-05 21:38 ` Benno Lossin
2025-07-07 7:46 ` Alexandre Courbot
2025-07-07 9:40 ` Danilo Krummrich
2025-06-21 19:43 ` [PATCH 3/8] rust: platform: use generic device " Danilo Krummrich
2025-06-21 19:43 ` [PATCH 4/8] rust: pci: " Danilo Krummrich
2025-07-01 9:30 ` Greg KH
2025-06-21 19:43 ` [PATCH 5/8] rust: auxiliary: " Danilo Krummrich
2025-06-21 19:43 ` [PATCH 6/8] rust: platform: implement Driver::unbind() Danilo Krummrich
2025-06-21 19:43 ` [PATCH 7/8] rust: pci: " Danilo Krummrich
2025-06-21 19:43 ` [PATCH 8/8] samples: rust: pci: reset pci-testdev in unbind() Danilo Krummrich
2025-07-01 9:25 ` Greg KH [this message]
2025-07-01 10:40 ` [PATCH 0/8] Device: generic accessors for drvdata + Driver::unbind() Danilo Krummrich
2025-07-07 7:18 ` Alexandre Courbot
2025-07-07 9:26 ` Danilo Krummrich
2025-07-08 22:25 ` 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=2025070142-difficult-lucid-d949@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=david.m.ertman@intel.com \
--cc=gary@garyguo.net \
--cc=ira.weiny@intel.com \
--cc=kwilczynski@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--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).