mbox series

[0/3] Miscdevices in Rust

Message ID 20240926-b4-miscdevice-v1-0-7349c2b2837a@google.com (mailing list archive)
Headers show
Series Miscdevices in Rust | expand

Message

Alice Ryhl Sept. 26, 2024, 2:58 p.m. UTC
A misc device is generally the best place to start with your first Rust
driver, so having abstractions for miscdevice in Rust will be important
for our ability to teach Rust to kernel developers.

I intend to add a sample driver using these abstractions, and I also
intend to use it in Rust Binder to handle the case where binderfs is
turned off.

I know that the patchset is still a bit rough. It could use some work on
the file position aspect. But I'm sending this out now to get feedback
on the overall approach.

This patchset depends on files [1] and vma [2].

Link: https://lore.kernel.org/all/20240915-alice-file-v10-0-88484f7a3dcf@google.com/ [1]
Link: https://lore.kernel.org/all/20240806-vma-v5-1-04018f05de2b@google.com/ [2]
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
Alice Ryhl (3):
      rust: types: add Opaque::try_ffi_init
      rust: file: add f_pos and set_f_pos
      rust: miscdevice: add abstraction for defining miscdevices

 rust/bindings/bindings_helper.h |   1 +
 rust/kernel/fs/file.rs          |  20 ++
 rust/kernel/lib.rs              |   1 +
 rust/kernel/miscdevice.rs       | 401 ++++++++++++++++++++++++++++++++++++++++
 rust/kernel/types.rs            |  16 ++
 5 files changed, 439 insertions(+)
---
base-commit: a6266fcab443f4b6ae31016bd6c3872f8200d5e1
change-id: 20240926-b4-miscdevice-29a0fd8438b1

Best regards,

Comments

Greg KH Sept. 26, 2024, 3:05 p.m. UTC | #1
On Thu, Sep 26, 2024 at 02:58:54PM +0000, Alice Ryhl wrote:
> A misc device is generally the best place to start with your first Rust
> driver, so having abstractions for miscdevice in Rust will be important
> for our ability to teach Rust to kernel developers.
> 
> I intend to add a sample driver using these abstractions, and I also
> intend to use it in Rust Binder to handle the case where binderfs is
> turned off.
> 
> I know that the patchset is still a bit rough. It could use some work on
> the file position aspect. But I'm sending this out now to get feedback
> on the overall approach.

Very cool!

> This patchset depends on files [1] and vma [2].
>
> Link: https://lore.kernel.org/all/20240915-alice-file-v10-0-88484f7a3dcf@google.com/ [1]
> Link: https://lore.kernel.org/all/20240806-vma-v5-1-04018f05de2b@google.com/ [2]
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>

Does it really need all of those dependencies?  I know your development
stack is deep here, but maybe I can unwind a bit of the file stuff to
get this in for the next merge window (6.13-rc1) if those two aren't
going to be planned for there.

I'll look into this some more next week, thanks!

greg k-h
Miguel Ojeda Sept. 26, 2024, 3:11 p.m. UTC | #2
On Thu, Sep 26, 2024 at 5:05 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> stack is deep here, but maybe I can unwind a bit of the file stuff to
> get this in for the next merge window (6.13-rc1) if those two aren't
> going to be planned for there.

I think Christian wanted to merge the file abstractions in 6.13, he
has them here:

    https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git/log/?h=vfs.rust.file

Cheers,
Miguel
Alice Ryhl Sept. 26, 2024, 3:20 p.m. UTC | #3
On Thu, Sep 26, 2024 at 5:05 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Thu, Sep 26, 2024 at 02:58:54PM +0000, Alice Ryhl wrote:
> > A misc device is generally the best place to start with your first Rust
> > driver, so having abstractions for miscdevice in Rust will be important
> > for our ability to teach Rust to kernel developers.
> >
> > I intend to add a sample driver using these abstractions, and I also
> > intend to use it in Rust Binder to handle the case where binderfs is
> > turned off.
> >
> > I know that the patchset is still a bit rough. It could use some work on
> > the file position aspect. But I'm sending this out now to get feedback
> > on the overall approach.
>
> Very cool!
>
> > This patchset depends on files [1] and vma [2].
> >
> > Link: https://lore.kernel.org/all/20240915-alice-file-v10-0-88484f7a3dcf@google.com/ [1]
> > Link: https://lore.kernel.org/all/20240806-vma-v5-1-04018f05de2b@google.com/ [2]
> > Signed-off-by: Alice Ryhl <aliceryhl@google.com>
>
> Does it really need all of those dependencies?  I know your development
> stack is deep here, but maybe I can unwind a bit of the file stuff to
> get this in for the next merge window (6.13-rc1) if those two aren't
> going to be planned for there.

Ah, maybe not. The dependency on files is necessary to allow the file
to look at its own fields, e.g. whether O_NONBLOCK is set or what the
file position is. But we can take that out for now and add it once
both miscdevice and file have landed. I'm hoping that file will land
for 6.13, but untangling them allows both to land in 6.13.

As for vma, it's needed for mmap, but if I take out the ability to
define an mmap operation, I don't need it. We can always add back mmap
once both miscdevice and vma have landed.

Thank you for the suggestion on untangling the dependencies.

> I'll look into this some more next week, thanks!

Thanks!

Alice
Greg KH Sept. 26, 2024, 3:36 p.m. UTC | #4
On Thu, Sep 26, 2024 at 05:20:15PM +0200, Alice Ryhl wrote:
> On Thu, Sep 26, 2024 at 5:05 PM Greg Kroah-Hartman
> <gregkh@linuxfoundation.org> wrote:
> >
> > On Thu, Sep 26, 2024 at 02:58:54PM +0000, Alice Ryhl wrote:
> > > A misc device is generally the best place to start with your first Rust
> > > driver, so having abstractions for miscdevice in Rust will be important
> > > for our ability to teach Rust to kernel developers.
> > >
> > > I intend to add a sample driver using these abstractions, and I also
> > > intend to use it in Rust Binder to handle the case where binderfs is
> > > turned off.
> > >
> > > I know that the patchset is still a bit rough. It could use some work on
> > > the file position aspect. But I'm sending this out now to get feedback
> > > on the overall approach.
> >
> > Very cool!
> >
> > > This patchset depends on files [1] and vma [2].
> > >
> > > Link: https://lore.kernel.org/all/20240915-alice-file-v10-0-88484f7a3dcf@google.com/ [1]
> > > Link: https://lore.kernel.org/all/20240806-vma-v5-1-04018f05de2b@google.com/ [2]
> > > Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> >
> > Does it really need all of those dependencies?  I know your development
> > stack is deep here, but maybe I can unwind a bit of the file stuff to
> > get this in for the next merge window (6.13-rc1) if those two aren't
> > going to be planned for there.
> 
> Ah, maybe not. The dependency on files is necessary to allow the file
> to look at its own fields, e.g. whether O_NONBLOCK is set or what the
> file position is. But we can take that out for now and add it once
> both miscdevice and file have landed. I'm hoping that file will land
> for 6.13, but untangling them allows both to land in 6.13.
> 
> As for vma, it's needed for mmap, but if I take out the ability to
> define an mmap operation, I don't need it. We can always add back mmap
> once both miscdevice and vma have landed.

Yes, let's drop the mmap interface for now, and probably the seek stuff
too as most "normal" misc devices do not mess with them at all.

If that makes the dependencies simpler, that would be great.

thanks,

greg k-h
Benno Lossin Sept. 26, 2024, 6:58 p.m. UTC | #5
On 26.09.24 16:58, Alice Ryhl wrote:
> A misc device is generally the best place to start with your first Rust
> driver, so having abstractions for miscdevice in Rust will be important
> for our ability to teach Rust to kernel developers.

Sounds good!

> I intend to add a sample driver using these abstractions, and I also
> intend to use it in Rust Binder to handle the case where binderfs is
> turned off.
> 
> I know that the patchset is still a bit rough. It could use some work on
> the file position aspect. But I'm sending this out now to get feedback
> on the overall approach.
> 
> This patchset depends on files [1] and vma [2].
> 
> Link: https://lore.kernel.org/all/20240915-alice-file-v10-0-88484f7a3dcf@google.com/ [1]
> Link: https://lore.kernel.org/all/20240806-vma-v5-1-04018f05de2b@google.com/ [2]
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
> Alice Ryhl (3):
>       rust: types: add Opaque::try_ffi_init
>       rust: file: add f_pos and set_f_pos
>       rust: miscdevice: add abstraction for defining miscdevices

I recall that we had a sample miscdev driver in the old rust branch. Can
you include that in this series, or is there still some stuff missing? I
think it would be really useful for people that want to implement such a
driver to have something to look at.

---
Cheers,
Benno
Greg KH Sept. 27, 2024, 6:04 a.m. UTC | #6
On Thu, Sep 26, 2024 at 06:58:10PM +0000, Benno Lossin wrote:
> On 26.09.24 16:58, Alice Ryhl wrote:
> > A misc device is generally the best place to start with your first Rust
> > driver, so having abstractions for miscdevice in Rust will be important
> > for our ability to teach Rust to kernel developers.
> 
> Sounds good!
> 
> > I intend to add a sample driver using these abstractions, and I also
> > intend to use it in Rust Binder to handle the case where binderfs is
> > turned off.
> > 
> > I know that the patchset is still a bit rough. It could use some work on
> > the file position aspect. But I'm sending this out now to get feedback
> > on the overall approach.
> > 
> > This patchset depends on files [1] and vma [2].
> > 
> > Link: https://lore.kernel.org/all/20240915-alice-file-v10-0-88484f7a3dcf@google.com/ [1]
> > Link: https://lore.kernel.org/all/20240806-vma-v5-1-04018f05de2b@google.com/ [2]
> > Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> > ---
> > Alice Ryhl (3):
> >       rust: types: add Opaque::try_ffi_init
> >       rust: file: add f_pos and set_f_pos
> >       rust: miscdevice: add abstraction for defining miscdevices
> 
> I recall that we had a sample miscdev driver in the old rust branch. Can
> you include that in this series, or is there still some stuff missing? I
> think it would be really useful for people that want to implement such a
> driver to have something to look at.

I agree, I'll dig that up after -rc1 is out and add it to this series.

thanks,

greg k-h