[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8734b5lgm9.fsf@kernel.org>
Date: Wed, 09 Jul 2025 13:59:26 +0200
From: Andreas Hindborg <a.hindborg@...nel.org>
To: "Alice Ryhl" <aliceryhl@...gle.com>
Cc: "Greg Kroah-Hartman" <gregkh@...uxfoundation.org>, "Alexander Viro"
<viro@...iv.linux.org.uk>, "Arnd Bergmann" <arnd@...db.de>, "Miguel
Ojeda" <ojeda@...nel.org>, "Boqun Feng" <boqun.feng@...il.com>, "Gary
Guo" <gary@...yguo.net>, Björn Roy Baron
<bjorn3_gh@...tonmail.com>,
"Trevor Gross" <tmgross@...ch.edu>, "Danilo Krummrich"
<dakr@...nel.org>, "Matthew Maurer" <mmaurer@...gle.com>, "Lee Jones"
<lee@...nel.org>, <linux-kernel@...r.kernel.org>,
<rust-for-linux@...r.kernel.org>, "Benno Lossin" <lossin@...nel.org>
Subject: Re: [PATCH v2 3/4] rust: miscdevice: Provide additional
abstractions for iov_iter and kiocb structures
"Alice Ryhl" <aliceryhl@...gle.com> writes:
> On Tue, Jul 08, 2025 at 04:53:23PM +0200, Andreas Hindborg wrote:
>> "Alice Ryhl" <aliceryhl@...gle.com> writes:
>>
>> > These will be used for the read_iter() and write_iter() callbacks, which
>> > are now the preferred back-ends for when a user operates on a char device
>> > with read() and write() respectively.
>> >
>> > Co-developed-by: Lee Jones <lee@...nel.org>
>> > Signed-off-by: Lee Jones <lee@...nel.org>
>> > Signed-off-by: Alice Ryhl <aliceryhl@...gle.com>
>> > ---
>> > rust/kernel/miscdevice.rs | 97 ++++++++++++++++++++++++++++++++++++++++++++++-
>> > 1 file changed, 96 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/rust/kernel/miscdevice.rs b/rust/kernel/miscdevice.rs
>> > index 22f291211636f66efca6b33b675833236332719e..a49954c9b0d14117645be8139db792f1fd22589d 100644
>> > --- a/rust/kernel/miscdevice.rs
>> > +++ b/rust/kernel/miscdevice.rs
>> > @@ -14,13 +14,14 @@
>> > error::{to_result, Error, Result, VTABLE_DEFAULT_ERROR},
>> > ffi::{c_int, c_long, c_uint, c_ulong},
>> > fs::File,
>> > + iov::{IovIterDest, IovIterSource},
>> > mm::virt::VmaNew,
>> > prelude::*,
>> > seq_file::SeqFile,
>> > str::CStr,
>> > types::{ForeignOwnable, Opaque},
>> > };
>> > -use core::{marker::PhantomData, mem::MaybeUninit, pin::Pin};
>> > +use core::{marker::PhantomData, mem::MaybeUninit, pin::Pin, ptr::NonNull};
>> >
>> > /// Options for creating a misc device.
>> > #[derive(Copy, Clone)]
>> > @@ -136,6 +137,16 @@ fn mmap(
>> > build_error!(VTABLE_DEFAULT_ERROR)
>> > }
>> >
>> > + /// Read from this miscdevice.
>> > + fn read_iter(_kiocb: Kiocb<'_, Self::Ptr>, _iov: &mut IovIterDest<'_>) -> Result<usize> {
>> > + build_error!(VTABLE_DEFAULT_ERROR)
>> > + }
>> > +
>> > + /// Write to this miscdevice.
>> > + fn write_iter(_kiocb: Kiocb<'_, Self::Ptr>, _iov: &mut IovIterSource<'_>) -> Result<usize> {
>> > + build_error!(VTABLE_DEFAULT_ERROR)
>> > + }
>> > +
>> > /// Handler for ioctls.
>> > ///
>> > /// The `cmd` argument is usually manipulated using the utilities in [`kernel::ioctl`].
>> > @@ -177,6 +188,36 @@ fn show_fdinfo(
>> > }
>> > }
>> >
>> > +/// Wrapper for the kernel's `struct kiocb`.
>> > +///
>> > +/// The type `T` represents the private data of the file.
>> > +pub struct Kiocb<'a, T> {
>> > + inner: NonNull<bindings::kiocb>,
>> > + _phantom: PhantomData<&'a T>,
>> > +}
>>
>> Also, `kiocb` is not miscdevice specific. It should probably not live here.
>
> I can place it in rust/kernel/fs.rs, but this is an instance of the more
> general fact that miscdevice defines many things from `file_operations`
> that we should probably generalize in the future.
I support moving `Kiocb` to `fs` now, rather than later.
Best regards,
Andreas Hindborg
Powered by blists - more mailing lists