* [PATCH v4 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs
@ 2025-12-15 5:49 Alexandre Courbot
2025-12-15 5:49 ` [PATCH v4 1/2] " Alexandre Courbot
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Alexandre Courbot @ 2025-12-15 5:49 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich
Cc: John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi,
Edwin Peer, Eliot Courtney, rust-for-linux, linux-kernel,
Alexandre Courbot
This is useful in Nova's GSP message handling, as some messages are
empty and we currently need to explicitly use an empty structure for
them.
If accepted, I would like to merge it through `drm-rust-next` so Nova
code can start using this feature quickly.
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
Changes in v4:
- Improve safety comment to mention lack of invariants.
- Link to v3: https://patch.msgid.link/20251209-transmute_unit-v3-0-819fe584ba06@nvidia.com
Changes in v3:
- Use better safety statement. (thanks Gary!)
- Also add `PhantomData`. (thanks Gary!)
- Link to v2: https://patch.msgid.link/20251208-transmute_unit-v2-0-aa17a6848afb@nvidia.com
Changes in v2:
- Make use of new feature in Nova.
- Link to v1: https://patch.msgid.link/20251208-transmute_unit-v1-1-680c7386b5d9@nvidia.com
---
Alexandre Courbot (2):
rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs
gpu: nova-core: gsp: use () as message type for GspInitDone message
drivers/gpu/nova-core/gsp/commands.rs | 6 +++---
rust/kernel/transmute.rs | 8 ++++++++
2 files changed, 11 insertions(+), 3 deletions(-)
---
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20251208-transmute_unit-78ab58ba9e6e
Best regards,
--
Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v4 1/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs 2025-12-15 5:49 [PATCH v4 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs Alexandre Courbot @ 2025-12-15 5:49 ` Alexandre Courbot 2025-12-15 7:45 ` Benno Lossin 2025-12-15 11:31 ` Gary Guo 2025-12-15 5:49 ` [PATCH v4 2/2] gpu: nova-core: gsp: use () as message type for GspInitDone message Alexandre Courbot 2026-01-26 5:05 ` [PATCH v4 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs Miguel Ojeda 2 siblings, 2 replies; 13+ messages in thread From: Alexandre Courbot @ 2025-12-15 5:49 UTC (permalink / raw) To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich Cc: John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi, Edwin Peer, Eliot Courtney, rust-for-linux, linux-kernel, Alexandre Courbot This is useful when using types that may or may not be empty in generic code relying on these traits. It is also safe because technically a no-op. Reviewed-by: Alistair Popple <apopple@nvidia.com> Reviewed-by: Gary Guo <gary@garyguo.net> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> --- rust/kernel/transmute.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rust/kernel/transmute.rs b/rust/kernel/transmute.rs index be5dbf3829e2..5711580c9f9b 100644 --- a/rust/kernel/transmute.rs +++ b/rust/kernel/transmute.rs @@ -170,6 +170,10 @@ macro_rules! impl_frombytes { } impl_frombytes! { + // SAFETY: Inhabited ZSTs only have one possible bit pattern, and these two have no invariant. + (), + {<T>} core::marker::PhantomData<T>, + // SAFETY: All bit patterns are acceptable values of the types below. u8, u16, u32, u64, usize, i8, i16, i32, i64, isize, @@ -230,6 +234,10 @@ macro_rules! impl_asbytes { } impl_asbytes! { + // SAFETY: Inhabited ZSTs only have one possible bit pattern, and these two have no invariant. + (), + {<T>} core::marker::PhantomData<T>, + // SAFETY: Instances of the following types have no uninitialized portions. u8, u16, u32, u64, usize, i8, i16, i32, i64, isize, -- 2.52.0 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v4 1/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs 2025-12-15 5:49 ` [PATCH v4 1/2] " Alexandre Courbot @ 2025-12-15 7:45 ` Benno Lossin 2025-12-18 13:32 ` Alexandre Courbot 2025-12-15 11:31 ` Gary Guo 1 sibling, 1 reply; 13+ messages in thread From: Benno Lossin @ 2025-12-15 7:45 UTC (permalink / raw) To: Alexandre Courbot, Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron, Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich Cc: John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi, Edwin Peer, Eliot Courtney, rust-for-linux, linux-kernel On Mon Dec 15, 2025 at 6:49 AM CET, Alexandre Courbot wrote: > This is useful when using types that may or may not be empty in generic > code relying on these traits. It is also safe because technically a > no-op. > > Reviewed-by: Alistair Popple <apopple@nvidia.com> > Reviewed-by: Gary Guo <gary@garyguo.net> > Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Benno Lossin <lossin@kernel.org> Cheers, Benno > --- > rust/kernel/transmute.rs | 8 ++++++++ > 1 file changed, 8 insertions(+) ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v4 1/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs 2025-12-15 7:45 ` Benno Lossin @ 2025-12-18 13:32 ` Alexandre Courbot 2025-12-25 8:53 ` Miguel Ojeda 0 siblings, 1 reply; 13+ messages in thread From: Alexandre Courbot @ 2025-12-18 13:32 UTC (permalink / raw) To: Benno Lossin, Alexandre Courbot, Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron, Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich Cc: John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi, Edwin Peer, Eliot Courtney, rust-for-linux, linux-kernel On Mon Dec 15, 2025 at 4:45 PM JST, Benno Lossin wrote: > On Mon Dec 15, 2025 at 6:49 AM CET, Alexandre Courbot wrote: >> This is useful when using types that may or may not be empty in generic >> code relying on these traits. It is also safe because technically a >> no-op. >> >> Reviewed-by: Alistair Popple <apopple@nvidia.com> >> Reviewed-by: Gary Guo <gary@garyguo.net> >> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> > > Reviewed-by: Benno Lossin <lossin@kernel.org> Miguel, are you ok if we take this one through the drm-rust tree? Nova is likely to make use of it this cycle. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v4 1/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs 2025-12-18 13:32 ` Alexandre Courbot @ 2025-12-25 8:53 ` Miguel Ojeda 2026-01-23 11:44 ` Alexandre Courbot 0 siblings, 1 reply; 13+ messages in thread From: Miguel Ojeda @ 2025-12-25 8:53 UTC (permalink / raw) To: Alexandre Courbot Cc: Benno Lossin, Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron, Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich, John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi, Edwin Peer, Eliot Courtney, rust-for-linux, linux-kernel On Thu, Dec 18, 2025 at 2:32 PM Alexandre Courbot <acourbot@nvidia.com> wrote: > > Miguel, are you ok if we take this one through the drm-rust tree? Nova > is likely to make use of it this cycle. Sure: Acked-by: Miguel Ojeda <ojeda@kernel.org> (Catching up on emails...) Cheers, Miguel ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v4 1/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs 2025-12-25 8:53 ` Miguel Ojeda @ 2026-01-23 11:44 ` Alexandre Courbot 2026-01-24 16:17 ` Miguel Ojeda 0 siblings, 1 reply; 13+ messages in thread From: Alexandre Courbot @ 2026-01-23 11:44 UTC (permalink / raw) To: Miguel Ojeda Cc: Benno Lossin, Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron, Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich, John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi, Edwin Peer, Eliot Courtney, rust-for-linux, linux-kernel On Thu Dec 25, 2025 at 5:53 PM JST, Miguel Ojeda wrote: > On Thu, Dec 18, 2025 at 2:32 PM Alexandre Courbot <acourbot@nvidia.com> wrote: >> >> Miguel, are you ok if we take this one through the drm-rust tree? Nova >> is likely to make use of it this cycle. > > Sure: > > Acked-by: Miguel Ojeda <ojeda@kernel.org> > > (Catching up on emails...) Actually, the nova-core code that depends on this won't cut it this cycle, so it is probably more appropriate to merge this through the Rust tree. Sorry for the back-and-forth and last minute notice! ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v4 1/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs 2026-01-23 11:44 ` Alexandre Courbot @ 2026-01-24 16:17 ` Miguel Ojeda 2026-01-24 16:29 ` Danilo Krummrich 2026-01-25 1:33 ` Alexandre Courbot 0 siblings, 2 replies; 13+ messages in thread From: Miguel Ojeda @ 2026-01-24 16:17 UTC (permalink / raw) To: Alexandre Courbot Cc: Benno Lossin, Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron, Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich, John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi, Edwin Peer, Eliot Courtney, rust-for-linux, linux-kernel On Fri, Jan 23, 2026 at 12:45 PM Alexandre Courbot <acourbot@nvidia.com> wrote: > > Actually, the nova-core code that depends on this won't cut it this > cycle, so it is probably more appropriate to merge this through the Rust > tree. > > Sorry for the back-and-forth and last minute notice! No worries, I can do that -- do you want that I take the second patch too? Cheers, Miguel ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v4 1/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs 2026-01-24 16:17 ` Miguel Ojeda @ 2026-01-24 16:29 ` Danilo Krummrich 2026-01-25 1:33 ` Alexandre Courbot 1 sibling, 0 replies; 13+ messages in thread From: Danilo Krummrich @ 2026-01-24 16:29 UTC (permalink / raw) To: Miguel Ojeda Cc: Alexandre Courbot, Benno Lossin, Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron, Andreas Hindborg, Alice Ryhl, Trevor Gross, John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi, Edwin Peer, Eliot Courtney, rust-for-linux, linux-kernel On Sat Jan 24, 2026 at 5:17 PM CET, Miguel Ojeda wrote: > On Fri, Jan 23, 2026 at 12:45 PM Alexandre Courbot <acourbot@nvidia.com> wrote: >> >> Actually, the nova-core code that depends on this won't cut it this >> cycle, so it is probably more appropriate to merge this through the Rust >> tree. >> >> Sorry for the back-and-forth and last minute notice! > > No worries, I can do that -- do you want that I take the second patch too? There shouldn't be a conflict and it's always nice when a feature comes directly with a user. :) ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v4 1/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs 2026-01-24 16:17 ` Miguel Ojeda 2026-01-24 16:29 ` Danilo Krummrich @ 2026-01-25 1:33 ` Alexandre Courbot 1 sibling, 0 replies; 13+ messages in thread From: Alexandre Courbot @ 2026-01-25 1:33 UTC (permalink / raw) To: Miguel Ojeda Cc: Benno Lossin, Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron, Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich, John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi, Edwin Peer, Eliot Courtney, rust-for-linux, linux-kernel On Sun Jan 25, 2026 at 1:17 AM JST, Miguel Ojeda wrote: > On Fri, Jan 23, 2026 at 12:45 PM Alexandre Courbot <acourbot@nvidia.com> wrote: >> >> Actually, the nova-core code that depends on this won't cut it this >> cycle, so it is probably more appropriate to merge this through the Rust >> tree. >> >> Sorry for the back-and-forth and last minute notice! > > No worries, I can do that -- do you want that I take the second patch too? If it doesn't conflict, that's probably a good idea yes! Thanks, Alex. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v4 1/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs 2025-12-15 5:49 ` [PATCH v4 1/2] " Alexandre Courbot 2025-12-15 7:45 ` Benno Lossin @ 2025-12-15 11:31 ` Gary Guo 1 sibling, 0 replies; 13+ messages in thread From: Gary Guo @ 2025-12-15 11:31 UTC (permalink / raw) To: Alexandre Courbot Cc: Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich, John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi, Edwin Peer, Eliot Courtney, rust-for-linux, linux-kernel On Mon, 15 Dec 2025 14:49:09 +0900 Alexandre Courbot <acourbot@nvidia.com> wrote: > This is useful when using types that may or may not be empty in generic > code relying on these traits. It is also safe because technically a > no-op. > > Reviewed-by: Alistair Popple <apopple@nvidia.com> > Reviewed-by: Gary Guo <gary@garyguo.net> > Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> > --- > rust/kernel/transmute.rs | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/rust/kernel/transmute.rs b/rust/kernel/transmute.rs > index be5dbf3829e2..5711580c9f9b 100644 > --- a/rust/kernel/transmute.rs > +++ b/rust/kernel/transmute.rs > @@ -170,6 +170,10 @@ macro_rules! impl_frombytes { > } > > impl_frombytes! { > + // SAFETY: Inhabited ZSTs only have one possible bit pattern, and these two have no invariant. > + (), > + {<T>} core::marker::PhantomData<T>, > + > // SAFETY: All bit patterns are acceptable values of the types below. > u8, u16, u32, u64, usize, > i8, i16, i32, i64, isize, > @@ -230,6 +234,10 @@ macro_rules! impl_asbytes { > } > > impl_asbytes! { > + // SAFETY: Inhabited ZSTs only have one possible bit pattern, and these two have no invariant. Some nit: technically you can turn any ZST into bytes, even those with invariants or uninhabited. So while the comment is correct, it's kinda redundant for the object -> bytes direction :) No change required for this patch. Best, Gary > + (), > + {<T>} core::marker::PhantomData<T>, > + > // SAFETY: Instances of the following types have no uninitialized portions. > u8, u16, u32, u64, usize, > i8, i16, i32, i64, isize, > ^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v4 2/2] gpu: nova-core: gsp: use () as message type for GspInitDone message 2025-12-15 5:49 [PATCH v4 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs Alexandre Courbot 2025-12-15 5:49 ` [PATCH v4 1/2] " Alexandre Courbot @ 2025-12-15 5:49 ` Alexandre Courbot 2026-01-24 16:27 ` Danilo Krummrich 2026-01-26 5:05 ` [PATCH v4 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs Miguel Ojeda 2 siblings, 1 reply; 13+ messages in thread From: Alexandre Courbot @ 2025-12-15 5:49 UTC (permalink / raw) To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich Cc: John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi, Edwin Peer, Eliot Courtney, rust-for-linux, linux-kernel, Alexandre Courbot `GspInitDone` has no payload whatsoever, so the unit type `()` is the correct way to represent its message content. We can use it now that `()` implements `FromBytes`. Reviewed-by: Alistair Popple <apopple@nvidia.com> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> --- drivers/gpu/nova-core/gsp/commands.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-core/gsp/commands.rs index 0425c65b5d6f..2050771f9b53 100644 --- a/drivers/gpu/nova-core/gsp/commands.rs +++ b/drivers/gpu/nova-core/gsp/commands.rs @@ -142,7 +142,7 @@ fn init_variable_payload( } /// Message type for GSP initialization done notification. -struct GspInitDone {} +struct GspInitDone; // SAFETY: `GspInitDone` is a zero-sized type with no bytes, therefore it // trivially has no uninitialized bytes. @@ -151,13 +151,13 @@ unsafe impl FromBytes for GspInitDone {} impl MessageFromGsp for GspInitDone { const FUNCTION: MsgFunction = MsgFunction::GspInitDone; type InitError = Infallible; - type Message = GspInitDone; + type Message = (); fn read( _msg: &Self::Message, _sbuffer: &mut SBufferIter<array::IntoIter<&[u8], 2>>, ) -> Result<Self, Self::InitError> { - Ok(GspInitDone {}) + Ok(GspInitDone) } } -- 2.52.0 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v4 2/2] gpu: nova-core: gsp: use () as message type for GspInitDone message 2025-12-15 5:49 ` [PATCH v4 2/2] gpu: nova-core: gsp: use () as message type for GspInitDone message Alexandre Courbot @ 2026-01-24 16:27 ` Danilo Krummrich 0 siblings, 0 replies; 13+ messages in thread From: Danilo Krummrich @ 2026-01-24 16:27 UTC (permalink / raw) To: Alexandre Courbot Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi, Edwin Peer, Eliot Courtney, rust-for-linux, linux-kernel On Mon Dec 15, 2025 at 6:49 AM CET, Alexandre Courbot wrote: > `GspInitDone` has no payload whatsoever, so the unit type `()` is the > correct way to represent its message content. We can use it now that > `()` implements `FromBytes`. > > Reviewed-by: Alistair Popple <apopple@nvidia.com> > Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Acked-by: Danilo Krummrich <dakr@kernel.org> ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v4 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs 2025-12-15 5:49 [PATCH v4 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs Alexandre Courbot 2025-12-15 5:49 ` [PATCH v4 1/2] " Alexandre Courbot 2025-12-15 5:49 ` [PATCH v4 2/2] gpu: nova-core: gsp: use () as message type for GspInitDone message Alexandre Courbot @ 2026-01-26 5:05 ` Miguel Ojeda 2 siblings, 0 replies; 13+ messages in thread From: Miguel Ojeda @ 2026-01-26 5:05 UTC (permalink / raw) To: Alexandre Courbot Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich, John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi, Edwin Peer, Eliot Courtney, rust-for-linux, linux-kernel On Mon, Dec 15, 2025 at 6:49 AM Alexandre Courbot <acourbot@nvidia.com> wrote: > > This is useful in Nova's GSP message handling, as some messages are > empty and we currently need to explicitly use an empty structure for > them. > > If accepted, I would like to merge it through `drm-rust-next` so Nova > code can start using this feature quickly. > > Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Applied to `rust-next` -- thanks everyone! Cheers, Miguel ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2026-01-26 5:05 UTC | newest] Thread overview: 13+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-12-15 5:49 [PATCH v4 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs Alexandre Courbot 2025-12-15 5:49 ` [PATCH v4 1/2] " Alexandre Courbot 2025-12-15 7:45 ` Benno Lossin 2025-12-18 13:32 ` Alexandre Courbot 2025-12-25 8:53 ` Miguel Ojeda 2026-01-23 11:44 ` Alexandre Courbot 2026-01-24 16:17 ` Miguel Ojeda 2026-01-24 16:29 ` Danilo Krummrich 2026-01-25 1:33 ` Alexandre Courbot 2025-12-15 11:31 ` Gary Guo 2025-12-15 5:49 ` [PATCH v4 2/2] gpu: nova-core: gsp: use () as message type for GspInitDone message Alexandre Courbot 2026-01-24 16:27 ` Danilo Krummrich 2026-01-26 5:05 ` [PATCH v4 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs Miguel Ojeda
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox