Re: [PATCH v3 3/5] rust: drm: gem: shmem: Implement prime_import_sg_table callback

From: Alice Ryhl

Date: Fri Dec 04 2026 - 06:43:32 EST


On Thu, Dec 3, 2026 at 11:14 AM 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>

Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>