From: "Onur Özkan" <work@onurozkan.dev>
To: Alice Ryhl <aliceryhl@google.com>
Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
dri-devel@lists.freedesktop.org, dakr@kernel.org,
daniel.almeida@collabora.com, airlied@gmail.com, simona@ffwll.ch,
ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net,
bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, tmgross@umich.edu
Subject: Re: [PATCH 2/2] drm/tyr: unplug the GPU when reset fails
Date: Sun, 25 Oct 2026 14:23:38 +0300 [thread overview]
Message-ID: <20261025112341.60054-1-work@onurozkan.dev> (raw)
In-Reply-To: <20261021093808.1128449-1-aliceryhl@google.com>
On Wed, 21 Oct 2026 09:38:07 +0000
Alice Ryhl <aliceryhl@google.com> wrote:
> On Sun, Aug 23, 2026 at 01:50:08PM +0300, Onur Özkan wrote:
> > @@ -56,7 +57,7 @@ pub(crate) struct TyrPlatformDriverData<'bound> {
> > // ensure the correct drop order.
> > #[pin]
> > _reset: reset::ResetHandle<'bound>,
> > - _reg: drm::Registration<'bound, TyrDrmDriver>,
> > + _reg: Arc<Revocable<drm::Registration<'bound, TyrDrmDriver>>>,
> > _device: ARef<TyrDrmDevice>,
> > }
> >
> > @@ -161,17 +162,18 @@ fn probe<'bound>(
> > gpu_info,
> > });
> >
> > - // SAFETY: `reg` is stored in the platform driver data and is not leaked or
> > - // forgotten, so it is dropped before the `'bound` registration data can become
> > - // invalid.
> > + // SAFETY: `reg` is wrapped in a `Revocable` owned by the platform driver
> > + // data and its reset handle. Neither is leaked or forgotten, so `reg` is
> > + // dropped before the `'bound` registration data can become invalid.
> > let reg =
> > unsafe { drm::Registration::new_with_lt(pdev.as_ref(), unreg_dev, reg_data, 0)? };
> > let device = reg.device().into();
> > + let reg = Arc::pin_init(Revocable::new(reg), GFP_KERNEL)?;
>
> `drm::Registration::new` requires that the `Registration` is dropped
> before `'bound` expires so that `drm_dev_unplug()` runs and
> `TyrDrmRegistrationData<'bound>` is dropped while `'bound` is still
> valid. Wrapping it in an `Arc` makes this invariant fragile: if any
> `Arc` clone outlives `TyrPlatformDriverData` or is leaked,
> `drm::Registration` will not be dropped on platform unbind and
> `TyrDrmRegistrationData<'bound>` will outlive `'bound`.
>
> With `pin-init`'s new safe self-referential struct support in `rust-next`
> (see e.g. [1]), you can avoid both `Arc` and raw pointers altogether by
> storing `_reg: Revocable<drm::Registration<'bound, TyrDrmDriver>>`
> directly as a `#[pin]` field of `TyrPlatformDriverData<'bound>` and
> having `_reset` borrow it via field + existential lifetimes:
>
> #[pin_data]
> pub(crate) struct TyrPlatformDriverData<'bound> {
> #[pin]
> #[uses('_reg: invariant)]
> _reset: reset::ResetHandle<'_reg>,
> #[pin]
> _reg: Revocable<drm::Registration<'bound, TyrDrmDriver>>,
> }
>
> and in `reset.rs`:
>
> #[pin_data]
> struct Controller<'ctrl>
> where
> exists<'bound>: 'ctrl,
> {
> pdev: &'ctrl platform::Device<Bound>,
> state: Atomic<ResetState>,
> hw: Arc<HwGate<'ctrl>>,
> #[uses('bound: invariant)]
> registration:
> Pin<&'ctrl Revocable<drm::Registration<'bound, TyrDrmDriver>>>,
> }
>
> Then `probe()` simply initializes `_reg` first and passes `_reg` to
> `ResetHandle::new(pdev, hw, _reg)?`, `reset_work()` calls
> `self.with_registration(|reg| reg.revoke())`, and `#[pin_data]`
> statically checks that `_reset` drops before `_reg`.
>
> Also, as a heads-up for rebasing onto `drm-rust-next`:
> `_device: ARef<TyrDrmDevice>` has been removed from
> `TyrPlatformDriverData` (along with the empty `PinnedDrop` impl), and
> `drm::Registration::new()` now returns `impl PinInit<Self, Error>`
> directly without the `flags` argument, so `_reg` can be initialized in
> place via `Revocable::new(unsafe { drm::Registration::new(...) })`.
>
> [1] https://lore.kernel.org/r/20261019133647.1279779-1-gary@kernel.org
>
> Alice
Any idea when will we push drm-rust-next changes into rust-next?
- Onur
next prev parent reply other threads:[~2026-10-25 11:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-23 10:50 [PATCH 0/2] " Onur Özkan
2026-08-23 10:50 ` [PATCH 1/2] drm/tyr: move reset work to platform driver data Onur Özkan
2026-08-24 17:27 ` Daniel Almeida
2026-08-23 10:50 ` [PATCH 2/2] drm/tyr: unplug the GPU when reset fails Onur Özkan
2026-08-26 14:05 ` Daniel Almeida
2026-09-12 8:03 ` Onur Özkan
2026-10-21 9:38 ` Alice Ryhl
2026-10-25 11:23 ` Onur Özkan [this message]
2026-10-25 12:05 ` Alice Ryhl
2026-10-26 4:55 ` Onur Özkan
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=20261025112341.60054-1-work@onurozkan.dev \
--to=work@onurozkan.dev \
--cc=a.hindborg@kernel.org \
--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=gary@garyguo.net \
--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=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 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®