* [PATCH v2 0/3] rust: migrate users to zerocopy traits
@ 2026-09-06 10:28 Sagar Taunk
2026-09-06 10:28 ` [PATCH v2 1/3] rust: net: netlink: Migrate to zerocopy's `IntoBytes` Sagar Taunk
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Sagar Taunk @ 2026-09-06 10:28 UTC (permalink / raw)
To: Miguel Ojeda, Danilo Krummrich
Cc: Jakub Kicinski, Paolo Abeni, Eric Dumazet, David S . Miller,
Simon Horman, Abdiel Janulgue, Daniel Almeida, Robin Murphy,
Andreas Hindborg, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Greg Kroah-Hartman,
driver-core, rust-for-linux, netdev, linux-kernel, Sagar Taunk
This series migrates `dma.rs`, `uaccess.rs` and `net/netlink.rs`
from the kernel's `transmute::{FromBytes, AsBytes}` traits to the
equivalent zerocopy traits.
Sagar Taunk (3):
rust: net: netlink: Migrate to zerocopy's `IntoBytes`
rust: uaccess: migrate to zerocopy's `Frombytes/IntoBytes`
rust: dma.rs: Migrate to zerocopy's `Frombytes/IntoBytes`
rust/kernel/dma.rs | 22 +++++++++-------------
rust/kernel/net/netlink.rs | 3 +--
rust/kernel/uaccess.rs | 5 ++---
3 files changed, 12 insertions(+), 18 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/3] rust: net: netlink: Migrate to zerocopy's `IntoBytes`
2026-09-06 10:28 [PATCH v2 0/3] rust: migrate users to zerocopy traits Sagar Taunk
@ 2026-09-06 10:28 ` Sagar Taunk
2026-09-06 10:29 ` [PATCH v2 2/3] rust: uaccess: migrate to zerocopy's `Frombytes/IntoBytes` Sagar Taunk
2026-09-06 10:29 ` [PATCH v2 3/3] rust: dma.rs: Migrate " Sagar Taunk
2 siblings, 0 replies; 7+ messages in thread
From: Sagar Taunk @ 2026-09-06 10:28 UTC (permalink / raw)
To: Miguel Ojeda, Danilo Krummrich
Cc: Jakub Kicinski, Paolo Abeni, Eric Dumazet, David S . Miller,
Simon Horman, Abdiel Janulgue, Daniel Almeida, Robin Murphy,
Andreas Hindborg, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Greg Kroah-Hartman,
driver-core, rust-for-linux, netdev, linux-kernel, Sagar Taunk
Replace remaining imports of kernel's own `transmute::FromBytes`/`AsBytes`
traits with their zerocopy equivalent. In this case, `IntoBytes` which is
already re-exported through kernel's prelude.
Link: https://github.com/Rust-for-Linux/linux/issues/1241
Signed-off-by: Sagar Taunk <sagartaunk@proton.me>
---
rust/kernel/net/netlink.rs | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/rust/kernel/net/netlink.rs b/rust/kernel/net/netlink.rs
index 22ef3dde36fa..c3b50dd50a4c 100644
--- a/rust/kernel/net/netlink.rs
+++ b/rust/kernel/net/netlink.rs
@@ -12,7 +12,6 @@
alloc::{self, AllocError},
error::to_result,
prelude::*,
- transmute::AsBytes,
types::Opaque,
ThisModule,
};
@@ -84,7 +83,7 @@ impl GenlMsg {
#[inline]
fn put<T>(&mut self, attrtype: c_int, value: &T) -> Result
where
- T: ?Sized + AsBytes,
+ T: ?Sized + IntoBytes,
{
let skb = self.skb.skb.as_ptr();
let len = size_of_val(value);
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/3] rust: uaccess: migrate to zerocopy's `Frombytes/IntoBytes`
2026-09-06 10:28 [PATCH v2 0/3] rust: migrate users to zerocopy traits Sagar Taunk
2026-09-06 10:28 ` [PATCH v2 1/3] rust: net: netlink: Migrate to zerocopy's `IntoBytes` Sagar Taunk
@ 2026-09-06 10:29 ` Sagar Taunk
2026-09-06 10:29 ` [PATCH v2 3/3] rust: dma.rs: Migrate " Sagar Taunk
2 siblings, 0 replies; 7+ messages in thread
From: Sagar Taunk @ 2026-09-06 10:29 UTC (permalink / raw)
To: Miguel Ojeda, Danilo Krummrich
Cc: Jakub Kicinski, Paolo Abeni, Eric Dumazet, David S . Miller,
Simon Horman, Abdiel Janulgue, Daniel Almeida, Robin Murphy,
Andreas Hindborg, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Greg Kroah-Hartman,
driver-core, rust-for-linux, netdev, linux-kernel, Sagar Taunk
Replace explicit imports of `transmute::FromBytes`/`AsBytes` marker
traits with their zerocopy equivalents.
Link: https://github.com/Rust-for-Linux/linux/issues/1241
Signed-off-by: Sagar Taunk <sagartaunk@proton.me>
---
rust/kernel/uaccess.rs | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs
index 5f6c4d7a1a51..d93c1a21f324 100644
--- a/rust/kernel/uaccess.rs
+++ b/rust/kernel/uaccess.rs
@@ -13,7 +13,6 @@
fs::file,
prelude::*,
ptr::KnownSize,
- transmute::{AsBytes, FromBytes},
};
use core::mem::{size_of, MaybeUninit};
@@ -525,7 +524,7 @@ pub fn write_slice(&mut self, data: &[u8]) -> Result {
/// writer.write_dma(alloc, 0, 256)
/// }
/// ```
- pub fn write_dma<T: KnownSize + AsBytes + ?Sized>(
+ pub fn write_dma<T: KnownSize + IntoBytes + ?Sized>(
&mut self,
alloc: &Coherent<T>,
offset: usize,
@@ -599,7 +598,7 @@ pub fn write_slice_file(&mut self, data: &[u8], offset: &mut file::Offset) -> Re
/// Fails with [`EFAULT`] if the write happens on a bad address, or if the write goes out of
/// bounds of this [`UserSliceWriter`]. This call may modify the associated userspace slice even
/// if it returns an error.
- pub fn write<T: AsBytes>(&mut self, value: &T) -> Result {
+ pub fn write<T: IntoBytes>(&mut self, value: &T) -> Result {
let len = size_of::<T>();
if len > self.length {
return Err(EFAULT);
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 3/3] rust: dma.rs: Migrate to zerocopy's `Frombytes/IntoBytes`
2026-09-06 10:28 [PATCH v2 0/3] rust: migrate users to zerocopy traits Sagar Taunk
2026-09-06 10:28 ` [PATCH v2 1/3] rust: net: netlink: Migrate to zerocopy's `IntoBytes` Sagar Taunk
2026-09-06 10:29 ` [PATCH v2 2/3] rust: uaccess: migrate to zerocopy's `Frombytes/IntoBytes` Sagar Taunk
@ 2026-09-06 10:29 ` Sagar Taunk
2026-09-06 12:47 ` Gary Guo
2 siblings, 1 reply; 7+ messages in thread
From: Sagar Taunk @ 2026-09-06 10:29 UTC (permalink / raw)
To: Miguel Ojeda, Danilo Krummrich
Cc: Jakub Kicinski, Paolo Abeni, Eric Dumazet, David S . Miller,
Simon Horman, Abdiel Janulgue, Daniel Almeida, Robin Murphy,
Andreas Hindborg, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Greg Kroah-Hartman,
driver-core, rust-for-linux, netdev, linux-kernel, Sagar Taunk
Replace explicit imports of `transmute::FromBytes`/`AsBytes` with
zerocopy's equivalents.
Link: https://github.com/Rust-for-Linux/linux/issues/1241
Signed-off-by: Sagar Taunk <sagartaunk@proton.me>
---
rust/kernel/dma.rs | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
index 2ce09f8e90c6..9bd47f20c784 100644
--- a/rust/kernel/dma.rs
+++ b/rust/kernel/dma.rs
@@ -25,10 +25,6 @@
prelude::*,
ptr::KnownSize,
sync::aref::ARef,
- transmute::{
- AsBytes,
- FromBytes, //
- },
uaccess::UserSliceWriter, //
};
use core::{
@@ -417,7 +413,7 @@ fn from(direction: DataDirection) -> Self {
/// ```
pub struct CoherentBox<T: KnownSize + ?Sized>(Coherent<T>);
-impl<T: AsBytes + FromBytes> CoherentBox<[T]> {
+impl<T: IntoBytes + FromBytes> CoherentBox<[T]> {
/// [`CoherentBox`] variant of [`Coherent::zeroed_slice_with_attrs`].
#[inline]
pub fn zeroed_slice_with_attrs(
@@ -454,7 +450,7 @@ pub fn init_at<E>(&mut self, i: usize, init: impl Init<T, E>) -> Result
// SAFETY:
// - `ptr` is valid, properly aligned, and within this allocation.
- // - `T: AsBytes + FromBytes` guarantees all bit patterns are valid, so partial writes on
+ // - `T: IntoBytes + FromBytes` guarantees all bit patterns are valid, so partial writes on
// error cannot leave the element in an invalid state.
// - The DMA address has not been exposed yet, so there is no concurrent device access.
unsafe { pin_init::raw_try_init(ptr, init)? };
@@ -523,7 +519,7 @@ pub fn from_slice(
}
}
-impl<T: AsBytes + FromBytes> CoherentBox<T> {
+impl<T: IntoBytes + FromBytes> CoherentBox<T> {
/// Same as [`CoherentBox::zeroed_slice_with_attrs`], but for a single element.
#[inline]
pub fn zeroed_with_attrs(
@@ -554,7 +550,7 @@ fn deref(&self) -> &Self::Target {
}
}
-impl<T: AsBytes + FromBytes + KnownSize + ?Sized> DerefMut for CoherentBox<T> {
+impl<T: IntoBytes + FromBytes + KnownSize + ?Sized> DerefMut for CoherentBox<T> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
// SAFETY:
@@ -565,7 +561,7 @@ fn deref_mut(&mut self) -> &mut Self::Target {
}
}
-impl<T: AsBytes + FromBytes + KnownSize + ?Sized> From<CoherentBox<T>> for Coherent<T> {
+impl<T: IntoBytes + FromBytes + KnownSize + ?Sized> From<CoherentBox<T>> for Coherent<T> {
#[inline]
fn from(value: CoherentBox<T>) -> Self {
value.0
@@ -663,7 +659,7 @@ pub unsafe fn as_mut(&self) -> &mut T {
}
}
-impl<T: AsBytes + FromBytes> Coherent<T> {
+impl<T: IntoBytes + FromBytes> Coherent<T> {
/// Allocates a region of `T` of coherent memory.
fn alloc_with_attrs(
dev: &device::Device<Bound>,
@@ -753,7 +749,7 @@ pub fn init_with_attrs<E>(
// SAFETY:
// - `ptr` is valid, properly aligned, and points to exclusively owned memory.
// - If `raw_try_init` fails, `self` is dropped, which safely frees the underlying
- // `Coherent`'s DMA memory. `T: AsBytes + FromBytes` ensures there are no complex `Drop`
+ // `Coherent`'s DMA memory. `T: IntoBytes + FromBytes` ensures there are no complex `Drop`
// requirements we are bypassing.
unsafe { pin_init::raw_try_init(ptr, init)? };
@@ -948,9 +944,9 @@ unsafe impl<T: KnownSize + Send + ?Sized> Send for Coherent<T> {}
// methods that access the buffer contents (`field_read`, `field_write`, `as_slice`,
// `as_slice_mut`) are `unsafe`, and callers are responsible for ensuring no data races occur.
// The safe methods only return metadata or raw pointers whose use requires `unsafe`.
-unsafe impl<T: KnownSize + ?Sized + AsBytes + FromBytes + Sync> Sync for Coherent<T> {}
+unsafe impl<T: KnownSize + ?Sized + IntoBytes + FromBytes + Sync> Sync for Coherent<T> {}
-impl<T: KnownSize + AsBytes + ?Sized> debugfs::BinaryWriter for Coherent<T> {
+impl<T: KnownSize + IntoBytes + ?Sized> debugfs::BinaryWriter for Coherent<T> {
fn write_to_slice(
&self,
writer: &mut UserSliceWriter,
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 3/3] rust: dma.rs: Migrate to zerocopy's `Frombytes/IntoBytes`
2026-09-06 10:29 ` [PATCH v2 3/3] rust: dma.rs: Migrate " Sagar Taunk
@ 2026-09-06 12:47 ` Gary Guo
2026-09-06 15:48 ` Danilo Krummrich
0 siblings, 1 reply; 7+ messages in thread
From: Gary Guo @ 2026-09-06 12:47 UTC (permalink / raw)
To: Sagar Taunk, Miguel Ojeda, Danilo Krummrich
Cc: Jakub Kicinski, Paolo Abeni, Eric Dumazet, David S . Miller,
Simon Horman, Abdiel Janulgue, Daniel Almeida, Robin Murphy,
Andreas Hindborg, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Greg Kroah-Hartman,
driver-core, rust-for-linux, netdev, linux-kernel
On Sun Sep 6, 2026 at 11:29 AM BST, Sagar Taunk wrote:
> Replace explicit imports of `transmute::FromBytes`/`AsBytes` with
> zerocopy's equivalents.
>
> Link: https://github.com/Rust-for-Linux/linux/issues/1241
> Signed-off-by: Sagar Taunk <sagartaunk@proton.me>
I am surprised that just changing this is sufficient. Are all users of
`CoherentBox` already have the both zerocopy and kernel traits implemented?
Best,
Gary
> ---
> rust/kernel/dma.rs | 22 +++++++++-------------
> 1 file changed, 9 insertions(+), 13 deletions(-)
>
> diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
> index 2ce09f8e90c6..9bd47f20c784 100644
> --- a/rust/kernel/dma.rs
> +++ b/rust/kernel/dma.rs
> @@ -25,10 +25,6 @@
> prelude::*,
> ptr::KnownSize,
> sync::aref::ARef,
> - transmute::{
> - AsBytes,
> - FromBytes, //
> - },
> uaccess::UserSliceWriter, //
> };
> use core::{
> @@ -417,7 +413,7 @@ fn from(direction: DataDirection) -> Self {
> /// ```
> pub struct CoherentBox<T: KnownSize + ?Sized>(Coherent<T>);
>
> -impl<T: AsBytes + FromBytes> CoherentBox<[T]> {
> +impl<T: IntoBytes + FromBytes> CoherentBox<[T]> {
> /// [`CoherentBox`] variant of [`Coherent::zeroed_slice_with_attrs`].
> #[inline]
> pub fn zeroed_slice_with_attrs(
> @@ -454,7 +450,7 @@ pub fn init_at<E>(&mut self, i: usize, init: impl Init<T, E>) -> Result
>
> // SAFETY:
> // - `ptr` is valid, properly aligned, and within this allocation.
> - // - `T: AsBytes + FromBytes` guarantees all bit patterns are valid, so partial writes on
> + // - `T: IntoBytes + FromBytes` guarantees all bit patterns are valid, so partial writes on
> // error cannot leave the element in an invalid state.
> // - The DMA address has not been exposed yet, so there is no concurrent device access.
> unsafe { pin_init::raw_try_init(ptr, init)? };
> @@ -523,7 +519,7 @@ pub fn from_slice(
> }
> }
>
> -impl<T: AsBytes + FromBytes> CoherentBox<T> {
> +impl<T: IntoBytes + FromBytes> CoherentBox<T> {
> /// Same as [`CoherentBox::zeroed_slice_with_attrs`], but for a single element.
> #[inline]
> pub fn zeroed_with_attrs(
> @@ -554,7 +550,7 @@ fn deref(&self) -> &Self::Target {
> }
> }
>
> -impl<T: AsBytes + FromBytes + KnownSize + ?Sized> DerefMut for CoherentBox<T> {
> +impl<T: IntoBytes + FromBytes + KnownSize + ?Sized> DerefMut for CoherentBox<T> {
> #[inline]
> fn deref_mut(&mut self) -> &mut Self::Target {
> // SAFETY:
> @@ -565,7 +561,7 @@ fn deref_mut(&mut self) -> &mut Self::Target {
> }
> }
>
> -impl<T: AsBytes + FromBytes + KnownSize + ?Sized> From<CoherentBox<T>> for Coherent<T> {
> +impl<T: IntoBytes + FromBytes + KnownSize + ?Sized> From<CoherentBox<T>> for Coherent<T> {
> #[inline]
> fn from(value: CoherentBox<T>) -> Self {
> value.0
> @@ -663,7 +659,7 @@ pub unsafe fn as_mut(&self) -> &mut T {
> }
> }
>
> -impl<T: AsBytes + FromBytes> Coherent<T> {
> +impl<T: IntoBytes + FromBytes> Coherent<T> {
> /// Allocates a region of `T` of coherent memory.
> fn alloc_with_attrs(
> dev: &device::Device<Bound>,
> @@ -753,7 +749,7 @@ pub fn init_with_attrs<E>(
> // SAFETY:
> // - `ptr` is valid, properly aligned, and points to exclusively owned memory.
> // - If `raw_try_init` fails, `self` is dropped, which safely frees the underlying
> - // `Coherent`'s DMA memory. `T: AsBytes + FromBytes` ensures there are no complex `Drop`
> + // `Coherent`'s DMA memory. `T: IntoBytes + FromBytes` ensures there are no complex `Drop`
> // requirements we are bypassing.
> unsafe { pin_init::raw_try_init(ptr, init)? };
>
> @@ -948,9 +944,9 @@ unsafe impl<T: KnownSize + Send + ?Sized> Send for Coherent<T> {}
> // methods that access the buffer contents (`field_read`, `field_write`, `as_slice`,
> // `as_slice_mut`) are `unsafe`, and callers are responsible for ensuring no data races occur.
> // The safe methods only return metadata or raw pointers whose use requires `unsafe`.
> -unsafe impl<T: KnownSize + ?Sized + AsBytes + FromBytes + Sync> Sync for Coherent<T> {}
> +unsafe impl<T: KnownSize + ?Sized + IntoBytes + FromBytes + Sync> Sync for Coherent<T> {}
>
> -impl<T: KnownSize + AsBytes + ?Sized> debugfs::BinaryWriter for Coherent<T> {
> +impl<T: KnownSize + IntoBytes + ?Sized> debugfs::BinaryWriter for Coherent<T> {
> fn write_to_slice(
> &self,
> writer: &mut UserSliceWriter,
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 3/3] rust: dma.rs: Migrate to zerocopy's `Frombytes/IntoBytes`
2026-09-06 12:47 ` Gary Guo
@ 2026-09-06 15:48 ` Danilo Krummrich
2026-09-06 16:34 ` Sagar Taunk
0 siblings, 1 reply; 7+ messages in thread
From: Danilo Krummrich @ 2026-09-06 15:48 UTC (permalink / raw)
To: Gary Guo
Cc: Sagar Taunk, Miguel Ojeda, Jakub Kicinski, Paolo Abeni,
Eric Dumazet, David S . Miller, Simon Horman, Abdiel Janulgue,
Daniel Almeida, Robin Murphy, Andreas Hindborg, Boqun Feng,
Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
Tamir Duberstein, Alexandre Courbot, Onur Özkan,
Greg Kroah-Hartman, driver-core, rust-for-linux, netdev,
linux-kernel
On Sun Sep 6, 2026 at 2:47 PM CEST, Gary Guo wrote:
> I am surprised that just changing this is sufficient. Are all users of
> `CoherentBox` already have the both zerocopy and kernel traits implemented?
No, and I think the uaccess patch won't compile either. It breaks
impl<T: KnownSize + AsBytes + ?Sized> debugfs::BinaryWriter for Coherent<'_, T>
from the DMA code and I think it also breaks binder and tyr.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 3/3] rust: dma.rs: Migrate to zerocopy's `Frombytes/IntoBytes`
2026-09-06 15:48 ` Danilo Krummrich
@ 2026-09-06 16:34 ` Sagar Taunk
0 siblings, 0 replies; 7+ messages in thread
From: Sagar Taunk @ 2026-09-06 16:34 UTC (permalink / raw)
To: Danilo Krummrich
Cc: Gary Guo, Miguel Ojeda, Jakub Kicinski, Paolo Abeni, Eric Dumazet,
David S . Miller, Simon Horman, Abdiel Janulgue, Daniel Almeida,
Robin Murphy, Andreas Hindborg, Boqun Feng, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Greg Kroah-Hartman,
driver-core, rust-for-linux, netdev, linux-kernel
I apologise, I only tested `rust/` for users and missed the drivers. I haven't checked the `tyr` driver but it does break `nova-core` and I don't really know how to migrate it.
The `netlink.rs` patch does compile though should I resend only that or leave it?
If so, would it be a `v3` or should I send it as a new thread
On Sunday, September 6th, 2026 at 9:18 PM, Danilo Krummrich <dakr@kernel.org> wrote:
> On Sun Sep 6, 2026 at 2:47 PM CEST, Gary Guo wrote:
> > I am surprised that just changing this is sufficient. Are all users of
> > `CoherentBox` already have the both zerocopy and kernel traits implemented?
>
> No, and I think the uaccess patch won't compile either. It breaks
>
> impl<T: KnownSize + AsBytes + ?Sized> debugfs::BinaryWriter for Coherent<'_, T>
>
> from the DMA code and I think it also breaks binder and tyr.
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-09-06 16:34 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-06 10:28 [PATCH v2 0/3] rust: migrate users to zerocopy traits Sagar Taunk
2026-09-06 10:28 ` [PATCH v2 1/3] rust: net: netlink: Migrate to zerocopy's `IntoBytes` Sagar Taunk
2026-09-06 10:29 ` [PATCH v2 2/3] rust: uaccess: migrate to zerocopy's `Frombytes/IntoBytes` Sagar Taunk
2026-09-06 10:29 ` [PATCH v2 3/3] rust: dma.rs: Migrate " Sagar Taunk
2026-09-06 12:47 ` Gary Guo
2026-09-06 15:48 ` Danilo Krummrich
2026-09-06 16:34 ` Sagar Taunk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox