[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5204b598-7792-460b-bec2-e3a4a4c7e32d@gmail.com>
Date: Tue, 12 Aug 2025 15:00:11 -0300
From: Christian <christiansantoslima21@...il.com>
To: Alexandre Courbot <acourbot@...dia.com>, 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 v9] rust: transmute: Add methods for FromBytes trait
Hi, Alexandre.
> I mentioned it on v8 [1] and v7 [2], but the tests that break due to
> this change need to be updated by this patch as well. This includes:
>
> * The doctests in `rust/kernel/dma.rs`,
> * The `samples/rust/rust_dma.rs` sample,
> * The example for `FromBytes` introduced by this patch which uses `?` without
> defining a function.
Sorry for my inattention, I'll fix this in the next version.
> Please make sure to compile with `CONFIG_RUST_KERNEL_DOCTESTS` and
> `CONFIG_SAMPLE_RUST_DMA` to see the failures.
>
> Also, now that we are on 6.17-rc1, the types in `nova-core` that implement
> `FromBytes` will also fail to build unless they are switched to
> `FromBytesSized`. Which I guess speaks in favor of taking this into the Nova
> tree if there are not other planned user for this cycle?
>
> [1]
> https://lore.kernel.org/rust-for-linux/DB5KEWX9EJ2Q.3CX5EGS66OVHH@nvidia.com/
> [2]
> https://lore.kernel.org/rust-for-linux/DANSZ6Q476EC.3GY00K717QVUL@nvidia.com/
>
> In case this helps, here is the diff I needed to apply to get the tests
> to build:
>
> diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
> index 1801836f31455..3797c70c13040 100644
> --- a/rust/kernel/dma.rs
> +++ b/rust/kernel/dma.rs
> @@ -597,7 +597,7 @@ unsafe impl<T: AsBytes + FromBytes + Send> Send for CoherentAllocation<T> {}
> /// struct MyStruct { field: u32, }
> ///
> /// // SAFETY: All bit patterns are acceptable values for `MyStruct`.
> -/// unsafe impl kernel::transmute::FromBytes for MyStruct{};
> +/// unsafe impl kernel::transmute::FromBytesSized for MyStruct{};
> /// // SAFETY: Instances of `MyStruct` have no uninitialized portions.
> /// unsafe impl kernel::transmute::AsBytes for MyStruct{};
> ///
> @@ -641,7 +641,7 @@ macro_rules! dma_read {
> /// struct MyStruct { member: u32, }
> ///
> /// // SAFETY: All bit patterns are acceptable values for `MyStruct`.
> -/// unsafe impl kernel::transmute::FromBytes for MyStruct{};
> +/// unsafe impl kernel::transmute::FromBytesSized for MyStruct{};
> /// // SAFETY: Instances of `MyStruct` have no uninitialized portions.
> /// unsafe impl kernel::transmute::AsBytes for MyStruct{};
> ///
> diff --git a/rust/kernel/transmute.rs b/rust/kernel/transmute.rs
> index ba21fe49e4f07..e7bd698ec99cd 100644
> --- a/rust/kernel/transmute.rs
> +++ b/rust/kernel/transmute.rs
> @@ -16,6 +16,7 @@
> /// ```
> /// use kernel::transmute::FromBytes;
> ///
> +/// # fn test() -> Option<()> {
> /// let foo = [1, 2, 3, 4];
> ///
> /// let result = u32::from_bytes(&foo)?;
> @@ -25,6 +26,7 @@
> ///
> /// #[cfg(target_endian = "big")]
> /// assert_eq!(*result, 0x1020304);
> +/// # Some(()) }
> /// ```
> ///
> /// # Safety
> diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs
> index 9fb3ae1dd8587..36ad877d4804d 100644
> --- a/samples/rust/rust_dma.rs
> +++ b/samples/rust/rust_dma.rs
> @@ -65,7 +65,7 @@ fn new(h: u32, b: u32) -> Self {
> // SAFETY: All bit patterns are acceptable values for `MyStruct`.
> unsafe impl kernel::transmute::AsBytes for MyStruct {}
> // SAFETY: Instances of `MyStruct` have no uninitialized portions.
> -unsafe impl kernel::transmute::FromBytes for MyStruct {}
> +unsafe impl kernel::transmute::FromBytesSized for MyStruct {}
>
> kernel::pci_device_table!(
> PCI_TABLE,
>
> -- end of diff --
Thanks for your diffs, it'll help a lot.
And sorry for the delay. I'll send a new version as soon as possible.
Thanks, Christian
Powered by blists - more mailing lists