Skip to contentSkip to conversation

Miscdevices in Rust

PATCH Superseded Alice Ryhl 7 participants 19 messages Sep 26, 2024 – Oct 1, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Alice Ryhl

author reviewer
#0 lore raw

cover Miscdevices in Rust

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].

---
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,

Signature · 1 line
Alice Ryhl <[email protected]>
author reviewer
#1 lore raw

PATCH 1/3 rust: types: add Opaque::try_ffi_init

This will be used by the miscdevice abstractions, as the C function misc_register is fallible.

---
 rust/kernel/types.rs | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
rust/kernel/types.rs +16 -0
index 3238ffaab031..dd9c606c515c 100644
@@ -299,6 +299,22 @@ pub fn ffi_init(init_func: impl FnOnce(*mut T)) -> impl PinInit<Self> {
         }
     }
 
+    /// Creates a fallible pin-initializer from the given initializer closure.
+    ///
+    /// The returned initializer calls the given closure with the pointer to the inner `T` of this
+    /// `Opaque`. Since this memory is uninitialized, the closure is not allowed to read from it.
+    ///
+    /// This function is safe, because the `T` inside of an `Opaque` is allowed to be
+    /// uninitialized. Additionally, access to the inner `T` requires `unsafe`, so the caller needs
+    /// to verify at that point that the inner value is valid.
+    pub fn try_ffi_init<E>(
+        init_func: impl FnOnce(*mut T) -> Result<(), E>,
+    ) -> impl PinInit<Self, E> {
+        // SAFETY: We contain a `MaybeUninit`, so it is OK for the `init_func` to not fully
+        // initialize the `T`.
+        unsafe { init::pin_init_from_closure::<_, E>(move |slot| init_func(Self::raw_get(slot))) }
+    }
+
     /// Returns a raw pointer to the opaque data.
     pub const fn get(&self) -> *mut T {
         UnsafeCell::get(&self.value).cast::<T>()
Signature · 1 line
2.46.0.792.g87dc391469-goog
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] rust: types: add Opaque::try_ffi_init

Quoted 5 lines · Alice Ryhl

This will be used by the miscdevice abstractions, as the C function misc_register is fallible.

---

Quoted 33 lines
 rust/kernel/types.rs | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
rust/kernel/types.rs +16 -0
index 3238ffaab031..dd9c606c515c 100644
@@ -299,6 +299,22 @@ pub fn ffi_init(init_func: impl FnOnce(*mut T)) -> impl PinInit<Self> {
         }
     }
 
+    /// Creates a fallible pin-initializer from the given initializer closure.
+    ///
+    /// The returned initializer calls the given closure with the pointer to the inner `T` of this
+    /// `Opaque`. Since this memory is uninitialized, the closure is not allowed to read from it.
+    ///
+    /// This function is safe, because the `T` inside of an `Opaque` is allowed to be
+    /// uninitialized. Additionally, access to the inner `T` requires `unsafe`, so the caller needs
+    /// to verify at that point that the inner value is valid.
+    pub fn try_ffi_init<E>(
+        init_func: impl FnOnce(*mut T) -> Result<(), E>,
+    ) -> impl PinInit<Self, E> {
+        // SAFETY: We contain a `MaybeUninit`, so it is OK for the `init_func` to not fully
+        // initialize the `T`.
+        unsafe { init::pin_init_from_closure::<_, E>(move |slot| init_func(Self::raw_get(slot))) }
+    }
+
     /// Returns a raw pointer to the opaque data.
     pub const fn get(&self) -> *mut T {
         UnsafeCell::get(&self.value).cast::<T>()
Signature · 2 lines
-- 
2.46.0.792.g87dc391469-goog
author reviewer
#3 lore raw

PATCH 2/3 rust: file: add f_pos and set_f_pos

In reply to Alice Ryhl

Add accessors for the file position. Most of the time, you should not use these methods directly, and you should instead use a guard for the file position to prove that you hold the fpos lock. However, under limited circumstances, files are allowed to choose a different locking strategy for their file position. These accessors can be used to handle that case.

For now, these accessors are the only way to access the file position within the llseek and read_iter callbacks.

---
 rust/kernel/fs/file.rs | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
rust/kernel/fs/file.rs +20 -0
index e03dbe14d62a..c896a3b1d182 100644
@@ -333,6 +333,26 @@ pub fn flags(&self) -> u32 {
         // FIXME(read_once): Replace with `read_once` when available on the Rust side.
         unsafe { core::ptr::addr_of!((*self.as_ptr()).f_flags).read_volatile() }
     }
+
+    /// Read the file position.
+    ///
+    /// # Safety
+    ///
+    /// You must hold the fpos lock or otherwise ensure that no data race will happen.
+    #[inline]
+    pub unsafe fn f_pos(&self) -> i64 {
+        unsafe { (*self.as_ptr()).f_pos }
+    }
+
+    /// Set the file position.
+    ///
+    /// # Safety
+    ///
+    /// You must hold the fpos lock or otherwise ensure that no data race will happen.
+    #[inline]
+    pub unsafe fn set_f_pos(&self, value: i64) {
+        unsafe { (*self.as_ptr()).f_pos = value };
+    }
 }
 
 impl File {
Signature · 1 line
2.46.0.792.g87dc391469-goog
maintainer
#4 lore raw

Re: [PATCH 2/3] rust: file: add f_pos and set_f_pos

Quoted 9 lines · Alice Ryhl

Add accessors for the file position. Most of the time, you should not use these methods directly, and you should instead use a guard for the file position to prove that you hold the fpos lock. However, under limited circumstances, files are allowed to choose a different locking strategy for their file position. These accessors can be used to handle that case.

For now, these accessors are the only way to access the file position within the llseek and read_iter callbacks.

You really should not do that within ->read_iter(). If your method does that, it has the wrong signature.

If nothing else, it should be usable for preadv(2), so what file position are you talking about?

maintainer
#5 lore raw

Re: [PATCH 2/3] rust: file: add f_pos and set_f_pos

Quoted 8 lines · Al Viro
Quoted 7 lines · Alice Ryhl

Add accessors for the file position. Most of the time, you should not use these methods directly, and you should instead use a guard for the file position to prove that you hold the fpos lock. However, under limited circumstances, files are allowed to choose a different locking strategy for their file position. These accessors can be used to handle that case.

Quoted 8 lines
Quoted 2 lines

For now, these accessors are the only way to access the file position within the llseek and read_iter callbacks.

You really should not do that within ->read_iter(). If your method does that, it has the wrong signature.

If nothing else, it should be usable for preadv(2), so what file position are you talking about?

To elaborate: ->llseek() is the only method that has any business accessing ->f_pos (and that - possibly not forever). Note, BTW, that most of the time ->llseek() should be using one of the safe instances from fs/libfs.c or helpers from the same place; direct ->f_pos access in drivers is basically for things like
static loff_t cfam_llseek(struct file *file, loff_t offset, int whence)

{
        switch (whence) {
	case SEEK_CUR:
		break;
	case SEEK_SET:
		file->f_pos = offset;
		break;
	default:
		return -EINVAL;
	}

	return offset;
}

which is... really special. Translation: lseek(fd, n, SEEK_CUR) - return n and do nothing. lseek(fd, n, SEEK_SET) - usual semantics. Anything else
- fail with EINVAL. The mind-boggling part is SEEK_CUR, but that's userland ABI of that particular driver; if the authors can be convinced that we don't need to preserve that wart, it can be replaced with use of no_seek_end_llseek. If their very special userland relies upon it... not much we can do.

Anything else outside of core VFS should not touch the damn thing, unless they have a very good reason and are willing to explain what makes them special.

From quick grep through the tree, we seem to have grown a bunch of bogosities in vfio (including one in samples, presumably responsible for that infestation), there's a few strange ioctls that reset it to 0 or do other unnatural things (hell, VFAT has readdir() variant called that way), there are _really_ shitty cases in HFS, HFS+ and HPFS, where things like unlink() while somebody has the parent directory open will modify the current position(s), and then there's whatever ksmbd is playing at.

We really should not expose ->f_pos - that can't be done on the C side (yet), but let's not spread that idiocy.

maintainer
#6 lore raw

Re: [PATCH 2/3] rust: file: add f_pos and set_f_pos

Quoted 1 line · Al Viro

time ->llseek() should be using one of the safe instances from fs/libfs.c

d'oh... s/libfs.c/read_write.c/ - sorry.

author reviewer
#7 lore raw

Re: [PATCH 2/3] rust: file: add f_pos and set_f_pos

In reply to Al Viro
Quoted 58 lines · Al Viro
Quoted 8 lines · Al Viro
Quoted 7 lines · Alice Ryhl

Add accessors for the file position. Most of the time, you should not use these methods directly, and you should instead use a guard for the file position to prove that you hold the fpos lock. However, under limited circumstances, files are allowed to choose a different locking strategy for their file position. These accessors can be used to handle that case.

Quoted 8 lines
Quoted 2 lines

For now, these accessors are the only way to access the file position within the llseek and read_iter callbacks.

You really should not do that within ->read_iter(). If your method does that, it has the wrong signature.

If nothing else, it should be usable for preadv(2), so what file position are you talking about?

To elaborate: ->llseek() is the only method that has any business accessing ->f_pos (and that - possibly not forever). Note, BTW, that most of the time ->llseek() should be using one of the safe instances from fs/libfs.c or helpers from the same place; direct ->f_pos access in drivers is basically for things like
static loff_t cfam_llseek(struct file *file, loff_t offset, int whence)

{
        switch (whence) {
        case SEEK_CUR:
                break;
        case SEEK_SET:
                file->f_pos = offset;
                break;
        default:
                return -EINVAL;
        }

        return offset;
}

which is... really special. Translation: lseek(fd, n, SEEK_CUR) - return n and do nothing. lseek(fd, n, SEEK_SET) - usual semantics. Anything else
- fail with EINVAL. The mind-boggling part is SEEK_CUR, but that's userland ABI of that particular driver; if the authors can be convinced that we don't need to preserve that wart, it can be replaced with use of no_seek_end_llseek. If their very special userland relies upon it... not much we can do.

Anything else outside of core VFS should not touch the damn thing, unless they have a very good reason and are willing to explain what makes them special.

From quick grep through the tree, we seem to have grown a bunch of bogosities in vfio (including one in samples, presumably responsible for that infestation), there's a few strange ioctls that reset it to 0 or do other unnatural things (hell, VFAT has readdir() variant called that way), there are _really_ shitty cases in HFS, HFS+ and HPFS, where things like unlink() while somebody has the parent directory open will modify the current position(s), and then there's whatever ksmbd is playing at.

Quoted 2 lines

We really should not expose ->f_pos - that can't be done on the C side (yet), but let's not spread that idiocy.

Okay, interesting. I did not know about all of these llseek helpers. I'm definitely happy to make the Rust API force users to do the right thing if we can.

It sounds like we basically have a few different seeking behaviors that the driver can choose between, and we want to force the user to use one of them?

Alice

maintainer
#8 lore raw

Re: [PATCH 2/3] rust: file: add f_pos and set_f_pos

Quoted 7 lines · Alice Ryhl

Okay, interesting. I did not know about all of these llseek helpers. I'm definitely happy to make the Rust API force users to do the right thing if we can.

It sounds like we basically have a few different seeking behaviors that the driver can choose between, and we want to force the user to use one of them?

Depends... Basically, SEEK_HOLE/SEEK_DATA is seriously fs-specific (unsurprisingly), and pretty much everything wants the usual relation between SEEK_SET and SEEK_CUR (<SEEK_CUR,n> is the same as <SEEK_SET, current position + n>). SEEK_END availability varies - the simplest variant is <SEEK_END, n> == <SEEK_SET, size + n>, but there are cases that genuinely have nothing resembling end-relative seek (e.g. anything seq_file-related).

It's not so much available instances as available helpers; details of semantics may seriously vary by the driver.

Note that once upon a time ->f_pos had been exposed to ->read() et.al.; caused recurring bugs, until we switched to "sample ->f_pos before calling ->read(), pass the reference to local copy into the method, then put what's the method left behind in there back into ->f_pos".

Something similar might be a good idea for ->llseek(). Locking is an unpleasant problem, unfortunately. lseek() is not a terribly hot codepath, but read() and write() are. For a while we used to do exclusion on per-struct file basis for _all_ read/write/lseek; see 797964253d35 "file: reinstate f_pos locking optimization for regular files" for the point where it eroded.

FWIW, I suspect that unconditionally taking ->f_pos_mutex for llseek(2) would solve most of the problems - for one thing, with guaranteed per-struct-file serialization of vfs_llseek() we could handle SEEK_CUR right there, so that ->llseek() instances would never see it; for another, we just might be able to pull the same 'pass a reference to local variable and let it be handled there' trick for ->llseek(). That would require an audit of locking in the instances, though...

author reviewer
#9 lore raw

Re: [PATCH 2/3] rust: file: add f_pos and set_f_pos

Quoted 34 lines · Al Viro
Quoted 7 lines · Alice Ryhl

Okay, interesting. I did not know about all of these llseek helpers. I'm definitely happy to make the Rust API force users to do the right thing if we can.

It sounds like we basically have a few different seeking behaviors that the driver can choose between, and we want to force the user to use one of them?

Depends... Basically, SEEK_HOLE/SEEK_DATA is seriously fs-specific (unsurprisingly), and pretty much everything wants the usual relation between SEEK_SET and SEEK_CUR (<SEEK_CUR,n> is the same as <SEEK_SET, current position + n>). SEEK_END availability varies - the simplest variant is <SEEK_END, n> == <SEEK_SET, size + n>, but there are cases that genuinely have nothing resembling end-relative seek (e.g. anything seq_file-related).

It's not so much available instances as available helpers; details of semantics may seriously vary by the driver.

Note that once upon a time ->f_pos had been exposed to ->read() et.al.; caused recurring bugs, until we switched to "sample ->f_pos before calling ->read(), pass the reference to local copy into the method, then put what's the method left behind in there back into ->f_pos".

Something similar might be a good idea for ->llseek(). Locking is an unpleasant problem, unfortunately. lseek() is not a terribly hot codepath, but read() and write() are. For a while we used to do exclusion on per-struct file basis for _all_ read/write/lseek; see 797964253d35 "file: reinstate f_pos locking optimization for regular files" for the point where it eroded.

Quoted 7 lines

FWIW, I suspect that unconditionally taking ->f_pos_mutex for llseek(2) would solve most of the problems - for one thing, with guaranteed per-struct-file serialization of vfs_llseek() we could handle SEEK_CUR right there, so that ->llseek() instances would never see it; for another, we just might be able to pull the same 'pass a reference to local variable and let it be handled there' trick for ->llseek(). That would require an audit of locking in the instances, though...

Okay, thanks for the explanation. The file position stuff seems pretty complicated.

One thing to think about is whether there are some behaviors used by old drivers that new drivers should not use. We can design our Rust APIs to prevent using it in those legacy ways.

For now I'm dropping this patch from the series at Greg's request.

Alice

author reviewer
#10 lore raw

Re: [PATCH 2/3] rust: file: add f_pos and set_f_pos

In reply to Al Viro
Quoted 9 lines · Al Viro
Quoted 7 lines · Alice Ryhl

Add accessors for the file position. Most of the time, you should not use these methods directly, and you should instead use a guard for the file position to prove that you hold the fpos lock. However, under limited circumstances, files are allowed to choose a different locking strategy for their file position. These accessors can be used to handle that case.

Quoted 8 lines
Quoted 2 lines

For now, these accessors are the only way to access the file position within the llseek and read_iter callbacks.

You really should not do that within ->read_iter(). If your method does that, it has the wrong signature.

If nothing else, it should be usable for preadv(2), so what file position are you talking about?

Sorry, you are right. In read_iter we can access the file position via the kiocb. It only makes sense for seek.

Alice

#11 lore raw

Re: [PATCH 2/3] rust: file: add f_pos and set_f_pos

In reply to Alice Ryhl
Quoted 33 lines · Alice Ryhl

Add accessors for the file position. Most of the time, you should not use these methods directly, and you should instead use a guard for the file position to prove that you hold the fpos lock. However, under limited circumstances, files are allowed to choose a different locking strategy for their file position. These accessors can be used to handle that case.

For now, these accessors are the only way to access the file position within the llseek and read_iter callbacks.

---
 rust/kernel/fs/file.rs | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
rust/kernel/fs/file.rs +10 -0
index e03dbe14d62a..c896a3b1d182 100644
@@ -333,6 +333,26 @@ pub fn flags(&self) -> u32 {
         // FIXME(read_once): Replace with `read_once` when available on the Rust side.
         unsafe { core::ptr::addr_of!((*self.as_ptr()).f_flags).read_volatile() }
     }
+
+    /// Read the file position.
+    ///
+    /// # Safety
+    ///
+    /// You must hold the fpos lock or otherwise ensure that no data race will happen.
+    #[inline]
+    pub unsafe fn f_pos(&self) -> i64 {
+        unsafe { (*self.as_ptr()).f_pos }
+    }

rust/kernel/fs/file.rs pub fn flags(&self) -> u32 { · line 355

Quoted 10 lines
rust/kernel/fs/file.rs +10 -0
+
+    /// Set the file position.
+    ///
+    /// # Safety
+    ///
+    /// You must hold the fpos lock or otherwise ensure that no data race will happen.
+    #[inline]
+    pub unsafe fn set_f_pos(&self, value: i64) {
+        unsafe { (*self.as_ptr()).f_pos = value };
+    }

I don't think we want to expose f_pos with its weird locking rule through rust wrappers. Ideally, it's completely opaque to the callers and not accessed directly at all.

author reviewer
#12 lore raw

PATCH 3/3 rust: miscdevice: add abstraction for defining miscdevices

In reply to Alice Ryhl

Provide a MiscDevice trait that lets you specify the file operations that you wish to provide for your misc device. Most operations are optional.

In the future, the file operations in the MiscDevice can be moved to a general FileOperations trait so that it is useful for other file systems too.

---
 rust/bindings/bindings_helper.h |   1 +
 rust/kernel/lib.rs              |   1 +
 rust/kernel/miscdevice.rs       | 401 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 403 insertions(+)
rust/bindings/bindings_helper.h +1 -0
index ca13659ded4c..ec2e28ef6568 100644
@@ -18,6 +18,7 @@
 #include <linux/fs.h>
 #include <linux/jiffies.h>
 #include <linux/mdio.h>
+#include <linux/miscdevice.h>
 #include <linux/phy.h>
 #include <linux/pid_namespace.h>
 #include <linux/poll.h>
rust/kernel/lib.rs +1 -0
index 819126fc2d89..bf97817842c9 100644
@@ -41,6 +41,7 @@
 #[cfg(CONFIG_KUNIT)]
 pub mod kunit;
 pub mod list;
+pub mod miscdevice;
 pub mod mm;
 #[cfg(CONFIG_NET)]
 pub mod net;
rust/kernel/miscdevice.rs new file +401 -0

401 lines not on this page · raw message

Signature · 1 line
2.46.0.792.g87dc391469-goog
#13 lore raw
In reply to Alice Ryhl
Quoted 11 lines · Alice Ryhl

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!

Quoted 5 lines

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

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

author reviewer
#15 lore raw
In reply to Greg Kroah-Hartman
Quoted 18 lines · Greg Kroah-Hartman
Quoted 11 lines · Alice Ryhl

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!

Quoted 2 lines

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

Quoted 8 lines
Quoted 3 lines

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.

Quoted 1 line

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

Thanks!

Alice

#16 lore raw
Quoted 35 lines · Alice Ryhl
Quoted 18 lines · Greg Kroah-Hartman
Quoted 11 lines · Alice Ryhl

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!

Quoted 2 lines

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

Quoted 8 lines
Quoted 3 lines

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.

Quoted 3 lines

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

#17 lore raw
In reply to Alice Ryhl
Quoted 3 lines · Alice Ryhl

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!

Quoted 10 lines

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].

Quoted 8 lines

---
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

#18 lore raw
Quoted 26 lines · Benno Lossin
Quoted 3 lines · Alice Ryhl

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!

Quoted 10 lines

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].

Quoted 8 lines

---
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

Quoted 4 lines

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