rust/kernel/devres.rs | 27 ++- rust/kernel/faux.rs | 4 +- rust/kernel/miscdevice.rs | 341 ++++++++++++++++++++++--------- rust/kernel/revocable.rs | 7 +- rust/kernel/types.rs | 8 +- samples/rust/Kconfig | 8 + samples/rust/rust_misc_device.rs | 73 +++++-- 7 files changed, 350 insertions(+), 118 deletions(-)
This patch series adds support for device drivers to the misc device abstraction. For design details, please see: * patch 5 "rust: miscdevice: properly support device drivers" * patch 6 "rust: miscdevice: expose the parent device as &Device<Bound>" This patch series depends on the pin-init series from Benno [1] as well as on the misc device series from Christian [2], with UnsafePinned replaced with Opaque, as suggested by Alice, since UnsafePinned may still take a while to land. A branch containing this series and its dependencies can be found in [3]. Thanks to Benno for his great help with pin-init! [1] https://lore.kernel.org/rust-for-linux/20250529081027.297648-1-lossin@kernel.org/ [2] https://lore.kernel.org/lkml/20250517-b4-rust_miscdevice_registrationdata-v3-0-cdb33e228d37@gmail.com/ [3] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/log/?h=rust/misc Danilo Krummrich (7): rust: types: support fallible PinInit types in Opaque::pin_init rust: revocable: support fallible PinInit types rust: devres: support fallible in-place init for data rust: faux: impl AsRef<Device<Bound>> for Registration rust: miscdevice: properly support device drivers rust: miscdevice: expose the parent device as &Device<Bound> rust: sample: misc: implement device driver sample rust/kernel/devres.rs | 27 ++- rust/kernel/faux.rs | 4 +- rust/kernel/miscdevice.rs | 341 ++++++++++++++++++++++--------- rust/kernel/revocable.rs | 7 +- rust/kernel/types.rs | 8 +- samples/rust/Kconfig | 8 + samples/rust/rust_misc_device.rs | 73 +++++-- 7 files changed, 350 insertions(+), 118 deletions(-) base-commit: d5e34ea41dda1500a4dc163d6e96395fe7adc681 -- 2.49.0
On Fri May 30, 2025 at 4:24 PM CEST, Danilo Krummrich wrote: > This patch series adds support for device drivers to the misc device > abstraction. > > For design details, please see: > * patch 5 "rust: miscdevice: properly support device drivers" > * patch 6 "rust: miscdevice: expose the parent device as &Device<Bound>" > > This patch series depends on the pin-init series from Benno [1] as well as on > the misc device series from Christian [2], with UnsafePinned replaced with > Opaque, as suggested by Alice, since UnsafePinned may still take a while to > land. > > A branch containing this series and its dependencies can be found in [3]. > > Thanks to Benno for his great help with pin-init! No problem! I also found it very useful to get some more uses for pin-init. This way future contributors will benefit from the new features :) --- Cheers, Benno
Hi Danilo On 30.05.25 4:24 PM, Danilo Krummrich wrote: > This patch series adds support for device drivers to the misc device > abstraction. > > For design details, please see: > * patch 5 "rust: miscdevice: properly support device drivers" > * patch 6 "rust: miscdevice: expose the parent device as &Device<Bound>" > > This patch series depends on the pin-init series from Benno [1] as well as on > the misc device series from Christian [2], with UnsafePinned replaced with > Opaque, as suggested by Alice, since UnsafePinned may still take a while to > land. If you want I can send out a new version using `Opaque`. We could also add a type alias like: type UnsafePinned<T> = Opaque<T>; That would then be removed in the `UnsafePinned` patches. This should make the migration simpler. Cheers Christian > > A branch containing this series and its dependencies can be found in [3]. > > Thanks to Benno for his great help with pin-init! > > [1] https://lore.kernel.org/rust-for-linux/20250529081027.297648-1-lossin@kernel.org/ > [2] https://lore.kernel.org/lkml/20250517-b4-rust_miscdevice_registrationdata-v3-0-cdb33e228d37@gmail.com/ > [3] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/log/?h=rust/misc > > Danilo Krummrich (7): > rust: types: support fallible PinInit types in Opaque::pin_init > rust: revocable: support fallible PinInit types > rust: devres: support fallible in-place init for data > rust: faux: impl AsRef<Device<Bound>> for Registration > rust: miscdevice: properly support device drivers > rust: miscdevice: expose the parent device as &Device<Bound> > rust: sample: misc: implement device driver sample > > rust/kernel/devres.rs | 27 ++- > rust/kernel/faux.rs | 4 +- > rust/kernel/miscdevice.rs | 341 ++++++++++++++++++++++--------- > rust/kernel/revocable.rs | 7 +- > rust/kernel/types.rs | 8 +- > samples/rust/Kconfig | 8 + > samples/rust/rust_misc_device.rs | 73 +++++-- > 7 files changed, 350 insertions(+), 118 deletions(-) > > > base-commit: d5e34ea41dda1500a4dc163d6e96395fe7adc681
Hi Christian, On Fri, May 30, 2025 at 06:37:29PM +0200, Christian Schrefl wrote: > If you want I can send out a new version using `Opaque`. Sounds good, you can also give me a version that you want me to add to this series, given that in order to use Opaque you also need the Opaque patch of this series. Without you can't pass an impl PinInit<T, Error> to Opaque.
On 30.05.25 6:37 PM, Christian Schrefl wrote: > Hi Danilo > > On 30.05.25 4:24 PM, Danilo Krummrich wrote: >> This patch series adds support for device drivers to the misc device >> abstraction. >> >> For design details, please see: >> * patch 5 "rust: miscdevice: properly support device drivers" >> * patch 6 "rust: miscdevice: expose the parent device as &Device<Bound>" >> >> This patch series depends on the pin-init series from Benno [1] as well as on >> the misc device series from Christian [2], with UnsafePinned replaced with >> Opaque, as suggested by Alice, since UnsafePinned may still take a while to >> land. > > If you want I can send out a new version using `Opaque`. > > We could also add a type alias like: > > type UnsafePinned<T> = Opaque<T>; I forgot that Opaque doesn't drop, this would not be quite as simple, but with a newtype with a `Drop` impl it should be possible. > > That would then be removed in the `UnsafePinned` patches. > This should make the migration simpler. > > Cheers > Christian > >> >> A branch containing this series and its dependencies can be found in [3]. >> >> Thanks to Benno for his great help with pin-init! >> >> [1] https://lore.kernel.org/rust-for-linux/20250529081027.297648-1-lossin@kernel.org/ >> [2] https://lore.kernel.org/lkml/20250517-b4-rust_miscdevice_registrationdata-v3-0-cdb33e228d37@gmail.com/ >> [3] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/log/?h=rust/misc >> >> Danilo Krummrich (7): >> rust: types: support fallible PinInit types in Opaque::pin_init >> rust: revocable: support fallible PinInit types >> rust: devres: support fallible in-place init for data >> rust: faux: impl AsRef<Device<Bound>> for Registration >> rust: miscdevice: properly support device drivers >> rust: miscdevice: expose the parent device as &Device<Bound> >> rust: sample: misc: implement device driver sample >> >> rust/kernel/devres.rs | 27 ++- >> rust/kernel/faux.rs | 4 +- >> rust/kernel/miscdevice.rs | 341 ++++++++++++++++++++++--------- >> rust/kernel/revocable.rs | 7 +- >> rust/kernel/types.rs | 8 +- >> samples/rust/Kconfig | 8 + >> samples/rust/rust_misc_device.rs | 73 +++++-- >> 7 files changed, 350 insertions(+), 118 deletions(-) >> >> >> base-commit: d5e34ea41dda1500a4dc163d6e96395fe7adc681 >
On Fri May 30, 2025 at 7:29 PM CEST, Christian Schrefl wrote: > On 30.05.25 6:37 PM, Christian Schrefl wrote: >> On 30.05.25 4:24 PM, Danilo Krummrich wrote: >>> This patch series adds support for device drivers to the misc device >>> abstraction. >>> >>> For design details, please see: >>> * patch 5 "rust: miscdevice: properly support device drivers" >>> * patch 6 "rust: miscdevice: expose the parent device as &Device<Bound>" >>> >>> This patch series depends on the pin-init series from Benno [1] as well as on >>> the misc device series from Christian [2], with UnsafePinned replaced with >>> Opaque, as suggested by Alice, since UnsafePinned may still take a while to >>> land. >> >> If you want I can send out a new version using `Opaque`. >> >> We could also add a type alias like: >> >> type UnsafePinned<T> = Opaque<T>; > > I forgot that Opaque doesn't drop, this would not be quite as simple, > but with a newtype with a `Drop` impl it should be possible. That's one issue another is that `Opaque` also allows uninitialized memory and (if the upstream one isn't changed) also modifies the behavior of shared references. I don't think we should name it `UnsafePinned` if it doesn't guarantee the same thing as the upstream one. --- Cheers, Benno
On Fri, May 30, 2025 at 09:24:28PM +0200, Benno Lossin wrote: > On Fri May 30, 2025 at 7:29 PM CEST, Christian Schrefl wrote: > > On 30.05.25 6:37 PM, Christian Schrefl wrote: > >> On 30.05.25 4:24 PM, Danilo Krummrich wrote: > >>> This patch series adds support for device drivers to the misc device > >>> abstraction. > >>> > >>> For design details, please see: > >>> * patch 5 "rust: miscdevice: properly support device drivers" > >>> * patch 6 "rust: miscdevice: expose the parent device as &Device<Bound>" > >>> > >>> This patch series depends on the pin-init series from Benno [1] as well as on > >>> the misc device series from Christian [2], with UnsafePinned replaced with > >>> Opaque, as suggested by Alice, since UnsafePinned may still take a while to > >>> land. Maybe I'm missing something, but don't we have our own version of `UnsafePinned` [1] which can be replaced once Rust upstream has the `UnsafePinned` stabilized. I don't see any discussion about abandoning that effort. Regards, Boqun > >> > >> If you want I can send out a new version using `Opaque`. > >> > >> We could also add a type alias like: > >> > >> type UnsafePinned<T> = Opaque<T>; > > > > I forgot that Opaque doesn't drop, this would not be quite as simple, > > but with a newtype with a `Drop` impl it should be possible. > > That's one issue another is that `Opaque` also allows uninitialized > memory and (if the upstream one isn't changed) also modifies the > behavior of shared references. I don't think we should name it > `UnsafePinned` if it doesn't guarantee the same thing as the upstream > one. > > --- > Cheers, > Benno
On Fri, May 30, 2025 at 12:35:21PM -0700, Boqun Feng wrote: > On Fri, May 30, 2025 at 09:24:28PM +0200, Benno Lossin wrote: > > On Fri May 30, 2025 at 7:29 PM CEST, Christian Schrefl wrote: > > > On 30.05.25 6:37 PM, Christian Schrefl wrote: > > >> On 30.05.25 4:24 PM, Danilo Krummrich wrote: > > >>> This patch series adds support for device drivers to the misc device > > >>> abstraction. > > >>> > > >>> For design details, please see: > > >>> * patch 5 "rust: miscdevice: properly support device drivers" > > >>> * patch 6 "rust: miscdevice: expose the parent device as &Device<Bound>" > > >>> > > >>> This patch series depends on the pin-init series from Benno [1] as well as on > > >>> the misc device series from Christian [2], with UnsafePinned replaced with > > >>> Opaque, as suggested by Alice, since UnsafePinned may still take a while to > > >>> land. > > Maybe I'm missing something, but don't we have our own version of > `UnsafePinned` [1] which can be replaced once Rust upstream has the > `UnsafePinned` stabilized. I don't see any discussion about abandoning > that effort. > Missing the link.. [1]: https://lore.kernel.org/rust-for-linux/20250430-rust_unsafe_pinned-v2-0-fc8617a74024@gmail.com/ > Regards, > Boqun > > > >> > > >> If you want I can send out a new version using `Opaque`. > > >> > > >> We could also add a type alias like: > > >> > > >> type UnsafePinned<T> = Opaque<T>; > > > > > > I forgot that Opaque doesn't drop, this would not be quite as simple, > > > but with a newtype with a `Drop` impl it should be possible. > > > > That's one issue another is that `Opaque` also allows uninitialized > > memory and (if the upstream one isn't changed) also modifies the > > behavior of shared references. I don't think we should name it > > `UnsafePinned` if it doesn't guarantee the same thing as the upstream > > one. > > > > --- > > Cheers, > > Benno
© 2016 - 2025 Red Hat, Inc.