Re: [PATCH v3 3/5] rust: drm: gem: shmem: Implement prime_import_sg_table callback
From: Janne Grunau
Date: Sat Dec 05 2026 - 08:35:31 EST
On Fri, Dec 04, 2026 at 06:15:17PM -0300, Daniel Almeida wrote:
>
>
> > On 3 Dec 2026, at 07:14, Janne Grunau <j@xxxxxxxxxx> wrote:
> >
> > The C drm_gem_shmem_prime_import_sg_table() helper function uses
> > `__drm_gem_shmem_create()` to create shmem objects. In the absence of a
> > `gem_create_object` callback this allocates just a `struct
> > drm_gem_shmem_object` resulting in buffer overflows when using it as
> > Rust `Object<t>`.
> > Implementing the `gem_create_object` callback for RUST DRM drivers is
> > not sufficient as `__drm_gem_shmem_create()` uses `kfree(obj)` in error
> > paths. This is unsound if the DriverObject contains fields with
> > non-trivial `Drop` implementations as noted in [1].
> >
> > Imported BOs have no userspace creation arguments, so extend
> > `DriverObject` with a `create_imported(dev, size)` constructor and
> > implement it for Tyr's `BoData`, Nova, and the in-tree KUnit driver.
> >
> > Tested with the asahi downstream driver.
> >
> > Link: https://lore.kernel.org/rust-for-linux/20261118114102.490384-1-aliceryhl@xxxxxxxxxx/ [1]
> > Fixes: 80df573af9ef ("rust: drm: gem: shmem: Add DRM shmem helper abstraction")
> > Cc: stable+noautosel@xxxxxxxxxx # no in tree users
> > Suggested-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
> > Co-developed-by: Sami Tolvanen <samitolvanen@xxxxxxxxxx>
> > Signed-off-by: Sami Tolvanen <samitolvanen@xxxxxxxxxx>
> > Tested-by: Deborah Brouwer <deborah.brouwer@xxxxxxxxxxxxx>
> > Signed-off-by: Janne Grunau <j@xxxxxxxxxx>
> > ---
[...]
> > diff --git a/rust/kernel/drm/driver.rs b/rust/kernel/drm/driver.rs
> > index f6db91e81e79..7e8e842421a4 100644
> > --- a/rust/kernel/drm/driver.rs
> > +++ b/rust/kernel/drm/driver.rs
> > @@ -118,7 +118,7 @@ pub trait Driver {
> > type RegistrationData<'a>: Send + Sync + 'a;
> >
> > /// The type used to manage memory for this driver.
> > - type Object: AllocImpl;
> > + type Object: AllocImpl<Driver = Self>;
>
> I think this should be its own, preceding patch, IMHO.
>
> This change is needed regardless. The problem only became apparent now with
> imported buffers, but it is otherwise a pre-existing issue.
I don't disagree but I forgot to split this off before I sent v4 out.
I don't think it justifies a respin. We're very close to -rc6 and I'd
like to see this in the pull request for v7.5.
Janne