mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: "Danilo Krummrich" <dakr@kernel.org>, <acourbot@nvidia.com>,
	<aliceryhl@google.com>, <abdiel.janulgue@gmail.com>,
	<daniel.almeida@collabora.com>, <robin.murphy@arm.com>,
	<a.hindborg@kernel.org>, <ojeda@kernel.org>, <boqun@kernel.org>,
	<gary@garyguo.net>, <bjorn3_gh@protonmail.com>,
	<lossin@kernel.org>, <tmgross@umich.edu>, <ttabi@nvidia.com>
Cc: <nouveau@lists.freedesktop.org>,
	<dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org>,
	<driver-core@lists.linux.dev>, <rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH 1/3] rust: uaccess: generalize write_dma() to accept any Coherent<T>
Date: Wed, 25 Mar 2026 13:01:07 +0000	[thread overview]
Message-ID: <DHBVS7DX89G2.34ELW7TJAH7M8@garyguo.net> (raw)
In-Reply-To: <20260325003921.3420-1-dakr@kernel.org>

On Wed Mar 25, 2026 at 12:39 AM GMT, Danilo Krummrich wrote:
> Generalize write_dma() from &Coherent<[u8]> to &Coherent<T> where
> T: KnownSize + AsBytes + ?Sized. The function body only uses as_ptr()
> and size(), which work for any such T, so there is no reason to
> restrict it to byte slices.

I think there is a reason, which is that it weakens the strong typing that we
have. I think it'll be better to have this be

    fn write_dma<T>(&mut self, view: View<'_, Coherent<T>, [u8]>, offset: usize) -> Result

once we have I/O view and expect people to create cast views into bytes
explicitly.

Although, given that we already have APIs like

    fn write<T: AsBytes>(&mut self, value: &T)

I'm okay with putting this in until we have a replacement solution.

The fact that our current uaccess mechanism is untyped itself is something that
I dislike (it feels a step back that C can represent `arbitary_type __user*` and
we just have a `void __user*`). It's on my list of things to fix to make a
generic `UserPtr<T>`.

Best,
Gary

>
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> ---
>  rust/kernel/uaccess.rs | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs
> index e26ef90ba8ad..6c9c1cce3c63 100644
> --- a/rust/kernel/uaccess.rs
> +++ b/rust/kernel/uaccess.rs
> @@ -12,6 +12,7 @@
>      ffi::{c_char, c_void},
>      fs::file,
>      prelude::*,
> +    ptr::KnownSize,
>      transmute::{AsBytes, FromBytes},
>  };
>  use core::mem::{size_of, MaybeUninit};
> @@ -524,7 +525,12 @@ pub fn write_slice(&mut self, data: &[u8]) -> Result {
>      ///     writer.write_dma(alloc, 0, 256)
>      /// }
>      /// ```
> -    pub fn write_dma(&mut self, alloc: &Coherent<[u8]>, offset: usize, count: usize) -> Result {
> +    pub fn write_dma<T: KnownSize + AsBytes + ?Sized>(
> +        &mut self,
> +        alloc: &Coherent<T>,
> +        offset: usize,
> +        count: usize,
> +    ) -> Result {
>          let len = alloc.size();
>          if offset.checked_add(count).ok_or(EOVERFLOW)? > len {
>              return Err(ERANGE);
>
> base-commit: dff8302ca1d0e773c90dbeeb05e759f995c95482


  parent reply	other threads:[~2026-03-25 13:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-25  0:39 Danilo Krummrich
2026-03-25  0:39 ` [PATCH 2/3] rust: dma: generalize BinaryWriter impl for Coherent<T> Danilo Krummrich
2026-03-27 20:58   ` Danilo Krummrich
2026-03-25  0:39 ` [PATCH 3/3] gpu: nova-core: use sized array for GSP log buffers Danilo Krummrich
2026-03-27 20:58   ` Danilo Krummrich
2026-03-25 11:44 ` [PATCH 1/3] rust: uaccess: generalize write_dma() to accept any Coherent<T> Alice Ryhl
2026-03-25 13:01 ` Gary Guo [this message]
2026-03-25 13:46   ` Danilo Krummrich
2026-03-25 14:55     ` Gary Guo
2026-03-26  0:39 ` Alexandre Courbot
2026-03-26 13:33 ` Gary Guo
2026-03-26 18:17 ` Miguel Ojeda
2026-03-27 20:58 ` Danilo Krummrich

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=DHBVS7DX89G2.34ELW7TJAH7M8@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=dri-devel@lists.freedesktop.org \
    --cc=driver-core@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=ojeda@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    /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

all inboxes | Powered by JetHome®