rust: drm: gpuvm: add SmContext lifetime bound
Subsystems (4)
PATCH 1/1 rust: drm: gpuvm: add SmContext lifetime bound
From: Boris Brezillon <[email protected]>
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.
--- rust/kernel/drm/gpuvm/mod.rs | 4 +++- rust/kernel/drm/gpuvm/sm_ops.rs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-)
rust/kernel/drm/gpuvm/mod.rs +3 -1
@@ -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>(
rust/kernel/drm/gpuvm/sm_ops.rs +2 -2
@@ -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: &'amut UniqueRefGpuVm <T >, user_context: &'amut 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,
Signature · 1 line
Deborah Brouwer <[email protected]>
[email protected]
AI reviewThank 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…
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 <[email protected]>
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.
Quoted 13 lines
rust/kernel/drm/gpuvm/sm_ops.rs +1
-1@@ -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: &'amut UniqueRefGpuVm <T >, user_context: &'amut T ::SmContext <'ctx>, }
[ ... ]
rust/kernel/drm/gpuvm/sm_ops.rs struct SmMapData<'a, 'ctx, T: DriverGpuVm> {
Quoted 1 line
rust/kernel/drm/gpuvm/sm_ops.rs +0
-0@@ -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?
Quoted 5 lines
rust/kernel/drm/gpuvm/sm_ops.rs +1
-1}/// The argument for [`UniqueRefGpuVm::sm_map`]. -pub struct OpMapRequest <'a, 'ctx,T :DriverGpuVm > { +pub struct OpMapRequest <'a, 'ctx,T :DriverGpuVm + 'ctx> {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260610-gpuvm_smcontext_lifetime_bound_v1-v1-1-531e7d2ee7b4@collabora.com?part=1
Quoted 26 lines · Deborah Brouwer
From: Boris Brezillon <[email protected]>
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 <[email protected]>Signed-off-by Deborah Brouwer <[email protected]>--- rust/kernel/drm/gpuvm/mod.rs | 4 +++- rust/kernel/drm/gpuvm/sm_ops.rs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-)rust/kernel/drm/gpuvm/mod.rs +0
-0
rust/kernel/drm/gpuvm/mod.rs pub trait DriverGpuVm: Sized + Send { · line 269
Quoted 7 lines
rust/kernel/drm/gpuvm/mod.rs +3
-1@@ -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.
Quoted 1 line · Deborah Brouwer
[PATCH] rust: drm: gpuvm: add SmContext lifetime bound
Applied, thanks!
Branch: drm-rust-next
Tree: https://gitlab.freedesktop.org/drm/rust/kernel.git
[1/1] rust: drm: gpuvm: add SmContext lifetime bound
commit: 5f7410aa2652