[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <DBIN4DXACVKW.2XJPQV4RNJD70@nvidia.com>
Date: Tue, 22 Jul 2025 23:06:41 +0900
From: "Alexandre Courbot" <acourbot@...dia.com>
To: "Christian" <christiansantoslima21@...il.com>
Cc: "Miguel Ojeda" <ojeda@...nel.org>, "Alex Gaynor"
<alex.gaynor@...il.com>, "Boqun Feng" <boqun.feng@...il.com>, "Gary Guo"
<gary@...yguo.net>, Björn Roy Baron
<bjorn3_gh@...tonmail.com>, "Benno Lossin" <benno.lossin@...ton.me>,
"Andreas Hindborg" <a.hindborg@...nel.org>, "Alice Ryhl"
<aliceryhl@...gle.com>, "Trevor Gross" <tmgross@...ch.edu>, "Danilo
Krummrich" <dakr@...nel.org>, <rust-for-linux@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <~lkcamp/patches@...ts.sr.ht>,
<richard120310@...il.com>
Subject: Re: [PATCH v8] rust: transmute: Add methods for FromBytes trait
On Tue Jul 15, 2025 at 7:16 AM JST, Christian wrote:
> Hi, Alexandre. No problem, take your time.
>
>> Let's elaborate on when it is "possible", i.e. the reference is properly
>> aligned, and the size of the slice is equal to that of `T`. Let's also
>> clarify that `None` is returned in other cases.
>
> I see, thanks for a better explanation, I'll include it in the next patch.
>
>> > + fn from_mut_bytes(bytes: &mut [u8]) -> Option<&mut Self>
>>
>> `from_bytes_mut` sounds like a more idiomatic name for this method.
>
> It is done this way to match the zero copy API. [1]
Mmm I have checked the zerocopy doc and could not find any instance of
either `from_bytes_mut` or `from_mut_bytes`...
>
>> > + where
>> > + Self: AsBytes;
>> > +}
>>
>> Note that `samples/rust/rust_dma.rs` will fail to compile due to this
>> change - you must make it derive `FromBytesSized` instead. There may be
>> other implementors of `FromBytes` so please make sure to track and
>> update them to avoid breaking the build.
>
> In this case, if we don't include `AsBytes` the user can add padding
> bytes in the slice. [2]
To clarify, I am not complaining about the `Self: AsBytes` requirement,
I am just pointing out that you will need to update the sample so it
keeps building. :)
>
>> nova-next also adds new implementations of `FromBytes`, and since they
>> are not in mainline yet this will make it harder to adapt them... I see
>> two possible solutions if we want this for the next cycle:
>>
>> - Take this patch into nova-next and update `FromBytes` implementations
>> in lockstep,
>> - Add temporary default implementations for `from_bytes` and
>> `from_mut_bytes` that simply return `None` so current implementors
>> keep building.
>
> I think the first option is better considering the current state.
Sounds good to me as well!
Powered by blists - more mailing lists