From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B615B2DE1FE; Tue, 8 Jul 2025 14:53:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751986411; cv=none; b=cfoHFd8MG7mfvU0h8hayLQYhJ+4ke5/8jd426BV1JILUwT1ta1mwiuv1O6/pLwscoZ1bqAzZXBqpn/fvZq+dIkIK4VWDf6QNK9iapYHehOF2Z4tqWfSPnquVwiucm9yGXHWZ6mwqPzNyqyWn40kNOhasmla65GiZcKb/ps2hj98= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751986411; c=relaxed/simple; bh=CbchSDI0+aXY4EcxahPrJAQQLeD1XK9toKpKKPgC/r4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=Mz4mvOvh9rXdzJTp1zbjCAsw+me01ffuTYbjzreWfNfqye0XfZJaQq6UdQgjRPIs2Jw+fLq+dxhiJS6bMM+fofXkF4I6Aj6ydJnNob6rZxmGBLelEII+k2ekZcbphVHwn7/oLnYxEztdrwsrsAmxNn8VAQn9y3W0wMvk6g3RgVc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VU9TvYfB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VU9TvYfB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BBD9C4CEED; Tue, 8 Jul 2025 14:53:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751986411; bh=CbchSDI0+aXY4EcxahPrJAQQLeD1XK9toKpKKPgC/r4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=VU9TvYfB/sR5o/H8+5SBmbHOIYr+zhTJUFM9mUALq2q1Ik0irotNea2VkFFtVKZ3Z EdHBskIh3M6fLrga8tlkeyzVV/HPkFB4noS8HpnYYkMXjsvtEj7z25ASy0BDN8/ROt HXJ+HUzqUrWFWYsId8luypld+gg0lcfUJEQ8I80WAtWKPfmSG2PneF4eb26Wxxz7IB WdCLzBAJrIHZT+PVSI0M+AQHyoUDTFNuTogdfGPKA88PNiCScWWJmYNYmEvy+AdGKv p16ZYqM32jmk7VOqJHKb++enKyjHHIGNsw10OGuKLqx5lkExXg63B6xqNf7N0wNyhQ 7vc94RVVQumNQ== From: Andreas Hindborg To: "Alice Ryhl" Cc: "Greg Kroah-Hartman" , "Alexander Viro" , "Arnd Bergmann" , "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?Q?Bj=C3=B6rn?= Roy Baron , "Trevor Gross" , "Danilo Krummrich" , "Matthew Maurer" , "Lee Jones" , , , "Benno Lossin" Subject: Re: [PATCH v2 3/4] rust: miscdevice: Provide additional abstractions for iov_iter and kiocb structures In-Reply-To: <20250704-iov-iter-v2-3-e69aa7c1f40e@google.com> (Alice Ryhl's message of "Fri, 04 Jul 2025 09:26:02 +0000") References: <20250704-iov-iter-v2-0-e69aa7c1f40e@google.com> <20250704-iov-iter-v2-3-e69aa7c1f40e@google.com> User-Agent: mu4e 1.12.9; emacs 30.1 Date: Tue, 08 Jul 2025 16:53:23 +0200 Message-ID: <87qzyqn38c.fsf@kernel.org> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain "Alice Ryhl" 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 > Signed-off-by: Lee Jones > Signed-off-by: Alice Ryhl > --- > 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 { > + build_error!(VTABLE_DEFAULT_ERROR) > + } > + > + /// Write to this miscdevice. > + fn write_iter(_kiocb: Kiocb<'_, Self::Ptr>, _iov: &mut IovIterSource<'_>) -> Result { > + 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, > + _phantom: PhantomData<&'a T>, > +} Also, `kiocb` is not miscdevice specific. It should probably not live here. Best regards, Andreas Hindborg