* [PATCH v3 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs
@ 2025-12-09 2:57 Alexandre Courbot
2025-12-09 2:57 ` [PATCH v3 1/2] " Alexandre Courbot
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Alexandre Courbot @ 2025-12-09 2:57 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 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: ba65a4e7120a616d9c592750d9147f6dcafedffa
change-id: 20251208-transmute_unit-78ab58ba9e6e
Best regards,
--
Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 1/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs
2025-12-09 2:57 [PATCH v3 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs Alexandre Courbot
@ 2025-12-09 2:57 ` Alexandre Courbot
2025-12-09 12:14 ` Benno Lossin
2025-12-09 2:58 ` [PATCH v3 2/2] gpu: nova-core: gsp: use () as message type for GspInitDone message Alexandre Courbot
2025-12-09 12:18 ` [PATCH v3 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs Gary Guo
2 siblings, 1 reply; 6+ messages in thread
From: Alexandre Courbot @ 2025-12-09 2:57 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>
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..a888a312e7ff 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.
+ (),
+ {<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.
+ (),
+ {<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] 6+ messages in thread
* [PATCH v3 2/2] gpu: nova-core: gsp: use () as message type for GspInitDone message
2025-12-09 2:57 [PATCH v3 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs Alexandre Courbot
2025-12-09 2:57 ` [PATCH v3 1/2] " Alexandre Courbot
@ 2025-12-09 2:58 ` Alexandre Courbot
2025-12-09 12:18 ` [PATCH v3 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs Gary Guo
2 siblings, 0 replies; 6+ messages in thread
From: Alexandre Courbot @ 2025-12-09 2:58 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] 6+ messages in thread
* Re: [PATCH v3 1/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs
2025-12-09 2:57 ` [PATCH v3 1/2] " Alexandre Courbot
@ 2025-12-09 12:14 ` Benno Lossin
2025-12-11 1:21 ` Alice Ryhl
0 siblings, 1 reply; 6+ messages in thread
From: Benno Lossin @ 2025-12-09 12:14 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 Tue Dec 9, 2025 at 3:57 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>
> 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..a888a312e7ff 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.
Even inhabited ZSTs cannot just be conjured out of thin air, since there
might be safety invariants on the creation of such a type. Now these
two concrete ones do not have any, so this is fine, but should still be
mentioned in the comment IMO.
Cheers,
Benno
> + (),
> + {<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,
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs
2025-12-09 2:57 [PATCH v3 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs Alexandre Courbot
2025-12-09 2:57 ` [PATCH v3 1/2] " Alexandre Courbot
2025-12-09 2:58 ` [PATCH v3 2/2] gpu: nova-core: gsp: use () as message type for GspInitDone message Alexandre Courbot
@ 2025-12-09 12:18 ` Gary Guo
2 siblings, 0 replies; 6+ messages in thread
From: Gary Guo @ 2025-12-09 12:18 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 Tue, 09 Dec 2025 11:57:58 +0900
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>
Reviewed-by: Gary Guo <gary@garyguo.net>
> ---
> 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: ba65a4e7120a616d9c592750d9147f6dcafedffa
> change-id: 20251208-transmute_unit-78ab58ba9e6e
>
> Best regards,
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 1/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs
2025-12-09 12:14 ` Benno Lossin
@ 2025-12-11 1:21 ` Alice Ryhl
0 siblings, 0 replies; 6+ messages in thread
From: Alice Ryhl @ 2025-12-11 1:21 UTC (permalink / raw)
To: Benno Lossin
Cc: Alexandre Courbot, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Andreas Hindborg, Trevor Gross,
Danilo Krummrich, John Hubbard, Alistair Popple, Joel Fernandes,
Timur Tabi, Edwin Peer, Eliot Courtney, rust-for-linux,
linux-kernel
On Tue, Dec 09, 2025 at 01:14:08PM +0100, Benno Lossin wrote:
> On Tue Dec 9, 2025 at 3:57 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>
> > 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..a888a312e7ff 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.
>
> Even inhabited ZSTs cannot just be conjured out of thin air, since there
> might be safety invariants on the creation of such a type. Now these
> two concrete ones do not have any, so this is fine, but should still be
> mentioned in the comment IMO.
I think we can say "it has no invariants".
Alice
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-12-11 1:21 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-09 2:57 [PATCH v3 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs Alexandre Courbot
2025-12-09 2:57 ` [PATCH v3 1/2] " Alexandre Courbot
2025-12-09 12:14 ` Benno Lossin
2025-12-11 1:21 ` Alice Ryhl
2025-12-09 2:58 ` [PATCH v3 2/2] gpu: nova-core: gsp: use () as message type for GspInitDone message Alexandre Courbot
2025-12-09 12:18 ` [PATCH v3 0/2] rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs Gary Guo
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.