Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH v2 0/5] Fix import of dma-buf buffers as DRM GEM shmem objects
@ 2026-11-24 11:37 Janne Grunau
  2026-11-24 11:37 ` [PATCH v2 1/5] rust: drm: gem: shmem: Do not use drm_gem_shmem_dumb_create() Janne Grunau
  2026-11-26 21:57 ` [PATCH v2 0/5] Fix import of dma-buf buffers as DRM GEM shmem objects Deborah Brouwer
  0 siblings, 2 replies; 4+ messages in thread
From: Janne Grunau @ 2026-11-24 11:37 UTC (permalink / raw)
  To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, David Airlie, Simona Vetter,
	Sami Tolvanen, Lyude Paul, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann
  Cc: rust-for-linux, linux-kernel, dri-devel, nova-gpu, Janne Grunau,
	stable, stable+noautosel

Hej,

this series is triggered by the discussion of gem/shmem.rs SGTableMap
issues in [1] which has an additional issue with imported objects.
Imported objects are supported since GEM shmem's AllocOps use
drm_gem_shmem_prime_import_sg_table() as gem_prime_import_sg_table which
sets the same function pointer field in struct drm_driver.

The code is broken in two ways. SGTableMap::drop() calls
__drm_gem_shmem_free_sgt_locked() uncondiftionally which it must not do
for imported objects as the object does not own `sgt`.
The second issue is that the imported object is allocated by
__drm_gem_shmem_create() with sizeof(struct drm_gem_shmem_object) as
size instead of the size of Rust's Object<T>.

The first issue is fixed in the Asahi downstream driver together with a
drm_gem_is_imported() wrapper change taken from the Tyr downstream
driver.
The second issue is fixed by avoiding to allocate Rust GEM objects
from C. In addition to size issue v1 addressed Rust gem objects may
contain fields with non-trivial `Drop` implementations. Those fields
won't be destroyed in error paths in C code which "destroys" the objects
with `kfree(obj)`. Solve this by re-implementing
gem_prime_import_sg_table() in Rust.
The same issues apply to drm_gem_shmem_dumb_create(). As Asahi and Tyr
as render only devices do not use the `dumb_create` callback just drop
it. When a future driver uses the callback drm_gem_shmem_dumb_create()
needs to be re-implemented in Rust as well.

The series is tested in the Asahi downstream driver. As the prime import
code path is unused in-tree I marked the fixes as not suitable for stable
backports. The known downstream users of the code are aware of the
issues and carry fixes downstream. I don't expect new Rust DRM drivers
to be based on (old) stable trees.

Link: https://lore.kernel.org/rust-for-linux/20261019-rust-shmem-fixes-v1-1-3f7f6de5b5e7@google.com/ [1]
Signed-off-by: Janne Grunau <j@jannau.net>
---
Changes in v2:
- Switch to Rust gem_prime_import_sg_table() implementation
- Drop unsound drm_gem_shmem_dumb_create() as well
- Add `#[inline] annotation to BaseObject::is_imported()
- Drop typoed mail address from To:
- Added Alice's Reviewed-by tags
- Link to v1: https://lore.kernel.org/r/20261026-rust-drm-gem-shmem-imported-sgt-v1-0-36f15ace04b1@jannau.net

---
Janne Grunau (4):
      rust: drm: gem: shmem: Do not use drm_gem_shmem_dumb_create()
      drm/gem/shmem: Initialize private objects via drm_gem_shmem_init() too
      rust: drm: gem: shmem: Implement prime_import_sg_table callback
      rust: drm: gem: shmem: Do not free SG table of imported objects

Sami Tolvanen (1):
      rust: drm: gem: add an is_imported() accessor

 drivers/gpu/drm/drm_gem_shmem_helper.c | 34 +++++++-------
 drivers/gpu/drm/nova/gem.rs            |  4 ++
 drivers/gpu/drm/tyr/gem.rs             |  4 ++
 include/drm/drm_gem_shmem_helper.h     |  3 +-
 rust/helpers/drm.c                     |  6 +++
 rust/kernel/drm/gem/mod.rs             | 17 +++++++
 rust/kernel/drm/gem/shmem.rs           | 81 ++++++++++++++++++++++++++++++++--
 7 files changed, 126 insertions(+), 23 deletions(-)
---
base-commit: 3497a403264b094ebd61b8b755165d56e7d9dc37
change-id: 20261026-rust-drm-gem-shmem-imported-sgt-85c4a45be283

Best regards,
-- 
Janne Grunau <j@jannau.net>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/5] rust: drm: gem: shmem: Do not use drm_gem_shmem_dumb_create()
  2026-11-24 11:37 [PATCH v2 0/5] Fix import of dma-buf buffers as DRM GEM shmem objects Janne Grunau
@ 2026-11-24 11:37 ` Janne Grunau
  2026-11-25 15:03   ` Alice Ryhl
  2026-11-26 21:57 ` [PATCH v2 0/5] Fix import of dma-buf buffers as DRM GEM shmem objects Deborah Brouwer
  1 sibling, 1 reply; 4+ messages in thread
From: Janne Grunau @ 2026-11-24 11:37 UTC (permalink / raw)
  To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, David Airlie, Simona Vetter,
	Sami Tolvanen, Lyude Paul, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann
  Cc: rust-for-linux, linux-kernel, dri-devel, nova-gpu, Janne Grunau,
	stable

The existing gem::shmem using Rust GPU drivers (Ashi and Tyr) are render
only devices which should not set the dumb_create callback. When a
driver with KMS functionality is added it probably will not be able to use
drm_gem_shmem_dumb_create().
The Rust gem::shmem::Object<T> wrapper should be allocated and destroyed
from Rust code. DRM drivers have a `gem_create_object` callback which
could be used to allocate objects from Rust. The C code will "destroy"
objects with `kfree(object)` on error paths which is unsound if the Rust
object's DriverObject contains fields with a non-trivial `Drop`
implementation.

Suggested-by: Alice Ryhl <aliceryhl@google.com>
Fixes: 80df573af9ef ("rust: drm: gem: shmem: Add DRM shmem helper abstraction")
Cc: stable@vger.kernel.org
Signed-off-by: Janne Grunau <j@jannau.net>
---
 rust/kernel/drm/gem/shmem.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/kernel/drm/gem/shmem.rs b/rust/kernel/drm/gem/shmem.rs
index a687d46d170d..78a152f0f30c 100644
--- a/rust/kernel/drm/gem/shmem.rs
+++ b/rust/kernel/drm/gem/shmem.rs
@@ -394,7 +394,7 @@ impl<T: DriverObject> driver::AllocImpl for Object<T> {
         prime_fd_to_handle: None,
         gem_prime_import: None,
         gem_prime_import_sg_table: Some(bindings::drm_gem_shmem_prime_import_sg_table),
-        dumb_create: Some(bindings::drm_gem_shmem_dumb_create),
+        dumb_create: None,
         dumb_map_offset: None,
     };
 }

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/5] rust: drm: gem: shmem: Do not use drm_gem_shmem_dumb_create()
  2026-11-24 11:37 ` [PATCH v2 1/5] rust: drm: gem: shmem: Do not use drm_gem_shmem_dumb_create() Janne Grunau
@ 2026-11-25 15:03   ` Alice Ryhl
  0 siblings, 0 replies; 4+ messages in thread
From: Alice Ryhl @ 2026-11-25 15:03 UTC (permalink / raw)
  To: Janne Grunau
  Cc: Alice Ryhl, Miguel Ojeda, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, David Airlie, Simona Vetter,
	Sami Tolvanen, Lyude Paul, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, rust-for-linux, linux-kernel, dri-devel,
	nova-gpu, stable

On Tue, Nov 24, 2026 at 12:37:43PM +0100, Janne Grunau wrote:
> The existing gem::shmem using Rust GPU drivers (Ashi and Tyr) are render
> only devices which should not set the dumb_create callback. When a
> driver with KMS functionality is added it probably will not be able to use
> drm_gem_shmem_dumb_create().
> The Rust gem::shmem::Object<T> wrapper should be allocated and destroyed
> from Rust code. DRM drivers have a `gem_create_object` callback which
> could be used to allocate objects from Rust. The C code will "destroy"
> objects with `kfree(object)` on error paths which is unsound if the Rust
> object's DriverObject contains fields with a non-trivial `Drop`
> implementation.
> 
> Suggested-by: Alice Ryhl <aliceryhl@google.com>
> Fixes: 80df573af9ef ("rust: drm: gem: shmem: Add DRM shmem helper abstraction")
> Cc: stable@vger.kernel.org
> Signed-off-by: Janne Grunau <j@jannau.net>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/5] Fix import of dma-buf buffers as DRM GEM shmem objects
  2026-11-24 11:37 [PATCH v2 0/5] Fix import of dma-buf buffers as DRM GEM shmem objects Janne Grunau
  2026-11-24 11:37 ` [PATCH v2 1/5] rust: drm: gem: shmem: Do not use drm_gem_shmem_dumb_create() Janne Grunau
@ 2026-11-26 21:57 ` Deborah Brouwer
  1 sibling, 0 replies; 4+ messages in thread
From: Deborah Brouwer @ 2026-11-26 21:57 UTC (permalink / raw)
  To: Janne Grunau
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, David Airlie, Simona Vetter,
	Sami Tolvanen, Lyude Paul, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, rust-for-linux, linux-kernel, dri-devel,
	nova-gpu, stable, stable+noautosel

On Tue, Nov 24, 2026 at 12:37:42PM +0100, Janne Grunau wrote:
> Hej,
> 
> this series is triggered by the discussion of gem/shmem.rs SGTableMap
> issues in [1] which has an additional issue with imported objects.
> Imported objects are supported since GEM shmem's AllocOps use
> drm_gem_shmem_prime_import_sg_table() as gem_prime_import_sg_table which
> sets the same function pointer field in struct drm_driver.
> 
> The code is broken in two ways. SGTableMap::drop() calls
> __drm_gem_shmem_free_sgt_locked() uncondiftionally which it must not do
> for imported objects as the object does not own `sgt`.
> The second issue is that the imported object is allocated by
> __drm_gem_shmem_create() with sizeof(struct drm_gem_shmem_object) as
> size instead of the size of Rust's Object<T>.
> 
> The first issue is fixed in the Asahi downstream driver together with a
> drm_gem_is_imported() wrapper change taken from the Tyr downstream
> driver.
> The second issue is fixed by avoiding to allocate Rust GEM objects
> from C. In addition to size issue v1 addressed Rust gem objects may
> contain fields with non-trivial `Drop` implementations. Those fields
> won't be destroyed in error paths in C code which "destroys" the objects
> with `kfree(obj)`. Solve this by re-implementing
> gem_prime_import_sg_table() in Rust.
> The same issues apply to drm_gem_shmem_dumb_create(). As Asahi and Tyr
> as render only devices do not use the `dumb_create` callback just drop
> it. When a future driver uses the callback drm_gem_shmem_dumb_create()
> needs to be re-implemented in Rust as well.
> 
> The series is tested in the Asahi downstream driver. As the prime import
> code path is unused in-tree I marked the fixes as not suitable for stable
> backports. The known downstream users of the code are aware of the
> issues and carry fixes downstream. I don't expect new Rust DRM drivers
> to be based on (old) stable trees.
> 
> Link: https://lore.kernel.org/rust-for-linux/20261019-rust-shmem-fixes-v1-1-3f7f6de5b5e7@google.com/ [1]
> Signed-off-by: Janne Grunau <j@jannau.net>

Thank you Janne for this series, I tested it on my rock 5B
by running the igt tests [1]
with the proposed ioctl changes to tyr [2]
and it is working great.

So, for the whole series:

Tested-by: Deborah Brouwer <deborah.brouwer@collabora.com>

[1] https://gitlab.freedesktop.org/drm/igt-gpu-tools/-/tree/master/tests/panthor
[2] https://lore.kernel.org/rust-for-linux/20261122-tyr-ioctls-v7-0-3a2af624b992@linux.dev/

> ---
> Changes in v2:
> - Switch to Rust gem_prime_import_sg_table() implementation
> - Drop unsound drm_gem_shmem_dumb_create() as well
> - Add `#[inline] annotation to BaseObject::is_imported()
> - Drop typoed mail address from To:
> - Added Alice's Reviewed-by tags
> - Link to v1: https://lore.kernel.org/r/20261026-rust-drm-gem-shmem-imported-sgt-v1-0-36f15ace04b1@jannau.net
> 
> ---
> Janne Grunau (4):
>       rust: drm: gem: shmem: Do not use drm_gem_shmem_dumb_create()
>       drm/gem/shmem: Initialize private objects via drm_gem_shmem_init() too
>       rust: drm: gem: shmem: Implement prime_import_sg_table callback
>       rust: drm: gem: shmem: Do not free SG table of imported objects
> 
> Sami Tolvanen (1):
>       rust: drm: gem: add an is_imported() accessor
> 
>  drivers/gpu/drm/drm_gem_shmem_helper.c | 34 +++++++-------
>  drivers/gpu/drm/nova/gem.rs            |  4 ++
>  drivers/gpu/drm/tyr/gem.rs             |  4 ++
>  include/drm/drm_gem_shmem_helper.h     |  3 +-
>  rust/helpers/drm.c                     |  6 +++
>  rust/kernel/drm/gem/mod.rs             | 17 +++++++
>  rust/kernel/drm/gem/shmem.rs           | 81 ++++++++++++++++++++++++++++++++--
>  7 files changed, 126 insertions(+), 23 deletions(-)
> ---
> base-commit: 3497a403264b094ebd61b8b755165d56e7d9dc37
> change-id: 20261026-rust-drm-gem-shmem-imported-sgt-85c4a45be283
> 
> Best regards,
> -- 
> Janne Grunau <j@jannau.net>
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-26 21:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 11:37 [PATCH v2 0/5] Fix import of dma-buf buffers as DRM GEM shmem objects Janne Grunau
2026-11-24 11:37 ` [PATCH v2 1/5] rust: drm: gem: shmem: Do not use drm_gem_shmem_dumb_create() Janne Grunau
2026-11-25 15:03   ` Alice Ryhl
2026-11-26 21:57 ` [PATCH v2 0/5] Fix import of dma-buf buffers as DRM GEM shmem objects Deborah Brouwer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox