From: "Benno Lossin" <lossin@kernel.org>
To: "Sidong Yang" <sidong.yang@furiosa.ai>
Cc: "Daniel Almeida" <daniel.almeida@collabora.com>,
"Caleb Sander Mateos" <csander@purestorage.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Arnd Bergmann" <arnd@arndb.de>, "Jens Axboe" <axboe@kernel.dk>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
<rust-for-linux@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<io-uring@vger.kernel.org>
Subject: Re: [RFC PATCH v2 2/4] rust: io_uring: introduce rust abstraction for io-uring cmd
Date: Fri, 08 Aug 2025 10:49:14 +0200 [thread overview]
Message-ID: <DBWX0L4LIOF6.1AVJJV0SMDQ3P@kernel.org> (raw)
In-Reply-To: <aJWfl87T3wehIviV@sidongui-MacBookPro.local>
On Fri Aug 8, 2025 at 8:56 AM CEST, Sidong Yang wrote:
> On Wed, Aug 06, 2025 at 03:38:24PM +0200, Benno Lossin wrote:
>> On Wed Aug 6, 2025 at 2:38 PM CEST, Daniel Almeida wrote:
>> > Hi Benno,
>> >
>> >> On 2 Aug 2025, at 07:52, Benno Lossin <lossin@kernel.org> wrote:
>> >>
>> >> On Fri Aug 1, 2025 at 3:48 PM CEST, Daniel Almeida wrote:
>> >>>> On 27 Jul 2025, at 12:03, Sidong Yang <sidong.yang@furiosa.ai> wrote:
>> >>>> + #[inline]
>> >>>> + pub fn pdu(&mut self) -> &mut MaybeUninit<[u8; 32]> {
>> >>>
>> >>> Why MaybeUninit? Also, this is a question for others, but I don´t think
>> >>> that `u8`s can ever be uninitialized as all byte values are valid for `u8`.
>> >>
>> >> `u8` can be uninitialized. Uninitialized doesn't just mean "can take any
>> >> bit pattern", but also "is known to the compiler as being
>> >> uninitialized". The docs of `MaybeUninit` explain it like this:
>> >>
>> >> Moreover, uninitialized memory is special in that it does not have a
>> >> fixed value ("fixed" meaning "it won´t change without being written
>> >> to"). Reading the same uninitialized byte multiple times can give
>> >> different results.
>> >>
>> >> But the return type probably should be `&mut [MaybeUninit<u8>; 32]`
>> >> instead.
>> >
>> >
>> > Right, but I guess the question then is why would we ever need to use
>> > MaybeUninit here anyways.
>> >
>> > It's a reference to a C array. Just treat that as initialized.
>>
>> AFAIK C uninitialized memory also is considered uninitialized in Rust.
>> So if this array is not properly initialized on the C side, this would
>> be the correct type. If it is initialized, then just use `&mut [u8; 32]`.
>
> pdu field is memory chunk for driver can use it freely. The driver usually
> saves a private data and read or modify it on the other context. using
> just `&mut [u8;32]` would be simple and easy to use.
Private data is usually handled using `ForeignOwnable` in Rust. What
kind of data would be stored there? If it's a pointer, then `&mut [u8;
32]` would not be the correct choice.
---
Cheers,
Benno
next prev parent reply other threads:[~2025-08-08 8:49 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-27 15:03 [RFC PATCH v2 0/4] rust: miscdevice: abstraction for uring-cmd Sidong Yang
2025-07-27 15:03 ` [RFC PATCH v2 1/4] rust: bindings: add io_uring headers in bindings_helper.h Sidong Yang
2025-07-27 15:03 ` [RFC PATCH v2 2/4] rust: io_uring: introduce rust abstraction for io-uring cmd Sidong Yang
2025-08-01 13:48 ` Daniel Almeida
2025-08-02 10:52 ` Benno Lossin
2025-08-06 12:38 ` Daniel Almeida
2025-08-06 13:38 ` Benno Lossin
2025-08-08 6:56 ` Sidong Yang
2025-08-08 8:49 ` Benno Lossin [this message]
2025-08-08 9:43 ` Sidong Yang
2025-08-09 10:18 ` Benno Lossin
2025-08-09 12:51 ` Sidong Yang
2025-08-09 20:22 ` Benno Lossin
2025-08-10 13:50 ` Sidong Yang
2025-08-10 14:27 ` Daniel Almeida
2025-08-10 14:46 ` Sidong Yang
2025-08-10 20:06 ` Benno Lossin
2025-08-11 12:34 ` Sidong Yang
2025-08-11 12:44 ` Daniel Almeida
2025-08-11 14:50 ` Sidong Yang
2025-08-12 8:34 ` Benno Lossin
2025-08-12 12:19 ` Sidong Yang
2025-08-12 12:43 ` Daniel Almeida
2025-08-12 13:56 ` Sidong Yang
2025-08-12 13:59 ` Daniel Almeida
2025-08-12 14:38 ` Daniel Almeida
2025-08-13 0:54 ` Sidong Yang
2025-08-08 13:55 ` Caleb Sander Mateos
2025-08-09 12:53 ` Sidong Yang
2025-08-05 3:39 ` Sidong Yang
2025-08-05 13:02 ` Daniel Almeida
2025-08-06 9:11 ` Sidong Yang
2025-07-27 15:03 ` [RFC PATCH v2 3/4] rust: miscdevice: add uring_cmd() for MiscDevice trait Sidong Yang
2025-08-01 14:04 ` Daniel Almeida
2025-08-07 7:46 ` Sidong Yang
2025-07-27 15:03 ` [RFC PATCH v2 4/4] samples: rust: rust_misc_device: add uring_cmd example Sidong Yang
2025-08-01 14:11 ` Daniel Almeida
2025-08-07 6:30 ` Sidong Yang
2025-07-27 17:17 ` [RFC PATCH v2 0/4] rust: miscdevice: abstraction for uring-cmd Daniel Almeida
2025-08-01 14:13 ` Daniel Almeida
2025-08-07 6:17 ` Sidong Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DBWX0L4LIOF6.1AVJJV0SMDQ3P@kernel.org \
--to=lossin@kernel.org \
--cc=arnd@arndb.de \
--cc=axboe@kernel.dk \
--cc=csander@purestorage.com \
--cc=daniel.almeida@collabora.com \
--cc=gregkh@linuxfoundation.org \
--cc=io-uring@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sidong.yang@furiosa.ai \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).