Re: [PATCH 1/4] drm/tyr: name resource lifetimes after their types
From: Danilo Krummrich
Date: Thu Nov 19 2026 - 07:28:57 EST
On Thu Nov 19, 2026 at 12:28 PM CET, Gary Guo wrote:
> On Thu Nov 19, 2026 at 10:34 AM GMT, Danilo Krummrich wrote:
>> On Thu Nov 19, 2026 at 3:08 AM CET, Gary Guo wrote:
>>> On Wed Nov 18, 2026 at 11:37 PM GMT, Danilo Krummrich wrote:
>>>> 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.
>>
>> 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.
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?
>> (In the following patch, in TyrDrmRegistrationData, Firmware borrows Mmu. That
>> borrow has its own lifetime, distinct from TyrDrmRegistrationData's 'drm
>> parameter.)