From: Alice Ryhl <aliceryhl@google.com>
To: Daniel Almeida <daniel.almeida@collabora.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Philipp Zabel" <p.zabel@pengutronix.de>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
dri-devel@lists.freedesktop.org,
"Detlev Casanova" <detlev.casanova@collabora.com>,
"Nicolas Dufresne" <nicolas.dufresne@collabora.com>
Subject: Re: [PATCH 5/7] rust: reset: add SharedResetControl
Date: Thu, 26 Nov 2026 19:14:16 +0000 [thread overview]
Message-ID: <awiFCBnJ_i-N_Blb@google.com> (raw)
In-Reply-To: <20261126-b4-rust-reset-v1-5-9c4c3d029080@collabora.com>
On Thu, Nov 26, 2026 at 01:04:32PM -0300, Daniel Almeida wrote:
> + /// Deasserts the reset line and moves the [`SharedResetControl`] to the [`Deasserted`] state.
> + ///
> + /// Equivalent to the kernel's [`reset_control_deassert()`].
> + ///
> + /// [`reset_control_deassert()`]:
> + /// https://docs.kernel.org/driver-api/reset.html#c.reset_control_deassert
> + #[inline]
> + pub fn deassert(self) -> Result<SharedResetControl<'a, Deasserted>, Error<Self>> {
> + // INVARIANT: The reference that `self` owns moves to the value that this returns.
> + let reset = ManuallyDrop::new(self);
> +
> + // SAFETY: By the type invariants, `reset.inner` is a pointer that a C getter returned, and
> + // `reset` owns its reference.
> + to_result(unsafe { bindings::reset_control_deassert(reset.inner) })
> + .map(|()| SharedResetControl {
> + inner: reset.inner,
> + _phantom: PhantomData,
> + })
> + .map_err(|error| Error {
> + error,
> + reset: ManuallyDrop::into_inner(reset),
> + })
> + }
The C side here interacts badly with the error path of
`SharedResetControl::deassert()`.
In `drivers/reset/core.c`, `reset_control_deassert()` does:
if (rstc->shared) {
if (WARN_ON(atomic_read(&rstc->triggered_count) != 0))
return -EINVAL;
if (atomic_inc_return(&rstc->deassert_count) != 1)
return 0;
}
...
return rcdev->ops->deassert(rcdev, rstc->id);
Unlike `reset_control_reset()`, `reset_control_deassert()` does not
decrement `rstc->deassert_count` when `rcdev->ops->deassert()` returns
an error.
Because `SharedResetControl::deassert()` returns `reset` in the
`Unknown` state (`ASSERT_ON_DROP == false`) on error:
- If the caller drops `reset`, `deassert_count` stays leaked at 1, so
future shared users will see `deassert_count != 0` and skip
`ops->deassert()`.
- If the caller retries `reset.deassert()`, `atomic_inc_return()` returns
2 (`!= 1`), so `reset_control_deassert()` returns 0 without calling
`ops->deassert()`, leaving the line asserted while Rust treats the
control as `Deasserted`.
I wonder if this is a bug on the C side we should fix in core.c?
Alice
next prev parent reply other threads:[~2026-11-26 19:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 16:04 [PATCH 0/7] rust: reset: add reset control abstractions Daniel Almeida
2026-11-26 16:04 ` [PATCH 1/7] rust: reset: add reset control helpers Daniel Almeida
2026-11-26 16:04 ` [PATCH 2/7] rust: reset: add ExclusiveResetControl Daniel Almeida
2026-11-26 16:04 ` [PATCH 3/7] rust: reset: add ExclusiveResetControl::get_array() and get_array_optional() Daniel Almeida
2026-11-26 16:11 ` sashiko-bot
2026-11-26 16:04 ` [PATCH 4/7] rust: reset: add AssertedGuard Daniel Almeida
2026-11-26 16:04 ` [PATCH 5/7] rust: reset: add SharedResetControl Daniel Almeida
2026-11-26 19:14 ` Alice Ryhl [this message]
2026-11-26 16:04 ` [PATCH 6/7] rust: reset: add SharedResetControl::get_array() and get_array_optional() Daniel Almeida
2026-11-26 16:04 ` [PATCH 7/7] rust: reset: add devm_deassert() and devm_deassert_optional() Daniel Almeida
2026-11-26 16:33 ` [PATCH 0/7] rust: reset: add reset control abstractions Nicolas Dufresne
2026-11-26 18:02 ` Daniel Almeida
2026-11-26 18:11 ` Nicolas Dufresne
2026-11-26 18:36 ` Daniel Almeida
2026-11-26 18:46 ` Nicolas Dufresne
2026-11-27 10:30 ` Philipp Zabel
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=awiFCBnJ_i-N_Blb@google.com \
--to=aliceryhl@google.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=detlev.casanova@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nicolas.dufresne@collabora.com \
--cc=ojeda@kernel.org \
--cc=p.zabel@pengutronix.de \
--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.