From: Beata Michalska <beata.michalska@arm.com>
To: Danilo Krummrich <dakr@kernel.org>
Cc: Miguel Ojeda <ojeda@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J . Wysocki" <rafael@kernel.org>,
Boqun Feng <boqun@kernel.org>, Gary Guo <gary@garyguo.net>,
Bjorn Roy Baron <bjorn3_gh@protonmail.com>,
Benno Lossin <lossin@kernel.org>,
Andreas Hindborg <a.hindborg@kernel.org>,
Alice Ryhl <aliceryhl@google.com>,
Trevor Gross <tmgross@umich.edu>,
Daniel Almeida <daniel.almeida@collabora.com>,
Boris Brezillon <boris.brezillon@collabora.com>,
rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 1/3] rust: Add runtime PM support
Date: Sat, 23 May 2026 20:48:29 +0200 [thread overview]
Message-ID: <ahH2SVDvfshuXejy@arm.com> (raw)
In-Reply-To: <DIKIJ81CV55B.3TA7PV8N4BN0E@kernel.org>
Hi,
First of all apologies for such a late response.
I'm currently on leave and other things have kept me busy enough.
On Sun, May 17, 2026 at 02:08:07AM +0200, Danilo Krummrich wrote:
> (By far not a full review; but please find a few comments below.)
>
> On Thu May 14, 2026 at 5:09 PM CEST, Beata Michalska wrote:
> > +#[cfg(CONFIG_PM)]
> > +impl Request {
> > + #[inline(always)]
> > + fn resume(dev: &ARef<device::Device>, mode: Mode) -> Result {
>
> Those functions all require a bound device, so this has to be &Device<Bound>.
>
> Also, there is usually no advantage to write &ARef<T> instead of &T.
>
For the latter, indeed that makes little sens, agreed.
For the first one, PM core already makes sure that no PM transition request
is being carried out for devices without active binding.
This is being achieved via the disable_depth which is updated on
__pm_runtime_disable.
Now I do understand you would like to enforce the contact on the Rust side as
well.
> > +macro_rules! define_pm_callback {
> > + // Bare callback with no associate transition nor fallible descriptor
> > + (@parse_desc $name:ident) => { define_pm_callback!(@default $name); };
> > + // Callback with associated state transition
> > + (@parse_desc $name:ident ($from:ident, $pre:ident, $post:ident)) => {
> > + define_pm_callback!(@default $name, $from, $pre, $post);
> > + };
> > +
> > + (@default $name:ident $(, $from:ident, $pre:ident, $post:ident)? ) => {
> > + paste!(
> > + /// # Safety
> > + ///
> > + /// `dev` must be a valid `struct device *` provided by the PM core.
> > + unsafe extern "C" fn [<$name _callback>]<T:PMOps>(
> > + dev: *mut bindings::device
> > + ) -> core::ffi::c_int {
> > +
> > + let dev: &device::Device<device::CoreInternal> =
> > + // SAFETY: `dev` is provided by the PM core to a runtime PM callback and
> > + // is valid for the duration of the callback.
>
> This doesn't justify the CoreInternal type state; in fact, we can't justify it
> here as those callbacks are not called with the device lock held.
>
Point taken.
> It is guaranteed that the device remains bound during the callbacks though, so
> the Bound type state is valid.
>
> > + unsafe { device::Device::from_raw(dev) };
> > +
> > + // SAFETY: PM callbacks are only invoked while the device is bound
> > + // See [`pm_runtime_remove`](srctree/drivers/base/power/runtime.c)
> > + let bound_dev = unsafe { dev.as_bound() };
> > +
> > + bound_dev.drvdata::<T::DriverDataType>()
>
> This function does not exist anymore, please use drvdata_borrow() instead. I
> understand you want the type check this accessor does for you, but it shouldn't
> be necessary. It should be possible to design the trait in a way that the type
> system ensures that a driver cannot pass in the wrong type at compile time.
>
> In order to call drvdata_borrow() we currently need the CoreInternal type state
> (which we can't justify).
>
> To support this, we should add a BoundInternal type state, make CoreInternal
> deref to BoundInternal and implement drvdata_borrow() for BoundInternal.
>
> > + .and_then(|data| {
> > + let pm_ctx = T::get_pmcontext(data.get_ref())?;
> > + let pm_dev = match <T as PMOps>::DeviceType::try_from(dev) {
>
> Please don't use a fallible conversion here, take advantage of the type system
> instead, e.g. with the AsBusDevice trait, see [1] for reference.
>
> However, as mentioned above, I think it should be possible to tie bus specific
> driver traits and this together so we can check types at compile time. So, maybe
> AsBusDevice isn't even necessary.
I appreciate your comments.
Will try to amend the current version and add along necessary changes,
though there were no comments on the overall idea yet.
---
BR
Beata
>
> [1] https://lore.kernel.org/driver-core/20260506221027.858481-2-dakr@kernel.org/
next prev parent reply other threads:[~2026-05-23 18:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-14 15:09 [RFC PATCH 0/3] Rust: add runtime PM support Beata Michalska
2026-05-14 15:09 ` [RFC PATCH 1/3] rust: Add " Beata Michalska
2026-05-17 0:08 ` Danilo Krummrich
2026-05-23 18:48 ` Beata Michalska [this message]
2026-05-17 7:20 ` Onur Özkan
2026-05-14 15:09 ` [RFC PATCH 2/3] rust/platform: Add support for runtime PM Beata Michalska
2026-05-14 15:09 ` [RFC PATCH 3/3] [DO NOT MERGE] drm/tyr: wire runtime PM hooks Beata Michalska
2026-05-16 20:35 ` [RFC PATCH 0/3] Rust: add runtime PM support Miguel Ojeda
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=ahH2SVDvfshuXejy@arm.com \
--to=beata.michalska@arm.com \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=boris.brezillon@collabora.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--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.