From: Benno Lossin <lossin@kernel.org>
To: gary@garyguo.net
Cc: a.hindborg@kernel.org, acourbot@nvidia.com, aliceryhl@google.com,
bjorn3_gh@protonmail.com, boqun@kernel.org, dakr@kernel.org,
daniel.almeida@collabora.com, linux-kernel@vger.kernel.org,
lossin@kernel.org, ojeda@kernel.org,
rust-for-linux@vger.kernel.org, tamird@kernel.org,
tmgross@umich.edu, work@onurozkan.dev
Subject: Re: [PATCH 00/20] rust: pin-init: create self references safely
Date: Thu, 8 Oct 2026 17:20:31 +0100 [thread overview]
Message-ID: <20261008162031.158761-1-lossin@kernel.org> (raw)
In-Reply-To: <20261008-dev-selfref-v1-0-6c1eb269fe57@garyguo.net>
On Thu, 08 Oct 2026 14:23:47 +0200, Gary Guo <gary@garyguo.net> wrote:
> This is a big series that add support for one field to reference a sibling
> field in a safe and ergnonomic way. Unlike many other crates in the
> userspace Rust ecosystem, no additional allocation is required, thus it
> requires the struct to be pinned, which is exactly what pin-init provides.
>
> This is a very powerful feature, and thus can raise concerns about whether
> it is sound. I spent a lot of time studying the rules to make this sound,
> and presented durirng Kangrejos [1].
>
> The simple use case looks like this:
>
> #[pin_data]
> struct MyDriver<'bound> {
> dev: &'bound Device,
> #[pin]
> irq: irq::Registration<'bound, MyIrqHandler<'bound, 'bar>>,
> bar: Bar<'bound, BAR_SIZE>,
> }
>
> You simply need to mention a lifetime that shares the name with the field.
> There are more advanced use cases which require annotations like
>
> #[uses('bar: invariant)]
>
> to explicitly declare that the lifetime is used in invariant manner, and
> also
>
> where
> exists<'dev>: 'a
>
> to create new existential lifetimes as a way to erase invariant lifetimes
> that would otherwise bubble up to users. More info can be seen in my
> Plumbers slide [2]. Note that the syntax for explicit variance annotation
> has changed following discussions during Plumbers.
>
> The initial plan was to upstream the simple use case only and iron out the
> advanced features subsequently; however it turns out that DRM jobqueue
> would need the variance annotation feature, and Nova `Cmdq` would need to
> use the existential lifetime feature.
>
> During Plumbers the upstream schedule is discussed, and instead it was
> agreed that all the features should be upstreamed at once, but the usage of
> the advanced feature usage limited to the pre-agreed users only to limit
> the blast radius in case the feature needs to be reworked.
>
> Detailed documentation about the pin-init self-reference feature would be
> added the following cycle, when the usage of them become more clear.
>
> The pull request on GitHub [3] has a bunch of test suites, which are not
> synchronized to kernel tree.
>
> Link: https://kangrejos.com/2026/Self%20referential%20pin-init.pdf [1]
> Link: https://lpc.events/event/20/contributions/2498/attachments/2200/4855/presentation.pdf [2]
> Link: https://github.com/Rust-for-Linux/pin-init/pull/181 [3]
> Signed-off-by: Gary Guo <gary@garyguo.net>
> ---
> Gary Guo (20):
> kbuild: rust: allow `clippy::comparison_chain` globally
> rust: pin-init: internal: pin_data: infer self-referential struct
> rust: pin-init: internal: pin_data: rewrite fields that borrow others
> rust: pin-init: internal: pin_data: pin borrowed fields with wrapper
> rust: pin-init: internal: pin_data: teach drop check about generics that cannot dangle
> rust: pin-init: internal: pin_data: self-referential drop order checks
> rust: pin-init: internal: pin_data: check covariance of self-referential fields
> rust: pin-init: internal: pin_data: implement initialization of borrowed structs
> rust: pin-init: internal: pin_data: project self-referential fields
> rust: pin-init: internal: pin_data: add `with_project` method
> rust: pin-init: internal: pin_data: enable self-referential support
> rust: pin-init: internal: pin_data: allow lifetime to be shortened per field drop order
> rust: pin-init: internal: pin_data: parse explicit `#[borrowed]` annotation
> rust: pin-init: internal: pin_data: support mutable borrows
> rust: pin-init: internal: pin_data: parse explicit `#[uses]` annotation
> rust: pin-init: internal: pin_data: make field lifetime invariance imply type invariance
> rust: pin-init: internal: pin_data: complete invariant borrow support
> rust: pin-init: internal: pin_data: perform AST lifetime replacement if possible
> rust: pin-init: internal: pin_data: support shared projection
> rust: pin-init: internal: pin_data: support existential lifetimes
>
> Makefile | 2 +
> rust/pin-init/examples/selfref.rs | 60 ++
> rust/pin-init/internal/src/init.rs | 42 +-
> rust/pin-init/internal/src/pin_data.rs | 1556 +++++++++++++++++++++++++++++++-
> rust/pin-init/internal/src/util.rs | 268 +++++-
> rust/pin-init/src/__internal.rs | 357 +++++++-
> rust/pin-init/src/lib.rs | 1 +
> 7 files changed, 2238 insertions(+), 48 deletions(-)
incredible work, Gary! when you first told me about this, I didn't
imagine that it would look this clean from the user's side. I sadly am
unable to take a detailed look at all of the patches. but we've talked
extensively about the design; so I'm sure we'll be able to fix all bugs
that pop up:
Acked-by: Benno Lossin <lossin@kernel.org>
just for the record: I think that users of this feature should come
gradually. that way, fixing any issues (if there are any :) will be much
less stressful, since there are fewer places to fix. we've discussed
this and also mentioned it to Miguel. additionally, it would be great if
users would take a careful stance when using this feature. I'm not
worried, just cautious, since an unsoundness hole here could end up
being extremely ugly to fix and require re-architecting the users.
once again, great work!
best,
Benno
> ---
> base-commit: 0d9aa4b994379c6e0099737221ed421deb7e1a31
> change-id: 20261006-dev-selfref-27c37abfa849
>
> Best regards,
> --
> Gary Guo <gary@garyguo.net>
prev parent reply other threads:[~2026-10-08 16:20 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 12:23 [PATCH 00/20] rust: pin-init: create self references safely Gary Guo
2026-10-08 12:23 ` [PATCH 01/20] kbuild: rust: allow `clippy::comparison_chain` globally Gary Guo
2026-10-08 12:23 ` [PATCH 02/20] rust: pin-init: internal: pin_data: infer self-referential struct Gary Guo
2026-10-08 12:23 ` [PATCH 03/20] rust: pin-init: internal: pin_data: rewrite fields that borrow others Gary Guo
2026-10-08 12:23 ` [PATCH 04/20] rust: pin-init: internal: pin_data: pin borrowed fields with wrapper Gary Guo
2026-10-08 12:23 ` [PATCH 05/20] rust: pin-init: internal: pin_data: teach drop check about generics that cannot dangle Gary Guo
2026-10-08 12:23 ` [PATCH 06/20] rust: pin-init: internal: pin_data: self-referential drop order checks Gary Guo
2026-10-08 12:23 ` [PATCH 07/20] rust: pin-init: internal: pin_data: check covariance of self-referential fields Gary Guo
2026-10-08 12:23 ` [PATCH 08/20] rust: pin-init: internal: pin_data: implement initialization of borrowed structs Gary Guo
2026-10-08 12:23 ` [PATCH 09/20] rust: pin-init: internal: pin_data: project self-referential fields Gary Guo
2026-10-08 12:23 ` [PATCH 10/20] rust: pin-init: internal: pin_data: add `with_project` method Gary Guo
2026-10-08 12:23 ` [PATCH 11/20] rust: pin-init: internal: pin_data: enable self-referential support Gary Guo
2026-10-08 12:23 ` [PATCH 12/20] rust: pin-init: internal: pin_data: allow lifetime to be shortened per field drop order Gary Guo
2026-10-08 12:24 ` [PATCH 13/20] rust: pin-init: internal: pin_data: parse explicit `#[borrowed]` annotation Gary Guo
2026-10-08 12:24 ` [PATCH 14/20] rust: pin-init: internal: pin_data: support mutable borrows Gary Guo
2026-10-08 12:24 ` [PATCH 15/20] rust: pin-init: internal: pin_data: parse explicit `#[uses]` annotation Gary Guo
2026-10-08 12:24 ` [PATCH 16/20] rust: pin-init: internal: pin_data: make field lifetime invariance imply type invariance Gary Guo
[not found] ` <sashiko-outbox-164164@kernel.org>
2026-10-08 15:52 ` Gary Guo
2026-10-08 12:24 ` [PATCH 17/20] rust: pin-init: internal: pin_data: complete invariant borrow support Gary Guo
2026-10-08 12:24 ` [PATCH 18/20] rust: pin-init: internal: pin_data: perform AST lifetime replacement if possible Gary Guo
2026-10-08 12:24 ` [PATCH 19/20] rust: pin-init: internal: pin_data: support shared projection Gary Guo
2026-10-08 12:24 ` [PATCH 20/20] rust: pin-init: internal: pin_data: support existential lifetimes Gary Guo
2026-10-08 16:20 ` Benno Lossin [this message]
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=20261008162031.158761-1-lossin@kernel.org \
--to=lossin@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--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 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.