From: "Gary Guo" <gary@garyguo.net>
To: "Sagar Taunk" <sagartaunk@proton.me>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Danilo Krummrich" <dakr@kernel.org>
Cc: "Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Eric Dumazet" <edumazet@google.com>,
"David S . Miller" <davem@davemloft.net>,
"Simon Horman" <horms@kernel.org>,
"Abdiel Janulgue" <abdiel.janulgue@gmail.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Robin Murphy" <robin.murphy@arm.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/3] rust: dma.rs: Migrate to zerocopy's `Frombytes/IntoBytes`
Date: Sun, 06 Sep 2026 13:47:25 +0100 [thread overview]
Message-ID: <DL88TLWYE8H8.1FP5GCIYUL1BN@garyguo.net> (raw)
In-Reply-To: <20260906102826.202874-4-sagartaunk@proton.me>
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,
next prev parent reply other threads:[~2026-09-06 12:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-09-06 15:48 ` Danilo Krummrich
2026-09-06 16:34 ` Sagar Taunk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DL88TLWYE8H8.1FP5GCIYUL1BN@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=abdiel.janulgue@gmail.com \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=davem@davemloft.net \
--cc=driver-core@lists.linux.dev \
--cc=edumazet@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=pabeni@redhat.com \
--cc=robin.murphy@arm.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=sagartaunk@proton.me \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).