mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: "Danilo Krummrich" <dakr@kernel.org>, "Gary Guo" <gary@garyguo.net>
Cc: <aliceryhl@google.com>, <daniel.almeida@collabora.com>,
	<airlied@gmail.com>, <simona@ffwll.ch>, <lossin@kernel.org>,
	<ojeda@kernel.org>, <boqun@kernel.org>,
	<bjorn3_gh@protonmail.com>, <a.hindborg@kernel.org>,
	<tmgross@umich.edu>, <tamird@kernel.org>, <acourbot@nvidia.com>,
	<work@onurozkan.dev>, <dri-devel@lists.freedesktop.org>,
	<rust-for-linux@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/4] drm/tyr: name resource lifetimes after their types
Date: Thu, 19 Nov 2026 12:56:01 +0000	[thread overview]
Message-ID: <DMZ7CHWBWU4O.3EA040FFBVCLG@garyguo.net> (raw)
In-Reply-To: <DMZ6RL5X2UXE.33EY9MDLO2AJA@kernel.org>

On Thu Nov 19, 2026 at 12:28 PM GMT, Danilo Krummrich wrote:
> 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.

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.

>
> 	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. 

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.

>
> 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

>
>>> (In the following patch, in TyrDrmRegistrationData, Firmware borrows Mmu. That
>>> borrow has its own lifetime, distinct from TyrDrmRegistrationData's 'drm
>>> parameter.)



  reply	other threads:[~2026-11-19 12:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 23:37 [PATCH 0/4] drm/tyr: use pin-init self-referential support Danilo Krummrich
2026-11-18 23:37 ` [PATCH 1/4] drm/tyr: name resource lifetimes after their types Danilo Krummrich
2026-11-19  2:08   ` Gary Guo
2026-11-19 10:34     ` Danilo Krummrich
2026-11-19 11:28       ` Gary Guo
2026-11-19 12:28         ` Danilo Krummrich
2026-11-19 12:56           ` Gary Guo [this message]
2026-11-18 23:37 ` [PATCH 2/4] rust: pin-init: internal: suppress multiple_bound_locations Danilo Krummrich
2026-11-19  2:23   ` Gary Guo
2026-11-18 23:37 ` [PATCH 3/4] drm/tyr: use pin-init self-referential support Danilo Krummrich
2026-11-18 23:37 ` [PATCH 4/4] drm/tyr: use ScopeGuard for firmware loading cleanup Danilo Krummrich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DMZ7CHWBWU4O.3EA040FFBVCLG@garyguo.net \
    --to=gary@garyguo.net \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®