mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] rust: net: netlink: Migrate to zerocopy's IntoBytes
@ 2026-09-13  2:18 Sagar Taunk
  2026-09-14  2:24 ` Alexandre Courbot
  0 siblings, 1 reply; 2+ messages in thread
From: Sagar Taunk @ 2026-09-13  2:18 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Miguel Ojeda, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, netdev, rust-for-linux,
	linux-kernel
  Cc: Sagar Taunk

Replace the kernel's own `transmute::FromBytes` and `AsBytes` traits
with their zerocopy equivalents. Specifically, this updates
`GenlMsg::put` to rely on `IntoBytes` for converting attributes into
byte slices.

Also, add `Immutable` trait bound on `GenlMsg::put` as zerocopy
splits the `no interior mutability` guarantee that `AsBytes` bundled
together.

Link: https://github.com/Rust-for-Linux/linux/issues/1241
Signed-off-by: Sagar Taunk <sagartaunk@proton.me>
---
v2: Split into a separate patch per Shashiko's review; validates the
    attribute length with c_int::try_from() instead of casting with `as`.

 rust/kernel/net/netlink.rs | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/rust/kernel/net/netlink.rs b/rust/kernel/net/netlink.rs
index 22ef3dde36fa..3c2b142a7402 100644
--- a/rust/kernel/net/netlink.rs
+++ b/rust/kernel/net/netlink.rs
@@ -12,11 +12,12 @@
     alloc::{self, AllocError},
     error::to_result,
     prelude::*,
-    transmute::AsBytes,
     types::Opaque,
     ThisModule,
 };
 
+use zerocopy::{Immutable, IntoBytes};
+
 use core::{
     mem::ManuallyDrop,
     ptr::NonNull, //
@@ -84,7 +85,7 @@ impl GenlMsg {
     #[inline]
     fn put<T>(&mut self, attrtype: c_int, value: &T) -> Result
     where
-        T: ?Sized + AsBytes,
+        T: ?Sized + IntoBytes + Immutable,
     {
         let skb = self.skb.skb.as_ptr();
         let len = size_of_val(value);
-- 
2.55.0



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] rust: net: netlink: Migrate to zerocopy's IntoBytes
  2026-09-13  2:18 [PATCH v2] rust: net: netlink: Migrate to zerocopy's IntoBytes Sagar Taunk
@ 2026-09-14  2:24 ` Alexandre Courbot
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Courbot @ 2026-09-14  2:24 UTC (permalink / raw)
  To: Sagar Taunk
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Miguel Ojeda, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Onur Özkan, netdev, rust-for-linux, linux-kernel

On Sun Sep 13, 2026 at 11:18 AM JST, Sagar Taunk wrote:
> Replace the kernel's own `transmute::FromBytes` and `AsBytes` traits
> with their zerocopy equivalents. Specifically, this updates
> `GenlMsg::put` to rely on `IntoBytes` for converting attributes into
> byte slices.
>
> Also, add `Immutable` trait bound on `GenlMsg::put` as zerocopy
> splits the `no interior mutability` guarantee that `AsBytes` bundled
> together.
>
> Link: https://github.com/Rust-for-Linux/linux/issues/1241
> Signed-off-by: Sagar Taunk <sagartaunk@proton.me>
> ---
> v2: Split into a separate patch per Shashiko's review; validates the
>     attribute length with c_int::try_from() instead of casting with `as`.
>
>  rust/kernel/net/netlink.rs | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/rust/kernel/net/netlink.rs b/rust/kernel/net/netlink.rs
> index 22ef3dde36fa..3c2b142a7402 100644
> --- a/rust/kernel/net/netlink.rs
> +++ b/rust/kernel/net/netlink.rs
> @@ -12,11 +12,12 @@
>      alloc::{self, AllocError},
>      error::to_result,
>      prelude::*,
> -    transmute::AsBytes,
>      types::Opaque,
>      ThisModule,
>  };
>  
> +use zerocopy::{Immutable, IntoBytes};

Please use the vertical import style as per the guidelines [1].

With that,

Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>

[1] https://docs.kernel.org/rust/coding-guidelines.html#imports

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-14  2:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-13  2:18 [PATCH v2] rust: net: netlink: Migrate to zerocopy's IntoBytes Sagar Taunk
2026-09-14  2:24 ` Alexandre Courbot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®