On Mon, Oct 19, 2026 at 08:01:59AM +0000, Alice Ryhl wrote:
> On Fri, Oct 16, 2026 at 01:44:21PM -0700, Deborah Brouwer wrote:
> > Allow userspace to provide a buffer that is smaller or larger than the
> > object that the kernel expects to write into it.
> > 
> > Set a minimum buffer size to match those in PANTHOR_UOBJ_MIN_SIZE. If
> > userspace provides at least the minimum buffer size, then simply write
> > until the buffer is full.
> > 
> > If userspace provides a larger buffer than necessary, then zero out the
> > remaining buffer.
> > 
> > This ensures UAPI compatibility with Panthor.
> > 
> > Signed-off-by: Deborah Brouwer <[email protected]>
> > ---
> >  drivers/gpu/drm/tyr/file.rs | 47 
> > +++++++++++++++++++++++++++++++++++++--------
> >  1 file changed, 39 insertions(+), 8 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/tyr/file.rs b/drivers/gpu/drm/tyr/file.rs
> > index 9f60a90d4948..a153aa453ed1 100644
> > --- a/drivers/gpu/drm/tyr/file.rs
> > +++ b/drivers/gpu/drm/tyr/file.rs
> > @@ -1,11 +1,18 @@
> >  // SPDX-License-Identifier: GPL-2.0 or MIT
> >  
> > +use core::mem::{
> > +    offset_of,
> > +    size_of_val, //
> > +};
> 
> size_of_val is present in kernel::prelude::* and does not need explicit
> import.

Ack, will fix in next version.

> 
> > +    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/[email protected]/T/#m9a9a24e0cf1ae10451e3fc84955873b405d0da0b

> 
> > +    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)
    }

> 
> Alice

Reply via email to