From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Danilo Krummrich" <dakr@kernel.org>
Cc: <gregkh@linuxfoundation.org>, <rafael@kernel.org>,
<ojeda@kernel.org>, <boqun@kernel.org>, <gary@garyguo.net>,
<bjorn3_gh@protonmail.com>, <lossin@kernel.org>,
<a.hindborg@kernel.org>, <aliceryhl@google.com>,
<tmgross@umich.edu>, <ecourtney@nvidia.com>,
<m.wilczynski@samsung.com>, <david.m.ertman@intel.com>,
<ira.weiny@intel.com>, <leon@kernel.org>,
<daniel.almeida@collabora.com>, <bhelgaas@google.com>,
<kwilczynski@kernel.org>, <driver-core@lists.linux.dev>,
<linux-kernel@vger.kernel.org>, <nova-gpu@lists.linux.dev>,
<dri-devel@lists.freedesktop.org>, <linux-pwm@vger.kernel.org>,
<rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH v3 5/7] rust: devres: add DevresLt for ForLt-aware device resource access
Date: Wed, 24 Jun 2026 23:49:19 +0900 [thread overview]
Message-ID: <DJHD2MDVI1NM.39DDGWBM7KLG1@nvidia.com> (raw)
In-Reply-To: <20260618230834.812007-6-dakr@kernel.org>
On Fri Jun 19, 2026 at 8:08 AM JST, Danilo Krummrich wrote:
> Devres<T> stores resources as T and returns &'a T from access(). For
> lifetime-parameterized types like Bar<'a, SIZE> that are transmuted to
> 'static for storage, this exposes the synthetic 'static lifetime to
> callers -- any method on the stored type that returns a reference with
> its lifetime parameter would yield a &'static reference, which is
> unsound.
>
> Add DevresLt<F: ForLt>, a thin wrapper around Devres<F::Of<'static>>
> that shortens the stored 'static lifetime to the caller's borrow
> lifetime in all access methods.
>
> DevresLt::new() is unsafe because the caller must guarantee that the
> data remains valid for the device's full bound scope; the internal
> transmute from F::Of<'a> to F::Of<'static> would otherwise allow
> use-after-free.
>
> Two access patterns are provided:
>
> - CovariantForLt types get direct-reference accessors (access,
> try_access) that return shortened references via
> CovariantForLt::cast_ref.
>
> - Plain ForLt types use closure-based accessors (access_with,
> try_access_with) whose universally quantified lifetime prevents
> callers from smuggling in concrete short-lived references.
>
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
next prev parent reply other threads:[~2026-06-24 14:49 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-18 23:08 [PATCH v3 0/7] ForLt/CovariantForLt split, auxiliary closure API and DevresLt Danilo Krummrich
2026-06-18 23:08 ` [PATCH v3 1/7] rust: types: rename ForLt to CovariantForLt Danilo Krummrich
2026-06-18 23:15 ` sashiko-bot
2026-06-23 13:32 ` Alexandre Courbot
2026-06-24 15:13 ` Gary Guo
2026-06-18 23:08 ` [PATCH v3 2/7] rust: types: introduce ForLt base trait for CovariantForLt Danilo Krummrich
2026-06-24 15:20 ` Gary Guo
2026-06-24 18:06 ` Danilo Krummrich
2026-06-18 23:08 ` [PATCH v3 3/7] rust: auxiliary: add registration_data_with() for ForLt types Danilo Krummrich
2026-06-18 23:22 ` sashiko-bot
2026-06-24 14:37 ` Alexandre Courbot
2026-06-18 23:08 ` [PATCH v3 4/7] rust: auxiliary: sample: demonstrate ForLt with invariant Mutex type Danilo Krummrich
2026-06-18 23:21 ` sashiko-bot
2026-06-24 14:37 ` Alexandre Courbot
2026-06-18 23:08 ` [PATCH v3 5/7] rust: devres: add DevresLt for ForLt-aware device resource access Danilo Krummrich
2026-06-18 23:21 ` sashiko-bot
2026-06-24 14:49 ` Alexandre Courbot [this message]
2026-06-18 23:08 ` [PATCH v3 6/7] rust: pci: return DevresLt from Bar::into_devres() Danilo Krummrich
2026-06-24 15:05 ` Alexandre Courbot
2026-06-18 23:08 ` [PATCH v3 7/7] rust: io: mem: return DevresLt from IoMem/ExclusiveIoMem::into_devres() Danilo Krummrich
2026-06-24 15:09 ` Alexandre Courbot
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=DJHD2MDVI1NM.39DDGWBM7KLG1@nvidia.com \
--to=acourbot@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=david.m.ertman@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=driver-core@lists.linux.dev \
--cc=ecourtney@nvidia.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=ira.weiny@intel.com \
--cc=kwilczynski@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=m.wilczynski@samsung.com \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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 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.