drm/tyr: use pin-init self-referential support
Subsystems (5)
Danilo Krummrich
maintainercover drm/tyr: use pin-init self-referential support
This series uses pin-init's self-referential support to replace Arcs for resources whose lifetimes are bounded by their owners.
It also cleans up lifetime names, fixes a Clippy warning in generated pin-init code, and simplifies firmware loading cleanup with ScopeGuard.
Danilo Krummrich (4):
drm/tyr: name resource lifetimes after their types
rust: pin-init: internal: suppress multiple_bound_locations drm/tyr: use pin-init self-referential support drm/tyr: use ScopeGuard for firmware loading cleanup
drivers/gpu/drm/tyr/driver.rs | 38 +++--- drivers/gpu/drm/tyr/fw.rs | 151 ++++++++++++----------- drivers/gpu/drm/tyr/gem.rs | 15 +-- drivers/gpu/drm/tyr/mmu.rs | 56 ++++----- drivers/gpu/drm/tyr/mmu/address_space.rs | 40 +++--- drivers/gpu/drm/tyr/vm.rs | 119 +++++++++--------- rust/pin-init/internal/src/pin_data.rs | 3 +- 7 files changed, 209 insertions(+), 213 deletions(-)
base-commit: e55a991e09e3b44f0b0d8206bb523dc57c086341
Signature · 1 line
2.56.1
Danilo Krummrich
maintainerPATCH 1/4 drm/tyr: name resource lifetimes after their types
The firmware, buffer, VM and MMU types use 'drm for their resource lifetimes, even though each parameter is local to its type.
Rename these parameters to reflect the respective type's scope in preparation for converting the resource ownership to self-referential pin-init.
--- drivers/gpu/drm/tyr/fw.rs | 26 +++++++-------- drivers/gpu/drm/tyr/gem.rs | 8 ++--- drivers/gpu/drm/tyr/mmu.rs | 24 +++++++------- drivers/gpu/drm/tyr/mmu/address_space.rs | 30 ++++++++--------- drivers/gpu/drm/tyr/vm.rs | 42 ++++++++++++------------ 5 files changed, 65 insertions(+), 65 deletions(-)
drivers/gpu/drm/tyr/fw.rs +13 -13
@@ -131,7 +131,7 @@ fn try_from_fw(value: u32) -> Result<Self> { }/// A parsed section of the firmware binary. -struct Section <'drm> { +struct Section <'sec> {// Raw firmware section data for reset purposes #[expect(dead_code)] data:KVec <u8 >,
@@ -139,23 +139,23 @@ struct Section<'drm> {// Keep the BO backing this firmware section so that both the // GPU mapping and CPU mapping remain valid until the Section is dropped. #[expect(dead_code)] - mem: gem::KernelBo<'drm>, + mem: gem::KernelBo<'sec>, }/// Loaded firmware with sections mapped into MCU VM. -pub (crate )struct Firmware <'drm> { +pub (crate )struct Firmware <'fw> {/// Iomem need to access registers. - iomem:Arc <IoMem <'drm>>, + iomem:Arc <IoMem <'fw>>,/// MCU VM. - vm:Arc <Vm <'drm>>, + vm:Arc <Vm <'fw>>,/// List of firmware sections. #[expect(dead_code)] - sections:KVec <Section <'drm>>, + sections:KVec <Section <'fw>>, } -impl <'drm>Drop for Firmware <'drm> { +impl <'fw>Drop for Firmware <'fw> {fn drop (&mut self) {// Stop the MCU before releasing its firmware mappings and memory. let _ = self.stop ();
@@ -165,8 +165,8 @@ fn drop(&mut self) { } } -impl <'drm>Firmware <'drm> { -fn init_section_mem (dev: &Device , mem: &mut KernelBo <'drm>, data: &KVec <u8 >) ->Result { +impl <'fw>Firmware <'fw> { +fn init_section_mem (dev: &Device , mem: &mut KernelBo <'fw>, data: &KVec <u8 >) ->Result {if data.is_empty () {return Ok (()); }
@@ -213,12 +213,12 @@ fn load(/// Load firmware and map sections into MCU VM. pub (crate )fn new ( - dev: &'drmDevice <Bound >, - iomem:Arc <IoMem <'drm>>, + dev: &'fwDevice <Bound >, + iomem:Arc <IoMem <'fw>>, ddev: &TyrDrmDevice , - mmu:ArcBorrow <'_,Mmu <'drm>>, + mmu:ArcBorrow <'_,Mmu <'fw>>, gpu_info: &GpuInfo , - ) ->Result <Firmware <'drm>> { + ) ->Result <Firmware <'fw>> {let vm =Vm ::new (dev, ddev, mmu, gpu_info)?; vm.activate ()?;
drivers/gpu/drm/tyr/gem.rs +4 -4
@@ -82,16 +82,16 @@ pub(crate) enum KernelBoVaAlloc {/// a GEM object with automatic GPU virtual address (VA) space mapping and cleanup. /// /// When dropped, the buffer is automatically unmapped from the GPU VA space. -pub (crate )struct KernelBo <'drm> { +pub (crate )struct KernelBo <'bo> {/// The underlying GEM buffer object. bo:ARef <Bo >,/// The GPU VM this buffer is mapped into. - vm:Arc <Vm <'drm>>, + vm:Arc <Vm <'bo>>,/// The GPU VA range occupied by this buffer. va_range:Range <u64 >, } -impl <'drm>KernelBo <'drm> { +impl <'bo>KernelBo <'bo> {/// Creates a new kernel-owned buffer object and maps it into GPU VA space. /// /// This function allocates a new shmem-backed GEM object and immediately maps
@@ -99,7 +99,7 @@ impl<'drm> KernelBo<'drm> {/// cleaned up when the [`KernelBo`] is dropped. pub (crate )fn new ( ddev: &TyrDrmDevice , - vm:Arc <Vm <'drm>>, + vm:Arc <Vm <'bo>>, size:u64 , va_alloc:KernelBoVaAlloc , flags: VmMapFlags,
drivers/gpu/drm/tyr/mmu.rs +12 -12
@@ -43,23 +43,23 @@pub (crate )mod address_space; -pub (crate )type AsSlotManager <'drm> =SlotManager <AddressSpaceManager <'drm>,MAX_AS >; +pub (crate )type AsSlotManager <'as_mgr> =SlotManager <AddressSpaceManager <'as_mgr>,MAX_AS >;/// Locked wrapper for carrying out virtual memory (VM) operations on the MMU. #[pin_data] -pub (crate )struct Mmu <'drm> { +pub (crate )struct Mmu <'mmu> {/// Slot Manager instance used to allocate hardware slots and write to MMU registers. #[pin] -pub (crate ) as_manager:Mutex <AsSlotManager <'drm>>, +pub (crate ) as_manager:Mutex <AsSlotManager <'mmu>>, } -impl <'drm>Mmu <'drm> { +impl <'mmu>Mmu <'mmu> {/// Create an MMU component for this device. pub (crate )fn new ( - dev: &'drmDevice <Bound >, - iomem:ArcBorrow <'_,IoMem <'drm>>, + dev: &'mmuDevice <Bound >, + iomem:ArcBorrow <'_,IoMem <'mmu>>, gpu_info: &GpuInfo , - ) ->Result <Arc <Mmu <'drm>>> { + ) ->Result <Arc <Mmu <'mmu>>> {let present =AS_PRESENT ::from_raw (gpu_info.as_present).present ().get ();let slot_count = present.count_ones ().try_into ()?;
@@ -81,17 +81,17 @@ pub(crate) fn new(/// Assign a VM to an AS slot, provide a translation table, /// and update the MMU to make the VM resident. -pub (crate )fn activate_vm (&self, vm_as_data:ArcBorrow <'_,VmAsData <'drm>>) ->Result { +pub (crate )fn activate_vm (&self, vm_as_data:ArcBorrow <'_,VmAsData <'mmu>>) ->Result { self.as_manager.lock ().activate_vm (vm_as_data) }/// Evict a VM from its AS slot and flush the MMU. -pub (crate )fn deactivate_vm (&self, vm_as_data: &VmAsData <'drm>) ->Result { +pub (crate )fn deactivate_vm (&self, vm_as_data: &VmAsData <'mmu>) ->Result { self.as_manager.lock ().deactivate_vm (vm_as_data) }/// Flush MMU translation caches after a VM update. -pub (crate )fn flush_vm (&self, vm_as_data: &VmAsData <'drm>) ->Result { +pub (crate )fn flush_vm (&self, vm_as_data: &VmAsData <'mmu>) ->Result { self.as_manager.lock ().flush_vm (vm_as_data) }
@@ -103,7 +103,7 @@ pub(crate) fn flush_vm(&self, vm_as_data: &VmAsData<'drm>) -> Result {/// If the VM is not resident, this is a NOP. pub (crate )fn start_vm_update ( &self, - vm_as_data: &VmAsData <'drm>, + vm_as_data: &VmAsData <'mmu>, region: &Range <u64 >, ) ->Result { self.as_manager.lock ().start_vm_update (vm_as_data, region)
@@ -114,7 +114,7 @@ pub(crate) fn start_vm_update(/// If the VM is resident, this will let GPU accesses on the updated /// range go through, in case any of them were blocked. /// If the VM is not resident, this is a NOP. -pub (crate )fn end_vm_update (&self, vm_as_data: &VmAsData <'drm>) ->Result { +pub (crate )fn end_vm_update (&self, vm_as_data: &VmAsData <'mmu>) ->Result { self.as_manager.lock ().end_vm_update (vm_as_data) } }
drivers/gpu/drm/tyr/mmu/address_space.rs +15 -15
@@ -147,27 +147,27 @@ fn as_config(&self) -> Result<AddressSpaceConfig> {/// Coordinates all hardware-level address space operations through MMIO register /// operations including enabling, disabling, flushing, and updating address spaces. -pub (crate )struct AddressSpaceManager <'drm> { +pub (crate )struct AddressSpaceManager <'as_mgr> {/// Parent device used for logging. - dev: &'drmDevice <Bound >, + dev: &'as_mgrDevice <Bound >,/// Memory-mapped I/O region for GPU register access. - iomem:Arc <IoMem <'drm>>, + iomem:Arc <IoMem <'as_mgr>>,/// Bitmask of present address space slots from GPU_AS_PRESENT register. as_present:u32 , } -impl <'drm>AddressSpaceManager <'drm> { +impl <'as_mgr>AddressSpaceManager <'as_mgr> {/// Creates a new address space manager. /// /// Initializes the manager with references to the platform device and /// I/O memory region, along with the bitmask of available AS slots. pub (super )fn new ( - dev: &'drmDevice <Bound >, - iomem:Arc <IoMem <'drm>>, + dev: &'as_mgrDevice <Bound >, + iomem:Arc <IoMem <'as_mgr>>, as_present:u32 , - ) ->Result <AddressSpaceManager <'drm>> { + ) ->Result <AddressSpaceManager <'as_mgr>> {if as_present.trailing_ones () != as_present.count_ones () {dev_err! ( dev,
@@ -436,9 +436,9 @@ fn as_flush(&mut self, as_nr: usize) -> Result { } } -impl <'drm>SlotOperations <MAX_AS >for AddressSpaceManager <'drm> { +impl <'as_mgr>SlotOperations <MAX_AS >for AddressSpaceManager <'as_mgr> {/// VM address space data associated with a hardware slot. -type SlotData =Arc <VmAsData <'drm>>; +type SlotData =Arc <VmAsData <'as_mgr>>;fn seat (slot_data: &Self ::SlotData ) -> &LockedSeat <Self ,MAX_AS > { &slot_data.as_seat
@@ -458,11 +458,11 @@ fn evict(&mut self, slot_idx: usize, _slot_data: &Self::SlotData) -> Result { } } -impl <'drm>AsSlotManager <'drm> { +impl <'as_mgr>AsSlotManager <'as_mgr> {/// Locks a region for translation table updates if the VM has an active slot. pub (super )fn start_vm_update ( &mut self, - vm_as_data: &VmAsData <'drm>, + vm_as_data: &VmAsData <'as_mgr>, region: &Range <u64 >, ) ->Result {let seat = vm_as_data.as_seat.access (self);
@@ -476,7 +476,7 @@ pub(super) fn start_vm_update( }/// Completes translation table updates and unlocks the region. -pub (super )fn end_vm_update (&mut self, vm_as_data: &VmAsData <'drm>) ->Result { +pub (super )fn end_vm_update (&mut self, vm_as_data: &VmAsData <'as_mgr>) ->Result {let seat = vm_as_data.as_seat.access (self);match seat.slot () {Some (slot) => {
@@ -488,7 +488,7 @@ pub(super) fn end_vm_update(&mut self, vm_as_data: &VmAsData<'drm>) -> Result { }/// Flushes the translation table cache if the VM has an active slot. -pub (super )fn flush_vm (&mut self, vm_as_data: &VmAsData <'drm>) ->Result { +pub (super )fn flush_vm (&mut self, vm_as_data: &VmAsData <'as_mgr>) ->Result {let seat = vm_as_data.as_seat.access (self);match seat.slot () {Some (slot) => {
@@ -500,12 +500,12 @@ pub(super) fn flush_vm(&mut self, vm_as_data: &VmAsData<'drm>) -> Result { }/// Activates a VM by assigning it to a hardware slot. -pub (super )fn activate_vm (&mut self, vm_as_data:ArcBorrow <'_,VmAsData <'drm>>) ->Result { +pub (super )fn activate_vm (&mut self, vm_as_data:ArcBorrow <'_,VmAsData <'as_mgr>>) ->Result { self.activate (vm_as_data.into ()) }/// Deactivates a VM by evicting it from its hardware slot. -pub (super )fn deactivate_vm (&mut self, vm_as_data: &VmAsData <'drm>) ->Result { +pub (super )fn deactivate_vm (&mut self, vm_as_data: &VmAsData <'as_mgr>) ->Result { self.evict (&vm_as_data.as_seat) } }
drivers/gpu/drm/tyr/vm.rs +21 -21
96 lines not on this page · raw message
Signature · 1 line
2.56.1
Gary Guo
maintainerRe: [PATCH 1/4] drm/tyr: name resource lifetimes after their types
Quoted 2 lines · Danilo Krummrich
The firmware, buffer, VM and MMU types use 'drm for their resource lifetimes, even though each parameter is local to its type.
This doesn't make any sense, a lifetime on a type by definition cannot refer to a scope of itself.
'sec is not the lifetime of Section and 'fw is not the lifetime of Firmware and I think this is just confusing.
Best,
Gary
Quoted 60 lines
Rename these parameters to reflect the respective type's scope in preparation for converting the resource ownership to self-referential pin-init.
Signed-off-by Danilo Krummrich <[email protected]>--- drivers/gpu/drm/tyr/fw.rs | 26 +++++++-------- drivers/gpu/drm/tyr/gem.rs | 8 ++--- drivers/gpu/drm/tyr/mmu.rs | 24 +++++++------- drivers/gpu/drm/tyr/mmu/address_space.rs | 30 ++++++++--------- drivers/gpu/drm/tyr/vm.rs | 42 ++++++++++++------------ 5 files changed, 65 insertions(+), 65 deletions(-)drivers/gpu/drm/tyr/fw.rs +7
-7@@ -131,7 +131,7 @@ fn try_from_fw(value: u32) -> Result<Self> { }/// A parsed section of the firmware binary. -struct Section <'drm> { +struct Section <'sec> {// Raw firmware section data for reset purposes #[expect(dead_code)] data:KVec <u8 >,@@ -139,23 +139,23 @@ struct Section<'drm> {// Keep the BO backing this firmware section so that both the // GPU mapping and CPU mapping remain valid until the Section is dropped. #[expect(dead_code)] - mem: gem::KernelBo<'drm>, + mem: gem::KernelBo<'sec>, }/// Loaded firmware with sections mapped into MCU VM. -pub (crate )struct Firmware <'drm> { +pub (crate )struct Firmware <'fw> {/// Iomem need to access registers. - iomem:Arc <IoMem <'drm>>, + iomem:Arc <IoMem <'fw>>,/// MCU VM. - vm:Arc <Vm <'drm>>, + vm:Arc <Vm <'fw>>,/// List of firmware sections. #[expect(dead_code)] - sections:KVec <Section <'drm>>, + sections:KVec <Section <'fw>>, } -impl <'drm>Drop for Firmware <'drm> { +impl <'fw>Drop for Firmware <'fw> {fn drop (&mut self) {// Stop the MCU before releasing its firmware mappings and memory. let _ = self.stop ();@@ -165,8 +165,8 @@ fn drop(&mut self) { } }
Danilo Krummrich
maintainerRe: [PATCH 1/4] drm/tyr: name resource lifetimes after their types
Quoted 9 lines · Gary Guo
Quoted 2 lines · Danilo Krummrich
The firmware, buffer, VM and MMU types use 'drm for their resource lifetimes, even though each parameter is local to its type.
This doesn't make any sense, a lifetime on a type by definition cannot refer to a scope of itself.
'secis not the lifetime ofSectionand'fwis not the lifetime ofFirmwareand I think this is just confusing.
Yes, this was badly phrased. What is actually meant is that e.g. 'fw constrains how long a Firmware instance can be used.
(In the following patch, in TyrDrmRegistrationData, Firmware borrows Mmu. That borrow has its own lifetime, distinct from TyrDrmRegistrationData's 'drm parameter.)
Gary Guo
maintainerRe: [PATCH 1/4] drm/tyr: name resource lifetimes after their types
Quoted 5 lines · Danilo Krummrich
Quoted 4 lines · Gary Guo
Quoted 2 lines · Danilo Krummrich
The firmware, buffer, VM and MMU types use 'drm for their resource lifetimes, even though each parameter is local to its type.
Quoted 8 lines
Quoted 5 lines
This doesn't make any sense, a lifetime on a type by definition cannot refer to a scope of itself.
'secis not the lifetime ofSectionand'fwis not the lifetime ofFirmwareand I think this is just confusing.Yes, this was badly phrased. What is actually meant is that e.g. 'fw constrains how long a Firmware instance can be used.
I think this is weird still. Any lifetime on a type would constrain how long an instance of that type can be used, that's just type wellformness.
I think what you're saying is basically "I couldn't think of a good name so I use the name of the type instead". To me I think using 'a has the same effect and is less confusing because reader knows that it is a generic name and is not tied to any specific scope.
Best,
Gary
Quoted 4 lines
(In the following patch, in TyrDrmRegistrationData, Firmware borrows Mmu. That borrow has its own lifetime, distinct from TyrDrmRegistrationData's 'drm parameter.)
Danilo Krummrich
maintainerRe: [PATCH 1/4] drm/tyr: name resource lifetimes after their types
Quoted 15 lines · Gary Guo
Quoted 5 lines · Danilo Krummrich
Quoted 4 lines · Gary Guo
Quoted 2 lines · Danilo Krummrich
The firmware, buffer, VM and MMU types use 'drm for their resource lifetimes, even though each parameter is local to its type.
Quoted 8 lines
Quoted 5 lines
This doesn't make any sense, a lifetime on a type by definition cannot refer to a scope of itself.
'secis not the lifetime ofSectionand'fwis not the lifetime ofFirmwareand I think this is just confusing.Yes, this was badly phrased. What is actually meant is that e.g. 'fw constrains how long a Firmware instance can be used.
Quoted 7 lines
I think this is weird still. Any lifetime on a type would constrain how long an instance of that type can be used, that's just type wellformness.
I think what you're saying is basically "I couldn't think of a good name so I use the name of the type instead". To me I think using
'ahas the same effect and is less confusing because reader knows that it is a generic name and is not tied to any specific scope.
Oh, I agree, 'a technically achieves the same thing.
With self-referential pin-init, several lifetime roles appear together. In the Firmware example below, 'fw describes its external borrows, 'res is the (hidden) invariant device resource lifetime, and 'vm describes the borrow of the embedded VM.
pub(crate) struct Firmware<'fw>
where
exists<'res>: 'fw,
{
/// Iomem need to access registers.
iomem: &'fw IoMem<'fw>,
/// List of firmware sections.
#[uses('res: invariant)]
sections: KVec<Section<'vm, 'res>>,
/// MCU VM.
#[pin]
#[uses('res: invariant)]
vm: Vm<'fw, 'res>,
}
pub(crate) struct Vm<'vm, 'res> {
as_data: Arc<VmAsData<'res>>,
mmu: &'vm Mmu<'res>,
dev: &'res Device<Bound>,
#[pin]
gpuvm_unique: Mutex<UniqueRefGpuVm<GpuVmData<'res>>>,
gpuvm: ARef<GpuVm<GpuVmData<'res>>>,
va_range: Range<u64>,
}I find naming the external borrow parameter after the containing type easier to follow when reading these definitions.
I thought we did settle on this convention in the past; am I misremembering?
Quoted 3 lines
Quoted 3 lines
(In the following patch, in TyrDrmRegistrationData, Firmware borrows Mmu. That borrow has its own lifetime, distinct from TyrDrmRegistrationData's 'drm parameter.)
Gary Guo
maintainerRe: [PATCH 1/4] drm/tyr: name resource lifetimes after their types
Quoted 24 lines · Danilo Krummrich
Quoted 15 lines · Gary Guo
Quoted 5 lines · Danilo Krummrich
Quoted 4 lines · Gary Guo
Quoted 2 lines · Danilo Krummrich
The firmware, buffer, VM and MMU types use 'drm for their resource lifetimes, even though each parameter is local to its type.
Quoted 8 lines
Quoted 5 lines
This doesn't make any sense, a lifetime on a type by definition cannot refer to a scope of itself.
'secis not the lifetime ofSectionand'fwis not the lifetime ofFirmwareand I think this is just confusing.Yes, this was badly phrased. What is actually meant is that e.g. 'fw constrains how long a Firmware instance can be used.
Quoted 7 lines
I think this is weird still. Any lifetime on a type would constrain how long an instance of that type can be used, that's just type wellformness.
I think what you're saying is basically "I couldn't think of a good name so I use the name of the type instead". To me I think using
'ahas the same effect and is less confusing because reader knows that it is a generic name and is not tied to any specific scope.
Quoted 6 lines
Oh, I agree, 'a technically achieves the same thing.
With self-referential pin-init, several lifetime roles appear together. In the Firmware example below, 'fw describes its external borrows, 'res is the (hidden) invariant device resource lifetime, and 'vm describes the borrow of the embedded VM.
It's true that many lifetime names would appear with self-referential pin-init, but apart from invariant lifetimes, the covariant lifetime parameters are almost always the shortest living lifetime among things that it may reference.
Quoted 28 lines
pub(crate) struct Firmware<'fw>
where
exists<'res>: 'fw,
{
/// Iomem need to access registers.
iomem: &'fw IoMem<'fw>,
/// List of firmware sections.
#[uses('res: invariant)]
sections: KVec<Section<'vm, 'res>>,
/// MCU VM.
#[pin]
#[uses('res: invariant)]
vm: Vm<'fw, 'res>,
}
pub(crate) struct Vm<'vm, 'res> {
as_data: Arc<VmAsData<'res>>,
mmu: &'vm Mmu<'res>,
dev: &'res Device<Bound>,
#[pin]
gpuvm_unique: Mutex<UniqueRefGpuVm<GpuVmData<'res>>>,
gpuvm: ARef<GpuVm<GpuVmData<'res>>>,
va_range: Range<u64>,
}Quoted 2 lines
I find naming the external borrow parameter after the containing type easier to follow when reading these definitions.
In my view it's the exact opposite. If this is called 'a then it's 100% external borrow (surely nobody would call their field 'a?) while otherwise I'd need to see if it's a field or a lifetime parameter.
Quoted 2 lines
I thought we did settle on this convention in the past; am I misremembering?
I don't think there's an established convention. I know this is the pattern that Nova is using, and I didn't question that. But I am wary of having this becoming established as a standard pattern.
If a rule is to be established, I'd rather it being the following:
- for invariant lifetime parameter, use the name of the borrowed resource (because you know the exact lifetime).
- for covariant lifetime parameter (especially if multiple resources are borrowed and the lifetime is the shortest among those), pick a generic name
- for covariant lifetime parameter referencing just a single resource, I think either is fine -- (as long as it's unlikely to be used by unsafe code that may assume that it covers the full lifetime, e.g. 'bound).
Best,
Gary
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
(In the following patch, in TyrDrmRegistrationData, Firmware borrows Mmu. That borrow has its own lifetime, distinct from TyrDrmRegistrationData's 'drm parameter.)
Danilo Krummrich
maintainerRe: [PATCH 1/4] drm/tyr: name resource lifetimes after their types
Quoted 11 lines · Gary Guo
If a rule is to be established, I'd rather it being the following:
- for invariant lifetime parameter, use the name of the borrowed resource (because you know the exact lifetime).
- for covariant lifetime parameter (especially if multiple resources are borrowed and the lifetime is the shortest among those), pick a generic name
- for covariant lifetime parameter referencing just a single resource, I think either is fine -- (as long as it's unlikely to be used by unsafe code that may assume that it covers the full lifetime, e.g. 'bound).
I think in the end it comes down to personal preference, so this is fine with me too.
Though, I'd use a generic name in the latter case too, such that it doesn't need to be changed once a second resource is referenced later on.
Alice Ryhl
maintainerRe: [PATCH 1/4] drm/tyr: name resource lifetimes after their types
Quoted 5 lines · Danilo Krummrich
I think in the end it comes down to personal preference, so this is fine with me too.
Though, I'd use a generic name in the latter case too, such that it doesn't need to be changed once a second resource is referenced later on.
Agreed, using a generic name like 'a (or borrowed-resource names for invariant lifetimes) sounds good to me too.
Also, when updating this for v2, note that VmAsData<'drm> in mmu/address_space.rs and GpuVmData<'drm> (along with VmMapArgs, VmOpType, VmOpResources, VmOpRequest, and PtUpdateContext in vm.rs) were still left using 'drm.
Alice
Danilo Krummrich
maintainerRe: [PATCH 1/4] drm/tyr: name resource lifetimes after their types
Quoted 7 lines · Alice Ryhl
Quoted 5 lines · Danilo Krummrich
I think in the end it comes down to personal preference, so this is fine with me too.
Though, I'd use a generic name in the latter case too, such that it doesn't need to be changed once a second resource is referenced later on.
Quoted 7 lines
Agreed, using a generic name like
'a(or borrowed-resource names for invariant lifetimes) sounds good to me too.Also, when updating this for v2, note that
VmAsData<'drm>inmmu/address_space.rsandGpuVmData<'drm>(along withVmMapArgs,VmOpType,VmOpResources,VmOpRequest, andPtUpdateContextinvm.rs) were still left using'drm.
Before I respin I'll wait for Gary to look into how the existential lifetime could be moved to Vm (which is what I considered initially, but couldn't really get to work).
I think having it on Firmware is reasonable, but I think having it on Vm would probably be better.
Gary Guo
maintainerRe: [PATCH 1/4] drm/tyr: name resource lifetimes after their types
Quoted 16 lines · Danilo Krummrich
Quoted 7 lines · Alice Ryhl
Quoted 5 lines · Danilo Krummrich
I think in the end it comes down to personal preference, so this is fine with me too.
Though, I'd use a generic name in the latter case too, such that it doesn't need to be changed once a second resource is referenced later on.
Quoted 7 lines
Agreed, using a generic name like
'a(or borrowed-resource names for invariant lifetimes) sounds good to me too.Also, when updating this for v2, note that
VmAsData<'drm>inmmu/address_space.rsandGpuVmData<'drm>(along withVmMapArgs,VmOpType,VmOpResources,VmOpRequest, andPtUpdateContextinvm.rs) were still left using'drm.
Quoted 6 lines
Before I respin I'll wait for Gary to look into how the existential lifetime could be moved to Vm (which is what I considered initially, but couldn't really get to work).
I think having it on Firmware is reasonable, but I think having it on Vm would probably be better.
I think it's possible but doing so will be more messy (given that everything now needs to have with_...). Having it on Firmware looks like the most clean approach.
Best,
Gary
Danilo Krummrich
maintainerPATCH 2/4 rust: pin-init: internal: suppress multiple_bound_locations
In reply to Danilo KrummrichThe generated __drop_order_check() combines existential lifetime bounds with inferred field outlives bounds.
For instance, for Tyr's Firmware, this places 'res: 'fw in the generic parameter list and 'res: 'vm in the where clause, triggering Clippy's multiple_bound_locations lint at the struct declaration.
Allow this style lint on the generated drop-order check. This preserves all generated bounds and leaves the lint enabled for user-written code.
--- rust/pin-init/internal/src/pin_data.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
rust/pin-init/internal/src/pin_data.rs +2 -1
@@ -1246,7 +1246,8 @@ fn generate_drop_order_check(dcx: &mut DiagCtxt, info: &StructInfo) -> TokenStrelet struct_span = struct_name.span ().resolved_at (Span ::mixed_site ());quote_spanned! {struct_span => -#[allow(non_snake_case, unused)] +// Generated bounds can appear both on lifetime parameters and in the where clause. + #[allow (non_snake_case, unused, clippy::multiple_bound_locations)]fn __drop_order_check #impl_generics_with_field_lt (// This must be present so the function can *assume* the implied bounds on the erased // struct. For example, if the struct has `&'a T`, Rust will infer `T: 'a`; we still
Signature · 1 line
2.56.1
Gary Guo
maintainerRe: [PATCH 2/4] rust: pin-init: internal: suppress multiple_bound_locations
Quoted 6 lines · Danilo Krummrich
The generated
__drop_order_check()combines existential lifetime bounds with inferred field outlives bounds.For instance, for Tyr's Firmware, this places 'res: 'fw in the generic parameter list and 'res: 'vm in the where clause, triggering Clippy's
multiple_bound_locationslint at the struct declaration.
This paragraph is sloppy. It is not helpful at all without context (and also doesn't describe the issue properly even with context).
Anyway, this issue is known and I ran into it in drm jobqueue myself. That said, I plan to fix it with proper spans rather than band-aiding it with an allow (I also cannot take it as is without a UI test case to catch regression). I'd recommend putting a #![allow(clippy::multiple_bound_locations)] for now.
Best,
Gary
Quoted 24 lines
Allow this style lint on the generated drop-order check. This preserves all generated bounds and leaves the lint enabled for user-written code.
Cc Gary Guo <[email protected]>Fixes 73cf61724648 ("rust: pin-init: internal: pin_data: support existential lifetimes")Signed-off-by Danilo Krummrich <[email protected]>--- rust/pin-init/internal/src/pin_data.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)rust/pin-init/internal/src/pin_data.rs +2
-1@@ -1246,7 +1246,8 @@ fn generate_drop_order_check(dcx: &mut DiagCtxt, info: &StructInfo) -> TokenStrelet struct_span = struct_name.span ().resolved_at (Span ::mixed_site ());quote_spanned! {struct_span => -#[allow(non_snake_case, unused)] +// Generated bounds can appear both on lifetime parameters and in the where clause. + #[allow (non_snake_case, unused, clippy::multiple_bound_locations)]fn __drop_order_check #impl_generics_with_field_lt (// This must be present so the function can *assume* the implied bounds on the erased // struct. For example, if the struct has `&'a T`, Rust will infer `T: 'a`; we still
Danilo Krummrich
maintainerPATCH 3/4 drm/tyr: use pin-init self-referential support
In reply to Danilo KrummrichNow that pin-init supports self-referential structs, Arc is no longer needed just to share resources whose lifetimes are bounded by their owners.
Use pin-init's self-referential support to share the MMIO mapping, MMU and firmware VM through borrows instead of Arc, avoiding their separate allocations and reference counts.
Hide the invariant resource lifetime shared by the VM and its sections behind an existential lifetime that outlives 'fw, so Firmware only needs a single lifetime parameter.
--- drivers/gpu/drm/tyr/driver.rs | 38 +++--- drivers/gpu/drm/tyr/fw.rs | 152 ++++++++++++----------- drivers/gpu/drm/tyr/gem.rs | 15 +-- drivers/gpu/drm/tyr/mmu.rs | 36 +++--- drivers/gpu/drm/tyr/mmu/address_space.rs | 14 +-- drivers/gpu/drm/tyr/vm.rs | 119 +++++++++--------- 6 files changed, 187 insertions(+), 187 deletions(-)
drivers/gpu/drm/tyr/driver.rs +18 -20
@@ -29,7 +29,7 @@ regulator::Regulator, sizes::SZ_2M, sync::{ - Arc, + aref::ARef, Mutex, // }, time, //
@@ -71,7 +71,14 @@ pub(crate) struct TyrDrmRegistrationData<'drm> { pub(crate) pdev: &'drm platform::Device<Bound>,/// Firmware sections. - pub(crate) fw: Firmware<'drm>, +#[pin] +#[uses('mmu: invariant)] + pub(crate) fw: Firmware<'mmu>, + +/// MMU shared by the firmware and its buffer objects. +#[pin] +#[uses('iomem: invariant)] + mmu: Mmu<'iomem>,#[pin] clks: Mutex<Clocks>,
@@ -80,7 +87,7 @@ pub(crate) struct TyrDrmRegistrationData<'drm> { regulators: Mutex<Regulators>,/// GPU MMIO register mapping. - pub(crate) iomem: Arc<IoMem<'drm>>, + pub(crate) iomem: IoMem<'drm>,/// GPU information read from hardware during probe. pub(crate) gpu_info: GpuInfo,
@@ -132,7 +139,7 @@ fn probe<'bound>(let request = pdev.io_request_by_index (0 ).ok_or (ENODEV )?; -let iomem =Arc ::new (request.iomap_sized ::<SZ_2M >()?,GFP_KERNEL )?; +let iomem = request.iomap_sized ::<SZ_2M >()?;issue_soft_reset (pdev.as_ref (), &iomem)?; gpu::l2_power_on (pdev.as_ref (), &iomem)?;
@@ -149,18 +156,7 @@ fn probe<'bound>(unsafe { pdev.dma_set_mask_and_coherent (DmaMask ::try_new (pa_bits)?)? };let unreg_dev = drm::UnregisteredDevice ::<TyrDrmDriver >::new (pdev,Ok (()))?; - -let mmu =Mmu ::new (pdev.as_ref (), iomem.as_arc_borrow (), &gpu_info)?; - -let firmware =Firmware ::new ( - pdev.as_ref (), - iomem.clone (), - &unreg_dev, - mmu.as_arc_borrow (), - &gpu_info, - )?; - - firmware.boot ()?; +let ddev =ARef ::from (&*unreg_dev); Ok(try_pin_init!(TyrPlatformDriverData { // SAFETY: `_reg` is stored in `TyrPlatformDriverData` and dropped when the
@@ -168,9 +164,13 @@ fn probe<'bound>( _reg <- unsafe { drm::Registration::new( pdev.as_ref(), unreg_dev, - pin_init!(TyrDrmRegistrationData { + try_pin_init!(TyrDrmRegistrationData { + iomem, + gpu_info, + mmu <- Mmu::new(pdev.as_ref(), iomem, gpu_info), + fw <- Firmware::new(pdev.as_ref(), iomem, &ddev, mmu.get_ref(), gpu_info), + _: { fw.boot()?; }, pdev, - fw: firmware, clks <- new_mutex!(Clocks { core: core_clk, stacks: stacks_clk,
@@ -180,8 +180,6 @@ fn probe<'bound>( _mali: mali_regulator, _sram: sram_regulator, }), - iomem, - gpu_info, }), )}, _: { dev_dbg!(pdev, "Tyr initialized correctly.") },
drivers/gpu/drm/tyr/fw.rs +79 -73
213 lines not on this page · raw message
drivers/gpu/drm/tyr/gem.rs +6 -9
@@ -12,10 +12,7 @@ shmem, // }, prelude::*, - sync::{ - aref::ARef, - Arc, // - }, // + sync::aref::ARef, // };use crate ::{
@@ -82,16 +79,16 @@ pub(crate) enum KernelBoVaAlloc {/// a GEM object with automatic GPU virtual address (VA) space mapping and cleanup. /// /// When dropped, the buffer is automatically unmapped from the GPU VA space. -pub (crate )struct KernelBo <'bo> { +pub (crate )struct KernelBo <'bo, 'res> {/// The underlying GEM buffer object. bo:ARef <Bo >,/// The GPU VM this buffer is mapped into. - vm:Arc <Vm <'bo>>, + vm: &'boVm <'bo, 'res>,/// The GPU VA range occupied by this buffer. va_range:Range <u64 >, } -impl <'bo>KernelBo <'bo> { +impl <'bo, 'res>KernelBo <'bo, 'res> {/// Creates a new kernel-owned buffer object and maps it into GPU VA space. /// /// This function allocates a new shmem-backed GEM object and immediately maps
@@ -99,7 +96,7 @@ impl<'bo> KernelBo<'bo> {/// cleaned up when the [`KernelBo`] is dropped. pub (crate )fn new ( ddev: &TyrDrmDevice , - vm:Arc <Vm <'bo>>, + vm: &'boVm <'bo, 'res>, size:u64 , va_alloc:KernelBoVaAlloc , flags: VmMapFlags,
@@ -138,7 +135,7 @@ pub(crate) fn bo(&self) -> &Bo { } } -impl Drop for KernelBo <'_> { +impl Drop for KernelBo <'_, '_> {fn drop (&mut self) {let va = self.va_range.start;let size = self.va_range.end - self.va_range.start;
drivers/gpu/drm/tyr/mmu.rs +18 -18
@@ -21,7 +21,6 @@ new_mutex, prelude::*, sync::{ -Arc ,ArcBorrow ,Mutex ,// }, //
@@ -57,26 +56,27 @@ impl<'mmu> Mmu<'mmu> {/// Create an MMU component for this device. pub (crate )fn new ( dev: &'mmuDevice <Bound >, - iomem:ArcBorrow <'_,IoMem <'mmu>>, + iomem: &'mmuIoMem <'mmu>, gpu_info: &GpuInfo , - ) ->Result <Arc <Mmu <'mmu>>> { + ) ->impl PinInit <Self ,Error > + 'mmu {let present =AS_PRESENT ::from_raw (gpu_info.as_present).present ().get (); -let slot_count = present.count_ones ().try_into ()?; +try_pin_init! (Self { + as_manager <- { +let slot_count = present.count_ones ().try_into ()?; -let address_space_manager =AddressSpaceManager ::new (dev, iomem.into (), present)?; -let as_slot_manager = -SlotManager ::new (address_space_manager, slot_count).inspect_err (|e| { -dev_err! ( - dev, -"Failed to initialize MMU slot manager with {} slots: {:?}" , - slot_count, - e - ); - })?; -let mmu_init =try_pin_init! (Self { - as_manager <-new_mutex! (as_slot_manager), - }); -Arc ::pin_init (mmu_init,GFP_KERNEL ) +let address_space_manager =AddressSpaceManager ::new (dev, iomem, present)?; +let as_slot_manager = +SlotManager ::new (address_space_manager, slot_count).inspect_err (|e| { +dev_err! ( + dev, +"Failed to initialize MMU slot manager with {} slots: {:?}" , + slot_count, + e + ); + })?; +new_mutex! (as_slot_manager) + }, + }) }/// Assign a VM to an AS slot, provide a translation table,
drivers/gpu/drm/tyr/mmu/address_space.rs +7 -7
@@ -152,7 +152,7 @@ pub(crate) struct AddressSpaceManager<'as_mgr> { dev: &'as_mgr Device<Bound>, /// Memory-mapped I/O region for GPU register access. - iomem: Arc<IoMem<'as_mgr>>, + iomem: &'as_mgr IoMem<'as_mgr>,/// Bitmask of present address space slots from GPU_AS_PRESENT register. as_present: u32,
@@ -165,7 +165,7 @@ impl<'as_mgr> AddressSpaceManager<'as_mgr> {/// I/O memory region, along with the bitmask of available AS slots. pub (super )fn new ( dev: &'as_mgrDevice <Bound >, - iomem:Arc <IoMem <'as_mgr>>, + iomem: &'as_mgrIoMem <'as_mgr>, as_present:u32 , ) ->Result <AddressSpaceManager <'as_mgr>> {if as_present.trailing_ones () != as_present.count_ones () {
@@ -216,7 +216,7 @@ fn validate_as_slot(&self, as_nr: usize) -> Result {/// /// Returns an error if polling times out after 10ms or if register access fails. fn as_wait_ready (&self, as_nr:usize ) ->Result { -let io = &*self.iomem; +let io = self.iomem;let op = || {let status_reg =STATUS ::try_at (as_nr).ok_or (EINVAL )?;Ok (io.read (status_reg))
@@ -232,7 +232,7 @@ fn as_wait_ready(&self, as_nr: usize) -> Result {/// Returns an error if waiting for ready times out or if register write fails. fn as_send_cmd (&mut self, as_nr:usize , cmd:MmuCommand ) ->Result { self.as_wait_ready (as_nr)?; -let io = &*self.iomem; +let io = self.iomem;let command_reg =COMMAND ::try_at (as_nr).ok_or (EINVAL )?; io.write (command_reg,COMMAND ::zeroed ().with_command (cmd));Ok (())
@@ -253,7 +253,7 @@ fn as_send_cmd_and_wait(&mut self, as_nr: usize, cmd: MmuCommand) -> Result {fn as_enable (&mut self, as_nr:usize , as_config: &AddressSpaceConfig ) ->Result { self.validate_as_slot (as_nr)?; -let io = &*self.iomem; +let io = self.iomem;let transtab = as_config.transtab; io.write(
@@ -299,7 +299,7 @@ fn as_disable(&mut self, as_nr: usize) -> Result {// Flush AS before disabling self.as_send_cmd_and_wait (as_nr,MmuCommand ::FlushMem )?; -let io = &*self.iomem; +let io = self.iomem; io.write ( TRANSTAB_LO::try_at(as_nr).ok_or(EINVAL)?,
@@ -394,7 +394,7 @@ fn as_start_update(&mut self, as_nr: usize, region: &Range<u64>) -> Result {// because log2(32 KiB) = 15. let lockaddr_size = lock_region_log2 -1 ; -let io = &*self.iomem; +let io = self.iomem;// The LOCKADDR base field stores address bits 63:12, so remove the low 12 bits // before passing this value to the register macro helper.
drivers/gpu/drm/tyr/vm.rs +59 -60
187 lines not on this page · raw message
Signature · 1 line
2.56.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [High] drm/tyr: unaligned BO size in…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [High] drm/tyr: unaligned BO size in new_dummy_object() and KernelBo::new() [1]
--
commit c6eb3c50c479a4d12cbfccb1e7746b3f539a34fd
Author: Danilo Krummrich <[email protected]>
drm/tyr: use pin-init self-referential support
This commit replaces Arc-based sharing of the MMIO mapping, MMU, and firmware VM in the Tyr driver with borrows using pin-init's self-referential struct support.
Quoted 4 lines
drivers/gpu/drm/tyr/gem.rs +0
-0
[ ... ]
drivers/gpu/drm/tyr/gem.rs impl<'bo> KernelBo<'bo> { · line 102
Quoted 9 lines
drivers/gpu/drm/tyr/gem.rs +1
-1@@ -99,7 +96,7 @@ impl<'bo> KernelBo<'bo> {/// cleaned up when the [`KernelBo`] is dropped. pub (crate )fn new ( ddev: &TyrDrmDevice , - vm:Arc <Vm <'bo>>, + vm: &'boVm <'bo, 'res>, size:u64 , va_alloc:KernelBoVaAlloc , flags: VmMapFlags,
[Severity: High]
This problem wasn't introduced by this patch, but can KernelBo::new() and new_dummy_object() panic in drm_gem_private_object_init() on 16 KiB or 64 KiB page kernels [1]?
new_dummy_object() passes a hardcoded size of 4096 bytes to Bo::new(), and KernelBo::new() passes firmware section sizes that are only aligned to 4 KiB:
drivers/gpu/drm/tyr/gem.rs:new_dummy_object() {
let bo = Bo::new(
ddev,
4096,
...
}drivers/gpu/drm/tyr/gem.rs:KernelBo::new() {
...
let bo_size = usize::try_from(size).map_err(|_| EOVERFLOW)?;
let va_end = va.checked_add(size).ok_or(EINVAL)?;
let bo = Bo::new(
ddev,
bo_size,
...
}Bo::new() forwards the size to drm_gem_private_object_init(), which triggers BUG_ON((size & (PAGE_SIZE - 1)) != 0) during probe when PAGE_SIZE exceeds 4 KiB.
[1] https://sashiko.dev/#/bug/linux-c7c6866e-fcae-455a-98bc-11dd06209188
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Danilo Krummrich
maintainerPATCH 4/4 drm/tyr: use ScopeGuard for firmware loading cleanup
In reply to Danilo KrummrichUse ScopeGuard to call vm.kill() when firmware section loading fails. Dismiss it on success, replacing the nested closure and explicit error check.
--- drivers/gpu/drm/tyr/fw.rs | 59 ++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 32 deletions(-)
drivers/gpu/drm/tyr/fw.rs +27 -32
@@ -29,7 +29,8 @@ num::Bounded, prelude::*, str::CString, - time, // + time, + types::ScopeGuard, // };use crate ::{
@@ -228,46 +229,40 @@ pub(crate) fn new<'a, 'res>( sections: { let vm = vm.get_ref(); vm.activate ()?; +let guard =ScopeGuard ::new (|| vm.kill ()); -let result:Result <_ > = (|| { -let (fw, parsed_sections) =Self ::load (dev, ddev, gpu_info)?; -let mut sections =KVec ::new (); -for parsedin parsed_sections { -let size = - u64::from (parsed.va.end.checked_sub (parsed.va.start).ok_or (EINVAL )?); +let (fw, parsed_sections) =Self ::load (dev, ddev, gpu_info)?; +let mut sections =KVec ::new (); +for parsedin parsed_sections { +let size = + u64::from (parsed.va.end.checked_sub (parsed.va.start).ok_or (EINVAL )?); -let va = u64::from (parsed.va.start); +let va = u64::from (parsed.va.start); -let mut mem =KernelBo ::new ( - ddev, - vm, - size, -KernelBoVaAlloc ::Explicit (va), - parsed.vm_map_flags, - )?; +let mut mem =KernelBo ::new ( + ddev, + vm, + size, +KernelBoVaAlloc ::Explicit (va), + parsed.vm_map_flags, + )?; -let section_start = parsed.data_range.startas usize ; -let section_end = parsed.data_range.endas usize ; -let mut data =KVec ::new (); +let section_start = parsed.data_range.startas usize ; +let section_end = parsed.data_range.endas usize ; +let mut data =KVec ::new (); -// Ensure that the firmware slice is not out of bounds. -let fw_data = fw.data (); -let bytes = fw_data.get (section_start..section_end).ok_or (EINVAL )?; - data.extend_from_slice (bytes,GFP_KERNEL )?; +// Ensure that the firmware slice is not out of bounds. +let fw_data = fw.data (); +let bytes = fw_data.get (section_start..section_end).ok_or (EINVAL )?; + data.extend_from_slice (bytes,GFP_KERNEL )?; -Self ::init_section_mem (dev, &mut mem, &data)?; +Self ::init_section_mem (dev, &mut mem, &data)?; - sections.push (Section { data, mem },GFP_KERNEL )?; - } - -Ok (sections) - })(); - -if result.is_err () { - vm.kill (); + sections.push (Section { data, mem },GFP_KERNEL )?; } - result? + guard.dismiss (); + sections }, }) }
Signature · 1 line
2.56.1
Daniel Almeida
maintainerHi Danilo,
Thanks for doing this.
I spoke with Gary about this topic at Kangrejos and again a couple of weeks ago. What worries me is that we might introduce some restrictions that might paint us into a corner. IOW: we have significant downstream work, and I wonder whether it will work with this series after whatever refactors are needed.
To start with, Alvin's VM_BIND ioctl series [0] will need some changes, since it keeps the VM pool in the file data. I think this is doable if we move the pool into the registration data and have each file hold only an index to its own entry? i.e.: something like an XArray<Pool<Vm>> indexed by a number associated with the drm::File. Same for the group pool later. Is this what you had in mind?
Anything storing a KernelBo will also have to be outside of the file data, IIUC, since it now stores a &Vm. Also, downstream we defer KernelBo drops to a workqueue, because they can happen in the fence signalling path. I suppose we can keep doing that using ScopedWork/ScopedQueue?
— Daniel
[0]: https://lore.kernel.org/rust-for-linux/[email protected]/T/#t
Danilo Krummrich
maintainerQuoted 8 lines · Daniel Almeida
Hi Danilo,
Thanks for doing this.
I spoke with Gary about this topic at Kangrejos and again a couple of weeks ago. What worries me is that we might introduce some restrictions that might paint us into a corner. IOW: we have significant downstream work, and I wonder whether it will work with this series after whatever refactors are needed.
The reason for the existence of the converted reference counts hasn't been that reference counting was needed as an ownership model, it just was that we haven't had a way to express borrowing from sibling fields that are already guaranteed to be longer lived in any case.
The distinction is between A having an independent owner that keeps it alive for all B consumers, so the Bs can borrow A, and the Bs collectively owning A, so A is destroyed when the last B releases it. Reference counting expresses the latter ownership model. Both can still be subject to lifetime bounds.
In the majority of cases, drivers acquire device resources in stages, keeping earlier resources alive until their dependants have been torn down. Where ownership follows this hierarchy, borrowing can express those relationships without reference counting.
Quoted 6 lines
To start with, Alvin's
VM_BINDioctl series [0] will need some changes, since it keeps the VM pool in the file data. I think this is doable if we move the pool into the registration data and have each file hold only an index to its own entry? i.e.: something like an XArray<Pool<Vm>> indexed by a number associated with thedrm::File. Same for the group pool later. Is this what you had in mind?
No, the changes do not force XArray<Pool<Vm>> to be moved into the registration data; drm::File private data can borrow from DRM registration data. It can (and should) stay in the drm::File private data.
(I'm also working on a generalization of this, as it is a repeating pattern in drivers. We want driver private data associated with an ioctl, e.g. VM_CREATE, which is shorter lived than the drm::File data and hence shorter lived than the drm::RegistrationData.
Concurrent ioctls associated with a handle to this data, i.e. the VM in this example, need to be drained on either VM_DESTROY or drm::File private data destruction, e.g. caused by unregistration through driver unbind.)
Quoted 4 lines
Anything storing a KernelBo will also have to be outside of the file data, IIUC, since it now stores a &Vm. Also, downstream we defer KernelBo drops to a workqueue, because they can happen in the fence signalling path. I suppose we can keep doing that using ScopedWork/ScopedQueue?
I assume you refer to the Vm that lives in Firmware. If so, drm::File private data can borrow from it, as Firmware lives in the DRM registration data.
The teardown has to happen in ScopedWork regardless, as they all carried device resource induced lifetimes already and hence can't go into unbounded work anyway.
Thanks,
Danilo