* [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
2025-12-15 5:49 ` [PATCH v4 2/2] gpu: nova-core: gsp: use () as message type for GspInitDone message Alexandre Courbot
0 siblings, 2 replies; 5+ 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] 5+ 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
1 sibling, 2 replies; 5+ 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] 5+ 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
1 sibling, 0 replies; 5+ 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] 5+ 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; 5+ 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] 5+ 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; 5+ 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] 5+ messages in thread
end of thread, other threads:[~2025-12-15 11:31 UTC | newest]
Thread overview: 5+ 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-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
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).