Rust for Linux List
 help / color / mirror / Atom feed
From: Alice Ryhl <aliceryhl@google.com>
To: Deborah Brouwer <deborah.brouwer@collabora.com>
Cc: "Alice Ryhl" <aliceryhl@google.com>,
	"Miguel Ojeda" <ojeda@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>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3 2/2] drm/tyr: allow userspace buffers to be mismatched
Date: Tue, 20 Oct 2026 08:33:53 +0000	[thread overview]
Message-ID: <20261020083353.1821078-1-aliceryhl@google.com> (raw)
In-Reply-To: <atarvxFKYYuHhXGQ@um790>

On Mon, Oct 19, 2026 at 04:46:07PM -0700, Deborah Brouwer wrote:
> On Mon, Oct 19, 2026 at 08:01:59AM +0000, Alice Ryhl wrote:
> > > +    transmute::AsBytes,
> > 
> > Usie the trait from zerocopy instead.
> 
> If this other series making zerocopy available to Tyr gets merged,
> then I could rebase this series on it and switch over to IntoBytes:
> 
> https://lore.kernel.org/rust-for-linux/20261019-b4-gpu_info_intobytes-v4-0-0bc04df46549@collabora.com/T/#m9a9a24e0cf1ae10451e3fc84955873b405d0da0b

Rebasing this series on top of that one makes sense to me (you can also
already send v4 based on it and note the dependency in the cover letter).
Note that set_uobj will need T: IntoBytes + Immutable and can call
writer.write_slice_partial(src_obj.as_bytes(), 0)? unless write_truncated()
is also updated to use zerocopy.

> > > +    let mut writer = UserSlice::new(UserPtr::from_addr(usr_dst as usize), size).writer();
> > 
> > On 32-bit this will truncate upper bits. I guess that probably matches
> > what Panthor does. Is it what we want?
> 
> Yes, that's what Panthor does; it uses the "u64_to_user_ptr()" macro to do
> this deliberately.
> 
> Since UserPtr only accepts a usize argument, I have to cast in Tyr,
> but instead, what do you think if I added another method to UserPtr
> to accept a u64 address and cast it to usize just like in the C macro.
> Something like:
> 
>     /// Create a `UserPtr` from a u64 userspace address.
>     ///
>     /// Deliberately truncate upper bits for 32-bit systems.
>     #[doc(alias = "u64_to_user_ptr")]
>     #[inline]
>     pub fn from_u64(addr: u64) -> Self {
>         Self::from_addr(addr as usize)
>     }

Adding UserPtr::from_u64() like that sounds good to me! That keeps UserSlice
construction infallible (matching u64_to_user_ptr(), including when the slice
length is 0), and we can also use it to replace the existing `as usize` casts
in drivers/android/binder/thread.rs.

Alice

      reply	other threads:[~2026-10-20  8:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 20:44 [PATCH v3 0/2] drm/tyr: allow mismatched buffers for dev_query Deborah Brouwer
2026-10-16 20:44 ` [PATCH v3 1/2] rust: uaccess: add UserSliceWriter::clear() Deborah Brouwer
2026-10-16 20:44 ` [PATCH v3 2/2] drm/tyr: allow userspace buffers to be mismatched Deborah Brouwer
2026-10-19  8:01   ` Alice Ryhl
2026-10-19 23:46     ` Deborah Brouwer
2026-10-20  8:33       ` Alice Ryhl [this message]

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=20261020083353.1821078-1-aliceryhl@google.com \
    --to=aliceryhl@google.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=deborah.brouwer@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --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