Thread (4 messages) 4 messages, 4 authors, 25d ago

[PATCH v3] rust: net: netlink: Migrate to zerocopy's IntoBytes

flat view
COLD25d IN NET-NEXT: 5 (5M)

From: Sagar Taunk <hidden>
Date: 2026-09-15 14:42:52
Also in: lkml, rust-for-linux
Subsystem: networking [general], rust, the rest · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Miguel Ojeda, Linus Torvalds

1 review trailer (1 from subsystem maintainers); queued in net-next as 5e5916923759 on 2026-09-18.

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 <redacted>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
---
Changes Since V2: Follow vertical import style as told by Alexandre Courbot. 
No functional changes.

 rust/kernel/net/netlink.rs | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/rust/kernel/net/netlink.rs b/rust/kernel/net/netlink.rs
index 22ef3dde36fa..a2f4bd171dcf 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,
 };
@@ -22,6 +21,11 @@
     ptr::NonNull, //
 };
 
+use zerocopy::{
+    Immutable,
+    IntoBytes, //
+};
+
 /// The default netlink message size.
 pub const GENLMSG_DEFAULT_SIZE: usize = bindings::GENLMSG_DEFAULT_SIZE;
 
@@ -84,7 +88,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

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help