* [PATCH] rust: drm: gpuvm: add SmContext lifetime bound
@ 2026-06-11 0:04 Deborah Brouwer
2026-06-11 0:12 ` sashiko-bot
2026-06-11 8:03 ` Alice Ryhl
0 siblings, 2 replies; 3+ messages in thread
From: Deborah Brouwer @ 2026-06-11 0:04 UTC (permalink / raw)
To: Danilo Krummrich, Matthew Brost, Thomas Hellström,
Alice Ryhl, David Airlie, Simona Vetter, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross
Cc: dri-devel, rust-for-linux, linux-kernel, laura.nao, samitolvanen,
boris.brezillon, Deborah Brouwer
From: Boris Brezillon <boris.brezillon@collabora.com>
If a DriverGpuVm implementation is lifetime-parameterized, its
SmContext<'ctx> type may depend on lifetimes carried by that driver
implementation. In this case, SmContext<'ctx> is only valid if the
driver implementation outlives 'ctx.
Add a Self: 'ctx bound to DriverGpuVm::SmContext<'ctx> to express that
requirement. Then propagate the corresponding T: 'ctx bound to the GPUVM
state machine helper types that store T::SmContext<'ctx>.
This allows drivers to provide lifetime-parameterized implementations of
DriverGpuVm.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
---
rust/kernel/drm/gpuvm/mod.rs | 4 +++-
rust/kernel/drm/gpuvm/sm_ops.rs | 4 ++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/rust/kernel/drm/gpuvm/mod.rs b/rust/kernel/drm/gpuvm/mod.rs
index ae58f6f667c1..1ec649fa50ea 100644
--- a/rust/kernel/drm/gpuvm/mod.rs
+++ b/rust/kernel/drm/gpuvm/mod.rs
@@ -264,7 +264,9 @@ pub trait DriverGpuVm: Sized + Send {
type VmBoData;
/// The private data passed to callbacks.
- type SmContext<'ctx>;
+ type SmContext<'ctx>
+ where
+ Self: 'ctx;
/// Indicates that a new mapping should be created.
fn sm_step_map<'op, 'ctx>(
diff --git a/rust/kernel/drm/gpuvm/sm_ops.rs b/rust/kernel/drm/gpuvm/sm_ops.rs
index 69a8e5ab2821..742c151b2540 100644
--- a/rust/kernel/drm/gpuvm/sm_ops.rs
+++ b/rust/kernel/drm/gpuvm/sm_ops.rs
@@ -3,7 +3,7 @@
use super::*;
/// The actual data that gets threaded through the callbacks.
-struct SmData<'a, 'ctx, T: DriverGpuVm> {
+struct SmData<'a, 'ctx, T: DriverGpuVm + 'ctx> {
gpuvm: &'a mut UniqueRefGpuVm<T>,
user_context: &'a mut T::SmContext<'ctx>,
}
@@ -20,7 +20,7 @@ struct SmMapData<'a, 'ctx, T: DriverGpuVm> {
}
/// The argument for [`UniqueRefGpuVm::sm_map`].
-pub struct OpMapRequest<'a, 'ctx, T: DriverGpuVm> {
+pub struct OpMapRequest<'a, 'ctx, T: DriverGpuVm + 'ctx> {
/// Address in GPU virtual address space.
pub addr: u64,
/// Length of mapping to create.
---
base-commit: 550dc7536644db2d67c6f8cf525bba682fba08d9
change-id: 20260610-gpuvm_smcontext_lifetime_bound_v1-f829c05d80c9
Best regards,
--
Deborah Brouwer <deborah.brouwer@collabora.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] rust: drm: gpuvm: add SmContext lifetime bound
2026-06-11 0:04 [PATCH] rust: drm: gpuvm: add SmContext lifetime bound Deborah Brouwer
@ 2026-06-11 0:12 ` sashiko-bot
2026-06-11 8:03 ` Alice Ryhl
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-06-11 0:12 UTC (permalink / raw)
To: Deborah Brouwer; +Cc: ojeda, dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The `SmMapData` struct fails to compile because it lacks the `T: 'ctx` bound required by its `sm_data` field.
--
commit 79bf9106553be7b558ccc116bf8b7922eb388043
Author: Boris Brezillon <boris.brezillon@collabora.com>
rust: drm: gpuvm: add SmContext lifetime bound
This commit adds a Self: 'ctx bound to DriverGpuVm::SmContext<'ctx> and
propagates it as T: 'ctx to the GPUVM state machine helper types. This allows
drivers to provide lifetime-parameterized implementations of DriverGpuVm.
> diff --git a/rust/kernel/drm/gpuvm/sm_ops.rs b/rust/kernel/drm/gpuvm/sm_ops.rs
> index 69a8e5ab2821f..742c151b2540e 100644
> --- a/rust/kernel/drm/gpuvm/sm_ops.rs
> +++ b/rust/kernel/drm/gpuvm/sm_ops.rs
> @@ -3,7 +3,7 @@
> use super::*;
>
> /// The actual data that gets threaded through the callbacks.
> -struct SmData<'a, 'ctx, T: DriverGpuVm> {
> +struct SmData<'a, 'ctx, T: DriverGpuVm + 'ctx> {
> gpuvm: &'a mut UniqueRefGpuVm<T>,
> user_context: &'a mut T::SmContext<'ctx>,
> }
[ ... ]
> @@ -20,7 +20,7 @@ struct SmMapData<'a, 'ctx, T: DriverGpuVm> {
[Severity: Low]
Will this fail to compile because SmMapData lacks the T: 'ctx bound?
Since SmMapData embeds SmData<'a, 'ctx, T>, which now requires
T: DriverGpuVm + 'ctx, doesn't SmMapData also need the same lifetime bound to
satisfy the requirements of its sm_data field?
> }
>
> /// The argument for [`UniqueRefGpuVm::sm_map`].
> -pub struct OpMapRequest<'a, 'ctx, T: DriverGpuVm> {
> +pub struct OpMapRequest<'a, 'ctx, T: DriverGpuVm + 'ctx> {
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260610-gpuvm_smcontext_lifetime_bound_v1-v1-1-531e7d2ee7b4@collabora.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] rust: drm: gpuvm: add SmContext lifetime bound
2026-06-11 0:04 [PATCH] rust: drm: gpuvm: add SmContext lifetime bound Deborah Brouwer
2026-06-11 0:12 ` sashiko-bot
@ 2026-06-11 8:03 ` Alice Ryhl
1 sibling, 0 replies; 3+ messages in thread
From: Alice Ryhl @ 2026-06-11 8:03 UTC (permalink / raw)
To: Deborah Brouwer
Cc: Danilo Krummrich, Matthew Brost, Thomas Hellström,
David Airlie, Simona Vetter, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, dri-devel, rust-for-linux, linux-kernel, laura.nao,
samitolvanen, boris.brezillon
On Wed, Jun 10, 2026 at 05:04:31PM -0700, Deborah Brouwer wrote:
> From: Boris Brezillon <boris.brezillon@collabora.com>
>
> If a DriverGpuVm implementation is lifetime-parameterized, its
> SmContext<'ctx> type may depend on lifetimes carried by that driver
> implementation. In this case, SmContext<'ctx> is only valid if the
> driver implementation outlives 'ctx.
>
> Add a Self: 'ctx bound to DriverGpuVm::SmContext<'ctx> to express that
> requirement. Then propagate the corresponding T: 'ctx bound to the GPUVM
> state machine helper types that store T::SmContext<'ctx>.
>
> This allows drivers to provide lifetime-parameterized implementations of
> DriverGpuVm.
>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
> ---
> rust/kernel/drm/gpuvm/mod.rs | 4 +++-
> rust/kernel/drm/gpuvm/sm_ops.rs | 4 ++--
> 2 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/rust/kernel/drm/gpuvm/mod.rs b/rust/kernel/drm/gpuvm/mod.rs
> index ae58f6f667c1..1ec649fa50ea 100644
> --- a/rust/kernel/drm/gpuvm/mod.rs
> +++ b/rust/kernel/drm/gpuvm/mod.rs
> @@ -264,7 +264,9 @@ pub trait DriverGpuVm: Sized + Send {
> type VmBoData;
>
> /// The private data passed to callbacks.
> - type SmContext<'ctx>;
> + type SmContext<'ctx>
> + where
> + Self: 'ctx;
This imposes the requirement that the GpuVm private data cannot contain
any references that expire during 'ctx. Since 'ctx represents the
duration of a call to sm_map() or sm_unmap(), this seems reasonable.
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-11 8:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-11 0:04 [PATCH] rust: drm: gpuvm: add SmContext lifetime bound Deborah Brouwer
2026-06-11 0:12 ` sashiko-bot
2026-06-11 8:03 ` Alice Ryhl
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.