From: Danilo Krummrich <dakr@kernel.org>
To: Alice Ryhl <aliceryhl@google.com>
Cc: gregkh@linuxfoundation.org, rafael@kernel.org,
bhelgaas@google.com, ojeda@kernel.org, alex.gaynor@gmail.com,
boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com,
benno.lossin@proton.me, tmgross@umich.edu,
a.hindborg@samsung.com, airlied@gmail.com,
fujita.tomonori@gmail.com, lina@asahilina.net,
pstanner@redhat.com, ajanulgu@redhat.com, lyude@redhat.com,
robh@kernel.org, daniel.almeida@collabora.com,
saravanak@google.com, dirk.behme@de.bosch.com, j@jannau.net,
fabien.parent@linaro.org, chrisi.schrefl@gmail.com,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-pci@vger.kernel.org, devicetree@vger.kernel.org,
Wedson Almeida Filho <wedsonaf@gmail.com>
Subject: Re: [PATCH v4 02/13] rust: implement generic driver registration
Date: Fri, 6 Dec 2024 19:13:44 +0100 [thread overview]
Message-ID: <Z1M-2J1wtLwEhz8D@pollux> (raw)
In-Reply-To: <CAH5fLghRVFAb06YYfUbuyuR1pOK0cHzGk6A25c5hX3CyvMm+sw@mail.gmail.com>
On Fri, Dec 06, 2024 at 02:57:19PM +0100, Alice Ryhl wrote:
> On Thu, Dec 5, 2024 at 3:16 PM Danilo Krummrich <dakr@kernel.org> wrote:
> >
> > Implement the generic `Registration` type and the `DriverOps` trait.
> >
> > The `Registration` structure is the common type that represents a driver
> > registration and is typically bound to the lifetime of a module. However,
> > it doesn't implement actual calls to the kernel's driver core to register
> > drivers itself.
> >
> > Instead the `DriverOps` trait is provided to subsystems, which have to
> > implement `DriverOps::register` and `DrvierOps::unregister`. Subsystems
>
> typo
>
> > have to provide an implementation for both of those methods where the
> > subsystem specific variants to register / unregister a driver have to
> > implemented.
> >
> > For instance, the PCI subsystem would call __pci_register_driver() from
> > `DriverOps::register` and pci_unregister_driver() from
> > `DrvierOps::unregister`.
> >
> > Co-developed-by: Wedson Almeida Filho <wedsonaf@gmail.com>
> > Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com>
> > Signed-off-by: Danilo Krummrich <dakr@kernel.org>
>
> [...]
>
> > +/// The [`RegistrationOps`] trait serves as generic interface for subsystems (e.g., PCI, Platform,
> > +/// Amba, etc.) to provide the corresponding subsystem specific implementation to register /
> > +/// unregister a driver of the particular type (`RegType`).
> > +///
> > +/// For instance, the PCI subsystem would set `RegType` to `bindings::pci_driver` and call
> > +/// `bindings::__pci_register_driver` from `RegistrationOps::register` and
> > +/// `bindings::pci_unregister_driver` from `RegistrationOps::unregister`.
> > +pub trait RegistrationOps {
> > + /// The type that holds information about the registration. This is typically a struct defined
> > + /// by the C portion of the kernel.
> > + type RegType: Default;
>
> This Default implementation doesn't seem useful. You initialize it and
I think it is -- `RegType` is always the raw bindings:: type and in
`Registration::new` in `Opaque::try_ffi_init` we call
`ptr.write(T::RegType::default())` for - since `RegType` is a raw bindings::
type - zero initialization.
> then `register` calls a C function to initialize it. Having `register`
> return an `impl PinInit` seems like it would work better here.
This would work as well, but it would effectively move the common code from
`Registration::new` to the bus specific type.
I think it's quite nice that the bus specific code does not need to care about
messing with `try_pin_init`, `Opaque::try_ffi_init`, zero initialization, etc.,
but just needs to assign the relevant fields and call register.
>
> > + /// Registers a driver.
> > + ///
> > + /// On success, `reg` must remain pinned and valid until the matching call to
> > + /// [`RegistrationOps::unregister`].
> > + fn register(
> > + reg: &mut Self::RegType,
>
> If the intent is that RegType is going to be the raw bindings:: type,
> then this isn't going to work because you're creating &mut references
> to the raw type without a Opaque wrapper in between.
True, that seems unsound. Since this is called from when the corresponding
`Opaque` wrapper is created, I think we need to fall back to a raw pointer then
and make `register` and `unregister` unsafe.
I don't think that too big of a deal though, since those two should never be
called from anywhere else than `Registration:new` or `Registration::drop`.
>
> > + name: &'static CStr,
> > + module: &'static ThisModule,
> > + ) -> Result;
> > +
> > + /// Unregisters a driver previously registered with [`RegistrationOps::register`].
> > + fn unregister(reg: &mut Self::RegType);
>
> I believe this handles pinning incorrectly. You can't hand out &mut
> references to pinned values.
Same as above.
>
> Alice
next prev parent reply other threads:[~2024-12-06 18:13 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-05 14:14 [PATCH v4 00/13] Device / Driver PCI / Platform Rust abstractions Danilo Krummrich
2024-12-05 14:14 ` [PATCH v4 01/13] rust: pass module name to `Module::init` Danilo Krummrich
2024-12-05 14:14 ` [PATCH v4 02/13] rust: implement generic driver registration Danilo Krummrich
2024-12-06 13:57 ` Alice Ryhl
2024-12-06 18:13 ` Danilo Krummrich [this message]
2024-12-05 14:14 ` [PATCH v4 03/13] rust: implement `IdArray`, `IdTable` and `RawDeviceId` Danilo Krummrich
2024-12-07 1:14 ` Fabien Parent
2024-12-09 10:45 ` Danilo Krummrich
2024-12-05 14:14 ` [PATCH v4 04/13] rust: add rcu abstraction Danilo Krummrich
2024-12-05 14:14 ` [PATCH v4 05/13] rust: add `Revocable` type Danilo Krummrich
2024-12-06 15:11 ` Alice Ryhl
2024-12-09 10:40 ` Danilo Krummrich
2024-12-05 14:14 ` [PATCH v4 06/13] rust: add `io::{Io, IoRaw}` base types Danilo Krummrich
2024-12-06 14:13 ` Alice Ryhl
2024-12-11 14:52 ` Daniel Almeida
2024-12-05 14:14 ` [PATCH v4 07/13] rust: add devres abstraction Danilo Krummrich
2024-12-05 14:14 ` [PATCH v4 08/13] rust: pci: add basic PCI device / driver abstractions Danilo Krummrich
2024-12-06 14:01 ` Alice Ryhl
2024-12-09 10:44 ` Danilo Krummrich
2024-12-10 10:55 ` Alice Ryhl
2024-12-10 22:38 ` Danilo Krummrich
2024-12-11 13:06 ` Alice Ryhl
2024-12-11 14:32 ` Danilo Krummrich
2024-12-11 14:41 ` Greg KH
2024-12-11 14:42 ` Greg KH
2024-12-11 14:44 ` Alice Ryhl
2024-12-06 15:25 ` Alice Ryhl
2024-12-05 14:14 ` [PATCH v4 09/13] rust: pci: implement I/O mappable `pci::Bar` Danilo Krummrich
2024-12-06 10:44 ` Philipp Stanner
2024-12-05 14:14 ` [PATCH v4 10/13] samples: rust: add Rust PCI sample driver Danilo Krummrich
2024-12-05 14:14 ` [PATCH v4 11/13] rust: of: add `of::DeviceId` abstraction Danilo Krummrich
2024-12-09 21:22 ` Rob Herring
2024-12-05 14:14 ` [PATCH v4 12/13] rust: platform: add basic platform device / driver abstractions Danilo Krummrich
2024-12-09 22:37 ` Rob Herring
2024-12-09 23:13 ` Danilo Krummrich
2024-12-10 7:46 ` Greg KH
2024-12-10 9:34 ` Danilo Krummrich
2024-12-10 9:40 ` Greg KH
2024-12-05 14:14 ` [PATCH v4 13/13] samples: rust: add Rust platform sample driver Danilo Krummrich
2024-12-05 17:09 ` Dirk Behme
2024-12-05 18:03 ` Rob Herring
2024-12-06 6:39 ` Dirk Behme
2024-12-06 8:33 ` Danilo Krummrich
2024-12-06 9:29 ` Dirk Behme
2024-12-10 22:59 ` Rob Herring (Arm)
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=Z1M-2J1wtLwEhz8D@pollux \
--to=dakr@kernel.org \
--cc=a.hindborg@samsung.com \
--cc=airlied@gmail.com \
--cc=ajanulgu@redhat.com \
--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=chrisi.schrefl@gmail.com \
--cc=daniel.almeida@collabora.com \
--cc=devicetree@vger.kernel.org \
--cc=dirk.behme@de.bosch.com \
--cc=fabien.parent@linaro.org \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=j@jannau.net \
--cc=lina@asahilina.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=pstanner@redhat.com \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=saravanak@google.com \
--cc=tmgross@umich.edu \
--cc=wedsonaf@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.